Commit f63e4288 authored by Matt Caswell's avatar Matt Caswell
Browse files

Implement TLSv1.3 style CertificateStatus



We remove the separate CertificateStatus message for TLSv1.3, and instead
send back the response in the appropriate Certificate message extension.

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2020)
parent e96e0f8e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2136,6 +2136,7 @@ int ERR_load_SSL_strings(void);
# define SSL_F_SSL3_WRITE_PENDING                         159
# define SSL_F_SSL_ADD_CERT_CHAIN                         316
# define SSL_F_SSL_ADD_CERT_TO_BUF                        319
# define SSL_F_SSL_ADD_CERT_TO_WPACKET                    493
# define SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT        298
# define SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT                 277
# define SSL_F_SSL_ADD_CLIENTHELLO_USE_SRTP_EXT           307
@@ -2261,6 +2262,7 @@ int ERR_load_SSL_strings(void);
# define SSL_F_TLS_COLLECT_EXTENSIONS                     435
# define SSL_F_TLS_CONSTRUCT_CERTIFICATE_REQUEST          372
# define SSL_F_TLS_CONSTRUCT_CERT_STATUS                  429
# define SSL_F_TLS_CONSTRUCT_CERT_STATUS_BODY             494
# define SSL_F_TLS_CONSTRUCT_CHANGE_CIPHER_SPEC           427
# define SSL_F_TLS_CONSTRUCT_CKE_DHE                      404
# define SSL_F_TLS_CONSTRUCT_CKE_ECDHE                    405
@@ -2332,6 +2334,7 @@ int ERR_load_SSL_strings(void);
# define SSL_F_TLS_PREPARE_CLIENT_CERTIFICATE             360
# define SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST            361
# define SSL_F_TLS_PROCESS_CERT_STATUS                    362
# define SSL_F_TLS_PROCESS_CERT_STATUS_BODY               495
# define SSL_F_TLS_PROCESS_CERT_VERIFY                    379
# define SSL_F_TLS_PROCESS_CHANGE_CIPHER_SPEC             363
# define SSL_F_TLS_PROCESS_CKE_DHE                        411
+5 −0
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ static ERR_STRING_DATA SSL_str_functs[] = {
    {ERR_FUNC(SSL_F_SSL3_WRITE_PENDING), "ssl3_write_pending"},
    {ERR_FUNC(SSL_F_SSL_ADD_CERT_CHAIN), "ssl_add_cert_chain"},
    {ERR_FUNC(SSL_F_SSL_ADD_CERT_TO_BUF), "ssl_add_cert_to_buf"},
    {ERR_FUNC(SSL_F_SSL_ADD_CERT_TO_WPACKET), "ssl_add_cert_to_wpacket"},
    {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT),
     "ssl_add_clienthello_renegotiate_ext"},
    {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT),
@@ -259,6 +260,8 @@ static ERR_STRING_DATA SSL_str_functs[] = {
    {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CERTIFICATE_REQUEST),
     "tls_construct_certificate_request"},
    {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CERT_STATUS), "tls_construct_cert_status"},
    {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CERT_STATUS_BODY),
     "tls_construct_cert_status_body"},
    {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CHANGE_CIPHER_SPEC),
     "tls_construct_change_cipher_spec"},
    {ERR_FUNC(SSL_F_TLS_CONSTRUCT_CKE_DHE), "tls_construct_cke_dhe"},
@@ -373,6 +376,8 @@ static ERR_STRING_DATA SSL_str_functs[] = {
    {ERR_FUNC(SSL_F_TLS_PROCESS_CERTIFICATE_REQUEST),
     "tls_process_certificate_request"},
    {ERR_FUNC(SSL_F_TLS_PROCESS_CERT_STATUS), "tls_process_cert_status"},
    {ERR_FUNC(SSL_F_TLS_PROCESS_CERT_STATUS_BODY),
     "tls_process_cert_status_body"},
    {ERR_FUNC(SSL_F_TLS_PROCESS_CERT_VERIFY), "tls_process_cert_verify"},
    {ERR_FUNC(SSL_F_TLS_PROCESS_CHANGE_CIPHER_SPEC),
     "tls_process_change_cipher_spec"},
+11 −21
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@ static int final_ec_pt_formats(SSL *s, unsigned int context, int sent,
static int init_session_ticket(SSL *s, unsigned int context);
#ifndef OPENSSL_NO_OCSP
static int init_status_request(SSL *s, unsigned int context);
static int final_status_request(SSL *s, unsigned int context, int sent,
                                        int *al);
#endif
#ifndef OPENSSL_NO_NEXTPROTONEG
static int init_npn(SSL *s, unsigned int context);
@@ -162,7 +160,7 @@ static const EXTENSION_DEFINITION ext_defs[] = {
        | EXT_TLS1_3_CERTIFICATE,
        init_status_request, tls_parse_ctos_status_request,
        tls_parse_stoc_status_request, tls_construct_stoc_status_request,
        tls_construct_ctos_status_request, final_status_request
        tls_construct_ctos_status_request, NULL
    },
#else
    INVALID_EXTENSION,
@@ -792,18 +790,9 @@ static int init_session_ticket(SSL *s, unsigned int context)
#ifndef OPENSSL_NO_OCSP
static int init_status_request(SSL *s, unsigned int context)
{
    if (s->server)
    if (s->server) {
        s->tlsext_status_type = TLSEXT_STATUSTYPE_nothing;

    return 1;
}

static int final_status_request(SSL *s, unsigned int context, int sent,
                                        int *al)
{
    if (s->server)
        return 1;

    } else {
        /*
         * Ensure we get sensible values passed to tlsext_status_cb in the event
         * that we don't receive a status message
@@ -811,6 +800,7 @@ static int final_status_request(SSL *s, unsigned int context, int sent,
        OPENSSL_free(s->tlsext_ocsp_resp);
        s->tlsext_ocsp_resp = NULL;
        s->tlsext_ocsp_resplen = 0;
    }

    return 1;
}
+13 −3
Original line number Diff line number Diff line
@@ -776,14 +776,24 @@ int tls_parse_stoc_status_request(SSL *s, PACKET *pkt, X509 *x, size_t chain,
                                  int *al)
{
    /*
     * MUST be empty and only sent if we've requested a status
     * request message.
     * MUST only be sent if we've requested a status
     * request message. In TLS <= 1.2 it must also be empty.
     */
    if (s->tlsext_status_type == TLSEXT_STATUSTYPE_nothing
            || PACKET_remaining(pkt) > 0) {
            || (!SSL_IS_TLS13(s) && PACKET_remaining(pkt) > 0)) {
        *al = SSL_AD_UNSUPPORTED_EXTENSION;
        return 0;
    }

    if (SSL_IS_TLS13(s)) {
        /* We only know how to handle this if it's for the first Certificate in
         * the chain. We ignore any other repsonses.
         */
        if (chain != 0)
            return 1;
        return tls_process_cert_status_body(s, pkt, al);
    }

    /* Set flag to expect CertificateStatus message */
    s->tlsext_status_expected = 1;

+12 −1
Original line number Diff line number Diff line
@@ -760,7 +760,18 @@ int tls_construct_stoc_status_request(SSL *s, WPACKET *pkt, X509 *x,
        return 1;

    if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_status_request)
            || !WPACKET_put_bytes_u16(pkt, 0)) {
            || !WPACKET_start_sub_packet_u16(pkt)) {
        SSLerr(SSL_F_TLS_CONSTRUCT_STOC_STATUS_REQUEST, ERR_R_INTERNAL_ERROR);
        return 0;
    }

    /*
     * In TLSv1.3 we include the certificate status itself. In <= TLSv1.2 we
     * send back an empty extension, with the certificate status appearing as a
     * separate message
     */
    if ((SSL_IS_TLS13(s) && !tls_construct_cert_status_body(s, pkt))
            || !WPACKET_close(pkt)) {
        SSLerr(SSL_F_TLS_CONSTRUCT_STOC_STATUS_REQUEST, ERR_R_INTERNAL_ERROR);
        return 0;
    }
Loading