📄 ssl_lib.c
字号:
SSLerr(SSL_F_SSL_UNDEFINED_VOID_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return(0); }int ssl_undefined_const_function(const SSL *s) { SSLerr(SSL_F_SSL_UNDEFINED_CONST_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return(0); }SSL_METHOD *ssl_bad_method(int ver) { SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return(NULL); }const char *SSL_get_version(const SSL *s) { if (s->version == TLS1_VERSION) return("TLSv1"); else if (s->version == SSL3_VERSION) return("SSLv3"); else if (s->version == SSL2_VERSION) return("SSLv2"); else return("unknown"); }SSL *SSL_dup(SSL *s) { STACK_OF(X509_NAME) *sk; X509_NAME *xn; SSL *ret; int i; if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) return(NULL); ret->version = s->version; ret->type = s->type; ret->method = s->method; if (s->session != NULL) { /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */ SSL_copy_session_id(ret,s); } else { /* No session has been established yet, so we have to expect * that s->cert or ret->cert will be changed later -- * they should not both point to the same object, * and thus we can't use SSL_copy_session_id. */ ret->method->ssl_free(ret); ret->method = s->method; ret->method->ssl_new(ret); if (s->cert != NULL) { if (ret->cert != NULL) { ssl_cert_free(ret->cert); } ret->cert = ssl_cert_dup(s->cert); if (ret->cert == NULL) goto err; } SSL_set_session_id_context(ret, s->sid_ctx, s->sid_ctx_length); } ret->options=s->options; ret->mode=s->mode; SSL_set_max_cert_list(ret,SSL_get_max_cert_list(s)); SSL_set_read_ahead(ret,SSL_get_read_ahead(s)); ret->msg_callback = s->msg_callback; ret->msg_callback_arg = s->msg_callback_arg; SSL_set_verify(ret,SSL_get_verify_mode(s), SSL_get_verify_callback(s)); SSL_set_verify_depth(ret,SSL_get_verify_depth(s)); ret->generate_session_id = s->generate_session_id; SSL_set_info_callback(ret,SSL_get_info_callback(s)); ret->debug=s->debug; /* copy app data, a little dangerous perhaps */ if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL, &ret->ex_data, &s->ex_data)) goto err; /* setup rbio, and wbio */ if (s->rbio != NULL) { if (!BIO_dup_state(s->rbio,(char *)&ret->rbio)) goto err; } if (s->wbio != NULL) { if (s->wbio != s->rbio) { if (!BIO_dup_state(s->wbio,(char *)&ret->wbio)) goto err; } else ret->wbio=ret->rbio; } ret->rwstate = s->rwstate; ret->in_handshake = s->in_handshake; ret->handshake_func = s->handshake_func; ret->server = s->server; ret->new_session = s->new_session; ret->quiet_shutdown = s->quiet_shutdown; ret->shutdown=s->shutdown; ret->state=s->state; /* SSL_dup does not really work at any state, though */ ret->rstate=s->rstate; ret->init_num = 0; /* would have to copy ret->init_buf, ret->init_msg, ret->init_num, ret->init_off */ ret->hit=s->hit; X509_VERIFY_PARAM_inherit(ret->param, s->param); /* dup the cipher_list and cipher_list_by_id stacks */ if (s->cipher_list != NULL) { if ((ret->cipher_list=sk_SSL_CIPHER_dup(s->cipher_list)) == NULL) goto err; } if (s->cipher_list_by_id != NULL) if ((ret->cipher_list_by_id=sk_SSL_CIPHER_dup(s->cipher_list_by_id)) == NULL) goto err; /* Dup the client_CA list */ if (s->client_CA != NULL) { if ((sk=sk_X509_NAME_dup(s->client_CA)) == NULL) goto err; ret->client_CA=sk; for (i=0; i<sk_X509_NAME_num(sk); i++) { xn=sk_X509_NAME_value(sk,i); if (sk_X509_NAME_set(sk,i,X509_NAME_dup(xn)) == NULL) { X509_NAME_free(xn); goto err; } } } if (0) {err: if (ret != NULL) SSL_free(ret); ret=NULL; } return(ret); }void ssl_clear_cipher_ctx(SSL *s) { if (s->enc_read_ctx != NULL) { EVP_CIPHER_CTX_cleanup(s->enc_read_ctx); OPENSSL_free(s->enc_read_ctx); s->enc_read_ctx=NULL; } if (s->enc_write_ctx != NULL) { EVP_CIPHER_CTX_cleanup(s->enc_write_ctx); OPENSSL_free(s->enc_write_ctx); s->enc_write_ctx=NULL; }#ifndef OPENSSL_NO_COMP if (s->expand != NULL) { COMP_CTX_free(s->expand); s->expand=NULL; } if (s->compress != NULL) { COMP_CTX_free(s->compress); s->compress=NULL; }#endif }/* Fix this function so that it takes an optional type parameter */X509 *SSL_get_certificate(const SSL *s) { if (s->cert != NULL) return(s->cert->key->x509); else return(NULL); }/* Fix this function so that it takes an optional type parameter */EVP_PKEY *SSL_get_privatekey(SSL *s) { if (s->cert != NULL) return(s->cert->key->privatekey); else return(NULL); }SSL_CIPHER *SSL_get_current_cipher(const SSL *s) { if ((s->session != NULL) && (s->session->cipher != NULL)) return(s->session->cipher); return(NULL); }#ifdef OPENSSL_NO_COMPconst void *SSL_get_current_compression(SSL *s) { return NULL; }const void *SSL_get_current_expansion(SSL *s) { return NULL; }#elseconst COMP_METHOD *SSL_get_current_compression(SSL *s) { if (s->compress != NULL) return(s->compress->meth); return(NULL); }const COMP_METHOD *SSL_get_current_expansion(SSL *s) { if (s->expand != NULL) return(s->expand->meth); return(NULL); }#endifint ssl_init_wbio_buffer(SSL *s,int push) { BIO *bbio; if (s->bbio == NULL) { bbio=BIO_new(BIO_f_buffer()); if (bbio == NULL) return(0); s->bbio=bbio; } else { bbio=s->bbio; if (s->bbio == s->wbio) s->wbio=BIO_pop(s->wbio); } (void)BIO_reset(bbio);/* if (!BIO_set_write_buffer_size(bbio,16*1024)) */ if (!BIO_set_read_buffer_size(bbio,1)) { SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER,ERR_R_BUF_LIB); return(0); } if (push) { if (s->wbio != bbio) s->wbio=BIO_push(bbio,s->wbio); } else { if (s->wbio == bbio) s->wbio=BIO_pop(bbio); } return(1); }void ssl_free_wbio_buffer(SSL *s) { if (s->bbio == NULL) return; if (s->bbio == s->wbio) { /* remove buffering */ s->wbio=BIO_pop(s->wbio);#ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */ assert(s->wbio != NULL);#endif } BIO_free(s->bbio); s->bbio=NULL; } void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode) { ctx->quiet_shutdown=mode; }int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx) { return(ctx->quiet_shutdown); }void SSL_set_quiet_shutdown(SSL *s,int mode) { s->quiet_shutdown=mode; }int SSL_get_quiet_shutdown(const SSL *s) { return(s->quiet_shutdown); }void SSL_set_shutdown(SSL *s,int mode) { s->shutdown=mode; }int SSL_get_shutdown(const SSL *s) { return(s->shutdown); }int SSL_version(const SSL *s) { return(s->version); }SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl) { return(ssl->ctx); }#ifndef OPENSSL_NO_STDIOint SSL_CTX_set_default_verify_paths(SSL_CTX *ctx) { return(X509_STORE_set_default_paths(ctx->cert_store)); }int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, const char *CApath) { return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath)); }#endifvoid SSL_set_info_callback(SSL *ssl, void (*cb)(const SSL *ssl,int type,int val)) { ssl->info_callback=cb; }/* One compiler (Diab DCC) doesn't like argument names in returned function pointer. */void (*SSL_get_info_callback(const SSL *ssl))(const SSL * /*ssl*/,int /*type*/,int /*val*/) { return ssl->info_callback; }int SSL_state(const SSL *ssl) { return(ssl->state); }void SSL_set_verify_result(SSL *ssl,long arg) { ssl->verify_result=arg; }long SSL_get_verify_result(const SSL *ssl) { return(ssl->verify_result); }int SSL_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func) { return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, argl, argp, new_func, dup_func, free_func); }int SSL_set_ex_data(SSL *s,int idx,void *arg) { return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); }void *SSL_get_ex_data(const SSL *s,int idx) { return(CRYPTO_get_ex_data(&s->ex_data,idx)); }int SSL_CTX_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func) { return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, argl, argp, new_func, dup_func, free_func); }int SSL_CTX_set_ex_data(SSL_CTX *s,int idx,void *arg) { return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); }void *SSL_CTX_get_ex_data(const SSL_CTX *s,int idx) { return(CRYPTO_get_ex_data(&s->ex_data,idx)); }int ssl_ok(SSL *s) { return(1); }X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx) { return(ctx->cert_store); }void SSL_CTX_set_cert_store(SSL_CTX *ctx,X509_STORE *store) { if (ctx->cert_store != NULL) X509_STORE_free(ctx->cert_store); ctx->cert_store=store; }int SSL_want(const SSL *s) { return(s->rwstate); }/*! * \brief Set the callback for generating temporary RSA keys. * \param ctx the SSL context. * \param cb the callback */#ifndef OPENSSL_NO_RSAvoid SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl, int is_export, int keylength)) { SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,(void (*)(void))cb); }void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl, int is_export, int keylength)) { SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,(void (*)(void))cb); }#endif#ifdef DOXYGEN/*! * \brief The RSA temporary key callback function. * \param ssl the SSL session. * \param is_export \c TRUE if the temp RSA key is for an export ciphersuite. * \param keylength if \c is_export is \c TRUE, then \c keylength is the size * of the required key in bits. * \return the temporary RSA key. * \sa SSL_CTX_set_tmp_rsa_callback, SSL_set_tmp_rsa_callback */RSA *cb(SSL *ssl,int is_export,int keylength) {}#endif/*! * \brief Set the callback for generating temporary DH keys. * \param ctx the SSL context. * \param dh the callback */#ifndef OPENSSL_NO_DHvoid SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, int keylength)) { SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); }void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, int keylength)) { SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh); }#endif#ifndef OPENSSL_NO_ECDHvoid SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,EC_KEY *(*ecdh)(SSL *ssl,int is_export, int keylength)) { SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); }void SSL_set_tmp_ecdh_callback(SSL *ssl,EC_KEY *(*ecdh)(SSL *ssl,int is_export, int keylength)) { SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh); }#endifvoid 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)) { SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb); }void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)) { SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb); }#if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16)#include "../crypto/bio/bss_file.c"#endifIMPLEMENT_STACK_OF(SSL_CIPHER)IMPLEMENT_STACK_OF(SSL_COMP)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -