53#define EINVAL_CHANGE_CIPHER __einfo_error ( EINFO_EINVAL_CHANGE_CIPHER )
54#define EINFO_EINVAL_CHANGE_CIPHER \
55 __einfo_uniqify ( EINFO_EINVAL, 0x01, \
56 "Invalid Change Cipher record" )
57#define EINVAL_ALERT __einfo_error ( EINFO_EINVAL_ALERT )
58#define EINFO_EINVAL_ALERT \
59 __einfo_uniqify ( EINFO_EINVAL, 0x02, \
60 "Invalid Alert record" )
61#define EINVAL_HELLO __einfo_error ( EINFO_EINVAL_HELLO )
62#define EINFO_EINVAL_HELLO \
63 __einfo_uniqify ( EINFO_EINVAL, 0x03, \
64 "Invalid Server Hello record" )
65#define EINVAL_CERTIFICATE __einfo_error ( EINFO_EINVAL_CERTIFICATE )
66#define EINFO_EINVAL_CERTIFICATE \
67 __einfo_uniqify ( EINFO_EINVAL, 0x04, \
68 "Invalid Certificate" )
69#define EINVAL_CERTIFICATES __einfo_error ( EINFO_EINVAL_CERTIFICATES )
70#define EINFO_EINVAL_CERTIFICATES \
71 __einfo_uniqify ( EINFO_EINVAL, 0x05, \
72 "Invalid Server Certificate record" )
73#define EINVAL_HELLO_DONE __einfo_error ( EINFO_EINVAL_HELLO_DONE )
74#define EINFO_EINVAL_HELLO_DONE \
75 __einfo_uniqify ( EINFO_EINVAL, 0x06, \
76 "Invalid Server Hello Done record" )
77#define EINVAL_FINISHED __einfo_error ( EINFO_EINVAL_FINISHED )
78#define EINFO_EINVAL_FINISHED \
79 __einfo_uniqify ( EINFO_EINVAL, 0x07, \
80 "Invalid Server Finished record" )
81#define EINVAL_HANDSHAKE __einfo_error ( EINFO_EINVAL_HANDSHAKE )
82#define EINFO_EINVAL_HANDSHAKE \
83 __einfo_uniqify ( EINFO_EINVAL, 0x08, \
84 "Invalid Handshake record" )
85#define EINVAL_IV __einfo_error ( EINFO_EINVAL_IV )
86#define EINFO_EINVAL_IV \
87 __einfo_uniqify ( EINFO_EINVAL, 0x0a, \
88 "Invalid initialisation vector" )
89#define EINVAL_PADDING __einfo_error ( EINFO_EINVAL_PADDING )
90#define EINFO_EINVAL_PADDING \
91 __einfo_uniqify ( EINFO_EINVAL, 0x0b, \
92 "Invalid block padding" )
93#define EINVAL_RX_STATE __einfo_error ( EINFO_EINVAL_RX_STATE )
94#define EINFO_EINVAL_RX_STATE \
95 __einfo_uniqify ( EINFO_EINVAL, 0x0c, \
96 "Invalid receive state" )
97#define EINVAL_MAC __einfo_error ( EINFO_EINVAL_MAC )
98#define EINFO_EINVAL_MAC \
99 __einfo_uniqify ( EINFO_EINVAL, 0x0d, \
100 "Invalid MAC or authentication tag" )
101#define EINVAL_TICKET __einfo_error ( EINFO_EINVAL_TICKET )
102#define EINFO_EINVAL_TICKET \
103 __einfo_uniqify ( EINFO_EINVAL, 0x0e, \
104 "Invalid New Session Ticket record")
105#define EINVAL_KEY_EXCHANGE __einfo_error ( EINFO_EINVAL_KEY_EXCHANGE )
106#define EINFO_EINVAL_KEY_EXCHANGE \
107 __einfo_uniqify ( EINFO_EINVAL, 0x0f, \
108 "Invalid Server Key Exchange record" )
109#define EIO_ALERT __einfo_error ( EINFO_EIO_ALERT )
110#define EINFO_EIO_ALERT \
111 __einfo_uniqify ( EINFO_EIO, 0x01, \
112 "Unknown alert level" )
113#define ENOENT_CERT __einfo_error ( EINFO_ENOENT_CERT )
114#define EINFO_ENOENT_CERT \
115 __einfo_uniqify ( EINFO_ENOENT, 0x01, \
116 "Missing certificate" )
117#define ENOENT_KEY_EXCHANGE __einfo_error ( EINFO_ENOENT_KEY_EXCHANGE )
118#define EINFO_ENOENT_KEY_EXCHANGE \
119 __einfo_uniqify ( EINFO_ENOENT, 0x02, \
120 "No key exchange algorithm selected" )
121#define ENOMEM_CONTEXT __einfo_error ( EINFO_ENOMEM_CONTEXT )
122#define EINFO_ENOMEM_CONTEXT \
123 __einfo_uniqify ( EINFO_ENOMEM, 0x01, \
124 "Not enough space for crypto context" )
125#define ENOMEM_CERTIFICATE __einfo_error ( EINFO_ENOMEM_CERTIFICATE )
126#define EINFO_ENOMEM_CERTIFICATE \
127 __einfo_uniqify ( EINFO_ENOMEM, 0x02, \
128 "Not enough space for certificate" )
129#define ENOMEM_CHAIN __einfo_error ( EINFO_ENOMEM_CHAIN )
130#define EINFO_ENOMEM_CHAIN \
131 __einfo_uniqify ( EINFO_ENOMEM, 0x03, \
132 "Not enough space for certificate chain" )
133#define ENOMEM_TX_PLAINTEXT __einfo_error ( EINFO_ENOMEM_TX_PLAINTEXT )
134#define EINFO_ENOMEM_TX_PLAINTEXT \
135 __einfo_uniqify ( EINFO_ENOMEM, 0x04, \
136 "Not enough space for transmitted plaintext" )
137#define ENOMEM_TX_CIPHERTEXT __einfo_error ( EINFO_ENOMEM_TX_CIPHERTEXT )
138#define EINFO_ENOMEM_TX_CIPHERTEXT \
139 __einfo_uniqify ( EINFO_ENOMEM, 0x05, \
140 "Not enough space for transmitted ciphertext" )
141#define ENOMEM_RX_DATA __einfo_error ( EINFO_ENOMEM_RX_DATA )
142#define EINFO_ENOMEM_RX_DATA \
143 __einfo_uniqify ( EINFO_ENOMEM, 0x07, \
144 "Not enough space for received data" )
145#define ENOMEM_RX_CONCAT __einfo_error ( EINFO_ENOMEM_RX_CONCAT )
146#define EINFO_ENOMEM_RX_CONCAT \
147 __einfo_uniqify ( EINFO_ENOMEM, 0x08, \
148 "Not enough space to concatenate received data" )
149#define ENOTSUP_CIPHER __einfo_error ( EINFO_ENOTSUP_CIPHER )
150#define EINFO_ENOTSUP_CIPHER \
151 __einfo_uniqify ( EINFO_ENOTSUP, 0x01, \
152 "Unsupported cipher" )
153#define ENOTSUP_NULL __einfo_error ( EINFO_ENOTSUP_NULL )
154#define EINFO_ENOTSUP_NULL \
155 __einfo_uniqify ( EINFO_ENOTSUP, 0x02, \
156 "Refusing to use null cipher" )
157#define ENOTSUP_SIG_HASH __einfo_error ( EINFO_ENOTSUP_SIG_HASH )
158#define EINFO_ENOTSUP_SIG_HASH \
159 __einfo_uniqify ( EINFO_ENOTSUP, 0x03, \
160 "Unsupported signature and hash algorithm" )
161#define ENOTSUP_VERSION __einfo_error ( EINFO_ENOTSUP_VERSION )
162#define EINFO_ENOTSUP_VERSION \
163 __einfo_uniqify ( EINFO_ENOTSUP, 0x04, \
164 "Unsupported protocol version" )
165#define ENOTSUP_GROUP __einfo_error ( EINFO_ENOTSUP_GROUP )
166#define EINFO_ENOTSUP_GROUP \
167 __einfo_uniqify ( EINFO_ENOTSUP, 0x05, \
168 "Unsupported key exchange group" )
169#define EPERM_ALERT __einfo_error ( EINFO_EPERM_ALERT )
170#define EINFO_EPERM_ALERT \
171 __einfo_uniqify ( EINFO_EPERM, 0x01, \
172 "Received fatal alert" )
173#define EPERM_VERIFY __einfo_error ( EINFO_EPERM_VERIFY )
174#define EINFO_EPERM_VERIFY \
175 __einfo_uniqify ( EINFO_EPERM, 0x02, \
176 "Handshake verification failed" )
177#define EPERM_RENEG_INSECURE __einfo_error ( EINFO_EPERM_RENEG_INSECURE )
178#define EINFO_EPERM_RENEG_INSECURE \
179 __einfo_uniqify ( EINFO_EPERM, 0x04, \
180 "Secure renegotiation not supported" )
181#define EPERM_RENEG_VERIFY __einfo_error ( EINFO_EPERM_RENEG_VERIFY )
182#define EINFO_EPERM_RENEG_VERIFY \
183 __einfo_uniqify ( EINFO_EPERM, 0x05, \
184 "Secure renegotiation verification failed" )
185#define EPERM_KEY_EXCHANGE __einfo_error ( EINFO_EPERM_KEY_EXCHANGE )
186#define EINFO_EPERM_KEY_EXCHANGE \
187 __einfo_uniqify ( EINFO_EPERM, 0x06, \
188 "ServerKeyExchange verification failed" )
189#define EPERM_SAVE __einfo_error ( EINFO_EPERM_SAVE )
190#define EINFO_EPERM_SAVE \
191 __einfo_uniqify ( EINFO_EPERM, 0x07, \
192 "Pre-shared key was not established" )
193#define EPROTO_VERSION __einfo_error ( EINFO_EPROTO_VERSION )
194#define EINFO_EPROTO_VERSION \
195 __einfo_uniqify ( EINFO_EPROTO, 0x01, \
196 "Illegal protocol version upgrade" )
205 unsigned int description );
209 const void *
data,
size_t len );
445 static const char label[] =
"tls connection nonce";
494 DBGC ( tls,
"TLS %p could not initialise key schedule: %s\n",
519#define TLS_NUM_CIPHER_SUITES table_num_entries ( TLS_CIPHER_SUITES )
533 const char *exchange_name;
534 const char *pubkey_name;
535 const char *digest_name;
546 snprintf ( buf,
sizeof ( buf ),
"%s%s%s%s%s-%d-%s",
547 ( exchange_name ? exchange_name :
"" ),
548 ( exchange_name ?
"-" :
"" ),
549 ( pubkey_name ? pubkey_name :
"" ),
550 ( pubkey_name ?
"-" :
"" ),
551 cipher->
name, ( suite->
key_len * 8 ), digest_name );
568 if ( suite->
code == cipher_suite )
584 memset ( cipherspec, 0,
sizeof ( *cipherspec ) );
607 dynamic =
zalloc ( total );
609 DBGC ( tls,
"TLS %p could not allocate %zd bytes for crypto "
610 "context\n", tls, total );
622 cipherspec->
suite = suite;
635 unsigned int cipher_suite ) {
643 DBGC ( tls,
"TLS %p does not support cipher suite %#04x\n",
644 tls,
ntohs ( cipher_suite ) );
651 DBGC ( tls,
"TLS %p cannot use broken cipher suite %#04x\n",
652 tls,
ntohs ( cipher_suite ) );
672 DBGC ( tls,
"TLS %p selected cipher suite %s\n",
699 DBGC ( tls,
"TLS %p refusing to use null %s cipher\n",
707 DBGC ( tls,
"TLS %p could not generate %s %s traffic secret: "
718 DBGC ( tls,
"TLS %p could not generate %s %s keys: %s\n",
728 DBGC ( tls,
"TLS %p could not set %s cipher: %s\n",
736 DBGC ( tls,
"TLS %p activated %s cipher %s\n",
750#define TLS_NUM_SIG_HASH_ALGORITHMS \
751 table_num_entries ( TLS_SIG_HASH_ALGORITHMS )
814 if (
group->code && (
group->code == named_group ) )
859 DBGC ( tls,
"TLS %p received unexpected ServerKeyExchange:\n", tls );
897 typeof ( dh_val[0] ) dh_p;
898 typeof ( dh_val[1] ) dh_g;
899 typeof ( dh_val[2] ) dh_ys;
908 for ( i = 0 ; i < (
sizeof ( dh_val ) /
sizeof ( dh_val[0] ) ) ; i++ ){
910 if ( (
sizeof ( *dh_val[i] ) > remaining ) ||
911 (
ntohs ( dh_val[i]->
len ) > ( remaining -
912 sizeof ( *dh_val[i] ) ) )){
913 DBGC ( tls,
"TLS %p received underlength "
914 "ServerKeyExchange\n", tls );
918 frag_len = (
sizeof ( *dh_val[i] ) +
ntohs ( dh_val[i]->
len ));
920 remaining -= frag_len;
922 params->
len = (
len - remaining );
929 dh_g->data,
ntohs ( dh_g->len ) );
931 DBGC ( tls,
"TLS %p unsupported %d-bit group:\n",
932 tls, ( 8 *
ntohs ( dh_p->len ) ) );
972 if ( (
sizeof ( *ecdh ) >
len ) ||
973 ( ecdh->public_len > (
len - sizeof ( *ecdh ) ) ) ) {
974 DBGC ( tls,
"TLS %p received underlength ServerKeyExchange\n",
979 params->
len = (
sizeof ( *ecdh ) + ecdh->public_len );
983 DBGC ( tls,
"TLS %p unsupported curve type %d\n",
984 tls, ecdh->curve_type );
990 DBGC ( tls,
"TLS %p unsupported named group %d\n",
991 tls,
ntohs ( ecdh->named_group ) );
996 params->
partner = ecdh->public;
1007 .len_len =
sizeof (
uint8_t ),
1051 void *
public,
size_t len ) {
1053 size_t pubsize = exchange->
pubsize;
1057 if ( pubsize !=
len ) {
1058 DBGC ( tls,
"TLS %p wrong public %s key size (%zd bytes)\n",
1065 DBGC ( tls,
"TLS %p could not share public %s key: %s\n",
1086 size_t pubsize = exchange->
pubsize;
1100 if (
len > pubsize ) {
1101 DBGC ( tls,
"TLS %p overlength partner %s key:\n",
1102 tls, exchange->
name );
1110 pad_len = ( pubsize -
len );
1111 if ( pad_len && ( ! strip ) ) {
1112 DBGC ( tls,
"TLS %p underlength partner %s key:\n",
1113 tls, exchange->
name );
1122 DBGC ( tls,
"TLS %p could not agree shared %s key: %s\n",
1153 DBGC ( tls,
"TLS %p has no server certificate chain\n", tls );
1158 DBGC ( tls,
"TLS %p has no server certificate\n", tls );
1165 builder ) ) != 0 ) {
1166 DBGC ( tls,
"TLS %p could not encrypt %s key: %s\n",
1185 size_t pubsize = exchange->
pubsize;
1192 if ( (
rc =
asn1_grow ( builder, pubsize ) ) != 0 )
1197 pubsize ) ) != 0 ) {
1205 builder ) ) != 0 ) {
1244 const void *shared,
int *accumulated ) {
1258 while ( shared_len && ( ! *( (
const uint8_t * ) shared ) ) ) {
1262 assert ( shared_len > 0 );
1264 DBGC ( tls,
"TLS %p shared (pre-master) secret:\n", tls );
1265 DBGC_HDA ( tls, 0, shared, shared_len );
1269 DBGC ( tls,
"TLS %p could not apply shared secret: %s\n",
1301 DBGC ( tls,
"TLS %p cannot save pre-shared key before "
1302 "channel is established\n", tls );
1308 &session->
psk ) ) != 0 ) {
1309 DBGC ( tls,
"TLS %p could not save key material: %s\n",
1334 &session->
psk ) ) != 0 ) {
1335 DBGC ( tls,
"TLS %p could not load key material: %s\n",
1352 const void *auth,
size_t len ) {
1359 DBGC ( tls,
"TLS %p invalid authenticator value:\n", tls );
1368 DBGC ( tls,
"TLS %p could not generate server verification: "
1375 DBGC ( tls,
"TLS %p incorrect authenticator value:\n", tls );
1406 static const char label[] =
"tls session id";
1418 DBGC ( tls,
"TLS %p joining session %s\n", tls,
name );
1431 name_copy = ( ( (
void * ) session ) +
sizeof ( *session ) );
1433 session->
name = name_copy;
1441 sizeof ( session->
id.
data ) );
1447 DBGC ( tls,
"TLS %p created session %s\n", tls,
name );
1467 DBGC ( tls,
"TLS %p could not save: %s\n",
1475 DBGC ( tls,
"TLS %p saved session ID:\n", tls );
1501 DBGC ( tls,
"TLS %p resuming session ID:\n", tls );
1506 DBGC ( tls,
"TLS %p could not resume: %s\n",
1530 const void *
data,
size_t len ) {
1595 DBGC ( tls,
"TLS %p could not establish channel: %s\n",
1626 const void *
data,
size_t len ) {
1701 typeof ( *server_name_ext ) server_name;
1702 typeof ( *max_fragment_length_ext ) max_fragment_length;
1703 typeof ( *signature_algorithms_ext ) signature_algorithms;
1704 typeof ( *renegotiation_info_ext ) renegotiation_info;
1705 typeof ( *session_ticket_ext ) session_ticket;
1706 typeof ( *extended_master_secret_ext ) extended_master_secret;
1707 typeof ( *named_group_ext )
1718 uint8_t compression_methods_len;
1719 uint8_t compression_methods[1];
1721 typeof ( *extensions ) extensions;
1732 sizeof (
hello.type_length ) ) );
1737 sizeof (
hello.session_id ) );
1741 hello.compression_methods_len =
sizeof (
hello.compression_methods );
1743 extensions = &
hello.extensions;
1746 server_name_ext = &extensions->server_name;
1748 server_name_ext->len =
htons (
sizeof ( server_name_ext->data ) );
1749 server_name_ext->data.len
1750 =
htons (
sizeof ( server_name_ext->data.list ) );
1752 server_name_ext->data.list[0].len
1753 =
htons (
sizeof ( server_name_ext->data.list[0].name ) );
1754 memcpy ( server_name_ext->data.list[0].name, session->
name,
1755 sizeof ( server_name_ext->data.list[0].name ) );
1758 max_fragment_length_ext = &extensions->max_fragment_length;
1760 max_fragment_length_ext->len
1761 =
htons (
sizeof ( max_fragment_length_ext->data ) );
1765 signature_algorithms_ext = &extensions->signature_algorithms;
1767 signature_algorithms_ext->len
1768 =
htons (
sizeof ( signature_algorithms_ext->data ) );
1769 signature_algorithms_ext->data.len
1770 =
htons (
sizeof ( signature_algorithms_ext->data.code ) );
1772 signature_algorithms_ext->data.code[i++] = sighash->
code;
1775 renegotiation_info_ext = &extensions->renegotiation_info;
1777 renegotiation_info_ext->len
1778 =
htons (
sizeof ( renegotiation_info_ext->data ) );
1779 renegotiation_info_ext->data.len
1780 =
sizeof ( renegotiation_info_ext->data.data );
1782 sizeof ( renegotiation_info_ext->data.data ) );
1785 session_ticket_ext = &extensions->session_ticket;
1787 session_ticket_ext->len
1788 =
htons (
sizeof ( session_ticket_ext->data ) );
1790 sizeof ( session_ticket_ext->data.data ) );
1793 extended_master_secret_ext = &extensions->extended_master_secret;
1794 extended_master_secret_ext->type
1796 extended_master_secret_ext->len = 0;
1799 if (
sizeof ( extensions->named_group ) ) {
1800 named_group_ext = &extensions->named_group[0];
1802 named_group_ext->len
1803 =
htons (
sizeof ( named_group_ext->data ) );
1804 named_group_ext->data.len
1805 =
htons (
sizeof ( named_group_ext->data.code ) );
1808 named_group_ext->data.code[i++] =
group->code;
1813 return action ( tls, &
hello,
sizeof (
hello ) );
1841 typeof ( *certificate ) certificates[0];
1850 DBGC ( tls,
"TLS %p has no client certificate chain\n", tls );
1858 len += (
sizeof ( *certificate ) + cert->
raw.
len );
1859 DBGC ( tls,
"TLS %p sending client certificate %s\n",
1871 certificates =
iob_put ( iobuf,
sizeof ( *certificates ) );
1872 certificates->type_length =
1874 htonl (
sizeof ( *certificates ) +
len -
1875 sizeof ( certificates->type_length ) ) );
1879 certificate =
iob_put ( iobuf,
sizeof ( *certificate ) );
1912 DBGC ( tls,
"TLS %p has no key exchange algorithm\n", tls );
1923 key_xchg.type_length =
1925 htonl (
len +
sizeof ( key_xchg ) -
1926 sizeof ( key_xchg.type_length ) ) );
1927 for ( i = (
sizeof ( key_xchg.key_len ) - 1 ) ; i >= 0 ; i-- ) {
1928 key_xchg.key_len[i] = (
len & 0xff );
1935 sizeof ( key_xchg ) ) ) != 0 ) {
1936 DBGC ( tls,
"TLS %p could not construct Client Key "
1943 builder.
len ) ) != 0 ) {
1950 DBGC ( tls,
"TLS %p could not generate master secret: %s\n",
1983 DBGC ( tls,
"TLS %p has no client certificate chain\n", tls );
1989 DBGC ( tls,
"TLS %p has no client certificate\n", tls );
1999 DBGC ( tls,
"TLS %p could not identify (%s,%s) "
2000 "signature and hash algorithm\n", tls,
2009 tbshash ) ) != 0 ) {
2010 DBGC ( tls,
"TLS %p could not generate CertificateVerify "
2017 &builder ) ) != 0 ) {
2018 DBGC ( tls,
"TLS %p could not sign %s digest using %s client "
2019 "private key: %s\n", tls, digest->
name, pubkey->
name,
2021 goto err_pubkey_sign;
2026 int use_sig_hash = ( ( sig_hash ==
NULL ) ? 0 : 1 );
2036 sizeof (
header.type_length )));
2037 if ( use_sig_hash ) {
2039 sizeof (
header.sig_hash[0] ) );
2044 sizeof (
header ) ) ) != 0 ) {
2045 DBGC ( tls,
"TLS %p could not construct Certificate "
2053 builder.
len ) ) != 0 ) {
2075 static const struct {
2082 &change_cipher,
sizeof ( change_cipher ) );
2102 DBGC ( tls,
"TLS %p could not generate client verification: "
2108 memset ( &finished, 0,
sizeof ( finished ) );
2110 htonl (
sizeof ( finished ) -
2111 sizeof ( finished.type_length ) ) );
2113 sizeof ( finished.verify_data ) );
2117 sizeof ( finished ) ) ) != 0 )
2141 unsigned int description ) {
2147 .description = description,
2171 if ( (
sizeof ( *change_cipher ) !=
len ) ||
2173 DBGC ( tls,
"TLS %p received invalid Change Cipher\n", tls );
2177 iob_pull ( iobuf,
sizeof ( *change_cipher ) );
2182 DBGC ( tls,
"TLS %p could not activate RX cipher: %s\n",
2209 DBGC ( tls,
"TLS %p received overlength Alert\n", tls );
2216 switch (
alert->level ) {
2218 switch (
alert->description ) {
2220 DBGC ( tls,
"TLS %p closed by notification\n", tls );
2224 DBGC ( tls,
"TLS %p received warning alert %d\n",
2225 tls,
alert->description );
2230 DBGC ( tls,
"TLS %p received fatal alert %d\n",
2231 tls,
alert->description );
2234 DBGC ( tls,
"TLS %p received unknown alert level %d"
2235 "(alert %d)\n", tls,
alert->level,
alert->description );
2254 DBGC ( tls,
"TLS %p ignoring Hello Request\n", tls );
2260 DBGC ( tls,
"TLS %p refusing to renegotiate insecurely\n",
2280 const void *
data,
size_t len ) {
2317 if ( (
sizeof ( *hello_a ) >
len ) ||
2318 ( hello_a->session_id_len > (
len - sizeof ( *hello_a ) ) ) ||
2319 (
sizeof ( *hello_b ) > (
len -
sizeof ( *hello_a ) -
2320 hello_a->session_id_len ) ) ) {
2321 DBGC ( tls,
"TLS %p received underlength Server Hello\n", tls );
2325 session_id = hello_a->session_id;
2326 hello_b = ( (
void * ) ( session_id + hello_a->session_id_len ) );
2329 remaining = (
len -
sizeof ( *hello_a ) - hello_a->session_id_len -
2330 sizeof ( *hello_b ) );
2334 exts = ( (
void * ) hello_b->next );
2335 if ( (
sizeof ( *exts ) > remaining ) ||
2336 ( ( exts_len =
ntohs ( exts->len ) ) >
2337 ( remaining - sizeof ( *exts ) ) ) ) {
2338 DBGC ( tls,
"TLS %p received underlength extensions\n",
2345 for (
ext = ( (
void * ) exts->data ), remaining = exts_len ;
2347 ext = ( ( (
void * )
ext ) + sizeof ( *
ext ) + ext_len ),
2348 remaining -= (
sizeof ( *
ext ) + ext_len ) ) {
2351 if ( (
sizeof ( *
ext ) > remaining ) ||
2352 ( ( ext_len =
ntohs (
ext->len ) ) >
2353 ( remaining - sizeof ( *
ext ) ) ) ) {
2354 DBGC ( tls,
"TLS %p received underlength "
2355 "extension\n", tls );
2361 switch (
ext->type ) {
2363 reneg = ( (
void * )
ext->data );
2364 if ( (
sizeof ( *reneg ) > ext_len ) ||
2366 ( ext_len - sizeof ( *reneg ) ) ) ) {
2367 DBGC ( tls,
"TLS %p received "
2368 "underlength renegotiation "
2375 ems = ( (
void * )
ext->data );
2384 DBGC ( tls,
"TLS %p does not support protocol version %d.%d\n",
2389 DBGC ( tls,
"TLS %p server attempted to illegally upgrade to "
2390 "protocol version %d.%d\n",
2395 DBGC ( tls,
"TLS %p using protocol version %d.%d\n",
2416 if ( hello_a->session_id_len &&
2417 ( hello_a->session_id_len == session->
id.
len ) &&
2419 session->
id.
len ) == 0 ) ) {
2425 }
else if ( hello_a->session_id_len &&
2426 ( hello_a->session_id_len <=
2430 tls->
new_id.
len = hello_a->session_id_len;
2432 DBGC ( tls,
"TLS %p new session ID:\n", tls );
2440 if ( ( reneg ==
NULL ) ||
2441 ( reneg->len != sizeof ( tls->
verify ) ) ||
2443 sizeof ( tls->
verify ) ) != 0 ) ) {
2444 DBGC ( tls,
"TLS %p server failed secure "
2445 "renegotiation\n", tls );
2449 }
else if ( reneg !=
NULL ) {
2452 if ( reneg->len != 0 ) {
2453 DBGC ( tls,
"TLS %p server provided non-empty initial "
2454 "renegotiation\n", tls );
2472 const void *
data,
size_t len ) {
2481 if (
sizeof ( *new_session_ticket ) >
len ) {
2482 DBGC ( tls,
"TLS %p received underlength New Session Ticket\n",
2487 ticket_len =
ntohs ( new_session_ticket->len );
2488 if ( ticket_len > (
len -
sizeof ( *new_session_ticket ) ) ) {
2489 DBGC ( tls,
"TLS %p received overlength New Session Ticket\n",
2507 DBGC ( tls,
"TLS %p new session ticket:\n", tls );
2522 const void *
data,
size_t len ) {
2524 size_t remaining =
len;
2535 goto err_alloc_chain;
2539 while ( remaining ) {
2544 size_t certificate_len;
2548 if (
sizeof ( *certificate ) > remaining ) {
2549 DBGC ( tls,
"TLS %p underlength certificate:\n", tls );
2552 goto err_underlength;
2554 certificate_len =
tls_uint24 ( &certificate->length );
2555 if ( certificate_len > ( remaining -
sizeof ( *certificate ) )){
2556 DBGC ( tls,
"TLS %p overlength certificate:\n", tls );
2559 goto err_overlength;
2561 record_len = (
sizeof ( *certificate ) + certificate_len );
2566 certificate_len ) ) != 0 ) {
2567 DBGC ( tls,
"TLS %p could not append certificate: %s\n",
2573 DBGC ( tls,
"TLS %p found certificate %s\n",
2578 remaining -= record_len;
2601 const void *
data,
size_t len ) {
2606 size_t certificates_len;
2610 if (
sizeof ( *certificate ) >
len ) {
2611 DBGC ( tls,
"TLS %p received underlength Server Certificate\n",
2616 certificates_len =
tls_uint24 ( &certificate->length );
2617 if ( certificates_len > (
len -
sizeof ( *certificate ) ) ) {
2618 DBGC ( tls,
"TLS %p received overlength Server Certificate\n",
2626 certificates_len ) ) != 0 )
2641 const void *
data,
size_t len ) {
2661 DBGC ( tls,
"TLS %p has no server certificate chain\n", tls );
2666 DBGC ( tls,
"TLS %p has no server certificate\n", tls );
2673 DBGC ( tls,
"TLS %p using named group %s-%s\n",
2679 remaining = (
len - params.
len );
2682 if ( (
sizeof ( *
sig ) > remaining ) ||
2683 (
ntohs (
sig->signature_len ) > ( remaining -
2684 sizeof ( *
sig ) ) ) ) {
2685 DBGC ( tls,
"TLS %p received underlength ServerKeyExchange\n",
2694 if ( use_sig_hash ) {
2697 DBGC ( tls,
"TLS %p unsupported signature hash "
2698 "%#04x\n", tls,
sig->sig_hash[0] );
2701 pubkey = sig_hash->
pubkey;
2702 digest = sig_hash->
digest;
2703 DBGC ( tls,
"TLS %p using signature hash %s-%s\n",
2707 DBGC ( tls,
"TLS %p cannot use %s public key\n", tls,
2729 tbshash ) ) != 0 ) {
2730 DBGC ( tls,
"TLS %p could not generate "
2731 "ServerKeyExchange digest: %s\n",
2738 pubkey, digest, tbshash,
2740 DBGC ( tls,
"TLS %p ServerKeyExchange failed "
2741 "verification: %s\n", tls,
strerror (
rc ) );
2785 DBGC ( tls,
"TLS %p selected client certificate %s\n",
2795 goto err_auto_append;
2799 DBGC ( tls,
"TLS %p could not find certificate corresponding "
2800 "to private key\n", tls );
2822 const void *
data,
size_t len ) {
2829 if (
sizeof ( *hello_done ) !=
len ) {
2830 DBGC ( tls,
"TLS %p received overlength Server Hello Done\n",
2836 DBGC ( tls,
"TLS %p received duplicate Server Hello Done\n",
2845 DBGC ( tls,
"TLS %p could not start certificate validation: "
2863 const void *
data,
size_t len ) {
2868 DBGC ( tls,
"TLS %p could not confirm peer identity: %s\n",
2927 while ( ( remaining =
iob_len ( iobuf ) ) ) {
2933 const void *payload;
2938 if (
sizeof ( *handshake ) > remaining ) {
2942 payload_len =
tls_uint24 ( &handshake->length );
2943 if ( payload_len > ( remaining -
sizeof ( *handshake ) ) ) {
2947 payload = &handshake->payload;
2948 record_len = (
sizeof ( *handshake ) + payload_len );
2951 switch ( handshake->type ) {
2982 DBGC ( tls,
"TLS %p ignoring handshake type %d\n",
2983 tls, handshake->type );
3042 DBGC ( tls,
"TLS %p could not deliver data: "
3085 DBGC ( tls,
"TLS %p unknown record type %d\n", tls,
type );
3092 list_add ( &(*iobuf)->list, rx_data );
3095 DBGC ( tls,
"TLS %p could not concatenate non-data record "
3096 "type %d\n", tls,
type );
3098 goto err_concatenate;
3102 if ( (
rc = handler ( tls, *iobuf ) ) != 0 )
3155 const void *
data,
size_t len ) {
3186 const void *
data,
size_t len,
void *hmac ) {
3243 return (
count * each );
3294 const void *plaintext;
3295 const void *encrypt;
3307 plaintext = iobuf->
data;
3334 sizeof ( authhdr ),
iv.rec,
3335 sizeof (
iv.rec ) );
3337 sizeof (
iv ) ) ) != 0 ) {
3338 DBGC ( tls,
"TLS %p could not set TX IV: %s\n",
3345 tls_hmac ( cipherspec, &authhdr, plaintext,
3350 sizeof ( authhdr ) );
3354 encrypt_len = ( record_len + suite->
mac_len );
3356 pad_len = ( ( ( cipher->
blocksize - 1 ) &
3357 -( encrypt_len + 1 ) ) + 1 );
3361 encrypt_len += pad_len;
3364 tlshdr =
iob_put ( iobuf,
sizeof ( *tlshdr ) );
3372 sizeof (
iv.rec ) );
3375 ciphertext =
iob_put ( iobuf, record_len );
3376 assert ( ciphertext <= plaintext );
3377 if ( encrypt_len > record_len ) {
3378 memmove ( ciphertext, plaintext, record_len );
3379 encrypt = ciphertext;
3381 encrypt = plaintext;
3389 memset (
iob_put ( iobuf, pad_len ), ( pad_len - 1 ), pad_len );
3392 DBGC2 ( tls,
"Sending plaintext data:\n" );
3393 DBGC2_HDA ( tls, 0, encrypt, encrypt_len );
3401 plaintext += record_len;
3409 DBGC ( tls,
"TLS %p could not deliver ciphertext: %s\n",
3433 const void *
data,
size_t len ) {
3466 padding = ( iobuf->
tail - 1 );
3470 DBGC ( tls,
"TLS %p received underlength padding\n", tls );
3474 for ( i = 0 ; i <
pad ; i++ ) {
3475 if ( *(--padding) !=
pad ) {
3476 DBGC ( tls,
"TLS %p received bad padding\n", tls );
3528 DBGC ( tls,
"TLS %p received underlength IV\n", tls );
3535 len -=
sizeof (
iv.record );
3539 DBGC ( tls,
"TLS %p received underlength authentication tag\n",
3556 sizeof (
iv ) ) ) != 0 ) {
3557 DBGC ( tls,
"TLS %p could not set RX IV: %s\n",
3565 NULL, sizeof ( authhdr ) );
3573 check_len +=
iob_len ( iobuf );
3580 if ( pad_len < 0 ) {
3590 DBGC ( tls,
"TLS %p received underlength MAC\n", tls );
3599 DBGC2 ( tls,
"Received plaintext data:\n" );
3603 check_len +=
iob_len ( iobuf );
3610 tls_hmac_list ( cipherspec, &authhdr, rx_data, verify_mac );
3617 DBGC ( tls,
"TLS %p failed MAC verification\n", tls );
3623 DBGC ( tls,
"TLS %p failed authentication tag verification\n",
3750 reserve = ( ( -iv_len ) & ( cipher->
alignsize - 1 ) );
3751 remaining += reserve;
3761 frag_len = remaining;
3764 remaining -= frag_len;
3766 frag_len += remaining;
3773 DBGC ( tls,
"TLS %p could not allocate %zd of %zd "
3774 "bytes for receive buffer\n", tls,
3797 }
while ( remaining );
3961 DBGC ( tls,
"TLS %p certificate validation failed: %s\n",
3965 DBGC ( tls,
"TLS %p certificate validation succeeded\n", tls );
4030 DBGC ( tls,
"TLS %p could not send Client Hello: %s\n",
4038 DBGC ( tls,
"TLS %p could not send Certificate: %s\n",
4046 DBGC ( tls,
"TLS %p could not send Client Key "
4054 DBGC ( tls,
"TLS %p could not send Certificate "
4062 DBGC ( tls,
"TLS %p could not send Change Cipher: "
4068 DBGC ( tls,
"TLS %p could not activate TX cipher: "
4077 DBGC ( tls,
"TLS %p could not send Finished: %s\n",
4125 tls =
malloc (
sizeof ( *tls ) );
4130 memset ( tls, 0,
sizeof ( *tls ) );
#define NULL
NULL pointer (VOID *).
struct golan_eq_context ctx
u8 signature
CPU signature.
union @162305117151260234136356364136041353210355154177 key
typeof(acpi_finder=acpi_find)
ACPI table finder.
u32 link
Link to next descriptor.
struct arbelprm_rc_send_wqe rc
pseudo_bit_t value[0x00020]
unsigned long long uint64_t
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
int asn1_prepend_raw(struct asn1_builder *builder, const void *data, size_t len)
Prepend raw data to ASN.1 builder.
int asn1_grow(struct asn1_builder *builder, size_t extra)
Grow ASN.1 builder.
#define assert(condition)
Assert a condition at run-time.
u32 version
Driver version.
struct bofm_section_header done
struct x509_chain certstore
Certificate store.
int channel_set_cipher(struct secure_channel *channel, struct secure_pipe *pipe, struct cipher_algorithm *cipher, const void *key, size_t len)
Set cipher algorithm and key.
void channel_reopen(struct secure_channel *channel)
Reopen secure channel.
int channel_bind_encrypt(struct secure_channel *channel, struct x509_certificate *identity, struct exchange_algorithm *exchange, struct pubkey_algorithm *pubkey, struct asn1_builder *ciphertext)
Bind peer identity via shared secret encryption.
void channel_ephemeral(struct secure_channel *channel, const void *info, size_t info_len, void *out, size_t len)
Generate ephemeral secret.
void channel_unkey(struct secure_channel *channel)
Clear shared secret.
int channel_key_agree(struct secure_channel *channel, struct exchange_algorithm *exchange, const void *partner)
Agree shared secret.
int channel_open(struct secure_channel *channel)
Open secure channel.
void channel_close(struct secure_channel *channel)
Close secure channel.
int channel_bind_verify(struct secure_channel *channel, struct x509_certificate *identity, struct pubkey_algorithm *pubkey, struct digest_algorithm *digest, const void *value, const struct asn1_cursor *signature)
Bind peer identity via ephemeral public key signature verification.
int channel_establish(struct secure_channel *channel, const char *name, struct x509_root *root)
Establish channel as trusted for application data.
int channel_save(struct secure_channel *channel, struct secure_preshared_identity *psid)
Save a pre-shared key.
int channel_confirm(struct secure_channel *channel, const void *auth, size_t len)
Confirm peer identity.
int channel_key_share(struct secure_channel *channel, struct exchange_algorithm *exchange, void *public)
Share public key.
void channel_ephemeral_label(struct secure_channel *channel, const char *label, void *out, size_t len)
Generate labelled ephemeral secret.
int channel_load(struct secure_channel *channel, struct secure_preshared_identity *psid)
Load a pre-shared key.
static void channel_init(struct secure_channel *channel, struct secure_channel_operations *op)
Initialise secure channel.
static void channel_clear_preshared(struct secure_preshared_identity *psid)
Clear pre-shared bound peer identity.
static int channel_is_established(struct secure_channel *channel)
Check if secure channel has been established.
Cryptographic configuration.
#define TLS_VERSION_MAX
Maximum TLS version.
#define TLS_VERSION_MIN
Minimum TLS version.
struct cipher_algorithm cipher_null
struct exchange_algorithm exchange_null
struct pubkey_algorithm pubkey_null
struct digest_algorithm digest_null
uint32_t next
Next descriptor address.
struct eltorito_descriptor_fixed fixed
Fixed portion.
uint16_t ext
Extended status.
uint32_t type
Operating system type.
uint8_t data[48]
Additional event data.
uint16_t spec
ENA specification version.
struct ena_llq_option header
Header locations.
uint8_t meta
Metadata flags.
uint16_t group
Type of event.
uint8_t mac[ETH_ALEN]
MAC address.
struct eth_slow_lacp_entity_tlv partner
Partner information.
int ffdhe_has_params(struct exchange_algorithm *exchange, const void *dh_p, size_t dh_p_len, const void *dh_g, size_t dh_g_len)
Check group parameters.
Finite Field Diffie-Hellman Ephemeral key exchange.
static int is_ffdhe(struct exchange_algorithm *exchange)
Check if key exchange algorithm is a finite field DHE group.
#define __unused
Declare a variable or data structure as unused.
static unsigned int count
Number of entries.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define REQUIRE_OBJECT(object)
Require an object.
#define ENOMEM
Not enough space.
#define ENOTCONN
The socket is not connected.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
#define REQUIRING_SYMBOL(symbol)
Specify the file's requiring symbol.
void hmac_init(struct digest_algorithm *digest, void *ctx, const void *secret, size_t len)
Initialise HMAC.
void hmac_final(struct digest_algorithm *digest, void *ctx, void *hmac)
Finalise HMAC.
Keyed-Hashing for Message Authentication.
static void hmac_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Update HMAC.
static size_t hmac_ctxsize(struct digest_algorithm *digest)
Calculate HMAC context size.
#define cpu_to_be16(value)
#define cpu_to_le32(value)
#define cpu_to_be64(value)
#define be16_to_cpu(value)
static int is_block_cipher(struct cipher_algorithm *cipher)
static int cipher_setiv(struct cipher_algorithm *cipher, void *ctx, const void *iv, size_t ivlen)
#define cipher_decrypt(cipher, ctx, src, dst, len)
static int is_auth_cipher(struct cipher_algorithm *cipher)
static int pubkey_sign(struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, struct asn1_builder *signature)
#define cipher_encrypt(cipher, ctx, src, dst, len)
static void cipher_auth(struct cipher_algorithm *cipher, void *ctx, void *auth)
uint32_t pending
Pending events.
struct hv_monitor_parameter param[4][32]
Parameters.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
void * memmove(void *dest, const void *src, size_t len) __nonnull
void intf_close(struct interface *intf, int rc)
Close an object interface.
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
void intf_insert(struct interface *intf, struct interface *upper, struct interface *lower)
Insert a filter interface.
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
#define INTF_DESC_PASSTHRU(object_type, intf, operations, passthru)
Define an object interface descriptor with pass-through interface.
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
struct io_buffer * alloc_iob_raw(size_t len, size_t align, size_t offset)
Allocate I/O buffer with specified alignment and offset.
struct io_buffer * iob_concatenate(struct list_head *list)
Concatenate I/O buffers into a single buffer.
#define iob_push(iobuf, len)
static void iob_populate(struct io_buffer *iobuf, void *data, size_t len, size_t max_len)
Create a temporary I/O buffer.
#define iob_put(iobuf, len)
#define iob_disown(iobuf)
Disown an I/O buffer.
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
#define iob_reserve(iobuf, len)
#define iob_pull(iobuf, len)
#define iob_unput(iobuf, len)
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
int job_progress(struct interface *intf, struct job_progress *progress)
Get job progress.
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
#define list_last_entry(list, type, member)
Get the container of the last entry in a list.
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
#define list_del(list)
Delete an entry from a list.
#define INIT_LIST_HEAD(list)
Initialise a list head.
#define list_empty(list)
Test whether a list is empty.
#define LIST_HEAD(list)
Declare a static list head.
#define list_add(new, head)
Add a new entry to the head of a list.
void * zalloc(size_t size)
Allocate cleared memory.
void * malloc(size_t size)
Allocate memory.
void zfree(void *ptr)
Clear and free memory.
struct digest_algorithm md5_sha1_algorithm
Hybrid MD5+SHA1 digest algorithm.
Hybrid MD5+SHA1 hash as used by TLSv1.1 and earlier.
void alert(unsigned int row, const char *fmt,...)
Show alert message.
uint32_t channel
RNDIS channel.
static uint16_t struct vmbus_xfer_pages_operations * op
Data transfer interface opening.
uint32_t first
First block in range.
uint32_t digestsize
Digest size (i.e.
void pending_put(struct pending_operation *pending)
Mark an operation as no longer pending.
void pending_get(struct pending_operation *pending)
Mark an operation as pending.
static int is_pending(struct pending_operation *pending)
Check if an operation is pending.
static struct asn1_cursor * privkey_cursor(struct private_key *key)
Get private key ASN.1 cursor.
static void privkey_put(struct private_key *key)
Drop reference to private key.
static struct private_key * privkey_get(struct private_key *key)
Get reference to private key.
void process_del(struct process *process)
Remove process from process list.
void process_add(struct process *process)
Add process to process list.
#define PROC_DESC_ONCE(object_type, process, _step)
Define a process descriptor for a process that runs only once.
static void process_init_stopped(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process without adding to process list.
long int random(void)
Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
static void(* free)(struct refcnt *refcnt))
#define ref_get(refcnt)
Get additional reference to object.
#define ref_put(refcnt)
Drop reference to object.
#define ref_init(refcnt, free)
Initialise a reference counter.
struct x509_root root_certificates
Root certificates.
#define container_of(ptr, type, field)
Get containing structure.
struct stp_switch root
Root switch.
uint16_t hello
Hello time.
char * strerror(int errno)
Retrieve string representation of error number.
void * memswap(void *first, void *second, size_t len)
Swap memory regions.
int strcmp(const char *first, const char *second)
Compare strings.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
char * strcpy(char *dest, const char *src)
Copy string.
size_t strlen(const char *src)
Get length of string.
struct pubkey_algorithm * pubkey
Public-key algorithm (if applicable).
size_t len
Length of data.
const void * data
Start of data.
size_t len
Length of data.
const char * name
Algorithm name.
size_t blocksize
Block size.
size_t authsize
Authentication tag size.
size_t alignsize
Alignment size.
A message digest algorithm.
size_t digestsize
Digest size.
const char * name
Algorithm name.
A key exchange algorithm.
size_t sharedsize
Shared secret size.
size_t pubsize
Public key size.
const char * name
Algorithm name.
An object interface descriptor.
An object interface operation.
void * data
Start of data.
struct list_head list
List of which this buffer is a member.
A doubly-linked list entry (or list head).
const char * name
Algorithm name.
Secure channel operations.
struct secure_pipe tx
Transmit pipe.
struct secure_pipe rx
Receive pipe.
A secure channel transmit or receive pipe.
void * ctx
Cipher context.
struct cipher_algorithm * cipher
Cipher algorithm.
A pre-shared bound peer identity.
uint8_t fixed_iv_len
Fixed initialisation vector length.
struct cipher_algorithm * cipher
Bulk encryption cipher algorithm.
struct pubkey_algorithm * pubkey
Public-key encryption algorithm.
uint8_t key_len
Key length.
uint8_t mac_len
MAC length.
uint8_t record_iv_len
Record initialisation vector length.
struct digest_algorithm * digest
MAC digest algorithm.
struct tls_key_exchange_algorithm * exchange
Key exchange algorithm.
uint16_t code
Numeric code (in network-endian order).
struct digest_algorithm * handshake
Handshake digest algorithm (for TLSv1.2 and above).
A TLS cipher specification pair.
struct tls_cipherspec pending
Next cipher specification.
struct tls_cipherspec active
Current cipher specification.
const struct tls_endpoint * writer
Writer endpoint.
A TLS cipher specification.
void * fixed_iv
Fixed initialisation vector.
void * cipher_key
Cipher key.
struct tls_cipher_suite * suite
Cipher suite.
void * dynamic
Dynamically-allocated storage.
void * mac_secret
MAC secret.
struct private_key * key
Private key.
struct x509_chain * chain
Certificate chain (if any).
struct pending_operation negotiation
Security negotiation pending operation.
struct interface cipherstream
Ciphertext stream.
struct tls_session * session
Session.
struct tls_server server
Server state.
struct tls_key_schedule key
Key schedule.
struct tls_rx rx
Receive state.
struct tls_session_ticket new_ticket
New session ticket (if any).
struct tls_verify_data verify
Verification data.
struct secure_channel channel
Secure channel.
struct interface plainstream
Plaintext stream.
struct tls_tx tx
Transmit state.
struct exchange_algorithm * exchange
Key exchange algorithm.
int extended_master_secret
Extended master secret flag.
struct list_head list
List of connections within the same session.
struct tls_client client
Client state.
uint16_t version
Protocol version.
struct tls_session_id new_id
New session ID (if any).
struct refcnt refcnt
Reference counter.
int secure_renegotiation
Secure renegotiation flag.
const char name[7]
Name (for key expansion labels).
A TLS key exchange algorithm.
const char * name
Algorithm name.
struct exchange_algorithm * exchange
Default key exchange algorithm.
int(* parse)(struct tls_connection *tls, const void *data, size_t len, struct tls_key_exchange_parameters *params)
Parse key exchange parameters from Server Key Exchange record.
uint8_t len_len
Length of length field in Client Key Exchange record.
TLS key exchange parameters.
struct exchange_algorithm * exchange
Key exchange algorithm.
size_t len
Length of parameters (excluding trailing signature).
size_t partner_len
Length of partner key.
const void * partner
Partner key.
TLS key schedule operations.
struct digest_algorithm * digest
Digest algorithm.
TLS client or server random bytes.
struct tls_cipherspec_pair cipherspec
Cipher specifications.
struct list_head data
List of received data buffers.
struct io_buffer iobuf
Current received record header (static I/O buffer).
struct io_buffer * handshake
Received handshake fragment (if any).
enum tls_rx_state state
State machine current state.
struct tls_header header
Current received record header.
uint64_t seq
Sequence number.
struct pending_operation validation
Certificate validation pending operation.
struct interface validator
Certificate validator.
struct x509_root * root
Root of trust.
struct pending_operation negotiation
Security negotiation pending operation.
struct x509_chain * chain
Certificate chain (if any).
size_t len
Length of ticket data.
struct private_key * key
Private key.
const char * name
Server name.
struct secure_preshared_identity psid
Bound peer identity.
struct x509_root * root
Root of trust.
struct tls_preshared_key psk
Pre-shared key.
struct list_head conn
List of connections.
struct refcnt refcnt
Reference counter.
struct tls_session_ticket ticket
Session ticket.
struct tls_session_id id
Session ID.
struct list_head list
List of sessions.
A TLS signature algorithm.
struct asn1_algorithm * algorithm
Required certificate OID-identified algorithm.
struct pubkey_algorithm * pubkey
Public-key algorithm.
uint16_t code
Numeric code (in network-endian order).
struct digest_algorithm * digest
Digest algorithm.
uint64_t seq
Sequence number.
unsigned int pending
Pending transmissions.
struct tls_cipherspec_pair cipherspec
Cipher specifications.
struct process process
Transmit process.
uint8_t client[12]
Client verification data.
uint8_t server[12]
Server verification data.
struct x509_subject subject
Subject.
struct asn1_cursor raw
Raw certificate.
struct asn1_algorithm * signature_algorithm
Signature algorithm.
struct list_head links
List of links.
A link in an X.509 certificate chain.
struct asn1_algorithm * algorithm
Public key algorithm.
An X.509 root certificate list.
struct x509_public_key public_key
Public key information.
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
static struct io_buffer * tls_alloc_iob(struct tls_connection *tls, size_t len)
Allocate I/O buffer for transmitted record(s).
#define EINVAL_CHANGE_CIPHER
static struct interface_descriptor tls_cipherstream_desc
TLS ciphertext stream interface descriptor.
static void tls_hmac_init(struct tls_cipherspec *cipherspec, void *ctx, struct tls_auth_header *authhdr)
Initialise HMAC.
static int tls_new_ciphertext(struct tls_connection *tls, struct tls_header *tlshdr, struct list_head *rx_data)
Receive new ciphertext record.
static int tls_send_handshake(struct tls_connection *tls, const void *data, size_t len)
Transmit Handshake record.
static int tls_new_finished(struct tls_connection *tls, const void *data, size_t len)
Receive new Finished handshake record.
static int tls_progress(struct tls_connection *tls, struct job_progress *progress)
Report job progress.
static const char * tls_pipe_name(struct tls_connection *tls, struct secure_pipe *pipe)
Get pipe name (for debugging).
static void tls_validator_done(struct tls_connection *tls, int rc)
Handle certificate validation completion.
static int tls_resume(struct tls_connection *tls)
Resume session.
#define EINVAL_KEY_EXCHANGE
static int tls_send_alert(struct tls_connection *tls, unsigned int level, unsigned int description)
Transmit Alert record.
static int tls_set_digest(struct tls_connection *tls, struct digest_algorithm *digest)
Set key schedule digest algorithm.
static int tls_send_certificate(struct tls_connection *tls)
Transmit Certificate record.
static void tls_tx_resume(struct tls_connection *tls)
Resume TX state machine.
static struct interface_operation tls_validator_ops[]
TLS certificate validator interface operations.
static void free_tls_session(struct refcnt *refcnt)
Free TLS session.
static int tls_new_change_cipher(struct tls_connection *tls, struct io_buffer *iobuf)
Receive new Change Cipher record.
static void tls_clear_digest(struct tls_connection *tls)
Clear key schedule digest algorithm.
static void tls_tx_step(struct tls_connection *tls)
TLS TX state machine.
#define EINVAL_CERTIFICATES
static int tls_newdata_process_data(struct tls_connection *tls)
Handle received TLS data payload.
static int tls_change_cipher(struct tls_connection *tls, struct tls_cipherspec_pair *pair, struct secure_pipe *pipe)
Activate next cipher suite.
#define ENOENT_KEY_EXCHANGE
#define EPERM_KEY_EXCHANGE
static int tls_send_finished(struct tls_connection *tls)
Transmit Finished record.
static int tls_channel_save(struct secure_channel *channel, struct secure_preshared_identity *psid)
Save a pre-shared key for future resumption of the key schedule.
static struct interface_operation tls_cipherstream_ops[]
TLS ciphertext stream interface operations.
static struct secure_channel_operations tls_channel_ops
Secure channel operations.
#define EINVAL_CERTIFICATE
static int tls_send_record(struct tls_connection *tls, unsigned int type, struct io_buffer *iobuf)
Send plaintext record(s).
static int tls_set_cipher(struct tls_connection *tls, struct tls_cipherspec *cipherspec, struct tls_cipher_suite *suite)
Set cipher specification.
#define ENOMEM_CERTIFICATE
static int tls_send_client_hello(struct tls_connection *tls)
Transmit Client Hello record.
static int tls_client_hello(struct tls_connection *tls, int(*action)(struct tls_connection *tls, const void *data, size_t len))
Digest or transmit Client Hello record.
static int tls_save(struct tls_connection *tls)
Save session for future resumption.
static struct tls_cipher_suite * tls_find_cipher_suite(unsigned int cipher_suite)
Identify cipher suite.
static struct interface_descriptor tls_validator_desc
TLS certificate validator interface descriptor.
static void tls_set_uint24(tls24_t *field24, unsigned long value)
Set 24-bit field value.
static int tls_cipherstream_deliver(struct tls_connection *tls, struct io_buffer *iobuf, struct xfer_metadata *xfer __unused)
Receive new ciphertext.
static void tls_hmac_final(struct tls_cipherspec *cipherspec, void *ctx, void *hmac)
Finalise HMAC.
static const char * tls_cipher_name(struct tls_cipher_suite *suite)
Get cipher suite name (for debugging).
#define ENOMEM_TX_PLAINTEXT
#define EINVAL_HELLO_DONE
static int tls_key_agree(struct tls_connection *tls, struct exchange_algorithm *exchange, const void *partner, size_t len)
Agree shared secret.
#define TLS_NUM_CIPHER_SUITES
Number of supported cipher suites.
static int tls_newdata_process_header(struct tls_connection *tls)
Handle received TLS header.
static int tls_send_client_key_exchange(struct tls_connection *tls)
Transmit Client Key Exchange record.
static int tls_version(struct tls_connection *tls, unsigned int version)
Check for TLS version.
static struct tls_named_group * tls_find_param_group(const void *dh_p, size_t dh_p_len, const void *dh_g, size_t dh_g_len)
Identify named key exchange group by Diffie-Hellman parameters.
static int tls_ready(struct tls_connection *tls)
Determine if TLS connection is ready for application data.
static struct interface_descriptor tls_plainstream_desc
TLS plaintext stream interface descriptor.
static int tls_plainstream_deliver(struct tls_connection *tls, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
Deliver datagram as raw data.
struct tls_key_exchange_algorithm tls_null_exchange_algorithm
Null key exchange algorithm.
static void tls_nonce(struct tls_connection *tls, struct tls_random *nonce)
Generate deterministic connection nonce.
static int tls_session(struct tls_connection *tls, const char *name)
Find or create session for TLS connection.
static void free_tls(struct refcnt *refcnt)
Free TLS connection.
static int tls_establish(struct tls_connection *tls)
Establish secure channel.
static void tls_restart(struct tls_connection *tls)
Restart negotiation.
struct tls_cipher_suite tls_cipher_suite_null
Null cipher suite.
static int tls_channel_load(struct secure_channel *channel, struct secure_preshared_identity *psid)
Load a pre-shared key and resume the key schedule.
struct tls_key_exchange_algorithm tls_pubkey_exchange_algorithm
Public key exchange algorithm.
static size_t tls_plainstream_window(struct tls_connection *tls)
Check flow control window.
static void tls_hmac_list(struct tls_cipherspec *cipherspec, struct tls_auth_header *authhdr, struct list_head *list, void *hmac)
Calculate HMAC over list of I/O buffers.
static int tls_send_change_cipher(struct tls_connection *tls)
Transmit Change Cipher record.
struct tls_key_exchange_algorithm tls_ecdhe_exchange_algorithm
Ephemeral Elliptic Curve Diffie-Hellman key exchange algorithm.
static struct tls_named_group * tls_find_named_group(unsigned int named_group)
Identify named key exchange group.
static size_t tls_cipherstream_window(struct tls_connection *tls)
Check flow control window.
static int tls_send_plaintext(struct tls_connection *tls, unsigned int type, const void *data, size_t len)
Send plaintext record.
static void tls_hmac(struct tls_cipherspec *cipherspec, struct tls_auth_header *authhdr, const void *data, size_t len, void *hmac)
Calculate HMAC.
static void tls_channel_reset(struct secure_channel *channel)
Reset the key schedule.
static void tls_hmac_update(struct tls_cipherspec *cipherspec, void *ctx, const void *data, size_t len)
Update HMAC.
static int tls_channel_verify(struct secure_channel *channel, const void *auth, size_t len)
Verify authenticator value.
#define EPERM_RENEG_INSECURE
static int tls_key_build(struct tls_connection *tls, struct exchange_algorithm *exchange, struct asn1_builder *builder)
Build shareable key.
static int tls_new_server_hello(struct tls_connection *tls, const void *data, size_t len)
Receive new Server Hello handshake record.
static int tls_parse_ecdhe(struct tls_connection *tls, const void *data, size_t len, struct tls_key_exchange_parameters *params)
Parse key exchange parameters from ECDHE Server Key Exchange record.
static int tls_send_certificate_verify(struct tls_connection *tls)
Transmit Certificate Verify record.
static void tls_close_alert(struct tls_connection *tls, int rc)
Send closure alert and finish with TLS connection.
static int tls_keysize_is_variable(struct tls_connection *tls, struct exchange_algorithm *exchange)
Check if key exchange keys have a variable size.
static int tls_key_share(struct tls_connection *tls, struct exchange_algorithm *exchange, void *public, size_t len)
Share public key.
static void tls_close(struct tls_connection *tls, int rc)
Finish with TLS connection.
static int tls_select_cipher(struct tls_connection *tls, unsigned int cipher_suite)
Select cipher suite.
static int tls_new_certificate_request(struct tls_connection *tls, const void *data __unused, size_t len __unused)
Receive new Certificate Request handshake record.
static int tls_parse_null(struct tls_connection *tls, const void *data, size_t len, struct tls_key_exchange_parameters *params __unused)
Parse key exchange parameters from unexpected Server Key Exchange record.
static int tls_verify_padding(struct tls_connection *tls, struct io_buffer *iobuf)
Verify block padding.
static struct process_descriptor tls_process_desc
TLS TX process descriptor.
static int tls_new_session_ticket(struct tls_connection *tls, const void *data, size_t len)
Receive New Session Ticket handshake record.
#define EPERM_RENEG_VERIFY
static int tls_new_unknown(struct tls_connection *tls __unused, struct io_buffer *iobuf)
Receive new unknown record.
struct tls_key_exchange_algorithm tls_dhe_exchange_algorithm
Ephemeral Diffie-Hellman key exchange algorithm.
static int tls_new_data(struct tls_connection *tls, struct list_head *rx_data)
Receive new data record.
#define TLS_NUM_SIG_HASH_ALGORITHMS
Number of supported signature and hash algorithms.
static int tls_new_hello_request(struct tls_connection *tls, const void *data __unused, size_t len __unused)
Receive new Hello Request handshake record.
static int tls_new_handshake(struct tls_connection *tls, struct io_buffer *iobuf)
Receive new Handshake record.
static size_t tls_iob_reserved(struct tls_connection *tls, size_t len)
Calculate maximum additional length required for transmitted record(s).
static struct tls_signature_hash_algorithm * tls_signature_hash_algorithm(struct pubkey_algorithm *pubkey, struct digest_algorithm *digest)
Find TLS signature and hash algorithm.
static struct interface_operation tls_plainstream_ops[]
TLS plaintext stream interface operations.
static int tls_parse_chain(struct tls_connection *tls, const void *data, size_t len)
Parse certificate chain.
static int tls_new_certificate(struct tls_connection *tls, const void *data, size_t len)
Receive new Certificate handshake record.
static int tls_new_server_hello_done(struct tls_connection *tls, const void *data, size_t len)
Receive new Server Hello Done handshake record.
static int tls_channel_apply(struct secure_channel *channel, struct exchange_algorithm *exchange, const void *shared, int *accumulated)
Apply a new shared secret to key schedule.
static int tls_add_handshake(struct tls_connection *tls, const void *data, size_t len)
Add handshake record to verification hash.
static int tls_new_record(struct tls_connection *tls, unsigned int type, struct list_head *rx_data)
Receive new record.
static unsigned long tls_uint24(const tls24_t *field24)
Extract 24-bit field value.
static void tls_clear_cipher(struct tls_connection *tls, struct tls_cipherspec *cipherspec)
static int tls_key_encrypt(struct tls_connection *tls, struct exchange_algorithm *exchange, struct asn1_builder *builder)
Encrypt (and implicitly bind) shared secret.
static int tls_new_server_key_exchange(struct tls_connection *tls, const void *data, size_t len)
Receive new Server Key Exchange handshake record.
static int tls_parse_dhe(struct tls_connection *tls, const void *data, size_t len, struct tls_key_exchange_parameters *params)
Parse key exchange parameters from DHE Server Key Exchange record.
static int tls_new_alert(struct tls_connection *tls, struct io_buffer *iobuf)
Receive new Alert record.
static void tls_tx_resume_all(struct tls_session *session)
Resume TX state machine for all connections within a session.
static struct tls_signature_hash_algorithm * tls_find_signature_hash(unsigned int code)
Find TLS signature and hash algorithm.
int add_tls(struct interface *xfer, const char *name, struct x509_root *root, struct private_key *key)
Add TLS on an interface.
Transport Layer Security Protocol.
#define TLS_SERVER_KEY_EXCHANGE
#define TLS_TYPE_ALERT
Alert content type.
#define TLS_TX_BUFSIZE
TX maximum fragment length.
#define TLS_NEW_SESSION_TICKET
#define TLS_CLIENT_KEY_EXCHANGE
#define TLS_VERSION_TLS_1_2
TLS version 1.2.
#define TLS_NUM_NAMED_GROUPS
Number of non-anonymous TLS named groups.
#define TLS_CHANGE_CIPHER_SPEC
Change cipher spec magic byte.
#define TLS_CIPHER_SUITES
TLS cipher suite table.
#define TLS_VERSION_TLS_1_3
TLS version 1.3.
#define TLS_EXTENDED_MASTER_SECRET
#define TLS_RENEGOTIATION_INFO
#define TLS_RX_MIN_BUFSIZE
Minimum RX I/O buffer size.
#define TLS_MAX_FRAGMENT_LENGTH_VALUE
Advertised maximum fragment length.
#define TLS_CERTIFICATE_VERIFY
#define TLS_ALERT_CLOSE_NOTIFY
#define TLS_HELLO_REQUEST
#define TLS_RX_ALIGN
RX I/O buffer alignment.
#define TLS_TYPE_HANDSHAKE
Handshake content type.
#define TLS_TYPE_DATA
Application data content type.
#define TLS_ALERT_WARNING
#define TLS_CERTIFICATE_REQUEST
@ TLS_TX_CLIENT_KEY_EXCHANGE
@ TLS_TX_CERTIFICATE_VERIFY
#define TLS_TYPE_CHANGE_CIPHER
Change cipher content type.
#define TLS_SERVER_NAME_HOST_NAME
#define TLS_SIG_HASH_ALGORITHMS
TLS signature hash algorithm table.
#define TLS_SERVER_HELLO_DONE
#define TLS_MAX_FRAGMENT_LENGTH
#define TLS_RX_BUFSIZE
RX I/O buffer size.
#define TLS_NAMED_CURVE_TYPE
TLS named curve type.
#define TLS_SESSION_TICKET
#define TLS_NAMED_GROUPS
TLS named group table.
#define TLS_SIGNATURE_ALGORITHMS
struct exchange_algorithm tls_classic_pre_master_algorithm
Classic pre-master secret key exchange algorithm.
int tlskey_save(struct tls_key_schedule *tlskey, const void *nonce, size_t nonce_len, struct tls_preshared_key *psk)
Save pre-shared key.
int tlskey_master(struct tls_key_schedule *tlskey, int ems)
Generate master secret.
int tlskey_cipher(struct tls_key_schedule *tlskey, const struct tls_endpoint *writer, void *key, size_t key_len, void *iv, size_t iv_len, void *mac, size_t mac_len)
Generate cipher key material.
int tlskey_load(struct tls_key_schedule *tlskey, int ems, const struct tls_preshared_key *psk)
Load pre-shared key.
void tlskey_stop(struct tls_key_schedule *tlskey)
Stop key schedule.
void tlskey_reset(struct tls_key_schedule *tlskey)
Reset key schedule.
int tlskey_start(struct tls_key_schedule *tlskey, const struct tls_key_schedule_operations *op, struct digest_algorithm *digest, const struct tls_random *nonce)
Start key schedule.
int tlskey_tbshash(struct tls_key_schedule *tlskey, const struct tls_endpoint *end, struct digest_algorithm *digest, const void *data, size_t len, void *tbs)
Generate signable digest value.
int tlskey_apply(struct tls_key_schedule *tlskey, const void *shared, size_t shared_len)
Apply a new shared secret.
const struct tls_key_schedule_operations tlskey_hash
TLS key schedule based on P_Hash().
int tlskey_traffic(struct tls_key_schedule *tlskey, const struct tls_endpoint *writer, const struct tls_phase *phase)
Generate traffic secret.
const struct tls_key_schedule_operations tlskey_md5_sha1
TLS key schedule based on P_MD5()+P_SHA1().
int tlskey_verify(struct tls_key_schedule *tlskey, const struct tls_endpoint *end, void *verify, size_t verify_len)
Generate verification data.
void tlskey_digest(struct tls_key_schedule *tlskey, const void *data, size_t len)
Add handshake to running transcript digest.
const struct tls_phase tls_application
Application traffic phase.
static int tlskey_is_accumulating(struct tls_key_schedule *tlskey)
Check if key schedule accumulates shared secrets.
uint32_t data_len
Microcode data size (or 0 to indicate 2000 bytes).
int create_validator(struct interface *job, struct x509_chain *chain, struct x509_root *root)
Instantiate a certificate validator.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
u32 lifetime
For Lifetime-type KDEs, the lifetime in seconds.
u8 iv[16]
Initialization vector.
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
int x509_auto_append(struct x509_chain *chain, struct x509_chain *store)
Append X.509 certificates to X.509 certificate chain.
struct x509_chain * x509_alloc_chain(void)
Allocate X.509 certificate chain.
const char * x509_name(struct x509_certificate *cert)
Get X.509 certificate display name.
struct x509_certificate * x509_find_key(struct x509_chain *store, struct private_key *key)
Identify X.509 certificate by corresponding public key.
int x509_append_raw(struct x509_chain *chain, const void *data, size_t len)
Append X.509 certificate to X.509 certificate chain.
int x509_append(struct x509_chain *chain, struct x509_certificate *cert)
Append X.509 certificate to X.509 certificate chain.
static struct x509_certificate * x509_first(struct x509_chain *chain)
Get first certificate in X.509 certificate chain.
static struct x509_root * x509_root_get(struct x509_root *root)
Get reference to X.509 root certificate list.
static struct x509_certificate * x509_last(struct x509_chain *chain)
Get last certificate in X.509 certificate chain.
static void x509_root_put(struct x509_root *root)
Drop reference to X.509 root certificate list.
static void x509_chain_put(struct x509_chain *chain)
Drop reference to X.509 certificate chain.
size_t xfer_window(struct interface *intf)
Check flow control window.
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
int xfer_deliver_iob(struct interface *intf, struct io_buffer *iobuf)
Deliver datagram as I/O buffer without metadata.
Data transfer interfaces.