📄 ssl.h
字号:
/* ssl/ssl.h *//* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] */#ifndef HEADER_SSL_H #define HEADER_SSL_H #ifdef __cplusplusextern "C" {#endif#include <openssl/safestack.h>/* SSLeay version number for ASN.1 encoding of the session information *//* Version 0 - initial version * Version 1 - added the optional peer certificate */#define SSL_SESSION_ASN1_VERSION 0x0001/* text strings for the ciphers */#define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5 #define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5 #define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 #define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5 #define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 #define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5 #define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5 #define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA #define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 #define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA #define SSL_MAX_SSL_SESSION_ID_LENGTH 32#define SSL_MAX_SID_CTX_LENGTH 32#define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8)#define SSL_MAX_KEY_ARG_LENGTH 8#define SSL_MAX_MASTER_KEY_LENGTH 48/* These are used to specify which ciphers to use and not to use */#define SSL_TXT_LOW "LOW"#define SSL_TXT_MEDIUM "MEDIUM"#define SSL_TXT_HIGH "HIGH"#define SSL_TXT_kFZA "kFZA"#define SSL_TXT_aFZA "aFZA"#define SSL_TXT_eFZA "eFZA"#define SSL_TXT_FZA "FZA"#define SSL_TXT_aNULL "aNULL"#define SSL_TXT_eNULL "eNULL"#define SSL_TXT_NULL "NULL"#define SSL_TXT_kRSA "kRSA"#define SSL_TXT_kDHr "kDHr"#define SSL_TXT_kDHd "kDHd"#define SSL_TXT_kEDH "kEDH"#define SSL_TXT_aRSA "aRSA"#define SSL_TXT_aDSS "aDSS"#define SSL_TXT_aDH "aDH"#define SSL_TXT_DSS "DSS"#define SSL_TXT_DH "DH"#define SSL_TXT_EDH "EDH"#define SSL_TXT_ADH "ADH"#define SSL_TXT_RSA "RSA"#define SSL_TXT_DES "DES"#define SSL_TXT_3DES "3DES"#define SSL_TXT_RC4 "RC4"#define SSL_TXT_RC2 "RC2"#define SSL_TXT_IDEA "IDEA"#define SSL_TXT_MD5 "MD5"#define SSL_TXT_SHA1 "SHA1"#define SSL_TXT_SHA "SHA"#define SSL_TXT_EXP "EXP"#define SSL_TXT_EXPORT "EXPORT"#define SSL_TXT_EXP40 "EXPORT40"#define SSL_TXT_EXP56 "EXPORT56"#define SSL_TXT_SSLV2 "SSLv2"#define SSL_TXT_SSLV3 "SSLv3"#define SSL_TXT_TLSV1 "TLSv1"#define SSL_TXT_ALL "ALL"/* 'DEFAULT' at the start of the cipher list insert the following string * in addition to this being the default cipher string */#define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:RC4+RSA:+SSLv2:@STRENGTH"/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */#define SSL_SENT_SHUTDOWN 1#define SSL_RECEIVED_SHUTDOWN 2#include <openssl/crypto.h>#include <openssl/lhash.h>#include <openssl/buffer.h>#include <openssl/bio.h>#include <openssl/pem.h>#include <openssl/x509.h>#if (defined(NO_RSA) || defined(NO_MD5)) && !defined(NO_SSL2)#define NO_SSL2#endif#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1#define SSL_FILETYPE_PEM X509_FILETYPE_PEM/* This is needed to stop compilers complaining about the * 'struct ssl_st *' function parameters used to prototype callbacks * in SSL_CTX. */typedef struct ssl_st *ssl_crock_st;/* used to hold info on the particular ciphers used */typedef struct ssl_cipher_st { int valid; const char *name; /* text name */ unsigned long id; /* id, 4 bytes, first is version */ unsigned long algorithms; /* what ciphers are used */ unsigned long algo_strength; /* strength and export flags */ unsigned long algorithm2; /* Extra flags */ int strength_bits; /* Number of bits really used */ int alg_bits; /* Number of bits for algorithm */ unsigned long mask; /* used for matching */ unsigned long mask_strength; /* also used for matching */ } SSL_CIPHER;DECLARE_STACK_OF(SSL_CIPHER)typedef struct ssl_st SSL;typedef struct ssl_ctx_st SSL_CTX;/* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */typedef struct ssl_method_st { int version; int (*ssl_new)(SSL *s); void (*ssl_clear)(SSL *s); void (*ssl_free)(SSL *s); int (*ssl_accept)(SSL *s); int (*ssl_connect)(SSL *s); int (*ssl_read)(SSL *s,void *buf,int len); int (*ssl_peek)(SSL *s,char *buf,int len); int (*ssl_write)(SSL *s,const void *buf,int len); int (*ssl_shutdown)(SSL *s); int (*ssl_renegotiate)(SSL *s); int (*ssl_renegotiate_check)(SSL *s); long (*ssl_ctrl)(SSL *s,int cmd,long larg,char *parg); long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,char *parg); SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr); int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr); int (*ssl_pending)(SSL *s); int (*num_ciphers)(void); SSL_CIPHER *(*get_cipher)(unsigned ncipher); struct ssl_method_st *(*get_ssl_method)(int version); long (*get_timeout)(void); struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */ int (*ssl_version)(); long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)()); long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)()); } SSL_METHOD;/* Lets make this into an ASN.1 type structure as follows * SSL_SESSION_ID ::= SEQUENCE { * version INTEGER, -- structure version number * SSLversion INTEGER, -- SSL version number * Cipher OCTET_STRING, -- the 3 byte cipher ID * Session_ID OCTET_STRING, -- the Session ID * Master_key OCTET_STRING, -- the master key * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate * Session_ID_context [ 4 ] EXPLICIT OCTET_STRING, -- the Session ID context * Verify_result [ 5 ] EXPLICIT INTEGER -- X509_V_... code for `Peer' * Compression [6] IMPLICIT ASN1_OBJECT -- compression OID XXXXX * } * Look in ssl/ssl_asn1.c for more details * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-). */typedef struct ssl_session_st { int ssl_version; /* what ssl version session info is * being kept in here? */ /* only really used in SSLv2 */ unsigned int key_arg_length; unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH]; int master_key_length; unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH]; /* session_id - valid? */ unsigned int session_id_length; unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH]; /* this is used to determine whether the session is being reused in * the appropriate context. It is up to the application to set this, * via SSL_new */ unsigned int sid_ctx_length; unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; int not_resumable; /* The cert is the certificate used to establish this connection */ struct sess_cert_st /* SESS_CERT */ *sess_cert; /* This is the cert for the other end. * On clients, it will be the same as sess_cert->peer_key->x509 * (the latter is not enough as sess_cert is not retained * in the external representation of sessions, see ssl_asn1.c). */ X509 *peer; /* when app_verify_callback accepts a session where the peer's certificate * is not ok, we must remember the error for session reuse: */ long verify_result; /* only for servers */ int references; long timeout; long time; int compress_meth; /* Need to lookup the method */ SSL_CIPHER *cipher; unsigned long cipher_id; /* when ASN.1 loaded, this * needs to be used to load * the 'cipher' structure */ STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */ CRYPTO_EX_DATA ex_data; /* application specific data */ /* These are used to make removal of session-ids more * efficient and to implement a maximum cache size. */ struct ssl_session_st *prev,*next; } SSL_SESSION;#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L#define SSL_OP_TLS_D5_BUG 0x00000100L#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L#define SSL_OP_TLS_ROLLBACK_BUG 0x00000400L/* If set, always create a new key when using tmp_dh parameters */#define SSL_OP_SINGLE_DH_USE 0x00100000L/* Set to also use the tmp_rsa key when doing RSA operations. */#define SSL_OP_EPHEMERAL_RSA 0x00200000L/* The next flag deliberately changes the ciphertest, this is a check * for the PKCS#1 attack */#define SSL_OP_PKCS1_CHECK_1 0x08000000L#define SSL_OP_PKCS1_CHECK_2 0x10000000L#define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L/* SSL_OP_NON_EXPORT_FIRST looks utterly broken .. */#define SSL_OP_NON_EXPORT_FIRST 0x40000000L#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x80000000L#define SSL_OP_ALL 0x000FFFFFL#define SSL_OP_NO_SSLv2 0x01000000L#define SSL_OP_NO_SSLv3 0x02000000L#define SSL_OP_NO_TLSv1 0x04000000L/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success * when just a single record has been written): */#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L/* Make it possible to retry SSL_write() with changed buffer location * (buffer contents must stay the same!); this is not the default to avoid * the misconception that non-blocking SSL_write() behaves like * non-blocking write(): */#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, * they cannot be used to clear bits. */#define SSL_CTX_set_options(ctx,op) \ SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,op,NULL)#define SSL_CTX_get_options(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,0,NULL)#define SSL_set_options(ssl,op) \ SSL_ctrl(ssl,SSL_CTRL_OPTIONS,op,NULL)#define SSL_get_options(ssl) \ SSL_ctrl(ssl,SSL_CTRL_OPTIONS,0,NULL)#define SSL_CTX_set_mode(ctx,op) \ SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,op,NULL)#define SSL_CTX_get_mode(ctx) \ SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,0,NULL)#define SSL_set_mode(ssl,op) \ SSL_ctrl(ssl,SSL_CTRL_MODE,op,NULL)#define SSL_get_mode(ssl) \ SSL_ctrl(ssl,SSL_CTRL_MODE,0,NULL)#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20)typedef struct ssl_comp_st{ int id; char *name;#ifdef HEADER_COMP_H COMP_METHOD *method;#else char *method;#endif} SSL_COMP;DECLARE_STACK_OF(SSL_COMP)struct ssl_ctx_st { SSL_METHOD *method; unsigned long options; unsigned long mode; STACK_OF(SSL_CIPHER) *cipher_list; /* same as above but sorted for lookup */ STACK_OF(SSL_CIPHER) *cipher_list_by_id; struct x509_store_st /* X509_STORE */ *cert_store; struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSIONs */ /* Most session-ids that will be cached, default is * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */ 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -