openssl/ssl
Benjamin Kaduk 6b1bb98fad Add SSL_CTX early callback
Provide a callback interface that gives the application the ability
to adjust the nascent SSL object at the earliest stage of ClientHello
processing, immediately after extensions have been collected but
before they have been processed.

This is akin to BoringSSL's "select_certificate_cb" (though it is not
API compatible), and as the name indicates, one major use is to examine
the supplied server name indication and select what certificate to
present to the client.  However, it can also be used to make more
sweeping configuration changes to the SSL object according to the
selected server identity and configuration.  That may include adjusting
the permitted TLS versions, swapping out the SSL_CTX object (as is
traditionally done in a tlsext_servername_callback), changing the
server's cipher list, and more.

We also wish to allow an early callback to indicate that it needs to perform
additional work asynchronously and resume processing later.  To that effect,
refactor the second half of tls_process_client_hello() into a subroutine to be
called at the post-processing stage (including the early callback itself), to
allow the callback to result in remaining in the same work stage for a later
call to succeed.  This requires allocating for and storing the CLIENTHELLO_MSG
in the SSL object to be preserved across such calls, but the storage is
reclaimed after ClientHello processing finishes.

Information about the CliehtHello is available to the callback by means of
accessor functions that can only be used from the early callback.  This allows
extensions to make use of the existing internal parsing machinery without
exposing structure internals (e.g., of PACKET), so that applications do not
have to write fragile parsing code.

Applications are encouraged to utilize an early callback and not use
a servername_callback, in order to avoid unexpected behavior that
occurs due to the relative order of processing between things like
session resumption and the historical servername callback.

Also tidy up nearby style by removing unnecessary braces around one-line
conditional bodies.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2279)
2017-02-23 19:40:26 +01:00
..
record Remove an OPENSSL_assert() and replace with a soft assert and check 2017-02-16 09:35:56 +00:00
statem Add SSL_CTX early callback 2017-02-23 19:40:26 +01:00
bio_ssl.c
build.info
d1_lib.c Don't change the state of the ETM flags until CCS processing 2017-02-16 09:35:56 +00:00
d1_msg.c
d1_srtp.c
methods.c
packet_locl.h Miscellaneous style tweaks based on feedback received 2017-01-30 10:18:23 +00:00
packet.c Use for loop in WPACKET_fill_lengths instead of do...while 2017-01-30 10:18:24 +00:00
pqueue.c
s3_cbc.c
s3_enc.c fix a memory leak in ssl3_generate_key_block fix the error handling in ssl3_change_cipher_state 2017-01-23 11:41:59 +01:00
s3_lib.c Add more first-class support for SCSVS 2017-02-23 19:24:37 +01:00
s3_msg.c
ssl_asn1.c Fix i2d_SSL_SESSION pp output parameter should point to end of asn1 data. 2017-02-22 00:47:15 +01:00
ssl_cert.c Replace SSL_PKEY_RSA_ENC, SSL_PKEY_RSA_SIGN 2017-02-10 20:08:35 +00:00
ssl_ciph.c Let ssl_get_cipher_by_char yield not-valid ciphers 2017-02-23 19:24:37 +01:00
ssl_conf.c
ssl_err.c Add SSL_CTX early callback 2017-02-23 19:40:26 +01:00
ssl_init.c
ssl_lib.c Add SSL_CTX early callback 2017-02-23 19:40:26 +01:00
ssl_locl.h Add SSL_CTX early callback 2017-02-23 19:40:26 +01:00
ssl_mcnf.c
ssl_rsa.c
ssl_sess.c Various style fixes following review feedback 2017-01-30 10:18:25 +00:00
ssl_stat.c
ssl_txt.c Move extension data into sub-structs 2017-01-09 22:26:47 -05:00
ssl_utst.c
t1_enc.c Don't change the state of the ETM flags until CCS processing 2017-02-16 09:35:56 +00:00
t1_ext.c Rework error handling of custom_ext_meth_add towards strong exception safety. 2017-02-15 08:37:52 -05:00
t1_lib.c Add some more consistency checks in tls_decrypt_ticket. 2017-02-22 09:36:02 -05:00
t1_trce.c Add SSL_trace() support for KeyUpdate messages 2017-02-17 10:28:00 +00:00
tls13_enc.c Fix a shadowed global variable warning 2017-02-17 10:28:01 +00:00
tls_srp.c