59#define EINVAL_CHANGE_CIPHER __einfo_error ( EINFO_EINVAL_CHANGE_CIPHER )
60#define EINFO_EINVAL_CHANGE_CIPHER \
61 __einfo_uniqify ( EINFO_EINVAL, 0x01, \
62 "Invalid Change Cipher record" )
63#define EINVAL_ALERT __einfo_error ( EINFO_EINVAL_ALERT )
64#define EINFO_EINVAL_ALERT \
65 __einfo_uniqify ( EINFO_EINVAL, 0x02, \
66 "Invalid Alert record" )
67#define EINVAL_HELLO __einfo_error ( EINFO_EINVAL_HELLO )
68#define EINFO_EINVAL_HELLO \
69 __einfo_uniqify ( EINFO_EINVAL, 0x03, \
70 "Invalid Server Hello record" )
71#define EINVAL_CERTIFICATE __einfo_error ( EINFO_EINVAL_CERTIFICATE )
72#define EINFO_EINVAL_CERTIFICATE \
73 __einfo_uniqify ( EINFO_EINVAL, 0x04, \
74 "Invalid Certificate" )
75#define EINVAL_CERTIFICATES __einfo_error ( EINFO_EINVAL_CERTIFICATES )
76#define EINFO_EINVAL_CERTIFICATES \
77 __einfo_uniqify ( EINFO_EINVAL, 0x05, \
78 "Invalid Server Certificate record" )
79#define EINVAL_HELLO_DONE __einfo_error ( EINFO_EINVAL_HELLO_DONE )
80#define EINFO_EINVAL_HELLO_DONE \
81 __einfo_uniqify ( EINFO_EINVAL, 0x06, \
82 "Invalid Server Hello Done record" )
83#define EINVAL_FINISHED __einfo_error ( EINFO_EINVAL_FINISHED )
84#define EINFO_EINVAL_FINISHED \
85 __einfo_uniqify ( EINFO_EINVAL, 0x07, \
86 "Invalid Server Finished record" )
87#define EINVAL_HANDSHAKE __einfo_error ( EINFO_EINVAL_HANDSHAKE )
88#define EINFO_EINVAL_HANDSHAKE \
89 __einfo_uniqify ( EINFO_EINVAL, 0x08, \
90 "Invalid Handshake record" )
91#define EINVAL_IV __einfo_error ( EINFO_EINVAL_IV )
92#define EINFO_EINVAL_IV \
93 __einfo_uniqify ( EINFO_EINVAL, 0x0a, \
94 "Invalid initialisation vector" )
95#define EINVAL_PADDING __einfo_error ( EINFO_EINVAL_PADDING )
96#define EINFO_EINVAL_PADDING \
97 __einfo_uniqify ( EINFO_EINVAL, 0x0b, \
98 "Invalid block padding" )
99#define EINVAL_RX_STATE __einfo_error ( EINFO_EINVAL_RX_STATE )
100#define EINFO_EINVAL_RX_STATE \
101 __einfo_uniqify ( EINFO_EINVAL, 0x0c, \
102 "Invalid receive state" )
103#define EINVAL_MAC __einfo_error ( EINFO_EINVAL_MAC )
104#define EINFO_EINVAL_MAC \
105 __einfo_uniqify ( EINFO_EINVAL, 0x0d, \
106 "Invalid MAC or authentication tag" )
107#define EINVAL_TICKET __einfo_error ( EINFO_EINVAL_TICKET )
108#define EINFO_EINVAL_TICKET \
109 __einfo_uniqify ( EINFO_EINVAL, 0x0e, \
110 "Invalid New Session Ticket record")
111#define EINVAL_KEY_EXCHANGE __einfo_error ( EINFO_EINVAL_KEY_EXCHANGE )
112#define EINFO_EINVAL_KEY_EXCHANGE \
113 __einfo_uniqify ( EINFO_EINVAL, 0x0f, \
114 "Invalid Server Key Exchange record" )
115#define EIO_ALERT __einfo_error ( EINFO_EIO_ALERT )
116#define EINFO_EIO_ALERT \
117 __einfo_uniqify ( EINFO_EIO, 0x01, \
118 "Unknown alert level" )
119#define ENOENT_CERT __einfo_error ( EINFO_ENOENT_CERT )
120#define EINFO_ENOENT_CERT \
121 __einfo_uniqify ( EINFO_ENOENT, 0x01, \
122 "Missing server certificate" )
123#define ENOMEM_CONTEXT __einfo_error ( EINFO_ENOMEM_CONTEXT )
124#define EINFO_ENOMEM_CONTEXT \
125 __einfo_uniqify ( EINFO_ENOMEM, 0x01, \
126 "Not enough space for crypto context" )
127#define ENOMEM_CERTIFICATE __einfo_error ( EINFO_ENOMEM_CERTIFICATE )
128#define EINFO_ENOMEM_CERTIFICATE \
129 __einfo_uniqify ( EINFO_ENOMEM, 0x02, \
130 "Not enough space for certificate" )
131#define ENOMEM_CHAIN __einfo_error ( EINFO_ENOMEM_CHAIN )
132#define EINFO_ENOMEM_CHAIN \
133 __einfo_uniqify ( EINFO_ENOMEM, 0x03, \
134 "Not enough space for certificate chain" )
135#define ENOMEM_TX_PLAINTEXT __einfo_error ( EINFO_ENOMEM_TX_PLAINTEXT )
136#define EINFO_ENOMEM_TX_PLAINTEXT \
137 __einfo_uniqify ( EINFO_ENOMEM, 0x04, \
138 "Not enough space for transmitted plaintext" )
139#define ENOMEM_TX_CIPHERTEXT __einfo_error ( EINFO_ENOMEM_TX_CIPHERTEXT )
140#define EINFO_ENOMEM_TX_CIPHERTEXT \
141 __einfo_uniqify ( EINFO_ENOMEM, 0x05, \
142 "Not enough space for transmitted ciphertext" )
143#define ENOMEM_RX_DATA __einfo_error ( EINFO_ENOMEM_RX_DATA )
144#define EINFO_ENOMEM_RX_DATA \
145 __einfo_uniqify ( EINFO_ENOMEM, 0x07, \
146 "Not enough space for received data" )
147#define ENOMEM_RX_CONCAT __einfo_error ( EINFO_ENOMEM_RX_CONCAT )
148#define EINFO_ENOMEM_RX_CONCAT \
149 __einfo_uniqify ( EINFO_ENOMEM, 0x08, \
150 "Not enough space to concatenate received data" )
151#define ENOTSUP_CIPHER __einfo_error ( EINFO_ENOTSUP_CIPHER )
152#define EINFO_ENOTSUP_CIPHER \
153 __einfo_uniqify ( EINFO_ENOTSUP, 0x01, \
154 "Unsupported cipher" )
155#define ENOTSUP_NULL __einfo_error ( EINFO_ENOTSUP_NULL )
156#define EINFO_ENOTSUP_NULL \
157 __einfo_uniqify ( EINFO_ENOTSUP, 0x02, \
158 "Refusing to use null cipher" )
159#define ENOTSUP_SIG_HASH __einfo_error ( EINFO_ENOTSUP_SIG_HASH )
160#define EINFO_ENOTSUP_SIG_HASH \
161 __einfo_uniqify ( EINFO_ENOTSUP, 0x03, \
162 "Unsupported signature and hash algorithm" )
163#define ENOTSUP_VERSION __einfo_error ( EINFO_ENOTSUP_VERSION )
164#define EINFO_ENOTSUP_VERSION \
165 __einfo_uniqify ( EINFO_ENOTSUP, 0x04, \
166 "Unsupported protocol version" )
167#define ENOTSUP_GROUP __einfo_error ( EINFO_ENOTSUP_GROUP )
168#define EINFO_ENOTSUP_GROUP \
169 __einfo_uniqify ( EINFO_ENOTSUP, 0x05, \
170 "Unsupported key exchange group" )
171#define EPERM_ALERT __einfo_error ( EINFO_EPERM_ALERT )
172#define EINFO_EPERM_ALERT \
173 __einfo_uniqify ( EINFO_EPERM, 0x01, \
174 "Received fatal alert" )
175#define EPERM_VERIFY __einfo_error ( EINFO_EPERM_VERIFY )
176#define EINFO_EPERM_VERIFY \
177 __einfo_uniqify ( EINFO_EPERM, 0x02, \
178 "Handshake verification failed" )
179#define EPERM_RENEG_INSECURE __einfo_error ( EINFO_EPERM_RENEG_INSECURE )
180#define EINFO_EPERM_RENEG_INSECURE \
181 __einfo_uniqify ( EINFO_EPERM, 0x04, \
182 "Secure renegotiation not supported" )
183#define EPERM_RENEG_VERIFY __einfo_error ( EINFO_EPERM_RENEG_VERIFY )
184#define EINFO_EPERM_RENEG_VERIFY \
185 __einfo_uniqify ( EINFO_EPERM, 0x05, \
186 "Secure renegotiation verification failed" )
187#define EPERM_KEY_EXCHANGE __einfo_error ( EINFO_EPERM_KEY_EXCHANGE )
188#define EINFO_EPERM_KEY_EXCHANGE \
189 __einfo_uniqify ( EINFO_EPERM, 0x06, \
190 "ServerKeyExchange verification failed" )
191#define EPERM_EMS __einfo_error ( EINFO_EPERM_EMS )
192#define EINFO_EPERM_EMS \
193 __einfo_uniqify ( EINFO_EPERM, 0x07, \
194 "Extended master secret extension mismatch" )
195#define EPERM_BOUND __einfo_error ( EINFO_EPERM_BOUND )
196#define EINFO_EPERM_BOUND \
197 __einfo_uniqify ( EINFO_EPERM, 0x08, \
198 "Bound identity not validated" )
199#define EPROTO_VERSION __einfo_error ( EINFO_EPROTO_VERSION )
200#define EINFO_EPROTO_VERSION \
201 __einfo_uniqify ( EINFO_EPROTO, 0x01, \
202 "Illegal protocol version upgrade" )
212 const void *
data,
size_t len );
214 unsigned int description );
218 const void *
data,
size_t len );
428 static const char salt[16] =
"ephemeral master";
435 sizeof (
key->ephemeral ) ) ) != 0 ) {
436 DBGC ( tls,
"TLS %p could not generate random data: %s\n",
443 sizeof (
key->ephemeral ),
key->ephemeral );
479 DBGC2 ( tls,
"TLS %p ephemeral %s:\n", tls,
label );
493 sizeof (
key->ephemeral ) );
527 if ( !
key->keyed ) {
528 DBGC ( tls,
"TLS %p refusing empty binding\n", tls );
534 DBGC ( tls,
"TLS %p bound to %s\n", tls,
x509_name ( cert ) );
582 total = ( digest->
ctxsize + kdfsize );
583 dynamic =
zalloc ( total );
588 key->dynamic = dynamic;
589 key->handshake = dynamic; dynamic += digest->
ctxsize;
590 key->kdf = dynamic; dynamic += kdfsize;
591 assert ( (
key->dynamic + total ) == dynamic );
594 key->digest = digest;
621 while ( (
data =
va_arg ( args,
void * ) ) ) {
653 DBGC2 ( tls,
"TLS %p %s A(1):\n", tls, digest->
name );
662 memcpy ( ctx_partial,
ctx,
sizeof ( ctx_partial ) );
669 if ( frag_len > out_len )
672 DBGC2 ( tls,
"TLS %p %s output:\n", tls, digest->
name );
677 DBGC2 ( tls,
"TLS %p %s A(n):\n", tls, digest->
name );
694 size_t out_len, ... ) {
708 out, out_len, seeds );
720 out, out_len, seeds );
726 buf, out_len, seeds );
730 for ( i = 0 ; i < out_len ; i++ )
746#define tls_prf_label( tls, out, out_len, label, ... ) \
747 tls_prf ( (tls), (out), (out_len), \
748 label, ( sizeof ( label ) - 1 ), __VA_ARGS__, NULL )
758 const void *secret,
size_t secret_len ) {
763 size_t subsecret_len;
764 const void *md5_secret;
765 const void *sha1_secret;
767 DBGC2 ( tls,
"TLS %p KDF secret:\n", tls );
768 DBGC2_HD ( tls, secret, secret_len );
784 subsecret_len = ( ( secret_len + 1 ) / 2 );
786 sha1_secret = ( secret + secret_len - subsecret_len );
818 DBGC ( tls,
"TLS %p could not share ephemeral key: %s\n",
838 const void *
partner,
size_t partner_len,
867 if ( partner_len > pubsize ) {
868 DBGC ( tls,
"TLS %p partner key too long:\n", tls );
871 goto err_partner_len;
873 pad_len = ( pubsize - partner_len );
874 if ( pad_len && ( ! strip ) ) {
875 DBGC ( tls,
"TLS %p partner key too short:\n", tls );
878 goto err_partner_len;
884 tmp->shared ) ) != 0 ) {
885 DBGC ( tls,
"TLS %p could not agree shared key: %s\n",
891 shared =
tmp->shared;
892 shared_len = sharedsize;
893 while ( strip && shared_len && ( ! *shared ) ) {
899 DBGC ( tls,
"TLS %p pre-master secret:\n", tls );
900 DBGC_HDA ( tls, 0, shared, shared_len );
941 DBGC ( tls,
"TLS %p client random bytes:\n", tls );
943 DBGC ( tls,
"TLS %p server random bytes:\n", tls );
945 DBGC ( tls,
"TLS %p session hash:\n", tls );
946 DBGC_HD ( tls, digest_out,
sizeof ( digest_out ) );
950 tls_prf_label ( tls, master_secret,
sizeof ( master_secret ),
951 "extended master secret",
952 digest_out,
sizeof ( digest_out ) );
954 tls_prf_label ( tls, master_secret,
sizeof ( master_secret ),
963 DBGC ( tls,
"TLS %p generated %smaster secret:\n", tls,
965 DBGC_HD ( tls, master_secret,
sizeof ( master_secret ) );
984 size_t total = ( 2 * ( hash_size + key_size + iv_size ) );
994 tls_prf_label ( tls, key_block,
sizeof ( key_block ),
"key expansion",
1003 DBGC ( tls,
"TLS %p TX MAC secret:\n", tls );
1009 DBGC ( tls,
"TLS %p RX MAC secret:\n", tls );
1016 key, key_size ) ) != 0 ) {
1017 DBGC ( tls,
"TLS %p could not set TX key: %s\n",
1021 DBGC ( tls,
"TLS %p TX key:\n", tls );
1028 key, key_size ) ) != 0 ) {
1029 DBGC ( tls,
"TLS %p could not set TX key: %s\n",
1033 DBGC ( tls,
"TLS %p RX key:\n", tls );
1039 DBGC ( tls,
"TLS %p TX IV:\n", tls );
1045 DBGC ( tls,
"TLS %p RX IV:\n", tls );
1049 assert ( ( key_block + total ) ==
key );
1076 assert (
sizeof ( *secret ) <=
1093 memcpy ( secret,
key->kdf, sizeof ( *secret ) );
1103 assert (
sizeof ( secret->md5 ) <=
1105 assert (
sizeof ( secret->sha1 ) <=
1108 memcpy ( secret->md5, hkeys->
md5, sizeof ( secret->md5 ) );
1109 memcpy ( secret->sha1, hkeys->
sha1, sizeof ( secret->sha1 ) );
1158 const void *
data,
size_t len ) {
1199#define TLS_NUM_CIPHER_SUITES table_num_entries ( TLS_CIPHER_SUITES )
1213 if ( suite->
code == cipher_suite )
1229 memset ( cipherspec, 0,
sizeof ( *cipherspec ) );
1253 dynamic =
zalloc ( total );
1255 DBGC ( tls,
"TLS %p could not allocate %zd bytes for crypto "
1256 "context\n", tls, total );
1261 cipherspec->
dynamic = dynamic;
1268 cipherspec->
suite = suite;
1281 unsigned int cipher_suite ) {
1289 DBGC ( tls,
"TLS %p does not support cipher %04x\n",
1290 tls,
ntohs ( cipher_suite ) );
1308 DBGC ( tls,
"TLS %p selected %s-%s-%s-%d-%s\n", tls,
1328 DBGC ( tls,
"TLS %p refusing to use null cipher\n", tls );
1345#define TLS_NUM_SIG_HASH_ALGORITHMS \
1346 table_num_entries ( TLS_SIG_HASH_ALGORITHMS )
1409 if (
group->code && (
group->code == named_group ) )
1434 dh_g, dh_g_len ) ) {
1452 size_t len,
size_t param_len ) {
1471 DBGC ( tls,
"TLS %p has no server certificate\n", tls );
1478 remaining = (
len - param_len );
1481 if ( (
sizeof ( *
sig ) > remaining ) ||
1482 (
ntohs (
sig->signature_len ) > ( remaining -
1483 sizeof ( *
sig ) ) ) ) {
1484 DBGC ( tls,
"TLS %p received underlength ServerKeyExchange\n",
1493 if ( use_sig_hash ) {
1496 DBGC ( tls,
"TLS %p unsupported signature hash "
1497 "%#04x\n", tls,
sig->sig_hash[0] );
1500 pubkey = sig_hash->
pubkey;
1501 digest = sig_hash->
digest;
1502 DBGC ( tls,
"TLS %p using signature hash %s-%s\n",
1506 DBGC ( tls,
"TLS %p cannot use %s public key\n", tls,
1534 DBGC ( tls,
"TLS %p ServerKeyExchange failed "
1535 "verification\n", tls );
1559 const void *
data,
size_t len ){
1562 DBGC ( tls,
"TLS %p received unexpected ServerKeyExchange:\n", tls );
1583 .data = &pre_master_secret,
1584 .len =
sizeof ( pre_master_secret ),
1592 &pre_master_secret.random,
1593 sizeof ( pre_master_secret.random ) );
1595 sizeof ( pre_master_secret ) );
1609 DBGC ( tls,
"TLS %p has no server certificate\n", tls );
1616 &cursor, &builder ) ) != 0 ) {
1617 DBGC ( tls,
"TLS %p could not encrypt pre-master secret: %s\n",
1626 uint16_t encrypted_pre_master_secret_len;
1632 sizeof (
header.type_length ) ) );
1636 sizeof (
header ) ) ) != 0 ) {
1637 DBGC ( tls,
"TLS %p could not construct Client Key "
1645 builder.
len ) ) != 0 ) {
1680 const void *
data,
size_t len ) {
1687 typeof ( dh_val[0] ) dh_p;
1688 typeof ( dh_val[1] ) dh_g;
1689 typeof ( dh_val[2] ) dh_ys;
1700 for ( i = 0 ; i < (
sizeof ( dh_val ) /
sizeof ( dh_val[0] ) ) ; i++ ){
1702 if ( (
sizeof ( *dh_val[i] ) > remaining ) ||
1703 (
ntohs ( dh_val[i]->
len ) > ( remaining -
1704 sizeof ( *dh_val[i] ) ) )){
1705 DBGC ( tls,
"TLS %p received underlength "
1706 "ServerKeyExchange\n", tls );
1710 frag_len = (
sizeof ( *dh_val[i] ) +
ntohs ( dh_val[i]->
len ));
1712 remaining -= frag_len;
1714 param_len = (
len - remaining );
1721 dh_g->data,
ntohs ( dh_g->len ) );
1723 DBGC ( tls,
"TLS %p unsupported %d-bit group:\n",
1724 tls, ( 8 *
ntohs ( dh_p->len ) ) );
1729 exchange =
group->exchange;
1730 DBGC ( tls,
"TLS %p using named group %s\n", tls, exchange->
name );
1734 ntohs ( dh_ys->len ), 1 ) ) != 0 ) {
1764 key_xchg =
malloc (
sizeof ( *key_xchg ) );
1771 key_xchg->type_length =
1773 htonl (
sizeof ( *key_xchg ) -
1774 sizeof ( key_xchg->type_length ) ) );
1775 key_xchg->dh_xs_len =
htons (
sizeof ( key_xchg->dh_xs ) );
1781 sizeof ( *key_xchg ) ) ) !=0 ) {
1782 goto err_send_handshake;
1808 const void *
data,
size_t len ) {
1821 if ( (
sizeof ( *ecdh ) >
len ) ||
1822 ( ecdh->public_len > (
len - sizeof ( *ecdh ) ) ) ) {
1823 DBGC ( tls,
"TLS %p received underlength ServerKeyExchange\n",
1828 param_len = (
sizeof ( *ecdh ) + ecdh->public_len );
1832 DBGC ( tls,
"TLS %p unsupported curve type %d\n",
1833 tls, ecdh->curve_type );
1839 DBGC ( tls,
"TLS %p unsupported named group %d\n",
1840 tls,
ntohs ( ecdh->named_group ) );
1845 exchange =
group->exchange;
1846 DBGC ( tls,
"TLS %p using named group %s\n", tls, exchange->
name );
1850 ecdh->public_len, 0 ) ) != 0 ) {
1880 key_xchg.type_length =
1882 htonl (
sizeof ( key_xchg ) -
1883 sizeof ( key_xchg.type_length ) ) );
1884 key_xchg.public_len =
sizeof ( key_xchg.public );
1890 sizeof ( key_xchg ) ) ) !=0 ) {
1964 const void *
data,
size_t len ) {
2039 typeof ( *server_name_ext ) server_name;
2040 typeof ( *max_fragment_length_ext ) max_fragment_length;
2041 typeof ( *signature_algorithms_ext ) signature_algorithms;
2042 typeof ( *renegotiation_info_ext ) renegotiation_info;
2043 typeof ( *session_ticket_ext ) session_ticket;
2044 typeof ( *extended_master_secret_ext ) extended_master_secret;
2045 typeof ( *named_group_ext )
2056 uint8_t compression_methods_len;
2057 uint8_t compression_methods[1];
2059 typeof ( *extensions ) extensions;
2070 sizeof (
hello.type_length ) ) );
2075 sizeof (
hello.session_id ) );
2079 hello.compression_methods_len =
sizeof (
hello.compression_methods );
2081 extensions = &
hello.extensions;
2084 server_name_ext = &extensions->server_name;
2086 server_name_ext->len =
htons (
sizeof ( server_name_ext->data ) );
2087 server_name_ext->data.len
2088 =
htons (
sizeof ( server_name_ext->data.list ) );
2090 server_name_ext->data.list[0].len
2091 =
htons (
sizeof ( server_name_ext->data.list[0].name ) );
2092 memcpy ( server_name_ext->data.list[0].name, session->
name,
2093 sizeof ( server_name_ext->data.list[0].name ) );
2096 max_fragment_length_ext = &extensions->max_fragment_length;
2098 max_fragment_length_ext->len
2099 =
htons (
sizeof ( max_fragment_length_ext->data ) );
2103 signature_algorithms_ext = &extensions->signature_algorithms;
2105 signature_algorithms_ext->len
2106 =
htons (
sizeof ( signature_algorithms_ext->data ) );
2107 signature_algorithms_ext->data.len
2108 =
htons (
sizeof ( signature_algorithms_ext->data.code ) );
2110 signature_algorithms_ext->data.code[i++] = sighash->
code;
2113 renegotiation_info_ext = &extensions->renegotiation_info;
2115 renegotiation_info_ext->len
2116 =
htons (
sizeof ( renegotiation_info_ext->data ) );
2117 renegotiation_info_ext->data.len
2118 =
sizeof ( renegotiation_info_ext->data.data );
2120 sizeof ( renegotiation_info_ext->data.data ) );
2123 session_ticket_ext = &extensions->session_ticket;
2125 session_ticket_ext->len
2126 =
htons (
sizeof ( session_ticket_ext->data ) );
2127 memcpy ( session_ticket_ext->data.data, session->
ticket,
2128 sizeof ( session_ticket_ext->data.data ) );
2131 extended_master_secret_ext = &extensions->extended_master_secret;
2132 extended_master_secret_ext->type
2134 extended_master_secret_ext->len = 0;
2137 if (
sizeof ( extensions->named_group ) ) {
2138 named_group_ext = &extensions->named_group[0];
2140 named_group_ext->len
2141 =
htons (
sizeof ( named_group_ext->data ) );
2142 named_group_ext->data.len
2143 =
htons (
sizeof ( named_group_ext->data.code ) );
2146 named_group_ext->data.code[i++] =
group->code;
2151 return action ( tls, &
hello,
sizeof (
hello ) );
2179 typeof ( *certificate ) certificates[0];
2190 len += (
sizeof ( *certificate ) + cert->
raw.
len );
2191 DBGC ( tls,
"TLS %p sending client certificate %s\n",
2203 certificates =
iob_put ( iobuf,
sizeof ( *certificates ) );
2204 certificates->type_length =
2206 htonl (
sizeof ( *certificates ) +
len -
2207 sizeof ( certificates->type_length ) ) );
2211 certificate =
iob_put ( iobuf,
sizeof ( *certificate ) );
2235 DBGC ( tls,
"TLS %p could not exchange keys: %s\n",
2245 DBGC ( tls,
"TLS %p could not generate keys: %s\n",
2276 DBGC ( tls,
"TLS %p could not identify (%s,%s) "
2277 "signature and hash algorithm\n", tls,
2286 &builder ) ) != 0 ) {
2287 DBGC ( tls,
"TLS %p could not sign %s digest using %s client "
2288 "private key: %s\n", tls, digest->
name, pubkey->
name,
2290 goto err_pubkey_sign;
2295 int use_sig_hash = ( ( sig_hash ==
NULL ) ? 0 : 1 );
2305 sizeof (
header.type_length )));
2306 if ( use_sig_hash ) {
2308 sizeof (
header.sig_hash[0] ) );
2313 sizeof (
header ) ) ) != 0 ) {
2314 DBGC ( tls,
"TLS %p could not construct Certificate "
2322 builder.
len ) ) != 0 ) {
2341 static const struct {
2348 &change_cipher,
sizeof ( change_cipher ) );
2368 if ( ! (
key->bound &&
2370 DBGC ( tls,
"TLS %p bound identity is not valid\n", tls );
2377 "client finished", digest_out, sizeof ( digest_out ) );
2380 memset ( &finished, 0,
sizeof ( finished ) );
2382 htonl (
sizeof ( finished ) -
2383 sizeof ( finished.type_length ) ) );
2385 sizeof ( finished.verify_data ) );
2389 sizeof ( finished ) ) ) != 0 )
2407 unsigned int description ) {
2413 .description = description,
2437 if ( (
sizeof ( *change_cipher ) !=
len ) ||
2439 DBGC ( tls,
"TLS %p received invalid Change Cipher\n", tls );
2443 iob_pull ( iobuf,
sizeof ( *change_cipher ) );
2447 DBGC ( tls,
"TLS %p could not activate RX cipher: %s\n",
2474 DBGC ( tls,
"TLS %p received overlength Alert\n", tls );
2481 switch (
alert->level ) {
2483 switch (
alert->description ) {
2485 DBGC ( tls,
"TLS %p closed by notification\n", tls );
2489 DBGC ( tls,
"TLS %p received warning alert %d\n",
2490 tls,
alert->description );
2495 DBGC ( tls,
"TLS %p received fatal alert %d\n",
2496 tls,
alert->description );
2499 DBGC ( tls,
"TLS %p received unknown alert level %d"
2500 "(alert %d)\n", tls,
alert->level,
alert->description );
2519 DBGC ( tls,
"TLS %p ignoring Hello Request\n", tls );
2525 DBGC ( tls,
"TLS %p refusing to renegotiate insecurely\n",
2545 const void *
data,
size_t len ) {
2581 if ( (
sizeof ( *hello_a ) >
len ) ||
2582 ( hello_a->session_id_len > (
len - sizeof ( *hello_a ) ) ) ||
2583 (
sizeof ( *hello_b ) > (
len -
sizeof ( *hello_a ) -
2584 hello_a->session_id_len ) ) ) {
2585 DBGC ( tls,
"TLS %p received underlength Server Hello\n", tls );
2589 session_id = hello_a->session_id;
2590 hello_b = ( (
void * ) ( session_id + hello_a->session_id_len ) );
2593 remaining = (
len -
sizeof ( *hello_a ) - hello_a->session_id_len -
2594 sizeof ( *hello_b ) );
2598 exts = ( (
void * ) hello_b->next );
2599 if ( (
sizeof ( *exts ) > remaining ) ||
2600 ( ( exts_len =
ntohs ( exts->len ) ) >
2601 ( remaining - sizeof ( *exts ) ) ) ) {
2602 DBGC ( tls,
"TLS %p received underlength extensions\n",
2609 for (
ext = ( (
void * ) exts->data ), remaining = exts_len ;
2611 ext = ( ( (
void * )
ext ) + sizeof ( *
ext ) + ext_len ),
2612 remaining -= (
sizeof ( *
ext ) + ext_len ) ) {
2615 if ( (
sizeof ( *
ext ) > remaining ) ||
2616 ( ( ext_len =
ntohs (
ext->len ) ) >
2617 ( remaining - sizeof ( *
ext ) ) ) ) {
2618 DBGC ( tls,
"TLS %p received underlength "
2619 "extension\n", tls );
2625 switch (
ext->type ) {
2627 reneg = ( (
void * )
ext->data );
2628 if ( (
sizeof ( *reneg ) > ext_len ) ||
2630 ( ext_len - sizeof ( *reneg ) ) ) ) {
2631 DBGC ( tls,
"TLS %p received "
2632 "underlength renegotiation "
2639 ems = ( (
void * )
ext->data );
2648 DBGC ( tls,
"TLS %p does not support protocol version %d.%d\n",
2653 DBGC ( tls,
"TLS %p server attempted to illegally upgrade to "
2654 "protocol version %d.%d\n",
2659 DBGC ( tls,
"TLS %p using protocol version %d.%d\n",
2678 if ( hello_a->session_id_len &&
2684 DBGC ( tls,
"TLS %p resuming session ID:\n", tls );
2693 DBGC ( tls,
"TLS %p mismatched extended master secret "
2694 "extension\n", tls );
2701 if ( hello_a->session_id_len &&
2702 ( hello_a->session_id_len <= sizeof ( tls->
session_id ))){
2706 DBGC ( tls,
"TLS %p new session ID:\n", tls );
2716 if ( ( reneg ==
NULL ) ||
2717 ( reneg->len != sizeof ( tls->
verify ) ) ||
2719 sizeof ( tls->
verify ) ) != 0 ) ) {
2720 DBGC ( tls,
"TLS %p server failed secure "
2721 "renegotiation\n", tls );
2725 }
else if ( reneg !=
NULL ) {
2728 if ( reneg->len != 0 ) {
2729 DBGC ( tls,
"TLS %p server provided non-empty initial "
2730 "renegotiation\n", tls );
2748 const void *
data,
size_t len ) {
2757 if (
sizeof ( *new_session_ticket ) >
len ) {
2758 DBGC ( tls,
"TLS %p received underlength New Session Ticket\n",
2763 ticket_len =
ntohs ( new_session_ticket->len );
2764 if ( ticket_len > (
len -
sizeof ( *new_session_ticket ) ) ) {
2765 DBGC ( tls,
"TLS %p received overlength New Session Ticket\n",
2783 DBGC ( tls,
"TLS %p new session ticket:\n", tls );
2799 const void *
data,
size_t len ) {
2801 size_t remaining =
len;
2817 goto err_alloc_chain;
2821 while ( remaining ) {
2826 size_t certificate_len;
2830 if (
sizeof ( *certificate ) > remaining ) {
2831 DBGC ( tls,
"TLS %p underlength certificate:\n", tls );
2834 goto err_underlength;
2836 certificate_len =
tls_uint24 ( &certificate->length );
2837 if ( certificate_len > ( remaining -
sizeof ( *certificate ) )){
2838 DBGC ( tls,
"TLS %p overlength certificate:\n", tls );
2841 goto err_overlength;
2843 record_len = (
sizeof ( *certificate ) + certificate_len );
2848 certificate_len ) ) != 0 ) {
2849 DBGC ( tls,
"TLS %p could not append certificate: %s\n",
2855 DBGC ( tls,
"TLS %p found certificate %s\n",
2860 remaining -= record_len;
2866 DBGC ( tls,
"TLS %p certificate chain is empty\n", tls );
2873 DBGC ( tls,
"TLS %p server certificate does not match %s: %s\n",
2900 const void *
data,
size_t len ) {
2905 size_t certificates_len;
2909 if (
sizeof ( *certificate ) >
len ) {
2910 DBGC ( tls,
"TLS %p received underlength Server Certificate\n",
2915 certificates_len =
tls_uint24 ( &certificate->length );
2916 if ( certificates_len > (
len -
sizeof ( *certificate ) ) ) {
2917 DBGC ( tls,
"TLS %p received overlength Server Certificate\n",
2925 certificates_len ) ) != 0 )
2940 const void *
data,
size_t len ) {
2984 DBGC ( tls,
"TLS %p selected client certificate %s\n",
2994 goto err_auto_append;
2998 DBGC ( tls,
"TLS %p could not find certificate corresponding "
2999 "to private key\n", tls );
3021 const void *
data,
size_t len ) {
3028 if (
sizeof ( *hello_done ) !=
len ) {
3029 DBGC ( tls,
"TLS %p received overlength Server Hello Done\n",
3039 DBGC ( tls,
"TLS %p could not start certificate validation: "
3057 const void *
data,
size_t len ) {
3069 DBGC ( tls,
"TLS %p received premature Finished\n", tls );
3073 if (
sizeof ( *finished ) !=
len ) {
3074 DBGC ( tls,
"TLS %p received overlength Finished\n", tls );
3082 "server finished", digest_out, sizeof ( digest_out ) );
3085 DBGC ( tls,
"TLS %p verification failed\n", tls );
3111 sizeof ( session->
id ) );
3147 while ( ( remaining =
iob_len ( iobuf ) ) ) {
3153 const void *payload;
3158 if (
sizeof ( *handshake ) > remaining ) {
3162 payload_len =
tls_uint24 ( &handshake->length );
3163 if ( payload_len > ( remaining -
sizeof ( *handshake ) ) ) {
3167 payload = &handshake->payload;
3168 record_len = (
sizeof ( *handshake ) + payload_len );
3171 switch ( handshake->type ) {
3202 DBGC ( tls,
"TLS %p ignoring handshake type %d\n",
3203 tls, handshake->type );
3262 DBGC ( tls,
"TLS %p could not deliver data: "
3305 DBGC ( tls,
"TLS %p unknown record type %d\n", tls,
type );
3312 list_add ( &(*iobuf)->list, rx_data );
3315 DBGC ( tls,
"TLS %p could not concatenate non-data record "
3316 "type %d\n", tls,
type );
3318 goto err_concatenate;
3322 if ( (
rc = handler ( tls, *iobuf ) ) != 0 )
3375 const void *
data,
size_t len ) {
3406 const void *
data,
size_t len,
void *hmac ) {
3462 return (
count * each );
3512 const void *plaintext;
3513 const void *encrypt;
3522 plaintext = iobuf->
data;
3549 sizeof (
iv.rec ) );
3551 sizeof (
iv ) ) ) != 0 ) {
3552 DBGC ( tls,
"TLS %p could not set TX IV: %s\n",
3559 tls_hmac ( cipherspec, &authhdr, plaintext, record_len,
3564 &authhdr,
NULL, sizeof ( authhdr ) );
3568 encrypt_len = ( record_len + suite->
mac_len );
3570 pad_len = ( ( ( cipher->
blocksize - 1 ) &
3571 -( encrypt_len + 1 ) ) + 1 );
3575 encrypt_len += pad_len;
3578 tlshdr =
iob_put ( iobuf,
sizeof ( *tlshdr ) );
3586 sizeof (
iv.rec ) );
3589 ciphertext =
iob_put ( iobuf, record_len );
3590 assert ( ciphertext <= plaintext );
3591 if ( encrypt_len > record_len ) {
3592 memmove ( ciphertext, plaintext, record_len );
3593 encrypt = ciphertext;
3595 encrypt = plaintext;
3603 memset (
iob_put ( iobuf, pad_len ), ( pad_len - 1 ), pad_len );
3606 DBGC2 ( tls,
"Sending plaintext data:\n" );
3607 DBGC2_HDA ( tls, 0, encrypt, encrypt_len );
3609 ciphertext, encrypt_len );
3615 plaintext += record_len;
3623 DBGC ( tls,
"TLS %p could not deliver ciphertext: %s\n",
3647 const void *
data,
size_t len ) {
3680 padding = ( iobuf->
tail - 1 );
3684 DBGC ( tls,
"TLS %p received underlength padding\n", tls );
3688 for ( i = 0 ; i <
pad ; i++ ) {
3689 if ( *(--padding) !=
pad ) {
3690 DBGC ( tls,
"TLS %p received bad padding\n", tls );
3738 DBGC ( tls,
"TLS %p received underlength IV\n", tls );
3745 len -=
sizeof (
iv.record );
3749 DBGC ( tls,
"TLS %p received underlength authentication tag\n",
3766 sizeof (
iv ) ) ) != 0 ) {
3767 DBGC ( tls,
"TLS %p could not set RX IV: %s\n",
3775 NULL, sizeof ( authhdr ) );
3783 check_len +=
iob_len ( iobuf );
3790 if ( pad_len < 0 ) {
3800 DBGC ( tls,
"TLS %p received underlength MAC\n", tls );
3809 DBGC2 ( tls,
"Received plaintext data:\n" );
3813 check_len +=
iob_len ( iobuf );
3820 tls_hmac_list ( cipherspec, &authhdr, rx_data, verify_mac );
3827 DBGC ( tls,
"TLS %p failed MAC verification\n", tls );
3833 DBGC ( tls,
"TLS %p failed authentication tag verification\n",
3959 reserve = ( ( -iv_len ) & ( cipher->
alignsize - 1 ) );
3960 remaining += reserve;
3964 while ( remaining ) {
3970 frag_len = remaining;
3973 remaining -= frag_len;
3975 frag_len += remaining;
3982 DBGC ( tls,
"TLS %p could not allocate %zd of %zd "
3983 "bytes for receive buffer\n", tls,
4168 DBGC ( tls,
"TLS %p certificate validation failed: %s\n",
4172 DBGC ( tls,
"TLS %p certificate validation succeeded\n", tls );
4251 DBGC ( tls,
"TLS %p could not send Client Hello: %s\n",
4259 DBGC ( tls,
"TLS %p cold not send Certificate: %s\n",
4267 DBGC ( tls,
"TLS %p could not send Client Key "
4275 DBGC ( tls,
"TLS %p could not send Certificate "
4283 DBGC ( tls,
"TLS %p could not send Change Cipher: "
4289 DBGC ( tls,
"TLS %p could not activate TX cipher: "
4298 DBGC ( tls,
"TLS %p could not send Finished: %s\n",
4350 DBGC ( tls,
"TLS %p joining session %s\n", tls,
name );
4363 name_copy = ( ( (
void * ) session ) +
sizeof ( *session ) );
4365 session->
name = name_copy;
4379 DBGC ( tls,
"TLS %p created session %s\n", tls,
name );
4409 tls =
malloc (
sizeof ( *tls ) );
4414 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]
pseudo_bit_t hash[0x00010]
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
struct x509_chain certstore
Certificate store.
Cryptographic configuration.
#define TLS_VERSION_MAX
Maximum TLS version.
#define TLS_VERSION_MIN
Minimum TLS version.
struct cipher_algorithm cipher_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 EPROTO
Protocol error.
#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 hkdf_expand(struct digest_algorithm *digest, const void *prk, const void *info, size_t info_len, void *out, size_t len)
Expand pseudorandom key.
void hkdf_extract(struct digest_algorithm *digest, const void *salt, size_t salt_len, const void *ikm, size_t ikm_len, void *prk)
Extract fixed-length pseudorandom key.
HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
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.
void hmac_key(struct digest_algorithm *digest, void *ctx, const void *secret, size_t len, void *key)
Construct HMAC reduced key.
void hmac_init_key(struct digest_algorithm *digest, void *ctx, const void *key)
Initialise HMAC from reduced key.
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.
static size_t hmac_keysize(struct digest_algorithm *digest)
Calculate HMAC reduced key size.
uint8_t info_len
Reject information length.
#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 exchange_share(struct exchange_algorithm *exchange, const void *private, void *public)
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 int exchange_agree(struct exchange_algorithm *exchange, const void *private, const void *partner, void *shared)
static int cipher_setiv(struct cipher_algorithm *cipher, void *ctx, const void *iv, size_t ivlen)
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
#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)
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_algorithm
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.
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.
#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.
struct digest_algorithm sha1_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.
A key exchange algorithm.
size_t sharedsize
Shared secret size.
size_t privsize
Private key 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).
An MD5+SHA1 HMAC key block.
uint8_t md5[MD5_BLOCK_SIZE]
MD5 HMAC key.
uint8_t sha1[SHA1_BLOCK_SIZE]
SHA-1 HMAC key.
const char * name
Algorithm name.
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.
struct tls_server server
Server state.
struct tls_key_schedule key
Key schedule.
struct tls_rx rx
Receive state.
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.
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(* server)(struct tls_connection *tls, const void *data, size_t len)
Receive new Server Key Exchange record using ECDHE key exchange.
int(* client)(struct tls_connection *tls)
Transmit Client Key Exchange record.
struct x509_certificate * bound
Server identity to which the schedule has been bound (if any).
int keyed
Schedule holds secret key material.
struct digest_algorithm * digest
Digest algorithm.
struct tls_named_group * group
Named key exchange group.
void * dynamic
Dynamically-allocated storage.
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 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.
uint8_t random[32]
Random bytes.
struct private_key * key
Private key.
uint8_t id[32]
Session ID.
uint8_t resumption_master_secret[48]
Resumption master secret.
int extended_master_secret
Extended master secret flag.
const char * name
Server name.
struct x509_certificate * cert
Server certificate.
size_t id_len
Length of session ID.
size_t ticket_len
Length of session ticket.
struct x509_root * root
Root of trust.
struct list_head conn
List of connections.
struct refcnt refcnt
Reference counter.
size_t resumption_master_secret_len
Length of resumption master secret.
void * ticket
Session ticket.
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.
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.
static int tls_new_server_key_exchange_pubkey(struct tls_connection *tls, const void *data, size_t len)
Receive new Server Key Exchange record using public key transport.
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 int tls_verify_dh_params(struct tls_connection *tls, const void *data, size_t len, size_t param_len)
Verify Diffie-Hellman parameter signature.
static void tls_validator_done(struct tls_connection *tls, int rc)
Handle certificate validation completion.
#define EINVAL_KEY_EXCHANGE
static int tls_send_alert(struct tls_connection *tls, unsigned int level, unsigned int description)
Transmit Alert record.
static void tls_p_hash_va(struct tls_connection *tls, struct digest_algorithm *digest, const void *hkey, void *out, size_t out_len, va_list seeds)
Generate secure pseudo-random data using a single hash function.
static int tls_set_digest(struct tls_connection *tls, struct digest_algorithm *digest)
Set key schedule digest algorithm.
static void tls_prf(struct tls_connection *tls, void *out, size_t out_len,...)
Generate secure pseudo-random data.
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_resume_secret(struct tls_connection *tls)
Resume from resumption master secret.
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.
#define EPERM_KEY_EXCHANGE
#define tls_prf_label(tls, out, out_len, label,...)
Generate secure pseudo-random data.
static int tls_send_finished(struct tls_connection *tls)
Transmit Finished record.
static int tls_agree_ephemeral(struct tls_connection *tls, const void *partner, size_t partner_len, int strip)
Agree ephemeral public key (i.e.
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 void tls_generate_master_secret(struct tls_connection *tls)
Generate master secret.
static int tls_send_client_hello(struct tls_connection *tls)
Transmit Client Hello record.
static int tls_share_ephemeral(struct tls_connection *tls, void *public)
Share ephemeral public key.
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 tls_hmac_final(struct tls_cipherspec *cipherspec, void *ctx, void *hmac)
Finalise HMAC.
#define ENOMEM_TX_PLAINTEXT
#define EINVAL_HELLO_DONE
static int tls_new_server_key_exchange_ecdhe(struct tls_connection *tls, const void *data, size_t len)
Receive new Server Key Exchange record using ECDHE key exchange.
static void tls_ephemeral(struct tls_connection *tls, const void *info, size_t info_len, void *out, size_t len)
Generate ephemeral secret.
#define TLS_NUM_CIPHER_SUITES
Number of supported cipher suites.
static void tls_set_binding(struct tls_connection *tls, struct x509_certificate *cert)
Bind key schedule to a server identity.
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_change_cipher(struct tls_connection *tls, struct tls_cipherspec_pair *pair)
Activate next cipher suite.
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.
static int tls_generate_ephemeral_master(struct tls_connection *tls)
Generate ephemeral master secret.
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 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_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_alert(struct tls_connection *tls, int rc)
Send closure alert and finish with TLS connection.
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 int tls_new_server_key_exchange_dhe(struct tls_connection *tls, const void *data, size_t len)
Receive new Server Key Exchange record using DHE key exchange.
static void tls_ephemeral_label(struct tls_connection *tls, const char *label, void *out, size_t len)
Generate ephemeral secret from label.
static void tls_generate_resumption_master(struct tls_connection *tls)
Generate resumption master secret.
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 void tls_clear_binding(struct tls_connection *tls)
Clear key schedule binding.
static int tls_parse_chain(struct tls_connection *tls, const void *data, size_t len)
Parse certificate chain.
static void tls_regenerate_ephemeral_master(struct tls_connection *tls)
Regenerate ephemeral master secret.
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 void tls_set_kdf_master(struct tls_connection *tls, const void *secret, size_t secret_len)
Set key derivation function master 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_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.
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_ephemeral_algorithm
HKDF algorithm for ephemeral secrets.
#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_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
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.
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_is_valid(struct x509_certificate *cert, struct x509_root *root)
Check if X.509 certificate is valid.
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_get(struct x509_certificate *cert)
Get reference to X.509 certificate.
static void x509_put(struct x509_certificate *cert)
Drop reference to X.509 certificate.
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.