SSL_SET1_SERVER_CERT_TYPE(3SSL)

πŸ’– SSL_SET1_SERVER_CERT_TYPE ✨

okay bestie so this is a page from the OpenSSL manual, section 3SSL, and literally all it does is tell you how to do certificate type (RFC7250) support β€” like, choosing between X.509 certs and raw public keys. no cap, it's lowkey iconic. let's get into it 🫢


🌸 NAME 🌸

SSL_set1_client_cert_type, SSL_set1_server_cert_type, SSL_CTX_set1_client_cert_type, SSL_CTX_set1_server_cert_type, SSL_get0_client_cert_type, SSL_get0_server_cert_type, SSL_CTX_get0_client_cert_type, SSL_CTX_get0_server_cert_type β€” certificate type (RFC7250) support ✨


πŸŽ€ SYNOPSIS πŸŽ€

#include <openssl/ssl.h>

int SSL_set1_client_cert_type(SSL *s, const unsigned char *val, size_t len);
int SSL_set1_server_cert_type(SSL *s, const unsigned char *val, size_t len);
int SSL_CTX_set1_client_cert_type(SSL_CTX *ctx, const unsigned char *val, size_t len);
int SSL_CTX_set1_server_cert_type(SSL_CTX *ctx, const unsigned char *val, size_t len);
int SSL_get0_client_cert_type(const SSL *s, unsigned char **val, size_t *len);
int SSL_get0_server_cert_type(const SSL *s, unsigned char **val, size_t *len);
int SSL_CTX_get0_client_cert_type(const SSL_CTX *ctx, unsigned char **val, size_t *len);
int SSL_CTX_get0_server_cert_type(const SSL_CTX *s, unsigned char **val, size_t *len);
bestie the SSL_CTX_get0_server_cert_type one takes a parameter literally named s even though the type is SSL_CTX *. yes we clocked it. that's just how it is, copy it exactly, don't be normal about it πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

SSL_set1_client_cert_type() and SSL_CTX_set1_client_cert_type() set the values for the client certificate type extension. SSL_get0_client_cert_type() and SSL_CTX_get0_client_cert_type() retrieve the local values that are gonna be used in the client certificate type extension.

SSL_set1_server_cert_type() and SSL_CTX_set1_server_cert_type() set the values for the server certificate type extension. SSL_get0_server_cert_type() and SSL_CTX_get0_server_cert_type() retrieve the local values that are gonna be used in the server certificate type extension.


✨ NOTES ✨

so the certificate type extensions are the whole point of negotiating which certificate type gets used in the handshake. these extensions let each side tell its peer what it's actually able to accept. communication, slay 🌈

The client certificate type is sent from the client to the server, and it says what certificate types the client is able to present. Values are configured in preference order. On the server side, this setting decides which certificate types the server is willing to accept. The server ultimately chooses what type to request (if any) from the values that are mutually supported. By default β€” like, if you specified no explicit settings at all β€” only X.509 certificates are supported.

The server certificate type is sent from the client to the server, and it says what certificate types the client accepts. Values are configured in preference order. On the server side, this setting decides which certificate types the server is willing to present. The server ultimately chooses what type to use from the values that are mutually supported. By default β€” same deal, no explicit settings β€” only X.509 certificates are supported.

Having RPK specified first means that side will attempt to send (or request) RPKs if its peer also supports RPKs, otherwise X.509 certificate will be used if both have specified that (or have not configured these options). periodt.

The two supported values in the val array are:

  • TLSEXT_cert_type_x509 β€” which corresponds to an X.509 certificate normally used in TLS πŸ”₯
  • TLSEXT_cert_type_rpk β€” which corresponds to a raw public key πŸ”‘

If val is set to a non-NULL value, then the extension is sent in the handshake. If val is set to a NULL value (and len is 0), then the extension is disabled. The default value is NULL, meaning the extension is not sent, and X.509 certificates are used in the handshake.

Raw public keys may be used in place of certificates when specified in the certificate type and negotiated. Raw public keys have no subject, issuer, validity dates or digital signature. like, none of it. they're just out here raw πŸ™ˆ

Use the SSL_get_negotiated_client_cert_type(3) and SSL_get_negotiated_server_cert_type(3) functions to get the negotiated cert type values β€” at the conclusion of the handshake, or in callbacks that happen after the TLS ServerHello has been processed. iykyk πŸ’…


πŸ’œ RETURN VALUES πŸ’œ

All functions return 1 on success and 0 on failure.

⚠️ The memory returned from the get0 functions must not be freed. not you trying to free() it bestie, do NOT. 🫢

πŸ“ EXAMPLES πŸ“

To use raw public keys on the server, set up the SSL_CTX and SSL as follows:

SSL_CTX *ctx;
SSL *ssl;
unsigned char cert_type[] = { TLSEXT_cert_type_rpk, TLSEXT_cert_type_x509 };
EVP_PKEY *rpk;

/* Assign rpk to an EVP_PKEY from a file or other means */

if ((ctx = SSL_CTX_new(TLS_server_method())) == NULL)
    /* error */
if ((ssl = SSL_new(ctx)) == NULL)
    /* error */
if (!SSL_set1_server_cert_type(ssl, cert_type, sizeof(cert_type)))
    /* error */

/* A certificate does not need to be specified when using raw public keys */
if (!SSL_use_PrivateKey(ssl, rpk))
    /* error */

/* Perform SSL_accept() operations */

To connect to this server, set the client SSL_CTX and SSL as follows:

/* Connect function */

SSL_CTX *ctx;
SSL *ssl;
const char *dane_tlsa_domain = "smtp.example.com";
unsigned char cert_type[] = { TLSEXT_cert_type_rpk, TLSEXT_cert_type_x509 };
EVP_PKEY *rpk;
int verify_result;

/* Assign rpk to an EVP_PKEY from a file or other means */

if ((ctx = SSL_CTX_new(TLS_client_method())) == NULL)
    /* error */
if (SSL_CTX_dane_enable(ctx) <= 0)
    /* error */
if ((ssl = SSL_new(ctx)) == NULL)
    /* error */
/*
 * The `dane_tlsa_domain` arguments sets the default SNI hostname.
 * It may be set to NULL when enabling DANE on the server side.
 */
if (SSL_dane_enable(ssl, dane_tlsa_domain) <= 0)
    /* error */
if (!SSL_set1_server_cert_type(ssl, cert_type, sizeof(cert_type)))
    /* error */
if (!SSL_add_expected_rpk(ssl, rpk))
    /* error */

/* Do SSL_connect() handshake and handle errors here */

/* Optional: verify the peer RPK */
verify_result = SSL_get_verify_result(ssl);
if (verify_result == X509_V_OK) {
    /* The server's raw public key matched the TLSA record */
} else if (verify_result == X509_V_ERR_DANE_NO_MATCH) {
    /*
     * The server's raw public key, or public key in certificate, did not
     * match the TLSA record
     */
} else if (verify_result == X509_V_ERR_RPK_UNTRUSTED) {
    /*
     * No TLSA records of the correct type are available to verify the
     * server's raw public key. This would not happen in this example,
     * as a TLSA record is configured.
     */
} else {
    /* Some other verify error */
}

To validate client raw public keys, code from the client example may need to be incorporated into the server side. yeah, just borrow it, it's fine 🧚


🌈 SEE ALSO 🌈

SSL_get0_peer_rpk(3), SSL_get_negotiated_client_cert_type(3), SSL_get_negotiated_server_cert_type(3), SSL_use_certificate(3)


πŸ‘‘ HISTORY πŸ‘‘

These functions were added in OpenSSL 3.2. so they're giving modern. main character energy fr fr ✨


Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved.


and that's the whole page bestie!! 🌸 this was OpenSSL 4.0.3, dated 2026-09-29, and the manual page is SSL_SET1_SERVER_CERT_TYPE(3SSL) πŸ’… stay slaying, go negotiate those cert types, and remember: don't free the get0 memory, ok?? mwah πŸ«ΆπŸ’œ

πŸ“¦ where this page comes from