/*
- * Copyright 2014-2021 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2014-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
}
/* Pass received custom extension data to the application for parsing. */
-int custom_ext_parse(SSL *s, unsigned int context, unsigned int ext_type,
+int custom_ext_parse(SSL_CONNECTION *s, unsigned int context,
+ unsigned int ext_type,
const unsigned char *ext_data, size_t ext_size, X509 *x,
size_t chainidx)
{
- int al;
+ int al = 0;
custom_ext_methods *exts = &s->cert->custext;
custom_ext_method *meth;
ENDPOINT role = ENDPOINT_BOTH;
meth->ext_flags |= SSL_EXT_FLAG_RECEIVED;
/* If no parse function set return success */
- if (!meth->parse_cb)
+ if (meth->parse_cb == NULL)
return 1;
- if (meth->parse_cb(s, ext_type, context, ext_data, ext_size, x, chainidx,
- &al, meth->parse_arg) <= 0) {
+ if (meth->parse_cb(SSL_CONNECTION_GET_SSL(s), ext_type, context, ext_data,
+ ext_size, x, chainidx, &al, meth->parse_arg) <= 0) {
SSLfatal(s, al, SSL_R_BAD_EXTENSION);
return 0;
}
* Request custom extension data from the application and add to the return
* buffer.
*/
-int custom_ext_add(SSL *s, int context, WPACKET *pkt, X509 *x, size_t chainidx,
- int maxversion)
+int custom_ext_add(SSL_CONNECTION *s, int context, WPACKET *pkt, X509 *x,
+ size_t chainidx, int maxversion)
{
custom_ext_methods *exts = &s->cert->custext;
custom_ext_method *meth;
size_t i;
int al;
+ int for_comp = (context & SSL_EXT_TLS1_3_CERTIFICATE_COMPRESSION) != 0;
for (i = 0; i < exts->meths_count; i++) {
const unsigned char *out = NULL;
| SSL_EXT_TLS1_3_SERVER_HELLO
| SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS
| SSL_EXT_TLS1_3_CERTIFICATE
+ | SSL_EXT_TLS1_3_RAW_PUBLIC_KEY
| SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST)) != 0) {
/* Only send extensions present in ClientHello/CertificateRequest */
if (!(meth->ext_flags & SSL_EXT_FLAG_RECEIVED))
continue;
if (meth->add_cb != NULL) {
- int cb_retval = meth->add_cb(s, meth->ext_type, context, &out,
+ int cb_retval = meth->add_cb(SSL_CONNECTION_GET_SSL(s),
+ meth->ext_type, context, &out,
&outlen, x, chainidx, &al,
meth->add_arg);
if (cb_retval < 0) {
- SSLfatal(s, al, SSL_R_CALLBACK_FAILED);
+ if (!for_comp)
+ SSLfatal(s, al, SSL_R_CALLBACK_FAILED);
return 0; /* error */
}
if (cb_retval == 0)
|| !WPACKET_start_sub_packet_u16(pkt)
|| (outlen > 0 && !WPACKET_memcpy(pkt, out, outlen))
|| !WPACKET_close(pkt)) {
- SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
+ if (meth->free_cb != NULL)
+ meth->free_cb(SSL_CONNECTION_GET_SSL(s), meth->ext_type, context,
+ out, meth->add_arg);
+ if (!for_comp)
+ SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return 0;
}
if ((context & SSL_EXT_CLIENT_HELLO) != 0) {
* We can't send duplicates: code logic should prevent this.
*/
if (!ossl_assert((meth->ext_flags & SSL_EXT_FLAG_SENT) == 0)) {
- SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
+ if (meth->free_cb != NULL)
+ meth->free_cb(SSL_CONNECTION_GET_SSL(s), meth->ext_type,
+ context, out, meth->add_arg);
+ if (!for_comp)
+ SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
return 0;
}
/*
meth->ext_flags |= SSL_EXT_FLAG_SENT;
}
if (meth->free_cb != NULL)
- meth->free_cb(s, meth->ext_type, context, out, meth->add_arg);
+ meth->free_cb(SSL_CONNECTION_GET_SSL(s), meth->ext_type, context,
+ out, meth->add_arg);
}
return 1;
}
OPENSSL_free(meth->parse_arg);
}
OPENSSL_free(exts->meths);
+ exts->meths = NULL;
+ exts->meths_count = 0;
}
/* Return true if a client custom extension exists, false otherwise */
NULL) != NULL;
}
-static int add_custom_ext_intern(SSL_CTX *ctx, ENDPOINT role,
- unsigned int ext_type,
- unsigned int context,
- SSL_custom_ext_add_cb_ex add_cb,
- SSL_custom_ext_free_cb_ex free_cb,
- void *add_arg,
- SSL_custom_ext_parse_cb_ex parse_cb,
- void *parse_arg)
+int ossl_tls_add_custom_ext_intern(SSL_CTX *ctx, custom_ext_methods *exts,
+ ENDPOINT role, unsigned int ext_type,
+ unsigned int context,
+ SSL_custom_ext_add_cb_ex add_cb,
+ SSL_custom_ext_free_cb_ex free_cb,
+ void *add_arg,
+ SSL_custom_ext_parse_cb_ex parse_cb,
+ void *parse_arg)
{
- custom_ext_methods *exts = &ctx->cert->custext;
custom_ext_method *meth, *tmp;
/*
if (add_cb == NULL && free_cb != NULL)
return 0;
+ if (exts == NULL)
+ exts = &ctx->cert->custext;
+
#ifndef OPENSSL_NO_CT
/*
* We don't want applications registering callbacks for SCT extensions
*/
if (ext_type == TLSEXT_TYPE_signed_certificate_timestamp
&& (context & SSL_EXT_CLIENT_HELLO) != 0
+ && ctx != NULL
&& SSL_CTX_ct_is_enabled(ctx))
return 0;
#endif
parse_cb_wrap->parse_arg = parse_arg;
parse_cb_wrap->parse_cb = parse_cb;
- ret = add_custom_ext_intern(ctx, role, ext_type,
- context,
- custom_ext_add_old_cb_wrap,
- custom_ext_free_old_cb_wrap,
- add_cb_wrap,
- custom_ext_parse_old_cb_wrap,
- parse_cb_wrap);
+ ret = ossl_tls_add_custom_ext_intern(ctx, NULL, role, ext_type,
+ context,
+ custom_ext_add_old_cb_wrap,
+ custom_ext_free_old_cb_wrap,
+ add_cb_wrap,
+ custom_ext_parse_old_cb_wrap,
+ parse_cb_wrap);
if (!ret) {
OPENSSL_free(add_cb_wrap);
void *add_arg,
SSL_custom_ext_parse_cb_ex parse_cb, void *parse_arg)
{
- return add_custom_ext_intern(ctx, ENDPOINT_BOTH, ext_type, context, add_cb,
- free_cb, add_arg, parse_cb, parse_arg);
+ return ossl_tls_add_custom_ext_intern(ctx, NULL, ENDPOINT_BOTH, ext_type,
+ context, add_cb, free_cb, add_arg,
+ parse_cb, parse_arg);
}
int SSL_extension_supported(unsigned int ext_type)
case TLSEXT_TYPE_certificate_authorities:
case TLSEXT_TYPE_psk:
case TLSEXT_TYPE_post_handshake_auth:
+ case TLSEXT_TYPE_compress_certificate:
+ case TLSEXT_TYPE_client_cert_type:
+ case TLSEXT_TYPE_server_cert_type:
return 1;
default:
return 0;