sslimpl.h

来自「支持SSL v2/v3, TLS, PKCS #5, PKCS #7, PKCS」· C头文件 代码 · 共 1,251 行 · 第 1/3 页

H
1,251
字号
    int           encrypted;    /* SSL2 session is now encrypted.  ssl2 only */    /* These next two values are used by SSL2 and SSL3.      ** DoRecv uses them to extract application data.    ** The difference between writeOffset and readOffset is the amount of     ** data available to the application.   Note that the actual offset of     ** the data in "buf" is recordOffset (above), not readOffset.    ** In the current implementation, this is made available before the     ** MAC is checked!!    */    unsigned int  readOffset;  /* Spot where DATA reader (e.g. application                               ** or handshake code) will read next.                               ** Always zero for SSl3 application data.			       */    /* offset in buf/inbuf/hdr into which new data will be read from socket. */    unsigned int  writeOffset;     /* Buffer for ssl3 to read (encrypted) data from the socket */    sslBuffer     inbuf;			/*recvBufLock*/	/* ssl3 only */    /* The ssl[23]_GatherData functions read data into this buffer, rather    ** than into buf or inbuf, while in the GS_HEADER state.      ** The portion of the SSL record header put here always comes off the wire     ** as plaintext, never ciphertext.    ** For SSL2, the plaintext portion is two bytes long.  For SSl3 it is 5.    */    unsigned char hdr[5];					/* ssl 2 & 3 */};/* sslGather.state */#define GS_INIT		0#define GS_HEADER	1#define GS_MAC		2#define GS_DATA		3#define GS_PAD		4typedef SECStatus (*SSLCipher)(void *               context,                                unsigned char *      out,			       int *                outlen, 			       int                  maxout, 			       const unsigned char *in,			       int                  inlen);typedef SECStatus (*SSLDestroy)(void *context, PRBool freeit);/* * SSL2 buffers used in SSL3. *     writeBuf in the SecurityInfo maintained by sslsecur.c is used *              to hold the data just about to be passed to the kernel *     sendBuf in the ConnectInfo maintained by sslcon.c is used *              to hold handshake messages as they are accumulated *//*** This is "ci", as in "ss->sec.ci".**** Protection:  All the variables in here are protected by ** firstHandshakeLock AND (in ssl3) ssl3HandshakeLock */struct sslConnectInfoStr {    /* outgoing handshakes appended to this. */    sslBuffer       sendBuf;	                /*xmitBufLock*/ /* ssl 2 & 3 */    PRIPv6Addr      peer;                                       /* ssl 2 & 3 */    unsigned short  port;                                       /* ssl 2 & 3 */    sslSessionID   *sid;                                        /* ssl 2 & 3 */    /* see CIS_HAVE defines below for the bit values in *elements. */    char            elements;					/* ssl2 only */    char            requiredElements;				/* ssl2 only */    char            sentElements;                               /* ssl2 only */    char            sentFinished;                               /* ssl2 only */    /* Length of server challenge.  Used by client when saving challenge */    int             serverChallengeLen;                         /* ssl2 only */    /* type of authentication requested by server */    unsigned char   authType;                                   /* ssl2 only */    /* Challenge sent by client to server in client-hello message */    /* SSL3 gets a copy of this.  See ssl3_StartHandshakeHash().  */    unsigned char   clientChallenge[SSL_MAX_CHALLENGE_BYTES];   /* ssl 2 & 3 */    /* Connection-id sent by server to client in server-hello message */    unsigned char   connectionID[SSL_CONNECTIONID_BYTES];	/* ssl2 only */    /* Challenge sent by server to client in request-certificate message */    unsigned char   serverChallenge[SSL_MAX_CHALLENGE_BYTES];	/* ssl2 only */    /* Information kept to handle a request-certificate message */    unsigned char   readKey[SSL_MAX_MASTER_KEY_BYTES];		/* ssl2 only */    unsigned char   writeKey[SSL_MAX_MASTER_KEY_BYTES];		/* ssl2 only */    unsigned        keySize;					/* ssl2 only */};/* bit values for ci->elements, ci->requiredElements, sentElements. */#define CIS_HAVE_MASTER_KEY		0x01#define CIS_HAVE_CERTIFICATE		0x02#define CIS_HAVE_FINISHED		0x04#define CIS_HAVE_VERIFY			0x08/* Note: The entire content of this struct and whatever it points to gets * blown away by SSL_ResetHandshake().  This is "sec" as in "ss->sec". * * Unless otherwise specified below, the contents of this struct are  * protected by firstHandshakeLock AND (in ssl3) ssl3HandshakeLock. */struct sslSecurityInfoStr {    sslSendFunc      send;			/*xmitBufLock*/	/* ssl 2 & 3 */    int              isServer;			/* Spec Lock?*/	/* ssl 2 & 3 */    sslBuffer        writeBuf;			/*xmitBufLock*/	/* ssl 2 & 3 */    int              cipherType;				/* ssl 2 & 3 */    int              keyBits;					/* ssl 2 & 3 */    int              secretKeyBits;				/* ssl 2 & 3 */    CERTCertificate *peerCert;					/* ssl 2 & 3 */    SECKEYPublicKey *peerKey;					/* ssl3 only */    /*    ** Procs used for SID cache (nonce) management.     ** Different implementations exist for clients/servers     ** The lookup proc is only used for servers.  Baloney!    */    sslSessionIDCacheFunc     cache;				/* ssl 2 & 3 */    sslSessionIDUncacheFunc   uncache;				/* ssl 2 & 3 */    /*    ** everything below here is for ssl2 only.    ** This stuff is equivalent to SSL3's "spec", and is protected by the     ** same "Spec Lock" as used for SSL3's specs.    */    uint32           sendSequence;		/*xmitBufLock*/	/* ssl2 only */    uint32           rcvSequence;		/*recvBufLock*/	/* ssl2 only */    /* Hash information; used for one-way-hash functions (MD2, MD5, etc.) */    SECHashObject   *hash;			/* Spec Lock */ /* ssl2 only */    void            *hashcx;			/* Spec Lock */	/* ssl2 only */    SECItem          sendSecret;		/* Spec Lock */	/* ssl2 only */    SECItem          rcvSecret;			/* Spec Lock */	/* ssl2 only */    /* Session cypher contexts; one for each direction */    void            *readcx;			/* Spec Lock */	/* ssl2 only */    void            *writecx;			/* Spec Lock */	/* ssl2 only */    SSLCipher        enc;			/* Spec Lock */	/* ssl2 only */    SSLCipher        dec;			/* Spec Lock */	/* ssl2 only */    void           (*destroy)(void *, PRBool);	/* Spec Lock */	/* ssl2 only */    /* Blocking information for the session cypher */    int              blockShift;		/* Spec Lock */	/* ssl2 only */    int              blockSize;			/* Spec Lock */	/* ssl2 only */    /* These are used during a connection handshake */    sslConnectInfo   ci;					/* ssl 2 & 3 */};/*** ssl3State and CipherSpec structs*//* The SSL bulk cipher definition */typedef enum {    cipher_null,    cipher_rc4,     cipher_rc4_40,    cipher_rc4_56,    cipher_rc2,     cipher_rc2_40,    cipher_des,     cipher_3des,     cipher_des40,    cipher_idea,     cipher_fortezza,    cipher_missing              /* reserved for no such supported cipher */} SSL3BulkCipher;/* The specific cipher algorithm */typedef enum {    calg_null     = (int)0x80000000L,     calg_rc4      = CKM_RC4,     calg_rc2      = CKM_RC2_CBC,    calg_des      = CKM_DES_CBC,     calg_3des     = CKM_DES3_CBC,     calg_idea     = CKM_IDEA_CBC,    calg_fortezza = CKM_SKIPJACK_CBC64,     calg_init     = (int) 0x7fffffffL} CipherAlgorithm;/* hmac added to help TLS conversion by rjr... */typedef enum {    malg_null     = (int)0x80000000L,     malg_md5      = CKM_SSL3_MD5_MAC,     malg_sha      = CKM_SSL3_SHA1_MAC,     malg_md5_hmac = CKM_MD5_HMAC,    malg_sha_hmac = CKM_SHA_1_HMAC} MACAlgorithm;/* Key Exchange values moved to ssl.h */typedef SSLKEAType SSL3KEAType;typedef enum { 	mac_null, 	mac_md5, 	mac_sha, 	hmac_md5, 	/* TLS HMAC version of mac_md5 */	hmac_sha 	/* TLS HMAC version of mac_sha */} SSL3MACAlgorithm;typedef enum { type_stream, type_block } CipherType;#define MAX_IV_LENGTH 64/* * Do not depend upon 64 bit arithmetic in the underlying machine.  */typedef struct {    uint32         high;    uint32         low;} SSL3SequenceNumber;typedef struct {    SSL3Opaque write_iv[MAX_IV_LENGTH];    PK11SymKey *write_key;    PK11SymKey *write_mac_key;    PK11Context *write_mac_context;} ssl3KeyMaterial;typedef struct {    SSL3Opaque        wrapped_client_write_key[12]; /* wrapped with Ks */    SSL3Opaque        wrapped_server_write_key[12]; /* wrapped with Ks */    SSL3Opaque        client_write_iv         [24];    SSL3Opaque        server_write_iv         [24];    SSL3Opaque        wrapped_master_secret   [48];    PRUint16          wrapped_master_secret_len;} ssl3SidKeys;/*** These are the "specs" in the "ssl3" struct.** Access to the pointers to these specs, and all the specs' contents** (direct and indirect) is protected by the reader/writer lock ss->specLock.*/typedef struct {    const ssl3BulkCipherDef *cipher_def;    const ssl3MACDef * mac_def;    int                mac_size;    SSLCipher          encode;    void *             encodeContext;    SSLCipher          decode;    void *             decodeContext;    SSLDestroy         destroy;    PK11SymKey *       master_secret;    ssl3KeyMaterial    client;    ssl3KeyMaterial    server;    SSL3SequenceNumber write_seq_num;    SSL3SequenceNumber read_seq_num;    SSL3ProtocolVersion version;} ssl3CipherSpec;typedef enum {	never_cached, 		in_client_cache, 		in_server_cache, 		invalid_cache		/* no longer in any cache. */} Cached;struct sslSessionIDStr {    sslSessionID *        next;   /* chain used for client sockets, only */    CERTCertificate *     peerCert;    const char *          peerID;     /* client only */    const char *          urlSvrName; /* client only */    PRIPv6Addr            addr;    PRUint16              port;    SSL3ProtocolVersion   version;    PRUint32              time;    Cached                cached;    int                   references;    union {	struct {	    /* the V2 code depends upon the size of sessionID.  */	    unsigned char         sessionID[SSL_SESSIONID_BYTES];	    /* Stuff used to recreate key and read/write cipher objects */	    SECItem               masterKey;	    int                   cipherType;	    SECItem               cipherArg;	    int                   keyBits;	    int                   secretKeyBits;	} ssl2;	struct {	    /* values that are copied into the server's on-disk SID cache. */	    uint8                 sessionIDLength;	    SSL3Opaque            sessionID[SSL3_SESSIONID_BYTES];	    ssl3CipherSuite       cipherSuite;	    SSL3CompressionMethod compression;	    PRBool                resumable;	    int                   policy;	    PRBool                hasFortezza;	    ssl3SidKeys           keys;	    CK_MECHANISM_TYPE     masterWrapMech;				  /* mechanism used to wrap master secret */            SSL3KEAType           exchKeyType;				  /* key type used in exchange algorithm,				   * and to wrap the sym wrapping key. */	    /* The following values are NOT restored from the server's on-disk	     * session cache, but are restored from the client's cache.	     */ 	    PK11SymKey *      clientWriteKey;	    PK11SymKey *      serverWriteKey;	    PK11SymKey *      tek;	    /* The following values pertain to the slot that wrapped the 	    ** master secret. (used only in client)	    */	    SECMODModuleID    masterModuleID;				    /* what module wrapped the master secret */	    CK_SLOT_ID        masterSlotID;	    PRUint16	      masterWrapIndex;				/* what's the key index for the wrapping key */	    PRUint16          masterWrapSeries;	                        /* keep track of the slot series, so we don't 				 * accidently try to use new keys after the 				 * card gets removed and replaced.*/	    /* The following values pertain to the slot that did the signature	    ** for client auth.   (used only in client)	    */	    SECMODModuleID    clAuthModuleID;	    CK_SLOT_ID        clAuthSlotID;	    PRUint16          clAuthSeries;            char              masterValid;	    char              clAuthValid;	    /* the following values are used only in the client, and only 	     * with fortezza.	     */	    SSL3Opaque       clientWriteSave[80]; 	    int              clientWriteSaveLen;  	} ssl3;    } u;};typedef struct ssl3CipherSuiteDefStr {    ssl3CipherSuite          cipher_suite;    SSL3BulkCipher           bulk_cipher_alg;    SSL3MACAlgorithm         mac_alg;    SSL3KeyExchangeAlgorithm key_exchange_alg;} ssl3CipherSuiteDef;/*** There are tables of these, all const.*/typedef struct {    SSL3KeyExchangeAlgorithm kea;    SSL3KEAType              exchKeyType;    SSL3SignType             signKeyType;    PRBool                   is_limited;    int                      key_size_limit;    PRBool                   tls_keygen;} ssl3KEADef;typedef enum { kg_null, kg_strong, kg_export } SSL3KeyGenMode;/*** There are tables of these, all const.*/struct ssl3BulkCipherDefStr {    SSL3BulkCipher  cipher;    CipherAlgorithm calg;    int             key_size;    int             secret_key_size;    CipherType      type;    int             iv_size;    int             block_size;    SSL3KeyGenMode  keygen_mode;};/*** There are tables of these, all const.*/struct ssl3MACDefStr {    SSL3MACAlgorithm mac;    MACAlgorithm     malg;    int              pad_size;    int              mac_size;};typedef enum {    wait_client_hello,     wait_client_cert,     wait_client_key,    wait_cert_verify,     wait_change_cipher,     wait_finished,    wait_server_hello,     wait_server_cert,     wait_server_key,    wait_cert_request,     wait_hello_done,    idle_handshake} SSL3WaitState;/*** This is the "hs" member of the "ssl3" struct.** This entire struct is protected by ssl3HandshakeLock

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?