DragonFly On-Line Manual Pages
ssl(3) OpenSSL ssl(3)
NAME
SSL - OpenSSL SSL/TLS library
SYNOPSIS
DESCRIPTION
The OpenSSL ssl library implements the Secure Sockets Layer (SSL v2/v3)
and Transport Layer Security (TLS v1) protocols. It provides a rich API
which is documented here.
At first the library must be initialized; see SSL_library_init(3).
Then an SSL_CTX object is created as a framework to establish TLS/SSL
enabled connections (see SSL_CTX_new(3)). Various options regarding
certificates, algorithms etc. can be set in this object.
When a network connection has been created, it can be assigned to an
SSL object. After the SSL object has been created using SSL_new(3),
SSL_set_fd(3) or SSL_set_bio(3) can be used to associate the network
connection with the object.
Then the TLS/SSL handshake is performed using SSL_accept(3) or
SSL_connect(3) respectively. SSL_read(3) and SSL_write(3) are used to
read and write data on the TLS/SSL connection. SSL_shutdown(3) can be
used to shut down the TLS/SSL connection.
DATA STRUCTURES
Currently the OpenSSL ssl library functions deals with the following
data structures:
SSL_METHOD (SSL Method)
That's a dispatch structure describing the internal ssl library
methods/functions which implement the various protocol versions
(SSLv1, SSLv2 and TLSv1). It's needed to create an SSL_CTX.
SSL_CIPHER (SSL Cipher)
This structure holds the algorithm information for a particular
cipher which are a core part of the SSL/TLS protocol. The available
ciphers are configured on a SSL_CTX basis and the actually used
ones are then part of the SSL_SESSION.
SSL_CTX (SSL Context)
That's the global context structure which is created by a server or
client once per program life-time and which holds mainly default
values for the SSL structures which are later created for the
connections.
SSL_SESSION (SSL Session)
This is a structure containing the current TLS/SSL session details
for a connection: SSL_CIPHERs, client and server certificates,
keys, etc.
SSL (SSL Connection)
That's the main SSL/TLS structure which is created by a server or
client per established connection. This actually is the core
structure in the SSL API. Under run-time the application usually
deals with this structure which has links to mostly all other
structures.
HEADER FILES
Currently the OpenSSL ssl library provides the following C header files
containing the prototypes for the data structures and and functions:
ssl.h
That's the common header file for the SSL/TLS API. Include it into
your program to make the API of the ssl library available. It
internally includes both more private SSL headers and headers from
the crypto library. Whenever you need hard-core details on the
internals of the SSL API, look inside this header file.
ssl2.h
That's the sub header file dealing with the SSLv2 protocol only.
Usually you don't have to include it explicitly because it's
already included by ssl.h.
ssl3.h
That's the sub header file dealing with the SSLv3 protocol only.
Usually you don't have to include it explicitly because it's
already included by ssl.h.
ssl23.h
That's the sub header file dealing with the combined use of the
SSLv2 and SSLv3 protocols. Usually you don't have to include it
explicitly because it's already included by ssl.h.
tls1.h
That's the sub header file dealing with the TLSv1 protocol only.
Usually you don't have to include it explicitly because it's
already included by ssl.h.
API FUNCTIONS
Currently the OpenSSL ssl library exports 214 API functions. They are
documented in the following:
DEALING WITH PROTOCOL METHODS
Here we document the various API functions which deal with the SSL/TLS
protocol methods defined in SSL_METHOD structures.
const SSL_METHOD *SSLv23_method(void);
Constructor for the version-flexible SSL_METHOD structure for
clients, servers or both. See SSL_CTX_new(3) for details.
const SSL_METHOD *SSLv23_client_method(void);
Constructor for the version-flexible SSL_METHOD structure for
clients.
const SSL_METHOD *SSLv23_client_method(void);
Constructor for the version-flexible SSL_METHOD structure for
servers.
const SSL_METHOD *TLSv1_2_method(void);
Constructor for the TLSv1.2 SSL_METHOD structure for clients,
servers or both.
const SSL_METHOD *TLSv1_2_client_method(void);
Constructor for the TLSv1.2 SSL_METHOD structure for clients.
const SSL_METHOD *TLSv1_2_server_method(void);
Constructor for the TLSv1.2 SSL_METHOD structure for servers.
const SSL_METHOD *TLSv1_1_method(void);
Constructor for the TLSv1.1 SSL_METHOD structure for clients,
servers or both.
const SSL_METHOD *TLSv1_1_client_method(void);
Constructor for the TLSv1.1 SSL_METHOD structure for clients.
const SSL_METHOD *TLSv1_1_server_method(void);
Constructor for the TLSv1.1 SSL_METHOD structure for servers.
const SSL_METHOD *TLSv1_method(void);
Constructor for the TLSv1 SSL_METHOD structure for clients, servers
or both.
const SSL_METHOD *TLSv1_client_method(void);
Constructor for the TLSv1 SSL_METHOD structure for clients.
const SSL_METHOD *TLSv1_server_method(void);
Constructor for the TLSv1 SSL_METHOD structure for servers.
const SSL_METHOD *SSLv3_method(void);
Constructor for the SSLv3 SSL_METHOD structure for clients, servers
or both.
const SSL_METHOD *SSLv3_client_method(void);
Constructor for the SSLv3 SSL_METHOD structure for clients.
const SSL_METHOD *SSLv3_server_method(void);
Constructor for the SSLv3 SSL_METHOD structure for servers.
const SSL_METHOD *SSLv2_method(void);
Constructor for the SSLv2 SSL_METHOD structure for clients, servers
or both.
const SSL_METHOD *SSLv2_client_method(void);
Constructor for the SSLv2 SSL_METHOD structure for clients.
const SSL_METHOD *SSLv2_server_method(void);
Constructor for the SSLv2 SSL_METHOD structure for servers.
DEALING WITH CIPHERS
Here we document the various API functions which deal with the SSL/TLS
ciphers defined in SSL_CIPHER structures.
char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len);
Write a string to buf (with a maximum size of len) containing a
human readable description of cipher. Returns buf.
int SSL_CIPHER_get_bits(SSL_CIPHER *cipher, int *alg_bits);
Determine the number of bits in cipher. Because of export crippled
ciphers there are two bits: The bits the algorithm supports in
general (stored to alg_bits) and the bits which are actually used
(the return value).
const char *SSL_CIPHER_get_name(SSL_CIPHER *cipher);
Return the internal name of cipher as a string. These are the
various strings defined by the SSL2_TXT_xxx, SSL3_TXT_xxx and
TLS1_TXT_xxx definitions in the header files.
char *SSL_CIPHER_get_version(SSL_CIPHER *cipher);
Returns a string like ""TLSv1/SSLv3"" or ""SSLv2"" which indicates
the SSL/TLS protocol version to which cipher belongs (i.e. where it
was defined in the specification the first time).
DEALING WITH PROTOCOL CONTEXTS
Here we document the various API functions which deal with the SSL/TLS
protocol context defined in the SSL_CTX structure.
int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x);
long SSL_CTX_add_extra_chain_cert(SSL_CTX *ctx, X509 *x509);
int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c);
int SSL_CTX_check_private_key(const SSL_CTX *ctx);
long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, char *parg);
void SSL_CTX_flush_sessions(SSL_CTX *s, long t);
void SSL_CTX_free(SSL_CTX *a);
char *SSL_CTX_get_app_data(SSL_CTX *ctx);
X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *ctx);
STACK *SSL_CTX_get_client_CA_list(const SSL_CTX *ctx);
int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL *ssl, X509 **x509,
EVP_PKEY **pkey);
void SSL_CTX_get_default_read_ahead(SSL_CTX *ctx);
char *SSL_CTX_get_ex_data(const SSL_CTX *s, int idx);
int SSL_CTX_get_ex_new_index(long argl, char *argp, int
(*new_func);(void), int (*dup_func)(void), void (*free_func)(void))
void (*SSL_CTX_get_info_callback(SSL_CTX *ctx))(SSL *ssl, int cb, int
ret);
int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);
void SSL_CTX_get_read_ahead(SSL_CTX *ctx);
int SSL_CTX_get_session_cache_mode(SSL_CTX *ctx);
long SSL_CTX_get_timeout(const SSL_CTX *ctx);
int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int ok,
X509_STORE_CTX *ctx);
int SSL_CTX_get_verify_mode(SSL_CTX *ctx);
int SSL_CTX_load_verify_locations(SSL_CTX *ctx, char *CAfile, char
*CApath);
long SSL_CTX_need_tmp_RSA(SSL_CTX *ctx);
SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth);
int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c);
int SSL_CTX_sess_accept(SSL_CTX *ctx);
int SSL_CTX_sess_accept_good(SSL_CTX *ctx);
int SSL_CTX_sess_accept_renegotiate(SSL_CTX *ctx);
int SSL_CTX_sess_cache_full(SSL_CTX *ctx);
int SSL_CTX_sess_cb_hits(SSL_CTX *ctx);
int SSL_CTX_sess_connect(SSL_CTX *ctx);
int SSL_CTX_sess_connect_good(SSL_CTX *ctx);
int SSL_CTX_sess_connect_renegotiate(SSL_CTX *ctx);
int SSL_CTX_sess_get_cache_size(SSL_CTX *ctx);
SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(SSL *ssl,
unsigned char *data, int len, int *copy);
int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx)(SSL *ssl, SSL_SESSION
*sess);
void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx)(SSL_CTX *ctx,
SSL_SESSION *sess);
int SSL_CTX_sess_hits(SSL_CTX *ctx);
int SSL_CTX_sess_misses(SSL_CTX *ctx);
int SSL_CTX_sess_number(SSL_CTX *ctx);
void SSL_CTX_sess_set_cache_size(SSL_CTX *ctx,t);
void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, SSL_SESSION *(*cb)(SSL *ssl,
unsigned char *data, int len, int *copy));
void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx, int (*cb)(SSL *ssl,
SSL_SESSION *sess));
void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx, void (*cb)(SSL_CTX *ctx,
SSL_SESSION *sess));
int SSL_CTX_sess_timeouts(SSL_CTX *ctx);
LHASH *SSL_CTX_sessions(SSL_CTX *ctx);
void SSL_CTX_set_app_data(SSL_CTX *ctx, void *arg);
void SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *cs);
void SSL_CTX_set_cert_verify_cb(SSL_CTX *ctx, int (*cb)(), char *arg)
int SSL_CTX_set_cipher_list(SSL_CTX *ctx, char *str);
void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK *list);
void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx, int (*cb)(SSL *ssl, X509
**x509, EVP_PKEY **pkey));
void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, int (*cb);(void))
void SSL_CTX_set_default_read_ahead(SSL_CTX *ctx, int m);
int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
int SSL_CTX_set_ex_data(SSL_CTX *s, int idx, char *arg);
void SSL_CTX_set_info_callback(SSL_CTX *ctx, void (*cb)(SSL *ssl, int
cb, int ret));
void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int
version, int content_type, const void *buf, size_t len, SSL *ssl, void
*arg));
void SSL_CTX_set_msg_callback_arg(SSL_CTX *ctx, void *arg);
void SSL_CTX_set_options(SSL_CTX *ctx, unsigned long op);
void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode);
void SSL_CTX_set_read_ahead(SSL_CTX *ctx, int m);
void SSL_CTX_set_session_cache_mode(SSL_CTX *ctx, int mode);
int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth);
void SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
long SSL_CTX_set_tmp_dh(SSL_CTX* ctx, DH *dh);
long SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx, DH *(*cb)(void));
long SSL_CTX_set_tmp_rsa(SSL_CTX *ctx, RSA *rsa);
SSL_CTX_set_tmp_rsa_callback
"long SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx, RSA *(*cb)(SSL
*ssl, int export, int keylength));"
Sets the callback which will be called when a temporary private key
is required. The "export" flag will be set if the reason for
needing a temp key is that an export ciphersuite is in use, in
which case, "keylength" will contain the required keylength in
bits. Generate a key of appropriate size (using ???) and return it.
SSL_set_tmp_rsa_callback
long SSL_set_tmp_rsa_callback(SSL *ssl, RSA *(*cb)(SSL *ssl, int
export, int keylength));
The same as SSL_CTX_set_tmp_rsa_callback, except it operates on an
SSL session instead of a context.
void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, int (*cb);(void))
int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, unsigned char
*d, long len);
int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, char *file, int type);
int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long
len);
int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, char *file, int type);
int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char
*d);
int SSL_CTX_use_certificate_file(SSL_CTX *ctx, char *file, int type);
X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx);
EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx);
void SSL_CTX_set_psk_client_callback(SSL_CTX *ctx, unsigned int
(*callback)(SSL *ssl, const char *hint, char *identity, unsigned int
max_identity_len, unsigned char *psk, unsigned int max_psk_len));
int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *hint);
void SSL_CTX_set_psk_server_callback(SSL_CTX *ctx, unsigned int
(*callback)(SSL *ssl, const char *identity, unsigned char *psk, int
max_psk_len));
DEALING WITH SESSIONS
Here we document the various API functions which deal with the SSL/TLS
sessions defined in the SSL_SESSION structures.
int SSL_SESSION_cmp(const SSL_SESSION *a, const SSL_SESSION *b);
void SSL_SESSION_free(SSL_SESSION *ss);
char *SSL_SESSION_get_app_data(SSL_SESSION *s);
char *SSL_SESSION_get_ex_data(const SSL_SESSION *s, int idx);
int SSL_SESSION_get_ex_new_index(long argl, char *argp, int
(*new_func);(void), int (*dup_func)(void), void (*free_func)(void))
long SSL_SESSION_get_time(const SSL_SESSION *s);
long SSL_SESSION_get_timeout(const SSL_SESSION *s);
unsigned long SSL_SESSION_hash(const SSL_SESSION *a);
SSL_SESSION *SSL_SESSION_new(void);
int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x);
int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x);
void SSL_SESSION_set_app_data(SSL_SESSION *s, char *a);
int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, char *arg);
long SSL_SESSION_set_time(SSL_SESSION *s, long t);
long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
DEALING WITH CONNECTIONS
Here we document the various API functions which deal with the SSL/TLS
connection defined in the SSL structure.
int SSL_accept(SSL *ssl);
int SSL_add_dir_cert_subjects_to_stack(STACK *stack, const char *dir);
int SSL_add_file_cert_subjects_to_stack(STACK *stack, const char
*file);
int SSL_add_client_CA(SSL *ssl, X509 *x);
char *SSL_alert_desc_string(int value);
char *SSL_alert_desc_string_long(int value);
char *SSL_alert_type_string(int value);
char *SSL_alert_type_string_long(int value);
int SSL_check_private_key(const SSL *ssl);
void SSL_clear(SSL *ssl);
long SSL_clear_num_renegotiations(SSL *ssl);
int SSL_connect(SSL *ssl);
void SSL_copy_session_id(SSL *t, const SSL *f);
long SSL_ctrl(SSL *ssl, int cmd, long larg, char *parg);
int SSL_do_handshake(SSL *ssl);
SSL *SSL_dup(SSL *ssl);
STACK *SSL_dup_CA_list(STACK *sk);
void SSL_free(SSL *ssl);
SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
char *SSL_get_app_data(SSL *ssl);
X509 *SSL_get_certificate(const SSL *ssl);
const char *SSL_get_cipher(const SSL *ssl);
int SSL_get_cipher_bits(const SSL *ssl, int *alg_bits);
char *SSL_get_cipher_list(const SSL *ssl, int n);
char *SSL_get_cipher_name(const SSL *ssl);
char *SSL_get_cipher_version(const SSL *ssl);
STACK *SSL_get_ciphers(const SSL *ssl);
STACK *SSL_get_client_CA_list(const SSL *ssl);
SSL_CIPHER *SSL_get_current_cipher(SSL *ssl);
long SSL_get_default_timeout(const SSL *ssl);
int SSL_get_error(const SSL *ssl, int i);
char *SSL_get_ex_data(const SSL *ssl, int idx);
int SSL_get_ex_data_X509_STORE_CTX_idx(void);
int SSL_get_ex_new_index(long argl, char *argp, int (*new_func);(void),
int (*dup_func)(void), void (*free_func)(void))
int SSL_get_fd(const SSL *ssl);
void (*SSL_get_info_callback(const SSL *ssl);)()
STACK *SSL_get_peer_cert_chain(const SSL *ssl);
X509 *SSL_get_peer_certificate(const SSL *ssl);
EVP_PKEY *SSL_get_privatekey(const SSL *ssl);
int SSL_get_quiet_shutdown(const SSL *ssl);
BIO *SSL_get_rbio(const SSL *ssl);
int SSL_get_read_ahead(const SSL *ssl);
SSL_SESSION *SSL_get_session(const SSL *ssl);
char *SSL_get_shared_ciphers(const SSL *ssl, char *buf, int len);
int SSL_get_shutdown(const SSL *ssl);
const SSL_METHOD *SSL_get_ssl_method(SSL *ssl);
int SSL_get_state(const SSL *ssl);
long SSL_get_time(const SSL *ssl);
long SSL_get_timeout(const SSL *ssl);
int (*SSL_get_verify_callback(const SSL *ssl))(int,X509_STORE_CTX *)
int SSL_get_verify_mode(const SSL *ssl);
long SSL_get_verify_result(const SSL *ssl);
char *SSL_get_version(const SSL *ssl);
BIO *SSL_get_wbio(const SSL *ssl);
int SSL_in_accept_init(SSL *ssl);
int SSL_in_before(SSL *ssl);
int SSL_in_connect_init(SSL *ssl);
int SSL_in_init(SSL *ssl);
int SSL_is_init_finished(SSL *ssl);
STACK *SSL_load_client_CA_file(char *file);
void SSL_load_error_strings(void);
SSL *SSL_new(SSL_CTX *ctx);
long SSL_num_renegotiations(SSL *ssl);
int SSL_peek(SSL *ssl, void *buf, int num);
int SSL_pending(const SSL *ssl);
int SSL_read(SSL *ssl, void *buf, int num);
int SSL_renegotiate(SSL *ssl);
char *SSL_rstate_string(SSL *ssl);
char *SSL_rstate_string_long(SSL *ssl);
long SSL_session_reused(SSL *ssl);
void SSL_set_accept_state(SSL *ssl);
void SSL_set_app_data(SSL *ssl, char *arg);
void SSL_set_bio(SSL *ssl, BIO *rbio, BIO *wbio);
int SSL_set_cipher_list(SSL *ssl, char *str);
void SSL_set_client_CA_list(SSL *ssl, STACK *list);
void SSL_set_connect_state(SSL *ssl);
int SSL_set_ex_data(SSL *ssl, int idx, char *arg);
int SSL_set_fd(SSL *ssl, int fd);
void SSL_set_info_callback(SSL *ssl, void (*cb);(void))
void SSL_set_msg_callback(SSL *ctx, void (*cb)(int write_p, int
version, int content_type, const void *buf, size_t len, SSL *ssl, void
*arg));
void SSL_set_msg_callback_arg(SSL *ctx, void *arg);
void SSL_set_options(SSL *ssl, unsigned long op);
void SSL_set_quiet_shutdown(SSL *ssl, int mode);
void SSL_set_read_ahead(SSL *ssl, int yes);
int SSL_set_rfd(SSL *ssl, int fd);
int SSL_set_session(SSL *ssl, SSL_SESSION *session);
void SSL_set_shutdown(SSL *ssl, int mode);
int SSL_set_ssl_method(SSL *ssl, const SSL_METHOD *meth);
void SSL_set_time(SSL *ssl, long t);
void SSL_set_timeout(SSL *ssl, long t);
void SSL_set_verify(SSL *ssl, int mode, int (*callback);(void))
void SSL_set_verify_result(SSL *ssl, long arg);
int SSL_set_wfd(SSL *ssl, int fd);
int SSL_shutdown(SSL *ssl);
int SSL_state(const SSL *ssl);
char *SSL_state_string(const SSL *ssl);
char *SSL_state_string_long(const SSL *ssl);
long SSL_total_renegotiations(SSL *ssl);
int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
int SSL_use_PrivateKey_ASN1(int type, SSL *ssl, unsigned char *d, long
len);
int SSL_use_PrivateKey_file(SSL *ssl, char *file, int type);
int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
int SSL_use_RSAPrivateKey_file(SSL *ssl, char *file, int type);
int SSL_use_certificate(SSL *ssl, X509 *x);
int SSL_use_certificate_ASN1(SSL *ssl, int len, unsigned char *d);
int SSL_use_certificate_file(SSL *ssl, char *file, int type);
int SSL_version(const SSL *ssl);
int SSL_want(const SSL *ssl);
int SSL_want_nothing(const SSL *ssl);
int SSL_want_read(const SSL *ssl);
int SSL_want_write(const SSL *ssl);
int SSL_want_x509_lookup(const SSL *ssl);
int SSL_write(SSL *ssl, const void *buf, int num);
void SSL_set_psk_client_callback(SSL *ssl, unsigned int (*callback)(SSL
*ssl, const char *hint, char *identity, unsigned int max_identity_len,
unsigned char *psk, unsigned int max_psk_len));
int SSL_use_psk_identity_hint(SSL *ssl, const char *hint);
void SSL_set_psk_server_callback(SSL *ssl, unsigned int (*callback)(SSL
*ssl, const char *identity, unsigned char *psk, int max_psk_len));
const char *SSL_get_psk_identity_hint(SSL *ssl);
const char *SSL_get_psk_identity(SSL *ssl);
SEE ALSO
openssl(1), crypto(3), SSL_accept(3), SSL_clear(3), SSL_connect(3),
SSL_CIPHER_get_name(3), SSL_COMP_add_compression_method(3),
SSL_CTX_add_extra_chain_cert(3), SSL_CTX_add_session(3),
SSL_CTX_ctrl(3), SSL_CTX_flush_sessions(3),
SSL_CTX_get_ex_new_index(3), SSL_CTX_get_verify_mode(3),
SSL_CTX_load_verify_locations(3) SSL_CTX_new(3),
SSL_CTX_sess_number(3), SSL_CTX_sess_set_cache_size(3),
SSL_CTX_sess_set_get_cb(3), SSL_CTX_sessions(3),
SSL_CTX_set_cert_store(3), SSL_CTX_set_cert_verify_callback(3),
SSL_CTX_set_cipher_list(3), SSL_CTX_set_client_CA_list(3),
SSL_CTX_set_client_cert_cb(3), SSL_CTX_set_default_passwd_cb(3),
SSL_CTX_set_generate_session_id(3), SSL_CTX_set_info_callback(3),
SSL_CTX_set_max_cert_list(3), SSL_CTX_set_mode(3),
SSL_CTX_set_msg_callback(3), SSL_CTX_set_options(3),
SSL_CTX_set_quiet_shutdown(3), SSL_CTX_set_read_ahead(3),
SSL_CTX_set_session_cache_mode(3), SSL_CTX_set_session_id_context(3),
SSL_CTX_set_ssl_version(3), SSL_CTX_set_timeout(3),
SSL_CTX_set_tmp_rsa_callback(3), SSL_CTX_set_tmp_dh_callback(3),
SSL_CTX_set_verify(3), SSL_CTX_use_certificate(3),
SSL_alert_type_string(3), SSL_do_handshake(3), SSL_get_SSL_CTX(3),
SSL_get_ciphers(3), SSL_get_client_CA_list(3),
SSL_get_default_timeout(3), SSL_get_error(3),
SSL_get_ex_data_X509_STORE_CTX_idx(3), SSL_get_ex_new_index(3),
SSL_get_fd(3), SSL_get_peer_cert_chain(3), SSL_get_rbio(3),
SSL_get_session(3), SSL_get_verify_result(3), SSL_get_version(3),
SSL_library_init(3), SSL_load_client_CA_file(3), SSL_new(3),
SSL_pending(3), SSL_read(3), SSL_rstate_string(3),
SSL_session_reused(3), SSL_set_bio(3), SSL_set_connect_state(3),
SSL_set_fd(3), SSL_set_session(3), SSL_set_shutdown(3),
SSL_shutdown(3), SSL_state_string(3), SSL_want(3), SSL_write(3),
SSL_SESSION_free(3), SSL_SESSION_get_ex_new_index(3),
SSL_SESSION_get_time(3), d2i_SSL_SESSION(3),
SSL_CTX_set_psk_client_callback(3), SSL_CTX_use_psk_identity_hint(3),
SSL_get_psk_identity(3)
HISTORY
The ssl(3) document appeared in OpenSSL 0.9.2
1.0.2h 2016-05-03 ssl(3)
SSL_CTX_DANE_ENABLE(3) OpenSSL SSL_CTX_DANE_ENABLE(3)
NAME
SSL_CTX_dane_enable, SSL_CTX_dane_mtype_set, SSL_dane_enable,
SSL_dane_tlsa_add, SSL_get0_dane_authority, SSL_get0_dane_tlsa,
SSL_CTX_dane_set_flags, SSL_CTX_dane_clear_flags, SSL_dane_set_flags,
SSL_dane_clear_flags - enable DANE TLS authentication of the remote TLS
server in the local TLS client
SYNOPSIS
#include <openssl/ssl.h>
int SSL_CTX_dane_enable(SSL_CTX *ctx);
int SSL_CTX_dane_mtype_set(SSL_CTX *ctx, const EVP_MD *md,
uint8_t mtype, uint8_t ord);
int SSL_dane_enable(SSL *s, const char *basedomain);
int SSL_dane_tlsa_add(SSL *s, uint8_t usage, uint8_t selector,
uint8_t mtype, unsigned const char *data, size_t dlen);
int SSL_get0_dane_authority(SSL *s, X509 **mcert, EVP_PKEY **mspki);
int SSL_get0_dane_tlsa(SSL *s, uint8_t *usage, uint8_t *selector,
uint8_t *mtype, unsigned const char **data,
size_t *dlen);
unsigned long SSL_CTX_dane_set_flags(SSL_CTX *ctx, unsigned long flags);
unsigned long SSL_CTX_dane_clear_flags(SSL_CTX *ctx, unsigned long flags);
unsigned long SSL_dane_set_flags(SSL *ssl, unsigned long flags);
unsigned long SSL_dane_clear_flags(SSL *ssl, unsigned long flags);
DESCRIPTION
These functions implement support for DANE TLSA (RFC6698 and RFC7671)
peer authentication.
SSL_CTX_dane_enable() must be called first to initialize the shared
state required for DANE support. Individual connections associated
with the context can then enable per-connection DANE support as
appropriate. DANE authentication is implemented in the
X509_verify_cert(3) function, and applications that override
X509_verify_cert(3) via SSL_CTX_set_cert_verify_callback(3) are
responsible to authenticate the peer chain in whatever manner they see
fit.
SSL_CTX_dane_mtype_set() may then be called zero or more times to
adjust the supported digest algorithms. This must be done before any
SSL handles are created for the context.
The mtype argument specifies a DANE TLSA matching type and the md
argument specifies the associated digest algorithm handle. The ord
argument specifies a strength ordinal. Algorithms with a larger
strength ordinal are considered more secure. Strength ordinals are
used to implement RFC7671 digest algorithm agility. Specifying a NULL
digest algorithm for a matching type disables support for that matching
type. Matching type Full(0) cannot be modified or disabled.
By default, matching type "SHA2-256(1)" (see RFC7218 for definitions of
the DANE TLSA parameter acronyms) is mapped to "EVP_sha256()" with a
strength ordinal of 1 and matching type "SHA2-512(2)" is mapped to
"EVP_sha512()" with a strength ordinal of 2.
SSL_dane_enable() must be called before the SSL handshake is initiated
with SSL_connect(3) if (and only if) you want to enable DANE for that
connection. (The connection must be associated with a DANE-enabled SSL
context). The basedomain argument specifies the RFC7671 TLSA base
domain, which will be the primary peer reference identifier for
certificate name checks. Additional server names can be specified via
SSL_add1_host(3). The basedomain is used as the default SNI hint if
none has yet been specified via SSL_set_tlsext_host_name(3).
SSL_dane_tlsa_add() may then be called one or more times, to load each
of the TLSA records that apply to the remote TLS peer. (This too must
be done prior to the beginning of the SSL handshake). The arguments
specify the fields of the TLSA record. The data field is provided in
binary (wire RDATA) form, not the hexadecimal ASCII presentation form,
with an explicit length passed via dlen. The library takes a copy of
the data buffer contents and the caller may free the original data
buffer when convenient. A return value of 0 indicates that "unusable"
TLSA records (with invalid or unsupported parameters) were provided. A
negative return value indicates an internal error in processing the
record.
The caller is expected to check the return value of each
SSL_dane_tlsa_add() call and take appropriate action if none are usable
or an internal error is encountered in processing some records.
If no TLSA records are added successfully, DANE authentication is not
enabled, and authentication will be based on any configured traditional
trust-anchors; authentication success in this case does not mean that
the peer was DANE-authenticated.
SSL_get0_dane_authority() can be used to get more detailed information
about the matched DANE trust-anchor after successful connection
completion. The return value is negative if DANE verification failed
(or was not enabled), 0 if an EE TLSA record directly matched the leaf
certificate, or a positive number indicating the depth at which a TA
record matched an issuer certificate. The complete verified chain can
be retrieved via SSL_get0_verified_chain(3). The return value is an
index into this verified chain, rather than the list of certificates
sent by the peer as returned by SSL_get_peer_cert_chain(3).
If the mcert argument is not NULL and a TLSA record matched a chain
certificate, a pointer to the matching certificate is returned via
mcert. The returned address is a short-term internal reference to the
certificate and must not be freed by the application. Applications
that want to retain access to the certificate can call X509_up_ref(3)
to obtain a long-term reference which must then be freed via
X509_free(3) once no longer needed.
If no TLSA records directly matched any elements of the certificate
chain, but a DANE-TA(2) SPKI(1) Full(0) record provided the public key
that signed an element of the chain, then that key is returned via
mspki argument (if not NULL). In this case the return value is the
depth of the top-most element of the validated certificate chain. As
with mcert this is a short-term internal reference, and
EVP_PKEY_up_ref(3) and EVP_PKEY_free(3) can be used to acquire and
release long-term references respectively.
SSL_get0_dane_tlsa() can be used to retrieve the fields of the TLSA
record that matched the peer certificate chain. The return value
indicates the match depth or failure to match just as with
SSL_get0_dane_authority(). When the return value is nonnegative, the
storage pointed to by the usage, selector, mtype and data parameters is
updated to the corresponding TLSA record fields. The data field is in
binary wire form, and is therefore not NUL-terminated, its length is
returned via the dlen parameter. If any of these parameters is NULL,
the corresponding field is not returned. The data parameter is set to
a short-term internal-copy of the associated data field and must not be
freed by the application. Applications that need long-term access to
this field need to copy the content.
SSL_CTX_dane_set_flags() and SSL_dane_set_flags() can be used to enable
optional DANE verification features. SSL_CTX_dane_clear_flags() and
SSL_dane_clear_flags() can be used to disable the same features. The
flags argument is a bit mask of the features to enable or disable. The
flags set for an SSL_CTX context are copied to each SSL handle
associated with that context at the time the handle is created.
Subsequent changes in the context's flags have no effect on the flags
set for the handle.
At present, the only available option is
DANE_FLAG_NO_DANE_EE_NAMECHECKS which can be used to disable server
name checks when authenticating via DANE-EE(3) TLSA records. For some
applications, primarily web browsers, it is not safe to disable name
checks due to "unknown key share" attacks, in which a malicious server
can convince a client that a connection to a victim server is instead a
secure connection to the malicious server. The malicious server may
then be able to violate cross-origin scripting restrictions. Thus,
despite the text of RFC7671, name checks are by default enabled for
DANE-EE(3) TLSA records, and can be disabled in applications where it
is safe to do so. In particular, SMTP and XMPP clients should set this
option as SRV and MX records already make it possible for a remote
domain to redirect client connections to any server of its choice, and
in any case SMTP and XMPP clients do not execute scripts downloaded
from remote servers.
RETURN VALUES
The functions SSL_CTX_dane_enable(), SSL_CTX_dane_mtype_set(),
SSL_dane_enable() and SSL_dane_tlsa_add() return a positive value on
success. Negative return values indicate resource problems (out of
memory, etc.) in the SSL library, while a return value of 0 indicates
incorrect usage or invalid input, such as an unsupported TLSA record
certificate usage, selector or matching type. Invalid input also
includes malformed data, either a digest length that does not match the
digest algorithm, or a Full(0) (binary ASN.1 DER form) certificate or a
public key that fails to parse.
The functions SSL_get0_dane_authority() and SSL_get0_dane_tlsa() return
a negative value when DANE authentication failed or was not enabled, a
nonnegative value indicates the chain depth at which the TLSA record
matched a chain certificate, or the depth of the top-most certificate,
when the TLSA record is a full public key that is its signer.
The functions SSL_CTX_dane_set_flags(), SSL_CTX_dane_clear_flags(),
SSL_dane_set_flags() and SSL_dane_clear_flags() return the flags in
effect before they were called.
EXAMPLES
Suppose "smtp.example.com" is the MX host of the domain "example.com",
and has DNSSEC-validated TLSA records. The calls below will perform
DANE authentication and arrange to match either the MX hostname or the
destination domain name in the SMTP server certificate. Wildcards are
supported, but must match the entire label. The actual name matched in
the certificate (which might be a wildcard) is retrieved, and must be
copied by the application if it is to be retained beyond the lifetime
of the SSL connection.
SSL_CTX *ctx;
SSL *ssl;
int (*verify_cb)(int ok, X509_STORE_CTX *sctx) = NULL;
int num_usable = 0;
const char *nexthop_domain = "example.com";
const char *dane_tlsa_domain = "smtp.example.com";
uint8_t usage, selector, mtype;
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 */
if (SSL_dane_enable(ssl, dane_tlsa_domain) <= 0)
/* error */
/*
* For many applications it is safe to skip DANE-EE(3) namechecks. Do not
* disable the checks unless "unknown key share" attacks pose no risk for
* your application.
*/
SSL_dane_set_flags(ssl, DANE_FLAG_NO_DANE_EE_NAMECHECKS);
if (!SSL_add1_host(ssl, nexthop_domain))
/* error */
SSL_set_hostflags(ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
for (... each TLSA record ...) {
unsigned char *data;
size_t len;
int ret;
/* set usage, selector, mtype, data, len */
/*
* Opportunistic DANE TLS clients support only DANE-TA(2) or DANE-EE(3).
* They treat all other certificate usages, and in particular PKIX-TA(0)
* and PKIX-EE(1), as unusable.
*/
switch (usage) {
default:
case 0: /* PKIX-TA(0) */
case 1: /* PKIX-EE(1) */
continue;
case 2: /* DANE-TA(2) */
case 3: /* DANE-EE(3) */
break;
}
ret = SSL_dane_tlsa_add(ssl, usage, selector, mtype, data, len);
/* free data as appropriate */
if (ret < 0)
/* handle SSL library internal error */
else if (ret == 0)
/* handle unusable TLSA record */
else
++num_usable;
}
/*
* At this point, the verification mode is still the default SSL_VERIFY_NONE.
* Opportunistic DANE clients use unauthenticated TLS when all TLSA records
* are unusable, so continue the handshake even if authentication fails.
*/
if (num_usable == 0) {
/* Log all records unusable? */
/* Optionally set verify_cb to a suitable non-NULL callback. */
SSL_set_verify(ssl, SSL_VERIFY_NONE, verify_cb);
} else {
/* At least one usable record. We expect to verify the peer */
/* Optionally set verify_cb to a suitable non-NULL callback. */
/*
* Below we elect to fail the handshake when peer verification fails.
* Alternatively, use the permissive SSL_VERIFY_NONE verification mode,
* complete the handshake, check the verification status, and if not
* verified disconnect gracefully at the application layer, especially if
* application protocol supports informing the server that authentication
* failed.
*/
SSL_set_verify(ssl, SSL_VERIFY_PEER, verify_cb);
}
/*
* Load any saved session for resumption, making sure that the previous
* session applied the same security and authentication requirements that
* would be expected of a fresh connection.
*/
/* Perform SSL_connect() handshake and handle errors here */
if (SSL_session_reused(ssl)) {
if (SSL_get_verify_result(ssl) == X509_V_OK) {
/*
* Resumed session was originally verified, this connection is
* authenticated.
*/
} else {
/*
* Resumed session was not originally verified, this connection is not
* authenticated.
*/
}
} else if (SSL_get_verify_result(ssl) == X509_V_OK) {
const char *peername = SSL_get0_peername(ssl);
EVP_PKEY *mspki = NULL;
int depth = SSL_get0_dane_authority(ssl, NULL, &mspki);
if (depth >= 0) {
(void) SSL_get0_dane_tlsa(ssl, &usage, &selector, &mtype, NULL, NULL);
printf("DANE TLSA %d %d %d %s at depth %d\n", usage, selector, mtype,
(mspki != NULL) ? "TA public key verified certificate" :
depth ? "matched TA certificate" : "matched EE certificate",
depth);
}
if (peername != NULL) {
/* Name checks were in scope and matched the peername */
printf("Verified peername: %s\n", peername);
}
} else {
/*
* Not authenticated, presumably all TLSA rrs unusable, but possibly a
* callback suppressed connection termination despite the presence of
* usable TLSA RRs none of which matched. Do whatever is appropriate for
* fresh unauthenticated connections.
*/
}
NOTES
It is expected that the majority of clients employing DANE TLS will be
doing "opportunistic DANE TLS" in the sense of RFC7672 and RFC7435.
That is, they will use DANE authentication when DNSSEC-validated TLSA
records are published for a given peer, and otherwise will use
unauthenticated TLS or even cleartext.
Such applications should generally treat any TLSA records published by
the peer with usages PKIX-TA(0) and PKIX-EE(1) as "unusable", and
should not include them among the TLSA records used to authenticate
peer connections. In addition, some TLSA records with supported usages
may be "unusable" as a result of invalid or unsupported parameters.
When a peer has TLSA records, but none are "usable", an opportunistic
application must avoid cleartext, but cannot authenticate the peer, and
so should generally proceed with an unauthenticated connection.
Opportunistic applications need to note the return value of each call
to SSL_dane_tlsa_add(), and if all return 0 (due to invalid or
unsupported parameters) disable peer authentication by calling
SSL_set_verify(3) with mode equal to SSL_VERIFY_NONE.
SEE ALSO
SSL_new(3), SSL_add1_host(3), SSL_set_hostflags(3),
SSL_set_tlsext_host_name(3), SSL_set_verify(3),
SSL_CTX_set_cert_verify_callback(3), SSL_get0_verified_chain(3),
SSL_get_peer_cert_chain(3), SSL_get_verify_result(3), SSL_connect(3),
SSL_get0_peername(3), X509_verify_cert(3), X509_up_ref(3),
X509_free(3), EVP_get_digestbyname(3), EVP_PKEY_up_ref(3),
EVP_PKEY_free(3)
HISTORY
These functions were added in OpenSSL 1.1.0.
COPYRIGHT
Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the OpenSSL license (the "License"). You may not use
this file except in compliance with the License. You can obtain a copy
in the file LICENSE in the source distribution or at
<https://www.openssl.org/source/license.html>.
1.1.1v 2023-08-01 SSL_CTX_DANE_ENABLE(3)