| 1 | #cxx . . $ `<file>/mlspp/include/mls/credential.h`/pragma once |
| 2 | |
| 3 | #include <mls/common.h>cxx . . $ `<file>/mlspp/include/mls/common.h`/ |
| 4 | #include <mls/crypto.h>cxx . . $ `<file>/mlspp/include/mls/crypto.h`/ |
| 5 | |
| 6 | namespace mlsppcxx . . $ mlspp/ { |
| 7 | |
| 8 | namespace hpkecxx . . $ mlspp/hpke/ { |
| 9 | struct UserInfoVCcxx . . $ mlspp/hpke/UserInfoVC#; |
| 10 | } |
| 11 | |
| 12 | // struct { |
| 13 | // opaque identity<0..2^16-1>; |
| 14 | // SignaturePublicKey public_key; |
| 15 | // } BasicCredential; |
| 16 | struct BasicCredentialcxx . . $ mlspp/BasicCredential# |
| 17 | { |
| 18 | BasicCredentialcxx . . $ mlspp/BasicCredential#BasicCredential(49f6e7a06ebc5aa8).() {} |
| 19 | |
| 20 | BasicCredentialcxx . . $ mlspp/BasicCredential#BasicCredential(ab3201cd0fdbb2eb).(bytescxx . . $ mlspp/bytes_ns/bytes# identity_in) |
| 21 | : identitycxx . . $ mlspp/BasicCredential#identity.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(identity_in)) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | bytescxx . . $ mlspp/bytes_ns/bytes# identitycxx . . $ mlspp/BasicCredential#identity.; |
| 26 | |
| 27 | TLS_SERIALIZABLEcxx . . $ mlspp/BasicCredential#_tls_fields_w(13f2dc044365987f).(identity) |
| 28 | }; |
| 29 | |
| 30 | struct X509Credentialcxx . . $ mlspp/X509Credential# |
| 31 | { |
| 32 | struct CertDatacxx . . $ mlspp/X509Credential#CertData# |
| 33 | { |
| 34 | bytescxx . . $ mlspp/bytes_ns/bytes# datacxx . . $ mlspp/X509Credential#CertData#data.; |
| 35 | |
| 36 | TLS_SERIALIZABLEcxx . . $ std/(data) |
| 37 | }; |
| 38 | |
| 39 | X509Credentialcxx . . $ mlspp/X509Credential#X509Credential(ced63f7c635d850d).() = default; |
| 40 | explicit X509Credentialcxx . . $ mlspp/X509Credential#X509Credential(89eaccbce9cd186b).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<bytescxx . . $ mlspp/bytes_ns/bytes#>& der_chain_in); |
| 41 | |
| 42 | SignatureSchemecxx . . $ mlspp/SignatureScheme# signature_schemecxx . . $ mlspp/X509Credential#signature_scheme(25c8e3499195dd1).() const; |
| 43 | SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey# public_keycxx . . $ mlspp/X509Credential#public_key(12d241d5a3fd9b02).() const; |
| 44 | bool valid_forcxx . . $ mlspp/X509Credential#valid_for(9a76ab9c2cdc40ef).(const SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#& pub) const; |
| 45 | |
| 46 | // TODO(rlb) This should be const or exposed via a method |
| 47 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<CertDatacxx . . $ mlspp/X509Credential#CertData#> der_chaincxx . . $ mlspp/X509Credential#der_chain.; |
| 48 | |
| 49 | private: |
| 50 | SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey# _public_keycxx . . $ mlspp/X509Credential#_public_key.; |
| 51 | SignatureSchemecxx . . $ mlspp/SignatureScheme# _signature_schemecxx . . $ mlspp/X509Credential#_signature_scheme.; |
| 52 | }; |
| 53 | |
| 54 | tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#& |
| 55 | operatorcxx . . $ mlspp/`operator<<`(29b09f31e48c5f2c).<<(tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#& str, const X509Credentialcxx . . $ mlspp/X509Credential#& obj); |
| 56 | |
| 57 | tlscxx . . $ mlspp/tls/::istreamcxx . . $ mlspp/tls/istream#& |
| 58 | operatorcxx . . $ mlspp/`operator>>`(53950f4f66bc7667).>>(tlscxx . . $ mlspp/tls/::istreamcxx . . $ mlspp/tls/istream#& str, X509Credentialcxx . . $ mlspp/X509Credential#& obj); |
| 59 | |
| 60 | struct UserInfoVCCredentialcxx . . $ mlspp/UserInfoVCCredential# |
| 61 | { |
| 62 | UserInfoVCCredentialcxx . . $ mlspp/UserInfoVCCredential#UserInfoVCCredential(49f6e7a06ebc5aa8).() = default; |
| 63 | explicit UserInfoVCCredentialcxx . . $ mlspp/UserInfoVCCredential#UserInfoVCCredential(8d4ab0a187bf9331).(stdcxx . . $ std/::stringcxx . . $ std/string# userinfo_vc_jwt_in); |
| 64 | |
| 65 | stdcxx . . $ std/::stringcxx . . $ std/string# userinfo_vc_jwtcxx . . $ mlspp/UserInfoVCCredential#userinfo_vc_jwt.; |
| 66 | |
| 67 | bool valid_forcxx . . $ mlspp/UserInfoVCCredential#valid_for(9a76ab9c2cdc40ef).(const SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#& pub) const; |
| 68 | bool valid_fromcxx . . $ mlspp/UserInfoVCCredential#valid_from(37c0a6423f04786b).(const PublicJWKcxx . . $ mlspp/PublicJWK#& pub) const; |
| 69 | |
| 70 | friend tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream# operatorcxx . . $ mlspp/`operator<<`(3d592eb4e02d4d67).<<(tlscxx . . $ mlspp/tls/::ostreamcxx . . $ mlspp/tls/ostream#& str, |
| 71 | const UserInfoVCCredentialcxx . . $ mlspp/UserInfoVCCredential#& obj); |
| 72 | friend tlscxx . . $ mlspp/tls/::istreamcxx . . $ mlspp/tls/istream# operatorcxx . . $ mlspp/`operator>>`(fc9244adb8e2d223).>>(tlscxx . . $ mlspp/tls/::istreamcxx . . $ mlspp/tls/istream#& str, UserInfoVCCredentialcxx . . $ mlspp/UserInfoVCCredential#& obj); |
| 73 | friend bool operatorcxx . . $ mlspp/`operator==`(20dac2ddef4f4d38).==(const UserInfoVCCredentialcxx . . $ mlspp/UserInfoVCCredential#& lhs, |
| 74 | const UserInfoVCCredentialcxx . . $ mlspp/UserInfoVCCredential#& rhs); |
| 75 | friend bool operatorcxx . . $ mlspp/`operator!=`(20dac2ddef4f4d38).!=(const UserInfoVCCredentialcxx . . $ mlspp/UserInfoVCCredential#& lhs, |
| 76 | const UserInfoVCCredentialcxx . . $ mlspp/UserInfoVCCredential#& rhs); |
| 77 | |
| 78 | private: |
| 79 | stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<hpkecxx . . $ mlspp/hpke/::UserInfoVCcxx . . $ mlspp/hpke/UserInfoVC#> _vccxx . . $ mlspp/UserInfoVCCredential#_vc.; |
| 80 | }; |
| 81 | |
| 82 | bool |
| 83 | operatorcxx . . $ mlspp/`operator==`(be1fd05050b0c885).==(const X509Credentialcxx . . $ mlspp/X509Credential#& lhs, const X509Credentialcxx . . $ mlspp/X509Credential#& rhs); |
| 84 | |
| 85 | enum struct CredentialTypecxx . . $ mlspp/CredentialType# : uint16_tcxx . . $ uint16_t# |
| 86 | { |
| 87 | reservedcxx . . $ mlspp/CredentialType#reserved. = 0, |
| 88 | basiccxx . . $ mlspp/CredentialType#basic. = 1, |
| 89 | x509cxx . . $ mlspp/CredentialType#x509. = 2, |
| 90 | |
| 91 | userinfo_vc_draft_00cxx . . $ mlspp/CredentialType#userinfo_vc_draft_00. = 0xFE00, |
| 92 | multi_draft_00cxx . . $ mlspp/CredentialType#multi_draft_00. = 0xFF00, |
| 93 | |
| 94 | // GREASE values, included here mainly so that debugger output looks nice |
| 95 | GREASE_0cxx . . $ mlspp/CredentialType#GREASE_0. = 0x0A0A, |
| 96 | GREASE_1cxx . . $ mlspp/CredentialType#GREASE_1. = 0x1A1A, |
| 97 | GREASE_2cxx . . $ mlspp/CredentialType#GREASE_2. = 0x2A2A, |
| 98 | GREASE_3cxx . . $ mlspp/CredentialType#GREASE_3. = 0x3A3A, |
| 99 | GREASE_4cxx . . $ mlspp/CredentialType#GREASE_4. = 0x4A4A, |
| 100 | GREASE_5cxx . . $ mlspp/CredentialType#GREASE_5. = 0x5A5A, |
| 101 | GREASE_6cxx . . $ mlspp/CredentialType#GREASE_6. = 0x6A6A, |
| 102 | GREASE_7cxx . . $ mlspp/CredentialType#GREASE_7. = 0x7A7A, |
| 103 | GREASE_8cxx . . $ mlspp/CredentialType#GREASE_8. = 0x8A8A, |
| 104 | GREASE_9cxx . . $ mlspp/CredentialType#GREASE_9. = 0x9A9A, |
| 105 | GREASE_Acxx . . $ mlspp/CredentialType#GREASE_A. = 0xAAAA, |
| 106 | GREASE_Bcxx . . $ mlspp/CredentialType#GREASE_B. = 0xBABA, |
| 107 | GREASE_Ccxx . . $ mlspp/CredentialType#GREASE_C. = 0xCACA, |
| 108 | GREASE_Dcxx . . $ mlspp/CredentialType#GREASE_D. = 0xDADA, |
| 109 | GREASE_Ecxx . . $ mlspp/CredentialType#GREASE_E. = 0xEAEA, |
| 110 | }; |
| 111 | |
| 112 | // struct { |
| 113 | // Credential credential; |
| 114 | // SignaturePublicKey credential_key; |
| 115 | // opaque signature<V>; |
| 116 | // } CredentialBinding |
| 117 | // |
| 118 | // struct { |
| 119 | // CredentialBinding bindings<V>; |
| 120 | // } MultiCredential; |
| 121 | struct CredentialBindingcxx . . $ mlspp/CredentialBinding#; |
| 122 | struct CredentialBindingInputcxx . . $ mlspp/CredentialBindingInput#; |
| 123 | |
| 124 | struct MultiCredentialcxx . . $ mlspp/MultiCredential# |
| 125 | { |
| 126 | MultiCredentialcxx . . $ mlspp/MultiCredential#MultiCredential(49f6e7a06ebc5aa8).() = default; |
| 127 | MultiCredentialcxx . . $ mlspp/MultiCredential#MultiCredential(1a27324a5f510bbe).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CredentialBindingInputcxx . . $ mlspp/CredentialBindingInput#>& binding_inputs, |
| 128 | const SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#& signature_key); |
| 129 | |
| 130 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<CredentialBindingcxx . . $ mlspp/CredentialBinding#> bindingscxx . . $ mlspp/MultiCredential#bindings.; |
| 131 | |
| 132 | bool valid_forcxx . . $ mlspp/MultiCredential#valid_for(9a76ab9c2cdc40ef).(const SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#& pub) const; |
| 133 | |
| 134 | TLS_SERIALIZABLEcxx . . $ `mlspp/lib/bytes/include/tls/tls_syntax.h:333:9`!(bindings) |
| 135 | }; |
| 136 | |
| 137 | // struct { |
| 138 | // CredentialType credential_type; |
| 139 | // select (credential_type) { |
| 140 | // case basic: |
| 141 | // BasicCredential; |
| 142 | // |
| 143 | // case x509: |
| 144 | // opaque cert_data<1..2^24-1>; |
| 145 | // }; |
| 146 | // } Credential; |
| 147 | struct Credentialcxx . . $ mlspp/Credential# |
| 148 | { |
| 149 | Credentialcxx . . $ mlspp/Credential#Credential(49f6e7a06ebc5aa8).() = default; |
| 150 | |
| 151 | CredentialTypecxx . . $ mlspp/CredentialType# typecxx . . $ mlspp/Credential#type(4ec975920d5c26ae).() const; |
| 152 | |
| 153 | template<typename T> |
| 154 | const T& getcxx . . $ mlspp/Credential#get(ea465e50d690edfe).() const |
| 155 | { |
| 156 | return var::getcxx . . $ std/get(3745fbf9a4df67d6).<T>(_credcxx . . $ mlspp/Credential#_cred.); |
| 157 | } |
| 158 | |
| 159 | static Credentialcxx . . $ mlspp/Credential# basiccxx . . $ mlspp/Credential#basic(2a432aa7c0aa22fc).(const bytescxx . . $ mlspp/bytes_ns/bytes#& identity); |
| 160 | static Credentialcxx . . $ mlspp/Credential# x509cxx . . $ mlspp/Credential#x509(3dd90220e7cf33f5).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<bytescxx . . $ mlspp/bytes_ns/bytes#>& der_chain); |
| 161 | static Credentialcxx . . $ mlspp/Credential# userinfo_vccxx . . $ mlspp/Credential#userinfo_vc(608e56844219f95b).(const stdcxx . . $ std/::stringcxx . . $ std/string#& userinfo_vc_jwt); |
| 162 | static Credentialcxx . . $ mlspp/Credential# multicxx . . $ mlspp/Credential#multi(2baa8a922395a7e9).( |
| 163 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CredentialBindingInputcxx . . $ mlspp/CredentialBindingInput#>& binding_inputs, |
| 164 | const SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#& signature_key); |
| 165 | |
| 166 | bool valid_forcxx . . $ mlspp/Credential#valid_for(9a76ab9c2cdc40ef).(const SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#& pub) const; |
| 167 | |
| 168 | TLS_SERIALIZABLEcxx . . $ mlspp/Credential#_tls_serializable.(_cred) |
| 169 | TLS_TRAITScxx . . $ std/tuple#(tls::variant<CredentialType>) |
| 170 | |
| 171 | private: |
| 172 | using SpecificCredentialcxx . . $ mlspp/Credential#SpecificCredential# = var::variantcxx . . $ std/variant#<BasicCredentialcxx . . $ mlspp/BasicCredential#, |
| 173 | X509Credentialcxx . . $ mlspp/X509Credential#, |
| 174 | UserInfoVCCredentialcxx . . $ mlspp/UserInfoVCCredential#, |
| 175 | MultiCredentialcxx . . $ mlspp/MultiCredential#>; |
| 176 | |
| 177 | Credentialcxx . . $ mlspp/Credential#Credential(c0b2462d20828d3c).(SpecificCredentialcxx . . $ mlspp/Credential#SpecificCredential# specific); |
| 178 | SpecificCredentialcxx . . $ mlspp/Credential#SpecificCredential# _credcxx . . $ mlspp/Credential#_cred.; |
| 179 | }; |
| 180 | |
| 181 | // XXX(RLB): This struct needs to appear below Credential so that all types are |
| 182 | // concrete at the appropriate points. |
| 183 | struct CredentialBindingInputcxx . . $ mlspp/CredentialBindingInput# |
| 184 | { |
| 185 | CipherSuitecxx . . $ mlspp/CipherSuite# cipher_suitecxx . . $ mlspp/CredentialBindingInput#cipher_suite.; |
| 186 | Credentialcxx . . $ mlspp/Credential# credentialcxx . . $ mlspp/CredentialBindingInput#credential.; |
| 187 | const SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#& credential_privcxx . . $ mlspp/CredentialBindingInput#credential_priv.; |
| 188 | }; |
| 189 | |
| 190 | struct CredentialBindingcxx . . $ mlspp/CredentialBinding# |
| 191 | { |
| 192 | CipherSuitecxx . . $ mlspp/CipherSuite# cipher_suitecxx . . $ mlspp/CredentialBinding#cipher_suite.; |
| 193 | Credentialcxx . . $ mlspp/Credential# credentialcxx . . $ mlspp/CredentialBinding#credential.; |
| 194 | SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey# credential_keycxx . . $ mlspp/CredentialBinding#credential_key.; |
| 195 | bytescxx . . $ mlspp/bytes_ns/bytes# signaturecxx . . $ mlspp/CredentialBinding#signature.; |
| 196 | |
| 197 | CredentialBindingcxx . . $ mlspp/CredentialBinding#CredentialBinding(49f6e7a06ebc5aa8).() = default; |
| 198 | CredentialBindingcxx . . $ mlspp/CredentialBinding#CredentialBinding(3fd21b6206897d2).(CipherSuitecxx . . $ mlspp/CipherSuite# suite_in, |
| 199 | Credentialcxx . . $ mlspp/Credential# credential_in, |
| 200 | const SignaturePrivateKeycxx . . $ mlspp/SignaturePrivateKey#& credential_priv, |
| 201 | const SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#& signature_key); |
| 202 | |
| 203 | bool valid_forcxx . . $ mlspp/CredentialBinding#valid_for(9a76ab9c2cdc40ef).(const SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#& signature_key) const; |
| 204 | |
| 205 | TLS_SERIALIZABLEcxx . . $ mlspp/CredentialBinding#signature.(cipher_suite, credential, credential_key, signature) |
| 206 | |
| 207 | private: |
| 208 | bytescxx . . $ mlspp/bytes_ns/bytes# to_be_signedcxx . . $ mlspp/CredentialBinding#to_be_signed(2aa6f66295221c4d).(const SignaturePublicKeycxx . . $ mlspp/SignaturePublicKey#& signature_key) const; |
| 209 | }; |
| 210 | |
| 211 | } // namespace mlspp |
| 212 | |
| 213 | namespace mlsppcxx . . $ mlspp/::tlscxx . . $ mlspp/tls/ { |
| 214 | |
| 215 | TLS_VARIANT_MAPcxx . . $ mlspp/CredentialType#basic.(mlspp::CredentialType, |
| 216 | mlspp::BasicCredential, |
| 217 | basic) |
| 218 | TLS_VARIANT_MAPcxx . . $ mlspp/(mlspp::CredentialType, |
| 219 | mlspp::X509Credential, |
| 220 | x509) |
| 221 | TLS_VARIANT_MAPcxx . . $ mlspp/CredentialType#(mlspp::CredentialType, |
| 222 | mlspp::UserInfoVCCredential, |
| 223 | userinfo_vc_draft_00) |
| 224 | TLS_VARIANT_MAPcxx . . $ mlspp/MultiCredential#(mlspp::CredentialType, |
| 225 | mlspp::MultiCredential, |
| 226 | multi_draft_00) |
| 227 | |
| 228 | } // namespace mlspp::tls |