Line data Source code
1 : #ifndef HEADER_fd_src_disco_keyguard_fd_keyguard_h 2 : #define HEADER_fd_src_disco_keyguard_fd_keyguard_h 3 : 4 : /* fd_keyguard creates digital signatures on behalf of validator 5 : components. */ 6 : 7 : #include "../fd_disco_base.h" 8 : 9 : FD_PROTOTYPES_BEGIN 10 : 11 : /* FD_KEYGUARD_SIGN_REQ_MTU is the maximum size (inclusive) of a signing 12 : request payload. The payload in this case is the message byte array 13 : passed to fd_ed25519_sign. */ 14 : 15 0 : #define FD_KEYGUARD_SIGN_REQ_MTU (32768UL) 16 : 17 : 18 : /* FD_KEYGUARD_AUTH_VOTERS_MAX is the maximum number of authorized voter 19 : keys the sign tile holds besides the identity. An authority_idx is 20 : ULONG_MAX for the identity or in [0,FD_KEYGUARD_AUTH_VOTERS_MAX). 21 : Vote transaction and Alpenglow vote signing requests encode 22 : authority_idx in 4 bits of the frag sig. */ 23 : 24 0 : #define FD_KEYGUARD_AUTH_VOTERS_MAX (16UL) 25 : FD_STATIC_ASSERT( FD_KEYGUARD_AUTH_VOTERS_MAX<=16UL, auth_voters_max_fits_sign_request ); 26 : 27 : /* Role definitions ***************************************************/ 28 : 29 0 : #define FD_KEYGUARD_ROLE_GOSSIP (1) /* gossip participant */ 30 0 : #define FD_KEYGUARD_ROLE_LEADER (2) /* block producer (shreds) */ 31 0 : #define FD_KEYGUARD_ROLE_REPAIR (4) /* Repair tile */ 32 0 : #define FD_KEYGUARD_ROLE_BUNDLE (5) /* Bundle tile */ 33 0 : #define FD_KEYGUARD_ROLE_EVENT (6) /* Event tile */ 34 0 : #define FD_KEYGUARD_ROLE_BUNDLE_CRANK (7) /* Sign cranking transactions for bundle tips */ 35 0 : #define FD_KEYGUARD_ROLE_RSERVE (8) /* Repair server tile */ 36 0 : #define FD_KEYGUARD_ROLE_VOTOR (9) /* Alpenglow votor tile (QUIC TLS, vote history file) */ 37 0 : #define FD_KEYGUARD_ROLE_FAILOV (10) /* Failover admission proof and TLS */ 38 0 : #define FD_KEYGUARD_ROLE_CNT (11) /* number of known roles */ 39 : 40 : /* The failover identity signs admission proofs, TLS, and the 41 : admission payload. */ 42 0 : #define FD_KEYGUARD_FAILOVER_CLIENT_DOMAIN "FD_FAILOVER_CLI1" 43 0 : #define FD_KEYGUARD_FAILOVER_SERVER_DOMAIN "FD_FAILOVER_SRV1" 44 0 : #define FD_KEYGUARD_FAILOVER_DOMAIN_SZ (16UL) 45 0 : #define FD_KEYGUARD_FAILOVER_PROOF_SZ (FD_KEYGUARD_FAILOVER_DOMAIN_SZ+32UL) 46 : 47 : /* Payload types ******************************************************/ 48 : 49 0 : #define FD_KEYGUARD_PAYLOAD_LG_TXN ( 0) /* Solana transaction message (e.g. vote) */ 50 0 : #define FD_KEYGUARD_PAYLOAD_LG_GOSSIP ( 1) /* Gossip CrdsData */ 51 0 : #define FD_KEYGUARD_PAYLOAD_LG_PRUNE ( 2) /* Gossip PruneData */ 52 0 : #define FD_KEYGUARD_PAYLOAD_LG_SHRED ( 3) /* Solana legacy or merkle shred */ 53 0 : #define FD_KEYGUARD_PAYLOAD_LG_TLS_CV ( 4) /* TLS 1.3 certificate verify payload */ 54 0 : #define FD_KEYGUARD_PAYLOAD_LG_REPAIR ( 6) /* RepairProtocol */ 55 0 : #define FD_KEYGUARD_PAYLOAD_LG_PING ( 7) /* Gossip ping protocol */ 56 0 : #define FD_KEYGUARD_PAYLOAD_LG_BUNDLE ( 8) /* Bundle block producer authentication */ 57 0 : #define FD_KEYGUARD_PAYLOAD_LG_EVENT ( 9) /* Event reporter authentication */ 58 0 : #define FD_KEYGUARD_PAYLOAD_LG_PONG (10) /* Gossip/Repair ping/pong protocol */ 59 0 : #define FD_KEYGUARD_PAYLOAD_LG_AG_VOTE (11) /* Alpenglow BLS vote */ 60 0 : #define FD_KEYGUARD_PAYLOAD_LG_BLS_PUBKEY (12) /* Alpenglow BLS public key query */ 61 0 : #define FD_KEYGUARD_PAYLOAD_LG_VOTE_HISTORY (14) /* Alpenglow vote history file */ 62 0 : #define FD_KEYGUARD_PAYLOAD_LG_FAILOV (15) /* Failover admission proof */ 63 : 64 0 : #define FD_KEYGUARD_PAYLOAD_TXN (1UL<<FD_KEYGUARD_PAYLOAD_LG_TXN ) 65 0 : #define FD_KEYGUARD_PAYLOAD_GOSSIP (1UL<<FD_KEYGUARD_PAYLOAD_LG_GOSSIP ) 66 0 : #define FD_KEYGUARD_PAYLOAD_PRUNE (1UL<<FD_KEYGUARD_PAYLOAD_LG_PRUNE ) 67 0 : #define FD_KEYGUARD_PAYLOAD_SHRED (1UL<<FD_KEYGUARD_PAYLOAD_LG_SHRED ) 68 0 : #define FD_KEYGUARD_PAYLOAD_TLS_CV (1UL<<FD_KEYGUARD_PAYLOAD_LG_TLS_CV ) 69 0 : #define FD_KEYGUARD_PAYLOAD_REPAIR (1UL<<FD_KEYGUARD_PAYLOAD_LG_REPAIR ) 70 0 : #define FD_KEYGUARD_PAYLOAD_PING (1UL<<FD_KEYGUARD_PAYLOAD_LG_PING ) 71 0 : #define FD_KEYGUARD_PAYLOAD_BUNDLE (1UL<<FD_KEYGUARD_PAYLOAD_LG_BUNDLE ) 72 0 : #define FD_KEYGUARD_PAYLOAD_EVENT (1UL<<FD_KEYGUARD_PAYLOAD_LG_EVENT ) 73 0 : #define FD_KEYGUARD_PAYLOAD_PONG (1UL<<FD_KEYGUARD_PAYLOAD_LG_PONG ) 74 0 : #define FD_KEYGUARD_PAYLOAD_AG_VOTE (1UL<<FD_KEYGUARD_PAYLOAD_LG_AG_VOTE ) 75 0 : #define FD_KEYGUARD_PAYLOAD_BLS_PUBKEY (1UL<<FD_KEYGUARD_PAYLOAD_LG_BLS_PUBKEY ) 76 0 : #define FD_KEYGUARD_PAYLOAD_VOTE_HISTORY (1UL<<FD_KEYGUARD_PAYLOAD_LG_VOTE_HISTORY) 77 0 : #define FD_KEYGUARD_PAYLOAD_FAILOV (1UL<<FD_KEYGUARD_PAYLOAD_LG_FAILOV ) 78 : 79 : /* Sign types *********************************************************/ 80 : 81 0 : #define FD_KEYGUARD_SIGN_TYPE_ED25519 (0) /* ed25519_sign(input) */ 82 0 : #define FD_KEYGUARD_SIGN_TYPE_SHA256_ED25519 (1) /* ed25519_sign(sha256(data)) */ 83 0 : #define FD_KEYGUARD_SIGN_TYPE_PUBKEY_CONCAT_ED25519 (2) /* ed25519_sign(pubkey-data) */ 84 0 : #define FD_KEYGUARD_SIGN_TYPE_BLS (3) /* bls_sign(vote) */ 85 0 : #define FD_KEYGUARD_SIGN_TYPE_BLS_PUBKEY (4) /* ulong authority index -> 48-byte public key, no signing */ 86 0 : #define FD_KEYGUARD_SIGN_TYPE_CNT (5) /* number of sign types */ 87 : 88 : /* Type confusion/ambiguity checks ************************************/ 89 : 90 : /* fd_keyguard_payload_match returns a bitwise OR of 91 : FD_KEYGUARD_PAYLOAD_{...}. 92 : 93 : [data,data+sz) is the payload that is requested to be signed. 94 : 95 : sign_type is in FD_KEYGUARD_SIGN_TYPE_{...}. 96 : 97 : Returns 0 if none matched. fd_ulong_popcnt(return value) is 1 if the 98 : payload is unambiguously of a single type. */ 99 : 100 : FD_FN_PURE ulong 101 : fd_keyguard_payload_match( uchar const * data, 102 : ulong sz, 103 : int sign_type ); 104 : 105 : /* Authorization ******************************************************/ 106 : 107 : struct fd_keyguard_authority { 108 : uchar identity_pubkey[32]; 109 : /* Pack tile is allowed to sign a transaction that invokes these two 110 : programs that come from the config.toml. We need to check these 111 : programs, because otherwise an attacker with RCE on pack can make 112 : the validator sign a transaction that invokes their malicious 113 : program which drains the identity key. */ 114 : uchar tip_payment_program[32]; 115 : uchar tip_distribution_program[32]; 116 : }; 117 : 118 : typedef struct fd_keyguard_authority fd_keyguard_authority_t; 119 : 120 : /* fd_keyguard_payload_authorize decides whether the keyguard accepts 121 : a signing request. 122 : 123 : [data,data+sz) is the payload that is requested to be signed. 124 : 125 : role is one of FD_KEYGUARD_ROLE_{...}. It is assumed that the origin 126 : of the request was previously authorized for the given role. 127 : 128 : Returns 1 if authorized, otherwise 0. 129 : 130 : This function is more restrictive than the respective 131 : fd_keyguard_payload_matches functions. */ 132 : 133 : int 134 : fd_keyguard_payload_authorize( fd_keyguard_authority_t const * authority, 135 : uchar const * data, 136 : ulong sz, 137 : int role, 138 : int sign_type ); 139 : 140 : FD_PROTOTYPES_END 141 : 142 : #endif /* HEADER_fd_src_disco_keyguard_fd_keyguard_h */