58#define EINVAL_CHANGE_CIPHER __einfo_error ( EINFO_EINVAL_CHANGE_CIPHER )
59#define EINFO_EINVAL_CHANGE_CIPHER \
60 __einfo_uniqify ( EINFO_EINVAL, 0x01, \
61 "Invalid Change Cipher record" )
62#define EINVAL_ALERT __einfo_error ( EINFO_EINVAL_ALERT )
63#define EINFO_EINVAL_ALERT \
64 __einfo_uniqify ( EINFO_EINVAL, 0x02, \
65 "Invalid Alert record" )
66#define EINVAL_HELLO __einfo_error ( EINFO_EINVAL_HELLO )
67#define EINFO_EINVAL_HELLO \
68 __einfo_uniqify ( EINFO_EINVAL, 0x03, \
69 "Invalid Server Hello record" )
70#define EINVAL_CERTIFICATE __einfo_error ( EINFO_EINVAL_CERTIFICATE )
71#define EINFO_EINVAL_CERTIFICATE \
72 __einfo_uniqify ( EINFO_EINVAL, 0x04, \
73 "Invalid Certificate" )
74#define EINVAL_CERTIFICATES __einfo_error ( EINFO_EINVAL_CERTIFICATES )
75#define EINFO_EINVAL_CERTIFICATES \
76 __einfo_uniqify ( EINFO_EINVAL, 0x05, \
77 "Invalid Server Certificate record" )
78#define EINVAL_HELLO_DONE __einfo_error ( EINFO_EINVAL_HELLO_DONE )
79#define EINFO_EINVAL_HELLO_DONE \
80 __einfo_uniqify ( EINFO_EINVAL, 0x06, \
81 "Invalid Server Hello Done record" )
82#define EINVAL_FINISHED __einfo_error ( EINFO_EINVAL_FINISHED )
83#define EINFO_EINVAL_FINISHED \
84 __einfo_uniqify ( EINFO_EINVAL, 0x07, \
85 "Invalid Server Finished record" )
86#define EINVAL_HANDSHAKE __einfo_error ( EINFO_EINVAL_HANDSHAKE )
87#define EINFO_EINVAL_HANDSHAKE \
88 __einfo_uniqify ( EINFO_EINVAL, 0x08, \
89 "Invalid Handshake record" )
90#define EINVAL_IV __einfo_error ( EINFO_EINVAL_IV )
91#define EINFO_EINVAL_IV \
92 __einfo_uniqify ( EINFO_EINVAL, 0x0a, \
93 "Invalid initialisation vector" )
94#define EINVAL_PADDING __einfo_error ( EINFO_EINVAL_PADDING )
95#define EINFO_EINVAL_PADDING \
96 __einfo_uniqify ( EINFO_EINVAL, 0x0b, \
97 "Invalid block padding" )
98#define EINVAL_RX_STATE __einfo_error ( EINFO_EINVAL_RX_STATE )
99#define EINFO_EINVAL_RX_STATE \
100 __einfo_uniqify ( EINFO_EINVAL, 0x0c, \
101 "Invalid receive state" )
102#define EINVAL_MAC __einfo_error ( EINFO_EINVAL_MAC )
103#define EINFO_EINVAL_MAC \
104 __einfo_uniqify ( EINFO_EINVAL, 0x0d, \
105 "Invalid MAC or authentication tag" )
106#define EINVAL_TICKET __einfo_error ( EINFO_EINVAL_TICKET )
107#define EINFO_EINVAL_TICKET \
108 __einfo_uniqify ( EINFO_EINVAL, 0x0e, \
109 "Invalid New Session Ticket record")
110#define EINVAL_KEY_EXCHANGE __einfo_error ( EINFO_EINVAL_KEY_EXCHANGE )
111#define EINFO_EINVAL_KEY_EXCHANGE \
112 __einfo_uniqify ( EINFO_EINVAL, 0x0f, \
113 "Invalid Server Key Exchange record" )
114#define EIO_ALERT __einfo_error ( EINFO_EIO_ALERT )
115#define EINFO_EIO_ALERT \
116 __einfo_uniqify ( EINFO_EIO, 0x01, \
117 "Unknown alert level" )
118#define ENOMEM_CONTEXT __einfo_error ( EINFO_ENOMEM_CONTEXT )
119#define EINFO_ENOMEM_CONTEXT \
120 __einfo_uniqify ( EINFO_ENOMEM, 0x01, \
121 "Not enough space for crypto context" )
122#define ENOMEM_CERTIFICATE __einfo_error ( EINFO_ENOMEM_CERTIFICATE )
123#define EINFO_ENOMEM_CERTIFICATE \
124 __einfo_uniqify ( EINFO_ENOMEM, 0x02, \
125 "Not enough space for certificate" )
126#define ENOMEM_CHAIN __einfo_error ( EINFO_ENOMEM_CHAIN )
127#define EINFO_ENOMEM_CHAIN \
128 __einfo_uniqify ( EINFO_ENOMEM, 0x03, \
129 "Not enough space for certificate chain" )
130#define ENOMEM_TX_PLAINTEXT __einfo_error ( EINFO_ENOMEM_TX_PLAINTEXT )
131#define EINFO_ENOMEM_TX_PLAINTEXT \
132 __einfo_uniqify ( EINFO_ENOMEM, 0x04, \
133 "Not enough space for transmitted plaintext" )
134#define ENOMEM_TX_CIPHERTEXT __einfo_error ( EINFO_ENOMEM_TX_CIPHERTEXT )
135#define EINFO_ENOMEM_TX_CIPHERTEXT \
136 __einfo_uniqify ( EINFO_ENOMEM, 0x05, \
137 "Not enough space for transmitted ciphertext" )
138#define ENOMEM_RX_DATA __einfo_error ( EINFO_ENOMEM_RX_DATA )
139#define EINFO_ENOMEM_RX_DATA \
140 __einfo_uniqify ( EINFO_ENOMEM, 0x07, \
141 "Not enough space for received data" )
142#define ENOMEM_RX_CONCAT __einfo_error ( EINFO_ENOMEM_RX_CONCAT )
143#define EINFO_ENOMEM_RX_CONCAT \
144 __einfo_uniqify ( EINFO_ENOMEM, 0x08, \
145 "Not enough space to concatenate received data" )
146#define ENOTSUP_CIPHER __einfo_error ( EINFO_ENOTSUP_CIPHER )
147#define EINFO_ENOTSUP_CIPHER \
148 __einfo_uniqify ( EINFO_ENOTSUP, 0x01, \
149 "Unsupported cipher" )
150#define ENOTSUP_NULL __einfo_error ( EINFO_ENOTSUP_NULL )
151#define EINFO_ENOTSUP_NULL \
152 __einfo_uniqify ( EINFO_ENOTSUP, 0x02, \
153 "Refusing to use null cipher" )
154#define ENOTSUP_SIG_HASH __einfo_error ( EINFO_ENOTSUP_SIG_HASH )
155#define EINFO_ENOTSUP_SIG_HASH \
156 __einfo_uniqify ( EINFO_ENOTSUP, 0x03, \
157 "Unsupported signature and hash algorithm" )
158#define ENOTSUP_VERSION __einfo_error ( EINFO_ENOTSUP_VERSION )
159#define EINFO_ENOTSUP_VERSION \
160 __einfo_uniqify ( EINFO_ENOTSUP, 0x04, \
161 "Unsupported protocol version" )
162#define ENOTSUP_CURVE __einfo_error ( EINFO_ENOTSUP_CURVE )
163#define EINFO_ENOTSUP_CURVE \
164 __einfo_uniqify ( EINFO_ENOTSUP, 0x05, \
165 "Unsupported elliptic curve" )
166#define EPERM_ALERT __einfo_error ( EINFO_EPERM_ALERT )
167#define EINFO_EPERM_ALERT \
168 __einfo_uniqify ( EINFO_EPERM, 0x01, \
169 "Received fatal alert" )
170#define EPERM_VERIFY __einfo_error ( EINFO_EPERM_VERIFY )
171#define EINFO_EPERM_VERIFY \
172 __einfo_uniqify ( EINFO_EPERM, 0x02, \
173 "Handshake verification failed" )
174#define EPERM_RENEG_INSECURE __einfo_error ( EINFO_EPERM_RENEG_INSECURE )
175#define EINFO_EPERM_RENEG_INSECURE \
176 __einfo_uniqify ( EINFO_EPERM, 0x04, \
177 "Secure renegotiation not supported" )
178#define EPERM_RENEG_VERIFY __einfo_error ( EINFO_EPERM_RENEG_VERIFY )
179#define EINFO_EPERM_RENEG_VERIFY \
180 __einfo_uniqify ( EINFO_EPERM, 0x05, \
181 "Secure renegotiation verification failed" )
182#define EPERM_KEY_EXCHANGE __einfo_error ( EINFO_EPERM_KEY_EXCHANGE )
183#define EINFO_EPERM_KEY_EXCHANGE \
184 __einfo_uniqify ( EINFO_EPERM, 0x06, \
185 "ServerKeyExchange verification failed" )
186#define EPERM_EMS __einfo_error ( EINFO_EPERM_EMS )
187#define EINFO_EPERM_EMS \
188 __einfo_uniqify ( EINFO_EPERM, 0x07, \
189 "Extended master secret extension mismatch" )
190#define EPROTO_VERSION __einfo_error ( EINFO_EPROTO_VERSION )
191#define EINFO_EPROTO_VERSION \
192 __einfo_uniqify ( EINFO_EPROTO, 0x01, \
193 "Illegal protocol version upgrade" )
202 unsigned int description );
206 const void *
data,
size_t len );
472 DBGC ( tls,
"TLS %p could not generate random data: %s\n",
492 while ( (
data =
va_arg ( args,
void * ) ) ) {
511 const void *secret,
size_t secret_len,
512 void *
out,
size_t out_len,
521 DBGC2 ( tls,
"TLS %p %s secret:\n", tls, digest->
name );
522 DBGC2_HD ( tls, secret, secret_len );
530 DBGC2 ( tls,
"TLS %p %s A(1):\n", tls, digest->
name );
538 memcpy ( ctx_partial,
ctx,
sizeof ( ctx_partial ) );
545 if ( frag_len > out_len )
548 DBGC2 ( tls,
"TLS %p %s output:\n", tls, digest->
name );
553 DBGC2 ( tls,
"TLS %p %s A(n):\n", tls, digest->
name );
572 size_t secret_len,
void *
out,
size_t out_len, ... ) {
575 size_t subsecret_len;
576 const void *md5_secret;
577 const void *sha1_secret;
586 out, out_len, seeds );
593 subsecret_len = ( ( secret_len + 1 ) / 2 );
595 sha1_secret = ( secret + secret_len - subsecret_len );
600 subsecret_len,
out, out_len, seeds );
606 subsecret_len, buf, out_len, seeds );
610 for ( i = 0 ; i < out_len ; i++ )
627#define tls_prf_label( tls, secret, secret_len, out, out_len, label, ... ) \
628 tls_prf ( (tls), (secret), (secret_len), (out), (out_len), \
629 label, ( sizeof ( label ) - 1 ), __VA_ARGS__, NULL )
648 const void *pre_master_secret,
649 size_t pre_master_secret_len ) {
657 DBGC ( tls,
"TLS %p pre-master secret:\n", tls );
658 DBGC_HD ( tls, pre_master_secret, pre_master_secret_len );
659 DBGC ( tls,
"TLS %p client random bytes:\n", tls );
661 DBGC ( tls,
"TLS %p server random bytes:\n", tls );
663 DBGC ( tls,
"TLS %p session hash:\n", tls );
664 DBGC_HD ( tls, digest_out,
sizeof ( digest_out ) );
668 tls_prf_label ( tls, pre_master_secret, pre_master_secret_len,
671 "extended master secret",
672 digest_out, sizeof ( digest_out ) );
674 tls_prf_label ( tls, pre_master_secret, pre_master_secret_len,
685 DBGC ( tls,
"TLS %p generated %smaster secret:\n", tls,
703 size_t total = ( 2 * ( hash_size + key_size + iv_size ) );
710 key_block, sizeof ( key_block ),
"key expansion",
719 DBGC ( tls,
"TLS %p TX MAC secret:\n", tls );
725 DBGC ( tls,
"TLS %p RX MAC secret:\n", tls );
732 key, key_size ) ) != 0 ) {
733 DBGC ( tls,
"TLS %p could not set TX key: %s\n",
737 DBGC ( tls,
"TLS %p TX key:\n", tls );
744 key, key_size ) ) != 0 ) {
745 DBGC ( tls,
"TLS %p could not set TX key: %s\n",
749 DBGC ( tls,
"TLS %p RX key:\n", tls );
755 DBGC ( tls,
"TLS %p TX IV:\n", tls );
761 DBGC ( tls,
"TLS %p RX IV:\n", tls );
824 const void *
data,
size_t len ) {
863#define TLS_NUM_CIPHER_SUITES table_num_entries ( TLS_CIPHER_SUITES )
877 if ( suite->
code == cipher_suite )
893 memset ( cipherspec, 0,
sizeof ( *cipherspec ) );
917 dynamic =
zalloc ( total );
919 DBGC ( tls,
"TLS %p could not allocate %zd bytes for crypto "
920 "context\n", tls, total );
932 cipherspec->
suite = suite;
945 unsigned int cipher_suite ) {
953 DBGC ( tls,
"TLS %p does not support cipher %04x\n",
954 tls,
ntohs ( cipher_suite ) );
972 DBGC ( tls,
"TLS %p selected %s-%s-%s-%d-%s\n", tls,
992 DBGC ( tls,
"TLS %p refusing to use null cipher\n", tls );
1009#define TLS_NUM_SIG_HASH_ALGORITHMS \
1010 table_num_entries ( TLS_SIG_HASH_ALGORITHMS )
1081#define TLS_NUM_NAMED_CURVES table_num_entries ( TLS_NAMED_CURVES )
1095 if (
curve->code == named_curve )
1159 const void *
data,
size_t len ) {
1235 typeof ( *server_name_ext ) server_name;
1236 typeof ( *max_fragment_length_ext ) max_fragment_length;
1237 typeof ( *signature_algorithms_ext ) signature_algorithms;
1238 typeof ( *renegotiation_info_ext ) renegotiation_info;
1239 typeof ( *session_ticket_ext ) session_ticket;
1240 typeof ( *extended_master_secret_ext ) extended_master_secret;
1241 typeof ( *named_curve_ext )
1252 uint8_t compression_methods_len;
1253 uint8_t compression_methods[1];
1255 typeof ( *extensions ) extensions;
1266 sizeof (
hello.type_length ) ) );
1271 sizeof (
hello.session_id ) );
1275 hello.compression_methods_len =
sizeof (
hello.compression_methods );
1277 extensions = &
hello.extensions;
1280 server_name_ext = &extensions->server_name;
1282 server_name_ext->len =
htons (
sizeof ( server_name_ext->data ) );
1283 server_name_ext->data.len
1284 =
htons (
sizeof ( server_name_ext->data.list ) );
1286 server_name_ext->data.list[0].len
1287 =
htons (
sizeof ( server_name_ext->data.list[0].name ) );
1288 memcpy ( server_name_ext->data.list[0].name, session->
name,
1289 sizeof ( server_name_ext->data.list[0].name ) );
1292 max_fragment_length_ext = &extensions->max_fragment_length;
1294 max_fragment_length_ext->len
1295 =
htons (
sizeof ( max_fragment_length_ext->data ) );
1299 signature_algorithms_ext = &extensions->signature_algorithms;
1301 signature_algorithms_ext->len
1302 =
htons (
sizeof ( signature_algorithms_ext->data ) );
1303 signature_algorithms_ext->data.len
1304 =
htons (
sizeof ( signature_algorithms_ext->data.code ) );
1306 signature_algorithms_ext->data.code[i++] = sighash->
code;
1309 renegotiation_info_ext = &extensions->renegotiation_info;
1311 renegotiation_info_ext->len
1312 =
htons (
sizeof ( renegotiation_info_ext->data ) );
1313 renegotiation_info_ext->data.len
1314 =
sizeof ( renegotiation_info_ext->data.data );
1316 sizeof ( renegotiation_info_ext->data.data ) );
1319 session_ticket_ext = &extensions->session_ticket;
1321 session_ticket_ext->len
1322 =
htons (
sizeof ( session_ticket_ext->data ) );
1323 memcpy ( session_ticket_ext->data.data, session->
ticket,
1324 sizeof ( session_ticket_ext->data.data ) );
1327 extended_master_secret_ext = &extensions->extended_master_secret;
1328 extended_master_secret_ext->type
1330 extended_master_secret_ext->len = 0;
1333 if (
sizeof ( extensions->named_curve ) ) {
1334 named_curve_ext = &extensions->named_curve[0];
1336 named_curve_ext->len
1337 =
htons (
sizeof ( named_curve_ext->data ) );
1338 named_curve_ext->data.len
1339 =
htons (
sizeof ( named_curve_ext->data.code ) );
1341 named_curve_ext->data.code[i++] =
curve->code;
1344 return action ( tls, &
hello,
sizeof (
hello ) );
1372 typeof ( *certificate ) certificates[0];
1383 len += (
sizeof ( *certificate ) + cert->
raw.
len );
1384 DBGC ( tls,
"TLS %p sending client certificate %s\n",
1396 certificates =
iob_put ( iobuf,
sizeof ( *certificates ) );
1397 certificates->type_length =
1399 htonl (
sizeof ( *certificates ) +
len -
1400 sizeof ( certificates->type_length ) ) );
1404 certificate =
iob_put ( iobuf,
sizeof ( *certificate ) );
1429 .data = &pre_master_secret,
1430 .len =
sizeof ( pre_master_secret ),
1438 ( sizeof ( pre_master_secret.random ) ) ) ) != 0 ) {
1444 &builder ) ) != 0 ) {
1445 DBGC ( tls,
"TLS %p could not encrypt pre-master secret: %s\n",
1454 uint16_t encrypted_pre_master_secret_len;
1460 sizeof (
header.type_length ) ) );
1464 sizeof (
header ) ) ) != 0 ) {
1465 DBGC ( tls,
"TLS %p could not construct Client Key "
1473 builder.
len ) ) != 0 ) {
1479 sizeof ( pre_master_secret ) );
1503 size_t param_len ) {
1519 assert ( param_len <= tls->server.exchange_len );
1525 if ( (
sizeof ( *
sig ) > remaining ) ||
1526 (
ntohs (
sig->signature_len ) > ( remaining -
1527 sizeof ( *
sig ) ) ) ) {
1528 DBGC ( tls,
"TLS %p received underlength ServerKeyExchange\n",
1538 if ( use_sig_hash ) {
1541 if ( ( ! pubkey ) || ( ! digest ) ) {
1542 DBGC ( tls,
"TLS %p ServerKeyExchange unsupported "
1543 "signature and hash algorithm\n", tls );
1547 DBGC ( tls,
"TLS %p ServerKeyExchange incorrect "
1548 "signature algorithm %s (expected %s)\n", tls,
1574 DBGC ( tls,
"TLS %p ServerKeyExchange failed "
1575 "verification\n", tls );
1607 for ( i = 0 ; i < (
sizeof ( dh_val ) /
sizeof ( dh_val[0] ) ) ; i++ ){
1609 if ( (
sizeof ( *dh_val[i] ) > remaining ) ||
1610 (
ntohs ( dh_val[i]->
len ) > ( remaining -
1611 sizeof ( *dh_val[i] ) ) )){
1612 DBGC ( tls,
"TLS %p received underlength "
1613 "ServerKeyExchange\n", tls );
1619 frag_len = (
sizeof ( *dh_val[i] ) +
ntohs ( dh_val[i]->
len ));
1621 remaining -= frag_len;
1631 sizeof (
private ) ) ) != 0 ) {
1637 typeof ( dh_val[0] ) dh_p = dh_val[0];
1638 typeof ( dh_val[1] ) dh_g = dh_val[1];
1639 typeof ( dh_val[2] ) dh_ys = dh_val[2];
1648 typeof ( *key_xchg ) key_xchg;
1653 dynamic =
malloc (
sizeof ( *dynamic ) );
1658 pre_master_secret = dynamic->pre_master_secret;
1659 key_xchg = &dynamic->key_xchg;
1660 key_xchg->type_length =
1662 htonl (
sizeof ( *key_xchg ) -
1663 sizeof ( key_xchg->type_length ) ) );
1664 key_xchg->dh_xs_len =
htons (
len );
1668 dh_g->data,
ntohs ( dh_g->len ),
1669 dh_ys->data,
ntohs ( dh_ys->len ),
1670 private, sizeof (
private ),
1672 pre_master_secret ) ) != 0 ) {
1673 DBGC ( tls,
"TLS %p could not calculate DHE key: %s\n",
1679 while (
len && ( ! *pre_master_secret ) ) {
1680 pre_master_secret++;
1686 sizeof ( *key_xchg ) ) ) !=0){
1687 goto err_send_handshake;
1734 sizeof ( *ecdh ) ) ) ) {
1735 DBGC ( tls,
"TLS %p received underlength ServerKeyExchange\n",
1741 param_len = (
sizeof ( *ecdh ) + ecdh->public_len );
1749 DBGC ( tls,
"TLS %p unsupported curve type %d\n",
1750 tls, ecdh->curve_type );
1757 DBGC ( tls,
"TLS %p unsupported named curve %d\n",
1758 tls,
ntohs ( ecdh->named_curve ) );
1763 DBGC ( tls,
"TLS %p using named curve %s\n", tls, curve->
curve->
name );
1769 if ( ecdh->public_len != (
offset + pointsize ) ) {
1770 DBGC ( tls,
"TLS %p invalid %s key\n",
1778 if ( curve->
format && ( ecdh->public[0] != curve->
format ) ) {
1779 DBGC ( tls,
"TLS %p invalid %s curve point format\n",
1789 uint8_t pre_master_secret[pointsize];
1793 uint8_t public[ecdh->public_len];
1798 sizeof (
private ) ) ) != 0){
1804 private, ( key_xchg.public +
offset ),
1805 pre_master_secret ) ) != 0 ) {
1806 DBGC ( tls,
"TLS %p could not exchange ECDHE key: %s\n",
1812 key_xchg.type_length =
1814 htonl (
sizeof ( key_xchg ) -
1815 sizeof ( key_xchg.type_length ) ) );
1816 key_xchg.public_len =
sizeof ( key_xchg.public );
1818 key_xchg.public[0] = curve->
format;
1822 sizeof ( key_xchg ) ) ) !=0){
1853 DBGC ( tls,
"TLS %p could not exchange keys: %s\n",
1860 DBGC ( tls,
"TLS %p could not generate keys: %s\n",
1891 DBGC ( tls,
"TLS %p could not identify (%s,%s) "
1892 "signature and hash algorithm\n", tls,
1901 &builder ) ) != 0 ) {
1902 DBGC ( tls,
"TLS %p could not sign %s digest using %s client "
1903 "private key: %s\n", tls, digest->
name, pubkey->
name,
1905 goto err_pubkey_sign;
1910 int use_sig_hash = ( ( sig_hash ==
NULL ) ? 0 : 1 );
1920 sizeof (
header.type_length )));
1921 if ( use_sig_hash ) {
1923 sizeof (
header.sig_hash[0] ) );
1928 sizeof (
header ) ) ) != 0 ) {
1929 DBGC ( tls,
"TLS %p could not construct Certificate "
1937 builder.
len ) ) != 0 ) {
1956 static const struct {
1963 &change_cipher,
sizeof ( change_cipher ) );
1985 "client finished", digest_out, sizeof ( digest_out ) );
1988 memset ( &finished, 0,
sizeof ( finished ) );
1990 htonl (
sizeof ( finished ) -
1991 sizeof ( finished.type_length ) ) );
1993 sizeof ( finished.verify_data ) );
1997 sizeof ( finished ) ) ) != 0 )
2015 unsigned int description ) {
2021 .description = description,
2045 if ( (
sizeof ( *change_cipher ) !=
len ) ||
2047 DBGC ( tls,
"TLS %p received invalid Change Cipher\n", tls );
2051 iob_pull ( iobuf,
sizeof ( *change_cipher ) );
2055 DBGC ( tls,
"TLS %p could not activate RX cipher: %s\n",
2082 DBGC ( tls,
"TLS %p received overlength Alert\n", tls );
2089 switch (
alert->level ) {
2091 switch (
alert->description ) {
2093 DBGC ( tls,
"TLS %p closed by notification\n", tls );
2097 DBGC ( tls,
"TLS %p received warning alert %d\n",
2098 tls,
alert->description );
2103 DBGC ( tls,
"TLS %p received fatal alert %d\n",
2104 tls,
alert->description );
2107 DBGC ( tls,
"TLS %p received unknown alert level %d"
2108 "(alert %d)\n", tls,
alert->level,
alert->description );
2127 DBGC ( tls,
"TLS %p ignoring Hello Request\n", tls );
2133 DBGC ( tls,
"TLS %p refusing to renegotiate insecurely\n",
2153 const void *
data,
size_t len ) {
2189 if ( (
sizeof ( *hello_a ) >
len ) ||
2190 ( hello_a->session_id_len > (
len - sizeof ( *hello_a ) ) ) ||
2191 (
sizeof ( *hello_b ) > (
len -
sizeof ( *hello_a ) -
2192 hello_a->session_id_len ) ) ) {
2193 DBGC ( tls,
"TLS %p received underlength Server Hello\n", tls );
2197 session_id = hello_a->session_id;
2198 hello_b = ( (
void * ) ( session_id + hello_a->session_id_len ) );
2201 remaining = (
len -
sizeof ( *hello_a ) - hello_a->session_id_len -
2202 sizeof ( *hello_b ) );
2206 exts = ( (
void * ) hello_b->next );
2207 if ( (
sizeof ( *exts ) > remaining ) ||
2208 ( ( exts_len =
ntohs ( exts->len ) ) >
2209 ( remaining - sizeof ( *exts ) ) ) ) {
2210 DBGC ( tls,
"TLS %p received underlength extensions\n",
2217 for (
ext = ( (
void * ) exts->data ), remaining = exts_len ;
2219 ext = ( ( (
void * )
ext ) + sizeof ( *
ext ) + ext_len ),
2220 remaining -= (
sizeof ( *
ext ) + ext_len ) ) {
2223 if ( (
sizeof ( *
ext ) > remaining ) ||
2224 ( ( ext_len =
ntohs (
ext->len ) ) >
2225 ( remaining - sizeof ( *
ext ) ) ) ) {
2226 DBGC ( tls,
"TLS %p received underlength "
2227 "extension\n", tls );
2233 switch (
ext->type ) {
2235 reneg = ( (
void * )
ext->data );
2236 if ( (
sizeof ( *reneg ) > ext_len ) ||
2238 ( ext_len - sizeof ( *reneg ) ) ) ) {
2239 DBGC ( tls,
"TLS %p received "
2240 "underlength renegotiation "
2247 ems = ( (
void * )
ext->data );
2256 DBGC ( tls,
"TLS %p does not support protocol version %d.%d\n",
2261 DBGC ( tls,
"TLS %p server attempted to illegally upgrade to "
2262 "protocol version %d.%d\n",
2267 DBGC ( tls,
"TLS %p using protocol version %d.%d\n",
2286 if ( hello_a->session_id_len &&
2292 DBGC ( tls,
"TLS %p resuming session ID:\n", tls );
2300 DBGC ( tls,
"TLS %p mismatched extended master secret "
2301 "extension\n", tls );
2308 if ( hello_a->session_id_len &&
2309 ( hello_a->session_id_len <= sizeof ( tls->
session_id ))){
2313 DBGC ( tls,
"TLS %p new session ID:\n", tls );
2323 if ( ( reneg ==
NULL ) ||
2324 ( reneg->len != sizeof ( tls->
verify ) ) ||
2326 sizeof ( tls->
verify ) ) != 0 ) ) {
2327 DBGC ( tls,
"TLS %p server failed secure "
2328 "renegotiation\n", tls );
2332 }
else if ( reneg !=
NULL ) {
2335 if ( reneg->len != 0 ) {
2336 DBGC ( tls,
"TLS %p server provided non-empty initial "
2337 "renegotiation\n", tls );
2355 const void *
data,
size_t len ) {
2364 if (
sizeof ( *new_session_ticket ) >
len ) {
2365 DBGC ( tls,
"TLS %p received underlength New Session Ticket\n",
2370 ticket_len =
ntohs ( new_session_ticket->len );
2371 if ( ticket_len > (
len -
sizeof ( *new_session_ticket ) ) ) {
2372 DBGC ( tls,
"TLS %p received overlength New Session Ticket\n",
2390 DBGC ( tls,
"TLS %p new session ticket:\n", tls );
2406 const void *
data,
size_t len ) {
2407 size_t remaining =
len;
2419 goto err_alloc_chain;
2423 while ( remaining ) {
2428 size_t certificate_len;
2433 if (
sizeof ( *certificate ) > remaining ) {
2434 DBGC ( tls,
"TLS %p underlength certificate:\n", tls );
2437 goto err_underlength;
2439 certificate_len =
tls_uint24 ( &certificate->length );
2440 if ( certificate_len > ( remaining -
sizeof ( *certificate ) )){
2441 DBGC ( tls,
"TLS %p overlength certificate:\n", tls );
2444 goto err_overlength;
2446 record_len = (
sizeof ( *certificate ) + certificate_len );
2451 certificate_len ) ) != 0 ) {
2452 DBGC ( tls,
"TLS %p could not append certificate: %s\n",
2458 DBGC ( tls,
"TLS %p found certificate %s\n",
2463 remaining -= record_len;
2487 const void *
data,
size_t len ) {
2492 size_t certificates_len;
2496 if (
sizeof ( *certificate ) >
len ) {
2497 DBGC ( tls,
"TLS %p received underlength Server Certificate\n",
2502 certificates_len =
tls_uint24 ( &certificate->length );
2503 if ( certificates_len > (
len -
sizeof ( *certificate ) ) ) {
2504 DBGC ( tls,
"TLS %p received overlength Server Certificate\n",
2512 certificates_len ) ) != 0 )
2527 const void *
data,
size_t len ) {
2581 DBGC ( tls,
"TLS %p selected client certificate %s\n",
2591 goto err_auto_append;
2595 DBGC ( tls,
"TLS %p could not find certificate corresponding "
2596 "to private key\n", tls );
2618 const void *
data,
size_t len ) {
2625 if (
sizeof ( *hello_done ) !=
len ) {
2626 DBGC ( tls,
"TLS %p received overlength Server Hello Done\n",
2636 DBGC ( tls,
"TLS %p could not start certificate validation: "
2654 const void *
data,
size_t len ) {
2664 if (
sizeof ( *finished ) !=
len ) {
2665 DBGC ( tls,
"TLS %p received overlength Finished\n", tls );
2674 "server finished", digest_out, sizeof ( digest_out ) );
2677 DBGC ( tls,
"TLS %p verification failed\n", tls );
2736 while ( ( remaining =
iob_len ( iobuf ) ) ) {
2742 const void *payload;
2747 if (
sizeof ( *handshake ) > remaining ) {
2751 payload_len =
tls_uint24 ( &handshake->length );
2752 if ( payload_len > ( remaining -
sizeof ( *handshake ) ) ) {
2756 payload = &handshake->payload;
2757 record_len = (
sizeof ( *handshake ) + payload_len );
2760 switch ( handshake->type ) {
2791 DBGC ( tls,
"TLS %p ignoring handshake type %d\n",
2792 tls, handshake->type );
2851 DBGC ( tls,
"TLS %p could not deliver data: "
2894 DBGC ( tls,
"TLS %p unknown record type %d\n", tls,
type );
2901 list_add ( &(*iobuf)->list, rx_data );
2904 DBGC ( tls,
"TLS %p could not concatenate non-data record "
2905 "type %d\n", tls,
type );
2907 goto err_concatenate;
2911 if ( (
rc = handler ( tls, *iobuf ) ) != 0 )
2964 const void *
data,
size_t len ) {
2995 const void *
data,
size_t len,
void *hmac ) {
3051 return (
count * each );
3101 const void *plaintext;
3102 const void *encrypt;
3111 plaintext = iobuf->
data;
3132 sizeof (
iv.rec ) ) ) != 0 ) {
3144 tls_hmac ( cipherspec, &authhdr, plaintext, record_len,
3149 &authhdr,
NULL, sizeof ( authhdr ) );
3153 encrypt_len = ( record_len + suite->
mac_len );
3156 -( encrypt_len + 1 ) ) + 1 );
3163 tlshdr =
iob_put ( iobuf,
sizeof ( *tlshdr ) );
3171 sizeof (
iv.rec ) );
3174 ciphertext =
iob_put ( iobuf, record_len );
3175 assert ( ciphertext <= plaintext );
3176 if ( encrypt_len > record_len ) {
3177 memmove ( ciphertext, plaintext, record_len );
3178 encrypt = ciphertext;
3180 encrypt = plaintext;
3191 DBGC2 ( tls,
"Sending plaintext data:\n" );
3192 DBGC2_HDA ( tls, 0, encrypt, encrypt_len );
3194 ciphertext, encrypt_len );
3200 plaintext += record_len;
3208 DBGC ( tls,
"TLS %p could not deliver ciphertext: %s\n",
3232 const void *
data,
size_t len ) {
3265 padding = ( iobuf->
tail - 1 );
3269 DBGC ( tls,
"TLS %p received underlength padding\n", tls );
3273 for ( i = 0 ; i <
pad ; i++ ) {
3274 if ( *(--padding) !=
pad ) {
3275 DBGC ( tls,
"TLS %p received bad padding\n", tls );
3323 DBGC ( tls,
"TLS %p received underlength IV\n", tls );
3330 len -=
sizeof (
iv.record );
3334 DBGC ( tls,
"TLS %p received underlength authentication tag\n",
3355 NULL, sizeof ( authhdr ) );
3363 check_len +=
iob_len ( iobuf );
3380 DBGC ( tls,
"TLS %p received underlength MAC\n", tls );
3389 DBGC2 ( tls,
"Received plaintext data:\n" );
3393 check_len +=
iob_len ( iobuf );
3400 tls_hmac_list ( cipherspec, &authhdr, rx_data, verify_mac );
3407 DBGC ( tls,
"TLS %p failed MAC verification\n", tls );
3413 DBGC ( tls,
"TLS %p failed authentication tag verification\n",
3539 reserve = ( ( -iv_len ) & ( cipher->
alignsize - 1 ) );
3540 remaining += reserve;
3544 while ( remaining ) {
3550 frag_len = remaining;
3553 remaining -= frag_len;
3555 frag_len += remaining;
3562 DBGC ( tls,
"TLS %p could not allocate %zd of %zd "
3563 "bytes for receive buffer\n", tls,
3750 DBGC ( tls,
"TLS %p certificate validation failed: %s\n",
3754 DBGC ( tls,
"TLS %p certificate validation succeeded\n", tls );
3762 DBGC ( tls,
"TLS %p server certificate does not match %s: %s\n",
3850 DBGC ( tls,
"TLS %p could not send Client Hello: %s\n",
3858 DBGC ( tls,
"TLS %p cold not send Certificate: %s\n",
3866 DBGC ( tls,
"TLS %p could not send Client Key "
3874 DBGC ( tls,
"TLS %p could not send Certificate "
3882 DBGC ( tls,
"TLS %p could not send Change Cipher: "
3888 DBGC ( tls,
"TLS %p could not activate TX cipher: "
3897 DBGC ( tls,
"TLS %p could not send Finished: %s\n",
3949 DBGC ( tls,
"TLS %p joining session %s\n", tls,
name );
3962 name_copy = ( ( (
void * ) session ) +
sizeof ( *session ) );
3964 session->
name = name_copy;
3973 DBGC ( tls,
"TLS %p created session %s\n", tls,
name );
4003 tls =
malloc (
sizeof ( *tls ) );
4008 memset ( tls, 0,
sizeof ( *tls ) );
#define NULL
NULL pointer (VOID *)
union @162305117151260234136356364136041353210355154177 key
Sense key.
struct golan_eq_context ctx
u8 signature
CPU signature.
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]
pseudo_bit_t hash[0x00010]
static unsigned int code
Response code.
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.
#define assert(condition)
Assert a condition at run-time.
u32 version
Driver version.
struct bofm_section_header done
uint16_t offset
Offset to command line.
struct x509_chain certstore
Certificate store.
Cryptographic configuration.
#define TLS_VERSION_MIN
Minimum TLS version.
struct cipher_algorithm cipher_null
struct pubkey_algorithm pubkey_null
struct digest_algorithm digest_null
int dhe_key(const void *modulus, size_t len, const void *generator, size_t generator_len, const void *partner, size_t partner_len, const void *private, size_t private_len, void *public, void *shared)
Calculate Diffie-Hellman key.
Ephemeral Diffie-Hellman key exchange.
uint32_t next
Next descriptor address.
int ecdhe_key(struct elliptic_curve *curve, const void *partner, const void *private, void *public, void *shared)
Calculate ECDHE key.
Elliptic Curve Ephemeral Diffie-Hellman (ECDHE) key exchange.
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.
uint8_t mac[ETH_ALEN]
MAC address.
#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 *key, size_t key_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 void digest_init(struct digest_algorithm *digest, void *ctx)
static int cipher_setkey(struct cipher_algorithm *cipher, void *ctx, const void *key, size_t keylen)
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
static int pubkey_encrypt(struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, const struct asn1_cursor *plaintext, struct asn1_builder *ciphertext)
static int pubkey_verify(struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, const struct asn1_cursor *signature)
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
static void 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)
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.
struct digest_algorithm md5_algorithm
MD5 algorithm.
void alert(unsigned int row, const char *fmt,...)
Show alert message.
Data transfer interface opening.
uint32_t first
First block in range.
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?
int rbg_generate(const void *additional, size_t additional_len, int prediction_resist, void *data, size_t len)
Generate bits using RBG.
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.
RSA public-key cryptography.
#define __rsa_digestinfo_prefix
Declare an RSA digestInfo prefix.
struct digest_algorithm sha1_algorithm
SHA-1 algorithm.
#define va_copy(dest, src)
#define va_start(ap, last)
__builtin_va_list va_list
#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 ctxsize
Context size.
size_t authsize
Authentication tag size.
size_t alignsize
Alignment size.
A message digest algorithm.
size_t digestsize
Digest size.
size_t ctxsize
Context size.
const char * name
Algorithm name.
const char * name
Curve name.
size_t keysize
Scalar (and private key) size.
size_t pointsize
Point (and public key) size.
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)
uint8_t sha1[SHA1_CTX_SIZE]
SHA-1 context.
uint8_t md5[MD5_CTX_SIZE]
MD5 context.
uint8_t md5[MD5_DIGEST_SIZE]
MD5 digest.
uint8_t sha1[SHA1_DIGEST_SIZE]
SHA-1 digest.
const char * name
Algorithm name.
An RSA digestInfo prefix.
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.
A TLS cipher specification.
void * fixed_iv
Fixed initialisation vector.
struct tls_cipher_suite * suite
Cipher suite.
void * cipher_ctx
Bulk encryption cipher context.
void * dynamic
Dynamically-allocated storage.
void * mac_secret
MAC secret.
uint8_t random[32]
Random data.
struct tls_client_random random
Random bytes.
struct private_key * key
Private key (if used)
struct x509_chain * chain
Certificate chain (if used)
struct pending_operation negotiation
Security negotiation pending operation.
struct interface cipherstream
Ciphertext stream.
struct tls_session * session
Session.
uint8_t master_secret[48]
Master secret.
struct tls_server server
Server state.
struct tls_rx rx
Receive state.
uint8_t * handshake_ctx
Digest algorithm context used for handshake verification.
void * new_session_ticket
New session ticket.
struct tls_verify_data verify
Verification data.
size_t session_id_len
Length of session ID.
struct interface plainstream
Plaintext stream.
struct tls_tx tx
Transmit state.
uint8_t session_id[32]
Session ID.
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.
struct digest_algorithm * handshake_digest
Digest algorithm used for handshake verification.
uint16_t version
Protocol version.
size_t new_session_ticket_len
Length of new session ticket.
struct refcnt refcnt
Reference counter.
int secure_renegotiation
Secure renegotiation flag.
A TLS key exchange algorithm.
const char * name
Algorithm name.
int(* exchange)(struct tls_connection *tls)
Transmit Client Key Exchange record.
uint8_t pre_master_secret_len
Pre-master secret length.
uint8_t format
Curve point format byte (if any)
struct elliptic_curve * curve
Elliptic curve.
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.
enum tls_rx_state state
State machine current state.
struct tls_header header
Current received record header.
uint64_t seq
Sequence number.
struct asn1_cursor key
Public key (within server certificate)
struct pending_operation validation
Certificate validation pending operation.
struct interface validator
Certificate validator.
struct x509_root * root
Root of trust.
void * exchange
Server Key Exchange record (if any)
struct pending_operation negotiation
Security negotiation pending operation.
struct x509_chain * chain
Certificate chain.
size_t exchange_len
Server Key Exchange record length.
uint8_t random[32]
Random bytes.
struct private_key * key
Private key.
uint8_t id[32]
Session ID.
int extended_master_secret
Extended master secret flag.
const char * name
Server name.
size_t id_len
Length of session ID.
size_t ticket_len
Length of session ticket.
uint8_t master_secret[48]
Master secret.
struct x509_root * root
Root of trust.
struct list_head conn
List of connections.
struct refcnt refcnt
Reference counter.
void * ticket
Session ticket.
struct list_head list
List of sessions.
A TLS signature algorithm.
struct tls_signature_hash_id code
Numeric code.
struct pubkey_algorithm * pubkey
Public-key algorithm.
struct digest_algorithm * digest
Digest algorithm.
A TLS signature and hash algorithm identifier.
uint8_t hash
Hash algorithm.
uint8_t signature
Signature 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_cursor raw
Raw public key information.
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.
#define tls_prf_label(tls, secret, secret_len, out, out_len, label,...)
Generate secure pseudo-random data.
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 struct pubkey_algorithm * tls_signature_hash_pubkey(struct tls_signature_hash_id code)
Find TLS signature algorithm.
static void tls_validator_done(struct tls_connection *tls, int rc)
Handle certificate validation completion.
static void md5_sha1_init(void *ctx)
Initialise MD5+SHA1 algorithm.
#define EINVAL_KEY_EXCHANGE
static int tls_generate_random(struct tls_connection *tls, void *data, size_t len)
Generate random data.
static int tls_send_alert(struct tls_connection *tls, unsigned int level, unsigned int description)
Transmit Alert record.
static int tls_select_handshake(struct tls_connection *tls, struct digest_algorithm *digest)
Select handshake digest algorithm.
static void tls_p_hash_va(struct tls_connection *tls, struct digest_algorithm *digest, const void *secret, size_t secret_len, void *out, size_t out_len, va_list seeds)
Generate secure pseudo-random data using a single hash function.
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_verify_dh_params(struct tls_connection *tls, size_t param_len)
Verify Diffie-Hellman parameter signature.
static int tls_new_change_cipher(struct tls_connection *tls, struct io_buffer *iobuf)
Receive new Change Cipher record.
static void tls_generate_master_secret(struct tls_connection *tls, const void *pre_master_secret, size_t pre_master_secret_len)
Generate master secret.
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.
#define EPERM_KEY_EXCHANGE
static int tls_send_finished(struct tls_connection *tls)
Transmit Finished record.
static struct interface_operation tls_cipherstream_ops[]
TLS ciphertext stream interface 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 suite.
#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 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 void tls_hmac_update_va(struct digest_algorithm *digest, void *ctx, va_list args)
Update HMAC with a list of ( data, len ) pairs.
static int tls_cipherstream_deliver(struct tls_connection *tls, struct io_buffer *iobuf, struct xfer_metadata *xfer __unused)
Receive new ciphertext.
static void md5_sha1_final(void *ctx, void *out)
Generate MD5+SHA1 digest.
static void tls_hmac_final(struct tls_cipherspec *cipherspec, void *ctx, void *hmac)
Finalise HMAC.
#define ENOMEM_TX_PLAINTEXT
#define EINVAL_HELLO_DONE
static struct digest_algorithm * tls_signature_hash_digest(struct tls_signature_hash_id code)
Find TLS hash algorithm.
#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 struct tls_named_curve * tls_find_named_curve(unsigned int named_curve)
Identify named curve.
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 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_change_cipher(struct tls_connection *tls, struct tls_cipherspec_pair *pair)
Activate next cipher suite.
static void md5_sha1_update(void *ctx, const void *data, size_t len)
Accumulate data with MD5+SHA1 algorithm.
static int tls_plainstream_deliver(struct tls_connection *tls, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
Deliver datagram as raw data.
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_send_client_key_exchange_dhe(struct tls_connection *tls)
Transmit Client Key Exchange record using DHE key exchange.
static void tls_restart(struct tls_connection *tls)
Restart negotiation.
struct tls_cipher_suite tls_cipher_suite_null
Null cipher suite.
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 int tls_send_client_key_exchange_pubkey(struct tls_connection *tls)
Transmit Client Key Exchange record using public key exchange.
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_prf(struct tls_connection *tls, const void *secret, size_t secret_len, void *out, size_t out_len,...)
Generate secure pseudo-random data.
static void tls_hmac_update(struct tls_cipherspec *cipherspec, void *ctx, const void *data, size_t len)
Update HMAC.
#define EPERM_RENEG_INSECURE
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_send_certificate_verify(struct tls_connection *tls)
Transmit Certificate Verify record.
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 next 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_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
#define TLS_NUM_NAMED_CURVES
Number of supported named curves.
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 struct digest_algorithm md5_sha1_algorithm
Hybrid MD5+SHA1 digest algorithm.
static int tls_parse_chain(struct tls_connection *tls, const void *data, size_t len)
Parse certificate chain.
static void tls_clear_handshake(struct tls_connection *tls)
Clear handshake digest algorithm.
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 void tls_verify_handshake(struct tls_connection *tls, void *out)
Calculate handshake verification hash.
static int tls_add_handshake(struct tls_connection *tls, const void *data, size_t len)
Add handshake record to verification hash.
static int tls_generate_keys(struct tls_connection *tls)
Generate key material.
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_new_server_key_exchange(struct tls_connection *tls, const void *data, size_t len)
Receive new Server Key Exchange handshake record.
static int tls_send_client_key_exchange_ecdhe(struct tls_connection *tls)
Transmit Client Key Exchange record using ECDHE key exchange.
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.
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_CHANGE_CIPHER_SPEC
Change cipher spec magic byte.
#define TLS_CIPHER_SUITES
TLS cipher suite table.
#define TLS_EXTENDED_MASTER_SECRET
#define TLS_VERSION_MAX
Maximum supported TLS version.
#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_NAMED_CURVES
TLS named curve table.
#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 curved type.
#define TLS_SESSION_TICKET
#define TLS_SIGNATURE_ALGORITHMS
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.
u32 lifetime
For Lifetime-type KDEs, the lifetime in seconds.
u16 keysize
Length of encryption key to be used, network byte order.
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.
int x509_check_name(struct x509_certificate *cert, const char *name)
Check X.509 certificate name.
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.