本文基于OpenSSL 1.1.0c
libssl实现了SSL v2/v3和TLS v1 协议。
SSL_CTX 对象:一个用来建立SSL/TLS连接的框架。通过这个对象可以用来设置证书、算法等。使用SSL_CTX_new()创建该对象。
SSL对象:当一个连接建立以后,将被分配到SSL对象。可使用SSL_new()创建SSL对象,之后,可使用SSL_set_fd()或SSL_set_bio()为其分配一个网络连接。
然后,使用SSL_accept()或SSL_connect()来进行TLS/SSL握手。然后,使用SSL_read()或SSL_write()在TLS/SSL上进行读写。然后,使用SSL_shutdown()关闭TLS/SSL连接。
数据结构
SSL_METHOD
SSL_CIPHER
SSL_CTX
SSL_SESSION
SSL
函数
Dealing with Protocol Methods
const SSL_METHOD *TLS_method(void);
const SSL_METHOD *TLS_client_method(void);
const SSL_METHOD *TLS_server_method(void);
const SSL_METHOD *TLSv1_2_method(void);
const SSL_METHOD *TLSv1_2_client_method(void);
const SSL_METHOD *TLSv1_2_server_method(void);
...
Dealing with Ciphers
char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len);
int SSL_CIPHER_get_bits(SSL_CIPHER *cipher, int *alg_bits);
const char *SSL_CIPHER_get_name(SSL_CIPHER *cipher);
const char *SSL_CIPHER_get_version(SSL_CIPHER *cipher);
Dealing with Protocol Contexts
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_ciphers(const 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);