📄 ssl.h
字号:
unsigned long session_cache_size; struct ssl_session_st *session_cache_head; struct ssl_session_st *session_cache_tail; /* This can have one of 2 values, ored together, * SSL_SESS_CACHE_CLIENT, * SSL_SESS_CACHE_SERVER, * Default is SSL_SESSION_CACHE_SERVER, which means only * SSL_accept which cache SSL_SESSIONS. */ int session_cache_mode; /* If timeout is not 0, it is the default timeout value set * when SSL_new() is called. This has been put in to make * life easier to set things up */ long session_timeout; /* If this callback is not null, it will be called each * time a session id is added to the cache. If this function * returns 1, it means that the callback will do a * SSL_SESSION_free() when it has finished using it. Otherwise, * on 0, it means the callback has finished with it. * If remove_session_cb is not null, it will be called when * a session-id is removed from the cache. After the call, * OpenSSL will SSL_SESSION_free() it. */ int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess); void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess); SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, unsigned char *data,int len,int *copy); struct { int sess_connect; /* SSL new conn - started */ int sess_connect_renegotiate;/* SSL reneg - requested */ int sess_connect_good; /* SSL new conne/reneg - finished */ int sess_accept; /* SSL new accept - started */ int sess_accept_renegotiate;/* SSL reneg - requested */ int sess_accept_good; /* SSL accept/reneg - finished */ int sess_miss; /* session lookup misses */ int sess_timeout; /* reuse attempt on timeouted session */ int sess_cache_full; /* session removed due to full cache */ int sess_hit; /* session reuse actually done */ int sess_cb_hit; /* session-id that was not * in the cache was * passed back via the callback. This * indicates that the application is * supplying session-id's from other * processes - spooky :-) */ } stats; int references;/**/ void (*info_callback)(); /* if defined, these override the X509_verify_cert() calls *//**/ int (*app_verify_callback)();/**/ char *app_verify_arg; /* never used; should be void * */ /* default values to use in SSL structures *//**/ struct cert_st /* CERT */ *cert;/**/ int read_ahead;/**/ int verify_mode;/**/ int verify_depth;/**/ unsigned int sid_ctx_length;/**/ unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];/**/ int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); int purpose; /* Purpose setting */ int trust; /* Trust setting */ /* Default password callback. *//**/ pem_password_cb *default_passwd_callback; /* Default password callback user data. *//**/ void *default_passwd_callback_userdata; /* get client cert callback *//**/ int (*client_cert_cb)(/* SSL *ssl, X509 **x509, EVP_PKEY **pkey */); /* what we put in client cert requests */ STACK_OF(X509_NAME) *client_CA;/**/ int quiet_shutdown; CRYPTO_EX_DATA ex_data; const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */ const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */ const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */ STACK_OF(X509) *extra_certs; STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */ };#define SSL_SESS_CACHE_OFF 0x0000#define SSL_SESS_CACHE_CLIENT 0x0001#define SSL_SESS_CACHE_SERVER 0x0002#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080/* This one, when set, makes the server session-id lookup not look * in the cache. If there is an application get_session callback * defined, this will still get called. */#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100 struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx);#define SSL_CTX_sess_number(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)#define SSL_CTX_sess_connect(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)#define SSL_CTX_sess_connect_good(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)#define SSL_CTX_sess_connect_renegotiate(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)#define SSL_CTX_sess_accept(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)#define SSL_CTX_sess_accept_renegotiate(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)#define SSL_CTX_sess_accept_good(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)#define SSL_CTX_sess_hits(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)#define SSL_CTX_sess_cb_hits(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)#define SSL_CTX_sess_misses(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)#define SSL_CTX_sess_timeouts(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)#define SSL_CTX_sess_cache_full(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)#define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb))#define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb)#define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb))#define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb)#define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb))#define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb)#define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb))#define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback)#define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb))#define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb)#define SSL_NOTHING 1#define SSL_WRITING 2#define SSL_READING 3#define SSL_X509_LOOKUP 4/* These will only be used when doing non-blocking IO */#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING)#define SSL_want_read(s) (SSL_want(s) == SSL_READING)#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING)#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP)struct ssl_st { /* protocol version * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION) */ int version; int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */ SSL_METHOD *method; /* SSLv3 */ /* There are 2 BIO's even though they are normally both the * same. This is so data can be read and written to different * handlers */#ifndef NO_BIO BIO *rbio; /* used by SSL_read */ BIO *wbio; /* used by SSL_write */ BIO *bbio; /* used during session-id reuse to concatenate * messages */#else char *rbio; /* used by SSL_read */ char *wbio; /* used by SSL_write */ char *bbio;#endif /* This holds a variable that indicates what we were doing * when a 0 or -1 is returned. This is needed for * non-blocking IO so we know what request needs re-doing when * in SSL_accept or SSL_connect */ int rwstate; /* true when we are actually in SSL_accept() or SSL_connect() */ int in_handshake; int (*handshake_func)(); /* Imagine that here's a boolean member "init" that is * switched as soon as SSL_set_{accept/connect}_state * is called for the first time, so that "state" and * "handshake_func" are properly initialized. But as * handshake_func is == 0 until then, we use this * test instead of an "init" member. */ int server; /* are we the server side? - mostly used by SSL_clear*/ int new_session;/* 1 if we are to use a new session */ int quiet_shutdown;/* don't send shutdown packets */ int shutdown; /* we have shut things down, 0x01 sent, 0x02 * for received */ int state; /* where we are */ int rstate; /* where we are when reading */ BUF_MEM *init_buf; /* buffer used during init */ int init_num; /* amount read/written */ int init_off; /* amount read/written */ /* used internally to point at a raw packet */ unsigned char *packet; unsigned int packet_length; struct ssl2_state_st *s2; /* SSLv2 variables */ struct ssl3_state_st *s3; /* SSLv3 variables */ int read_ahead; /* Read as many input bytes as possible * (for non-blocking reads) */ int hit; /* reusing a previous session */ int purpose; /* Purpose setting */ int trust; /* Trust setting */ /* crypto */ STACK_OF(SSL_CIPHER) *cipher_list; STACK_OF(SSL_CIPHER) *cipher_list_by_id; /* These are the ones being used, the ones in SSL_SESSION are * the ones to be 'copied' into these ones */ EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */ const EVP_MD *read_hash; /* used for mac generation */#ifndef NO_COMP COMP_CTX *expand; /* uncompress */#else char *expand;#endif EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */ const EVP_MD *write_hash; /* used for mac generation */#ifndef NO_COMP COMP_CTX *compress; /* compression */#else char *compress; #endif /* session info */ /* client cert? */ /* This is used to hold the server certificate used */ struct cert_st /* CERT */ *cert; /* the session_id_context is used to ensure sessions are only reused * in the appropriate context */ unsigned int sid_ctx_length; unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; /* This can also be in the session once a session is established */ SSL_SESSION *session; /* Used in SSL2 and SSL3 */ int verify_mode; /* 0 don't care about verify failure. * 1 fail if verify fails */ int verify_depth; int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */ void (*info_callback)(); /* optional informational callback */ int error; /* error bytes to be written */ int error_code; /* actual code */ SSL_CTX *ctx; /* set this flag to 1 and a sleep(1) is put into all SSL_read() * and SSL_write() calls, good for nbio debuging :-) */ int debug; /* extra application data */ long verify_result; CRYPTO_EX_DATA ex_data; /* for server side, keep the list of CA_dn we can use */ STACK_OF(X509_NAME) *client_CA; int references; unsigned long options; /* protocol behaviour */ unsigned long mode; /* API behaviour */ int first_packet; int client_version; /* what was passed, used for * SSLv3/TLS rollback check */ };#ifdef __cplusplus}#endif#include <openssl/ssl2.h>#include <openssl/ssl3.h>#include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */#include <openssl/ssl23.h>#ifdef __cplusplusextern "C" {#endif/* compatibility */#define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg))#define SSL_get_app_data(s) (SSL_get_ex_data(s,0))#define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a))#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0))#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0))#define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg))/* The following are the possible values for ssl->state are are * used to indicate where we are up to in the SSL connection establishment. * The macros that follow are about the only things you should need to use * and even then, only when using non-blocking IO. * It can also be useful to work out where you were when the connection * failed */#define SSL_ST_CONNECT 0x1000#define SSL_ST_ACCEPT 0x2000#define SSL_ST_MASK 0x0FFF#define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT)#define SSL_ST_BEFORE 0x4000#define SSL_ST_OK 0x03#define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT)#define SSL_CB_LOOP 0x01#define SSL_CB_EXIT 0x02#define SSL_CB_READ 0x04#define SSL_CB_WRITE 0x08#define SSL_CB_ALERT 0x4000 /* used in callback */#define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)#define SSL_CB_HANDSHAKE_START 0x10#define SSL_CB_HANDSHAKE_DONE 0x20/* Is the SSL_connection established? */#define SSL_get_state(a) SSL_state(a)#define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK)#define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT)#define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE)#define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT)#define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT)/* The following 2 states are kept in ssl->rstate when reads fail, * you should not need these */#define SSL_ST_READ_HEADER 0xF0#define SSL_ST_READ_BODY 0xF1#define SSL_ST_READ_DONE 0xF2/* Obtain latest Finished message * -- that we sent (SSL_get_finished) * -- that we expected from peer (SSL_get_peer_finished). * Returns length (0 == no Finished so far), copies up to 'count' bytes. */size_t SSL_get_finished(SSL *s, void *buf, size_t count);size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count);/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options * are 'ored' with SSL_VERIFY_PEER if they are desired */#define SSL_VERIFY_NONE 0x00#define SSL_VERIFY_PEER 0x01#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02#define SSL_VERIFY_CLIENT_ONCE 0x04#define OpenSSL_add_ssl_algorithms() SSL_library_init()#define SSLeay_add_ssl_algorithms() SSL_library_init()/* this is for backward compatibility */#if 0 /* NEW_SSLEAY */#define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c)#define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n)#define SSL_add_session(a,b) SSL_CTX_add_session((a),(b))#define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b))#define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b))#endif/* More backward compatibility */#define SSL_get_cipher(s) \ SSL_CIPHER_get_name(SSL_get_current_cipher(s))#define SSL_get_cipher_bits(s,np) \ SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)#define SSL_get_cipher_version(s) \ SSL_CIPHER_get_version(SSL_get_current_cipher(s))#define SSL_get_cipher_name(s) \ SSL_CIPHER_get_name(SSL_get_current_cipher(s))#define SSL_get_time(a) SSL_SESSION_get_time(a)#define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b))#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a)#define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b))#if 1 /*SSLEAY_MACROS*/#define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -