tls: Add Hello extension sending support
PATCH 1/12 tls: Add Hello extension sending support
Declare a struct for ServerHello/ClientHello extensions with write and handle callbacks, modify our ServerHello and ClientHello message builders to append the extensions to the messages.
--- ell/tls-private.h | 18 +++++++ ell/tls.c | 125 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 136 insertions(+), 7 deletions(-)
ell/tls-private.h +18 -0
@@ -99,6 +99,24 @@ struct tls_compression_method {const char *name; }; +struct tls_hello_extension { +const char *name; +const char *short_name; +uint16_t id; +ssize_t (*client_write)(struct l_tls *tls,uint8_t *buf,size_t len); +/* Handle a Client Hello extension (on server), can't be NULL */ +bool (*client_handle)(struct l_tls *tls, +const uint8_t *buf,size_t len); +/* Handle a Client Hello extension's absence (on server) */ +bool (*client_handle_absent)(struct l_tls *tls); +ssize_t (*server_write)(struct l_tls *tls,uint8_t *buf,size_t len); +/* Handle a Server Hello extension (on client) */ +bool (*server_handle)(struct l_tls *tls, +const uint8_t *buf,size_t len); +/* Handle a Server Hello extension's absence (on client) */ +bool (*server_handle_absent)(struct l_tls *tls); +}; +enum tls_handshake_state {TLS_HANDSHAKE_WAIT_START ,TLS_HANDSHAKE_WAIT_HELLO ,
ell/tls.c +118 -7
175 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH 2/12 tls: Parse and process received extensions
On the server call the .client_handle callbacks for each supported extension in the received ClientHello and pass the list of extensions we've handled to the ServerHello builder. On the client, process the extension responses in the ServerHello by calling .server_handle callbacks.
--- ell/tls.c | 179 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 154 insertions(+), 25 deletions(-)
ell/tls.c +154 -25
@@ -1601,6 +1601,135 @@ static bool tls_verify_finished(struct l_tls *tls, const uint8_t *received,return true; } +static bool tls_ptr_match (const void *a,const void *b) +{ +return a == b; +} + +static bool tls_handle_hello_extensions (struct l_tls *tls, +const uint8_t *buf,size_t len, +struct l_queue *seen) +{ +unsigned int i; +const struct tls_hello_extension *extension; +bool client_hello = tls->server; +uint16_t extensions_size; + +if (!len) +return true; + +if (len <2 || len >2 +65535 ) + goto decode_error; + + extensions_size =l_get_be16 (buf); + len -=2 ; + buf +=2 ; + +if (len != extensions_size) + goto decode_error; + +while (len) { +uint16_t ext_id; +size_t ext_len; +bool (*handler)(struct l_tls *tls, +const uint8_t *buf,size_t len); + +if (len <4 ) + goto decode_error; + + ext_id =l_get_be16 (buf +0 ); + ext_len =l_get_be16 (buf +2 ); + buf +=4 ; + len -=4 ; + +if (ext_len > len) + goto decode_error; + +/* +* RFC 5246, Section 7.4.1.4: "There MUST NOT be more than +* one extension of the same type." +*/ +if (l_queue_find (seen, tls_ptr_match,L_UINT_TO_PTR (ext_id))) { +TLS_DEBUG ("Duplicate extension %u" , ext_id); + goto decode_error; + } + +l_queue_push_tail (seen,L_UINT_TO_PTR (ext_id)); + + extension =NULL ; + +for (i =0 ; tls_extensions[i].name; i++) +if (tls_extensions[i].id == ext_id) { + extension = &tls_extensions[i]; +break ; + } + +if (!extension) + goto next; + + handler = client_hello ? + extension->client_handle : extension->server_handle; + +/* +* RFC 5246, Section 7.4.1.4: "If a client receives an +* extension type in ServerHello that it did not request in +* the associated ClientHello, it MUST abort the handshake +* with an unsupported_extension fatal alert." +*/ +if (!client_hello && !handler) { +TLS_DISCONNECT (TLS_ALERT_UNSUPPORTED_EXTENSION ,0 , +"%s extension not expected in " +"a ServerHello" , extension->name); +return false; + } + +if (!handler (tls, buf, ext_len)) { +TLS_DISCONNECT (TLS_ALERT_DECODE_ERROR ,0 , +"Hello %s extension parse error" , + extension->name); +return false; + } + +next: + buf += ext_len; + len -= ext_len; + } + +/* +* Trigger any actions needed when an extension is missing and its +* handler has not been called yet. +*/ +for (i =0 ; tls_extensions[i].name; i++) { +bool (*handler)(struct l_tls *tls); + + extension = &tls_extensions[i]; + handler = client_hello ? + extension->client_handle_absent : + extension->server_handle_absent; + +if (!handler) +continue ; + +if (l_queue_find (seen, tls_ptr_match, +L_UINT_TO_PTR (extension->id))) +continue ; + +if (!handler (tls)) { +TLS_DISCONNECT (TLS_ALERT_DECODE_ERROR ,0 , +"Hello %s extension missing" , + extension->name); +return false; + } + } + +return true; + +decode_error: +TLS_DISCONNECT (TLS_ALERT_DECODE_ERROR ,0 , +"Hello extensions decode error" ); +return false; +} +static void tls_handle_client_hello (struct l_tls *tls,const uint8_t *buf,size_t len) {
@@ -1609,6 +1738,7 @@ static void tls_handle_client_hello(struct l_tls *tls,const uint8_t *cipher_suites;const uint8_t *compression_methods;int i; +struct l_queue *extensions_offered =NULL ;/* Do we have enough for ProtocolVersion + Random + SessionID size? */ if (len <2 +32 +1 )
@@ -1650,22 +1780,12 @@ static void tls_handle_client_hello(struct l_tls *tls, len -= compression_methods_size; -if (len) { -uint16_t extensions_size; - -if (len <2 || len >2 +65535 ) - goto decode_error; - - extensions_size =l_get_be16 (compression_methods + - compression_methods_size); - len -=2 ; - -if (len != extensions_size) - goto decode_error; + extensions_offered =l_queue_new (); -/* TODO: validate each extension in the vector, 7.4.1.4 */ -/* TODO: check for duplicates? */ - } +if (!tls_handle_hello_extensions (tls, compression_methods + + compression_methods_size, + len, extensions_offered)) + goto cleanup;/* * Note: if the client is supplying a SessionID we know it is false
@@ -1688,7 +1808,7 @@ static void tls_handle_client_hello(struct l_tls *tls,TLS_DISCONNECT (TLS_ALERT_PROTOCOL_VERSION ,0 ,"Client version too low: %02x" , tls->client_version); -return ; + goto cleanup; } tls->negotiated_version = TLS_VERSION < tls->client_version ?
@@ -1721,13 +1841,13 @@ static void tls_handle_client_hello(struct l_tls *tls,TLS_DISCONNECT (TLS_ALERT_HANDSHAKE_FAIL ,0 ,"No common cipher suites matching negotiated " "TLS version and our certificate's key type" ); -return ; + goto cleanup; }if (!tls_set_prf_hmac (tls)) {TLS_DISCONNECT (TLS_ALERT_INTERNAL_ERROR ,0 ,"Error selecting the PRF HMAC" ); -return ; + goto cleanup; }TLS_DEBUG ("Negotiated %s" , tls->pending.cipher_suite->name);
@@ -1738,7 +1858,7 @@ static void tls_handle_client_hello(struct l_tls *tls,if (!memchr (compression_methods,0 , compression_methods_size)) {TLS_DISCONNECT (TLS_ALERT_HANDSHAKE_FAIL ,0 ,"No common compression methods" ); -return ; + goto cleanup; }while (compression_methods_size) {
@@ -1754,8 +1874,10 @@ static void tls_handle_client_hello(struct l_tls *tls,TLS_DEBUG ("Negotiated %s" , tls->pending.compression_method->name); -if (!tls_send_server_hello (tls,NULL )) -return ; +if (!tls_send_server_hello (tls, extensions_offered)) + goto cleanup; + +l_queue_destroy (extensions_offered,NULL );if (tls->pending.cipher_suite->key_xchg->certificate_check && tls->cert)if (!tls_send_certificate (tls))
@@ -1780,6 +1902,9 @@ static void tls_handle_client_hello(struct l_tls *tls, decode_error:TLS_DISCONNECT (TLS_ALERT_DECODE_ERROR ,0 ,"ClientHello decode error" ); + +cleanup: +l_queue_destroy (extensions_offered,NULL ); } static void tls_handle_server_hello(struct l_tls *tls,
@@ -1788,6 +1913,8 @@ static void tls_handle_server_hello(struct l_tls *tls,uint8_t session_id_size, cipher_suite_id[2 ], compression_method_id;const char *error;int i; +struct l_queue *extensions_seen; +bool result;/* Do we have enough for ProtocolVersion + Random + SessionID len ? */ if (len <2 +32 +1 )
@@ -1806,11 +1933,13 @@ static void tls_handle_server_hello(struct l_tls *tls, compression_method_id = buf[35 + session_id_size +2 ]; len -= session_id_size +2 +1 ; -if (len !=0 ) {/* We know we haven't solicited any extensions */ -TLS_DISCONNECT (TLS_ALERT_UNSUPPORTED_EXTENSION ,0 , -"ServerHello contains extensions" ); + extensions_seen =l_queue_new (); + result =tls_handle_hello_extensions (tls, buf +38 + session_id_size, + len, extensions_seen); +l_queue_destroy (extensions_seen,NULL ); + +if (!result)return ; - } tls->negotiated_version =l_get_be16 (buf);
Signature · 1 line
2.19.1
PATCH 3/12 tls: Implement the Supported Elliptic Curves extension
In reply to Andrew ZaborowskiDefined in RFC 8422 5.1.1
--- Makefile.am | 1 + ell/tls-extensions.c | 108 +++++++++++++++++++++++++++++++++++++++++++ ell/tls-private.h | 10 ++++ ell/tls.c | 3 +- 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 ell/tls-extensions.c
Makefile.am +1 -0
@@ -102,6 +102,7 @@ ell_libell_la_SOURCES = $(linux_headers) \ ell/tls-private.h \ ell/tls.c \ ell/tls-record.c \ + ell/tls-extensions.c \ ell/uuid.c \ ell/key.c \ ell/pkcs5-private.h \
ell/tls-extensions.c new file +108 -0
108 lines not on this page · raw message
ell/tls-private.h +10 -0
@@ -117,6 +117,15 @@ struct tls_hello_extension {bool (*server_handle_absent)(struct l_tls *tls); }; +extern const struct tls_hello_extension tls_extensions[]; + +struct tls_named_curve { +const char *name; +uint16_t id; +unsigned int l_group; +size_t point_bytes; +}; +enum tls_handshake_state {TLS_HANDSHAKE_WAIT_START ,TLS_HANDSHAKE_WAIT_HELLO ,
@@ -198,6 +207,7 @@ struct l_tls {size_t peer_pubkey_size;enum handshake_hash_type signature_hash;const struct tls_hash_algorithm *prf_hmac; +const struct tls_named_curve *negotiated_curve;/* SecurityParameters current and pending */
ell/tls.c +1 -2
@@ -191,6 +191,7 @@ static void tls_reset_handshake(struct l_tls *tls) tls->peer_cert =NULL ; tls->peer_pubkey =NULL ; tls->peer_pubkey_size =0 ; + tls->negotiated_curve =NULL ;for (hash =0 ; hash < __HANDSHAKE_HASH_COUNT; hash++)tls_drop_handshake_hash (tls, hash);
@@ -709,8 +710,6 @@ static const struct tls_hash_algorithm *tls_set_prf_hmac(struct l_tls *tls)return NULL ; } -static const struct tls_hello_extension tls_extensions[] = {{}}; -enum tls_handshake_type {TLS_HELLO_REQUEST =0 ,TLS_CLIENT_HELLO =1 ,
Signature · 1 line
2.19.1
PATCH 4/12 tls: Implement the Supported Point Formats extension
In reply to Andrew ZaborowskiDefined in RFC 8422 5.1.2
--- ell/tls-extensions.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
ell/tls-extensions.c +42 -0
@@ -96,6 +96,40 @@ static bool tls_elliptic_curves_client_absent(struct l_tls *tls)return true; } +static bool tls_ec_point_formats_client_handle (struct l_tls *tls, +const uint8_t *buf,size_t len) +{ +if (len <2 ) +return false; + +if (buf[0 ] != len -1 ) +return false; + +if (!memchr (buf +1 ,0 , len -1 )) { +TLS_DEBUG ("Uncompressed point format missing" ); +return false; + } + +return true; +} + +/* +* For compatibility with clients respond to a valid Client Hello Supported +* Point Formats extension with the hardcoded confirmation that we do +* support the single valid point format. As a client we never send this +* extension so we never have to handle a server response to it either. +*/ +static ssize_t tls_ec_point_formats_server_write (struct l_tls *tls, +uint8_t *buf,size_t len) +{ +if (len <2 ) +return -ENOMEM ; + + buf[0 ] =0x01 ;/* ec_point_format_list length */ + buf[1 ] =0x00 ;/* uncompressed */ +return 2 ; +} +const struct tls_hello_extension tls_extensions[] = { {"Supported Elliptic Curves" ,"elliptic_curves" ,10 ,
@@ -104,5 +138,13 @@ const struct tls_hello_extension tls_extensions[] = { tls_elliptic_curves_client_absent,NULL ,NULL ,NULL , }, + { + "Supported Point Formats", "ec_point_formats", 11, +NULL , + tls_ec_point_formats_client_handle, +NULL , + tls_ec_point_formats_server_write, + NULL, NULL, + }, {} };
Signature · 1 line
2.19.1
PATCH 5/12 tls: Allow user to set custom list of cipher suites
In reply to Andrew ZaborowskiTLS "security profiles" define which minimum cipher suites and other parameter values are allowed in a specific usage scenario for TLS, for example WPA3 in theory requires a specific security profile for its TLS-based EAP method. This will also allow the unit tests to test individual cipher suites.
--- ell/tls-private.h | 5 + ell/tls.c | 260 +++++++++++++++++++++++++++++++--------------- 2 files changed, 181 insertions(+), 84 deletions(-)
ell/tls-private.h +5 -0
@@ -180,6 +180,8 @@ struct l_tls {struct l_key *priv_key;size_t priv_key_size; +struct tls_cipher_suite **cipher_suite_pref_list; +/* Record layer */ uint8_t *record_buf;
@@ -267,6 +269,9 @@ void tls_tx_record(struct l_tls *tls, enum tls_content_type type,bool tls_handle_message (struct l_tls *tls,const uint8_t *message,int len,enum tls_content_type type,uint16_t version); +/* Optionally limit allowed cipher suites to a custom set */ +bool tls_set_cipher_suites (struct l_tls *tls,const char **suite_list); +int tls_parse_certificate_list (const void *data,size_t len,struct l_certchain **out_certchain);
ell/tls.c +176 -84
351 lines not on this page · raw message
Signature · 1 line
2.19.1
Re: [PATCH 05/12] tls: Allow user to set custom list of cipher suites
Hi Andrew,
Quoted 10 lines · Andrew Zaborowski
TLS "security profiles" define which minimum cipher suites and other parameter values are allowed in a specific usage scenario for TLS, for example WPA3 in theory requires a specific security profile for its TLS-based EAP method. This will also allow the unit tests to test individual cipher suites.
--- ell/tls-private.h | 5 + ell/tls.c | 260 +++++++++++++++++++++++++++++++--------------- 2 files changed, 181 insertions(+), 84 deletions(-)
Patches 1-5 applied, thanks.
Regards,
-Denis
PATCH 6/12 tls: Move cipher suite definitions to tls-suites.c
In reply to Andrew ZaborowskiMove the cipher suite-specific code to new file ell/tls-suites.c. Unfortunately this requires a few functions and arrays to be exported from tls.c.
--- Makefile.am | 1 + ell/tls-private.h | 25 +++ ell/tls-suites.c | 450 ++++++++++++++++++++++++++++++++++++++++++++ ell/tls.c | 465 ++-------------------------------------------- 4 files changed, 490 insertions(+), 451 deletions(-) create mode 100644 ell/tls-suites.c
Makefile.am +1 -0
@@ -103,6 +103,7 @@ ell_libell_la_SOURCES = $(linux_headers) \ ell/tls.c \ ell/tls-record.c \ ell/tls-extensions.c \ + ell/tls-suites.c \ ell/uuid.c \ ell/key.c \ ell/pkcs5-private.h \
ell/tls-private.h +25 -0
@@ -56,6 +56,8 @@ struct tls_hash_algorithm {const char *name; }; +extern const struct tls_hash_algorithm tls_handshake_hash_data[]; +typedef bool (*tls_get_hash_t )(struct l_tls *tls,uint8_t tls_id,uint8_t *out,size_t *len,enum l_checksum_type *type);
@@ -94,6 +96,8 @@ struct tls_cipher_suite {enum l_checksum_type prf_hmac; }; +extern struct tls_cipher_suite *tls_cipher_suite_pref[]; +struct tls_compression_method {int id;const char *name;
@@ -145,6 +149,19 @@ enum tls_content_type { TLS_CT_APPLICATION_DATA = 23, }; +enum tls_handshake_type { +TLS_HELLO_REQUEST =0 , +TLS_CLIENT_HELLO =1 , +TLS_SERVER_HELLO =2 , +TLS_CERTIFICATE =11 , +TLS_SERVER_KEY_EXCHANGE =12 , +TLS_CERTIFICATE_REQUEST =13 , +TLS_SERVER_HELLO_DONE =14 , +TLS_CERTIFICATE_VERIFY =15 , +TLS_CLIENT_KEY_EXCHANGE =16 , +TLS_FINISHED =20 , +}; +/* * Support the minimum required set of handshake hash types for the * Certificate Verify digital signature and the Finished PRF seed so we
@@ -269,9 +286,17 @@ void tls_tx_record(struct l_tls *tls, enum tls_content_type type,bool tls_handle_message (struct l_tls *tls,const uint8_t *message,int len,enum tls_content_type type,uint16_t version); +#define TLS_HANDSHAKE_HEADER_SIZE 4 + +void tls_tx_handshake (struct l_tls *tls,int type,uint8_t *buf,size_t length); +/* Optionally limit allowed cipher suites to a custom set */ bool tls_set_cipher_suites (struct l_tls *tls,const char **suite_list); +void tls_generate_master_secret (struct l_tls *tls, +const uint8_t *pre_master_secret, +int pre_master_secret_len); +int tls_parse_certificate_list (const void *data,size_t len,struct l_certchain **out_certchain);
ell/tls-suites.c new file +450 -0
450 lines not on this page · raw message
ell/tls.c +14 -451
536 lines not on this page · raw message
Signature · 1 line
2.19.1
Re: [PATCH 06/12] tls: Move cipher suite definitions to tls-suites.c
Hi Andrew,
Quoted 11 lines · Andrew Zaborowski
Move the cipher suite-specific code to new file
ell/tls-suites.c. Unfortunately this requires a few functions and arrays to be exported fromtls.c.--- Makefile.am | 1 + ell/tls-private.h | 25 +++ ell/tls-suites.c | 450 ++++++++++++++++++++++++++++++++++++++++++++ ell/tls.c | 465 ++-------------------------------------------- 4 files changed, 490 insertions(+), 451 deletions(-)create mode 100644
ell/tls-suites.c
<snip>
ell/tls.c static ssize_t tls_append_hello_extensions(struct l_tls *tls, · line 740
Quoted 10 lines
ell/tls.c +1
-2@@ -903,8 +734,7 @@ static ssize_t tls_append_hello_extensions(struct l_tls *tls,static bool tls_send_client_hello (struct l_tls *tls) { -uint8_t buf[1024 +L_ARRAY_SIZE (tls_compression_pref) + -2 *L_ARRAY_SIZE (tls_cipher_suite_pref)]; +uint8_t buf[1024 +L_ARRAY_SIZE (tls_compression_pref)];uint8_t *ptr = buf +TLS_HANDSHAKE_HEADER_SIZE ;uint8_t *len_ptr;unsigned int i;
Was this chunk intended?
Anyway, I went ahead and applied this patch. Send me a fix if needed.
Regards,
-Denis
Re: [PATCH 06/12] tls: Move cipher suite definitions to tls-suites.c
Hi Denis,
Quoted 14 lines · Denis Kenzior
ell/tls.c static ssize_t tls_append_hello_extensions(struct l_tls *tls, · line 740
Quoted 10 lines · Andrew Zaborowski
ell/tls.c +1
-2@@ -903,8 +734,7 @@ static ssize_t tls_append_hello_extensions(struct l_tls *tls,static bool tls_send_client_hello (struct l_tls *tls) { -uint8_t buf[1024 +L_ARRAY_SIZE (tls_compression_pref) + -2 *L_ARRAY_SIZE (tls_cipher_suite_pref)]; +uint8_t buf[1024 +L_ARRAY_SIZE (tls_compression_pref)];uint8_t *ptr = buf +TLS_HANDSHAKE_HEADER_SIZE ;uint8_t *len_ptr;unsigned int i;Was this chunk intended?
Quoted 1 line
Anyway, I went ahead and applied this patch. Send me a fix if needed.
Thank you. After scratching my head for a moment I remember this chunk is because tls_cipher_suite_pref is now in another file so ARRAY_SIZE won't work. But the message size is limited by the extensions implemented, right now it's less than 100 bytes actually. unit/test-tls will immediately tell us if it becomes too big.
Best regards
PATCH 7/12 tls: Add ServerKeyExchange callbacks to key exchange struct
In reply to Andrew ZaborowskiTLS Key Exchange algorithms using ephemeral keys (DHE_* and ECDHE_*) need to use the ServerKeyExchange message during the handshake unlike our current RSA key exchanhe, provide callbacks for sending and receiving those messages.
--- ell/tls-private.h | 4 ++++ ell/tls.c | 61 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 10 deletions(-)
ell/tls-private.h +4 -0
@@ -69,6 +69,10 @@ struct tls_key_exchange_algorithm {bool (*validate_cert_key_type)(struct l_cert *cert); +bool (*send_server_key_exchange)(struct l_tls *tls); +void (*handle_server_key_exchange)(struct l_tls *tls, +const uint8_t *buf,size_t len); +bool (*send_client_key_exchange)(struct l_tls *tls);void (*handle_client_key_exchange)(struct l_tls *tls,const uint8_t *buf,size_t len);
ell/tls.c +51 -10
89 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH 8/12 tls: ECHDE_RSA key exchange implementation client side
In reply to Andrew ZaborowskiAdd a new key exchange definition with the callbacks needed to handle the client side of the ECDHE_RSA key exchange, defined in RFC 8422. Key Exchange method-specific state is kept in a struct allocated by the method and pointed to by a void pointer in the l_tls struct so that the internals of the method are kept in tls-suites.c
--- ell/tls-extensions.c | 11 ++ ell/tls-private.h | 5 + ell/tls-suites.c | 246 +++++++++++++++++++++++++++++++++++++++++++ ell/tls.c | 4 + 4 files changed, 266 insertions(+)
ell/tls-extensions.c +11 -0
@@ -148,3 +148,14 @@ const struct tls_hello_extension tls_extensions[] = { }, {} }; + +const struct tls_named_curve *tls_find_curve (uint16_t id) +{ +unsigned int i; + +for (i =0 ; i <L_ARRAY_SIZE (tls_curve_pref); i++) +if (tls_curve_pref[i].id == id) +return &tls_curve_pref[i]; + +return NULL ; +}
ell/tls-private.h +5 -0
@@ -81,6 +81,8 @@ struct tls_key_exchange_algorithm { tls_get_hash_t get_hash);bool (*verify)(struct l_tls *tls,const uint8_t *in,size_t len,tls_get_hash_t get_hash); + +void (*free_params)(struct l_tls *tls); };struct tls_mac_algorithm {
@@ -246,6 +248,7 @@ struct l_tls {* 6.3 v1.2 + two IVs of 32 bytes. */ uint8_t key_block[192 ]; +void *key_xchg_params; } pending;enum tls_cipher_type cipher_type[2 ];
@@ -301,6 +304,8 @@ void tls_generate_master_secret(struct l_tls *tls,const uint8_t *pre_master_secret, int pre_master_secret_len); +const struct tls_named_curve *tls_find_curve (uint16_t id); +int tls_parse_certificate_list (const void *data,size_t len,struct l_certchain **out_certchain);
ell/tls-suites.c +246 -0
258 lines not on this page · raw message
ell/tls.c +4 -0
@@ -186,6 +186,10 @@ static void tls_reset_handshake(struct l_tls *tls)memset (tls->pending.key_block,0 ,sizeof (tls->pending.key_block)); +if (tls->pending.cipher_suite && + tls->pending.cipher_suite->key_xchg->free_params) + tls->pending.cipher_suite->key_xchg->free_params (tls); +l_cert_free (tls->peer_cert);l_key_free (tls->peer_pubkey);
Signature · 1 line
2.19.1
PATCH 9/12 tls: ECHDE_RSA key exchange implementation server side
In reply to Andrew ZaborowskiAdd the handler for the ECDHE ClientKeyExchange message rx and a builder for the ServerKeyExchange message tx, both specified in RFC 8422.
--- ell/tls-private.h | 1 + ell/tls-suites.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++ ell/tls.c | 18 +++++++ 3 files changed, 141 insertions(+)
ell/tls-private.h +1 -0
@@ -66,6 +66,7 @@ struct tls_key_exchange_algorithm {uint8_t id;bool certificate_check; +bool need_ecc;bool (*validate_cert_key_type)(struct l_cert *cert);
ell/tls-suites.c +122 -0
140 lines not on this page · raw message
ell/tls.c +18 -0
@@ -476,6 +476,24 @@ static bool tls_cipher_suite_is_compatible(struct l_tls *tls,return false; } +/* +* On the server we know what elliptic curve we'll be using as soon +* as we've processed the ClientHello so for EC-based key exchange +* methods require that a curve has been selected. +*/ +if (suite->key_xchg->need_ecc && tls->server && + !tls->negotiated_curve) { +if (error) { + *error = error_buf; +snprintf (error_buf,sizeof (error_buf), +"No common supported elliptic curves " +"with the client, can't use %s" , + suite->name); + } + +return false; + } +return true; }
Signature · 1 line
2.19.1
PATCH 10/12 tls: Add RFC4492 suites using the ECDHE_RSA key exchange
In reply to Andrew ZaborowskiAdd the 4 cipher suites defined in RFC 4492 that we can now support with the new ECDHE_RSA key exchange (see section 6 in RFC 4492 and 8422 for the full list of ECDH-based cipher suites.)
--- ell/tls-suites.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
ell/tls-suites.c +32 -0
@@ -802,16 +802,48 @@ static struct tls_cipher_suite tls_rsa_with_rc4_128_md5 = { .encryption = &tls_aes256_gcm, .prf_hmac = L_CHECKSUM_SHA384, .key_xchg = &tls_rsa, +}, tls_ecdhe_rsa_with_rc4_128_sha = { + .id = { 0xc0, 0x11 }, + .name = "TLS_ECDHE_RSA_WITH_RC4_128_SHA", + .verify_data_length = 12, + .encryption = &tls_rc4, + .mac = &tls_sha, + .key_xchg = &tls_ecdhe_rsa, +}, tls_ecdhe_rsa_with_3des_ede_cbc_sha = { + .id = { 0xc0, 0x12 }, + .name = "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", + .verify_data_length = 12, + .encryption = &tls_3des_ede, + .mac = &tls_sha, + .key_xchg = &tls_ecdhe_rsa, +}, tls_ecdhe_rsa_with_aes_128_cbc_sha = { + .id = { 0xc0, 0x13 }, + .name = "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + .verify_data_length = 12, + .encryption = &tls_aes128, + .mac = &tls_sha, + .key_xchg = &tls_ecdhe_rsa, +}, tls_ecdhe_rsa_with_aes_256_cbc_sha = { + .id = { 0xc0, 0x14 }, + .name = "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + .verify_data_length = 12, + .encryption = &tls_aes256, + .mac = &tls_sha, + .key_xchg = &tls_ecdhe_rsa, };struct tls_cipher_suite *tls_cipher_suite_pref[] = { + &tls_ecdhe_rsa_with_aes_256_cbc_sha, + &tls_ecdhe_rsa_with_aes_128_cbc_sha, &tls_rsa_with_aes_256_cbc_sha, &tls_rsa_with_aes_128_cbc_sha, &tls_rsa_with_aes_256_cbc_sha256, &tls_rsa_with_aes_128_cbc_sha256, &tls_rsa_with_aes_256_gcm_sha384, &tls_rsa_with_aes_128_gcm_sha256, + &tls_ecdhe_rsa_with_3des_ede_cbc_sha, &tls_rsa_with_3des_ede_cbc_sha, + &tls_ecdhe_rsa_with_rc4_128_sha, &tls_rsa_with_rc4_128_sha, &tls_rsa_with_rc4_128_md5, NULL,
Signature · 1 line
2.19.1
PATCH 11/12 tls: Add RFC5289 suites using the ECDHE_RSA key exchange
In reply to Andrew ZaborowskiAdd the 4 cipher suites defined in RFC 5289 that we can now support with the new ECDHE_RSA key exchange, 2 of these are the same ones defined in RFC 8422.
--- ell/tls-suites.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
ell/tls-suites.c +36 -0
@@ -738,6 +738,10 @@ static struct tls_mac_algorithm tls_md5 = { .id = 4, .hmac_type = L_CHECKSUM_SHA256, .mac_length =32 , +}, tls_sha384 = { + .id =5 , + .hmac_type = L_CHECKSUM_SHA384, + .mac_length = 48, }; static struct tls_cipher_suite tls_rsa_with_rc4_128_md5 = {
@@ -830,6 +834,34 @@ static struct tls_cipher_suite tls_rsa_with_rc4_128_md5 = { .encryption = &tls_aes256, .mac = &tls_sha, .key_xchg = &tls_ecdhe_rsa, +}, tls_ecdhe_rsa_with_aes_128_cbc_sha256 = { + .id = { 0xc0, 0x27 }, + .name = "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", + .verify_data_length = 12, + .encryption = &tls_aes128, + .mac = &tls_sha256, + .key_xchg = &tls_ecdhe_rsa, +}, tls_ecdhe_rsa_with_aes_256_cbc_sha384 = { + .id = { 0xc0, 0x28 }, + .name = "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", + .verify_data_length = 12, + .encryption = &tls_aes256, + .mac = &tls_sha384, + .prf_hmac = L_CHECKSUM_SHA384, + .key_xchg = &tls_ecdhe_rsa, +}, tls_ecdhe_rsa_with_aes_128_gcm_sha256 = { + .id = { 0xc0, 0x2f }, + .name = "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + .verify_data_length = 12, + .encryption = &tls_aes128_gcm, + .key_xchg = &tls_ecdhe_rsa, +}, tls_ecdhe_rsa_with_aes_256_gcm_sha384 = { + .id = { 0xc0, 0x30 }, + .name = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + .verify_data_length = 12, + .encryption = &tls_aes256_gcm, + .prf_hmac = L_CHECKSUM_SHA384, + .key_xchg = &tls_ecdhe_rsa, }; struct tls_cipher_suite *tls_cipher_suite_pref[] = {
@@ -837,8 +869,12 @@ struct tls_cipher_suite *tls_cipher_suite_pref[] = { &tls_ecdhe_rsa_with_aes_128_cbc_sha, &tls_rsa_with_aes_256_cbc_sha, &tls_rsa_with_aes_128_cbc_sha, + &tls_ecdhe_rsa_with_aes_256_cbc_sha384, + &tls_ecdhe_rsa_with_aes_128_cbc_sha256, &tls_rsa_with_aes_256_cbc_sha256, &tls_rsa_with_aes_128_cbc_sha256, + &tls_ecdhe_rsa_with_aes_256_gcm_sha384, + &tls_ecdhe_rsa_with_aes_128_gcm_sha256, &tls_rsa_with_aes_256_gcm_sha384, &tls_rsa_with_aes_128_gcm_sha256, &tls_ecdhe_rsa_with_3des_ede_cbc_sha,
Signature · 1 line
2.19.1
PATCH 12/12 random: Remove 256 byte limit
In reply to Andrew Zaborowski--- ell/random.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
ell/random.c +10 -11
@@ -37,7 +37,7 @@#define GRND_NONBLOCK 0x0001#endif -#ifndef GRND_RANOM +#ifndef GRND_RANDOM #define GRND_RANDOM 0x0002#endif
@@ -57,19 +57,18 @@ static inline int getrandom(void *buffer, size_t count, unsigned flags) {**/ LIB_EXPORT bool l_getrandom(void *buf, size_t len) { -int ret; - -if (len >256 ) -return false; +while (len) { +int ret; - ret =getrandom (buf, len,0 ); -if (ret <0 ) -return false; + ret =TEMP_FAILURE_RETRY (getrandom (buf, len,0 )); +if (ret <0 ) +return false; -if ((size_t ) ret == len) -return true; + buf += ret; + len -= ret; + } -return false; +return true; } LIB_EXPORT bool l_getrandom_is_supported()
Signature · 1 line
2.19.1
Re: [PATCH 12/12] random: Remove 256 byte limit
Hi Andrew,
Quoted 4 lines · Andrew Zaborowski
--- ell/random.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
Patches 07-12 applied, thanks.
Regards,
-Denis