Line data Source code
1 : #ifndef HEADER_fd_src_disco_bundle_fd_bundle_auth_h 2 : #define HEADER_fd_src_disco_bundle_fd_bundle_auth_h 3 : 4 : /* fd_bundle_auth.h acquires an auth token for a bundle server. 5 : 6 : The auth flow is as follows: 7 : - Client requests a challenge-response transaction 8 : - Server returns a 9 byte "challenge" to be signed using the client's 9 : identity key 10 : - Client sends back the signed challenge and requests an auth token 11 : - Server returns an auth token and a refresh token */ 12 : 13 : #include "../../waltz/grpc/fd_grpc_client.h" 14 : #include "../../disco/keyguard/fd_keyguard_client.h" 15 : 16 : struct fd_bundle_auther { 17 : int state; 18 : uint needs_poll : 1; 19 : uchar pubkey[ 32 ]; 20 : 21 : char challenge[ 9 ]; 22 : char access_token[ 1024 ]; 23 : ushort access_token_sz; 24 : }; 25 : 26 : typedef struct fd_bundle_auther fd_bundle_auther_t; 27 : 28 0 : #define FD_BUNDLE_CLIENT_REQ_Auth_GenerateAuthChallenge 1 29 0 : #define FD_BUNDLE_CLIENT_REQ_Auth_GenerateAuthTokens 2 30 : //#define FD_BUNDLE_CLIENT_REQ_Auth_RefreshAccessToken 3 31 : 32 0 : #define FD_BUNDLE_AUTH_STATE_REQ_CHALLENGE 0 33 0 : #define FD_BUNDLE_AUTH_STATE_WAIT_CHALLENGE 1 34 0 : #define FD_BUNDLE_AUTH_STATE_REQ_TOKENS 2 35 0 : #define FD_BUNDLE_AUTH_STATE_WAIT_TOKENS 3 36 0 : #define FD_BUNDLE_AUTH_STATE_DONE_WAIT 4 37 : 38 : FD_PROTOTYPES_BEGIN 39 : 40 : fd_bundle_auther_t * 41 : fd_bundle_auther_init( fd_bundle_auther_t * auther ); 42 : 43 : /* fd_bundle_auther_poll does request work. Should be called as soon as 44 : possible if auther->needs_poll is set. Otherwise, should be called 45 : at a low rate (once every ~100ms). */ 46 : 47 : void 48 : fd_bundle_auther_poll( fd_bundle_auther_t * auther, 49 : fd_grpc_client_t * client, 50 : fd_keyguard_client_t * keyguard ); 51 : 52 : /* fd_bundle_auther_reset restarts authentication. Intended to be 53 : called when a request fails with an auth failure. */ 54 : 55 : void 56 : fd_bundle_auther_reset( fd_bundle_auther_t * auther ); 57 : 58 : /* Response handlers */ 59 : 60 : void 61 : fd_bundle_auther_handle_request_fail( fd_bundle_auther_t * auther ); 62 : 63 : int 64 : fd_bundle_auther_handle_challenge_resp( 65 : fd_bundle_auther_t * auther, 66 : void const * data, 67 : ulong data_sz 68 : ); 69 : 70 : int 71 : fd_bundle_auther_handle_tokens_resp( 72 : fd_bundle_auther_t * auther, 73 : void const * data, 74 : ulong data_sz 75 : ); 76 : 77 : FD_PROTOTYPES_END 78 : 79 : #endif /* HEADER_fd_src_disco_bundle_fd_bundle_auth_h */