📄 ssl.h
字号:
/****************************************************************************
* *
* SSL v3/TLS Definitions Header File *
* Copyright Peter Gutmann 1998-2003 *
* *
****************************************************************************/
#ifndef _SSL_DEFINED
#define _SSL_DEFINED
/* Default SSL port */
#define SSL_PORT 443
/* SSL constants */
#define ID_SIZE 1 /* ID byte */
#define UINT16_SIZE 2 /* 16 bits */
#define LENGTH_SIZE 3 /* 24 bits */
#define SEQNO_SIZE 8 /* 64 bits */
#define VERSIONINFO_SIZE 2 /* 0x03, 0x0n */
#define ALERTINFO_SIZE 2 /* level + description */
#define SSL_HEADER_SIZE 5 /* Type, version, length */
#define SSL_NONCE_SIZE 32 /* Size of client/svr nonce */
#define SSL_SECRET_SIZE 48 /* Size of premaster/master secret */
#define MD5MAC_SIZE 16 /* Size of MD5 proto-HMAC/dual hash */
#define SHA1MAC_SIZE 20 /* Size of SHA-1 proto-HMAC/dual hash */
#define TLS_HASHEDMAC_SIZE 12 /* Size of TLS PRF( MD5 + SHA1 ) */
#define SESSIONID_SIZE 16 /* Size of session ID */
#define MAX_SESSIONID_SIZE 32 /* Max.allowed session ID size */
#define MAX_KEYBLOCK_SIZE ( ( 20 + 32 + 8 ) * 2 ) /* AES + SHA-1 */
#define MIN_PACKET_SIZE 4 /* Minimum SSL packet size */
#define MIN_SECURED_PACKET_SIZE ( 1 + MD5MAC_SIZE ) /* RC4-enc + MD5 MAC */
#define MAX_PACKET_SIZE 16384 /* Maximum SSL packet size */
/* The number of entries in the SSL session cache and the maximum amount of
time that an entry is retained in the cache */
#if defined( CONFIG_CONSERVE_MEMORY )
#define SESSIONCACHE_SIZE 128
#else
#define SESSIONCACHE_SIZE 1024
#endif /* CONFIG_CONSERVE_MEMORY */
#define SESSIONCACHE_TIMEOUT 3600
/* SSL packet/buffer size information */
#define EXTRA_PACKET_SIZE 64 /* Additional space for non-payload data */
/* SSL protocol-specific flags that augment the general session flags. The
alert-sent flag is required because we're required to send a close alert
when shutting down to prevent a truncation attack, however lower-level
code may have already sent an alert so we have to remember not to send it
twice */
#define SSL_PFLAG_NONE 0x0 /* No protocol-specific flags */
#define SSL_PFLAG_ALERTSENT 0x1 /* Close alert sent */
#define SSL_PFLAG_EXPLICITIV 0x2 /* TLS 1.1 with explicit IV */
/* SSL message types */
#define SSL_MSG_CHANGE_CIPHER_SPEC 20
#define SSL_MSG_ALERT 21
#define SSL_MSG_HANDSHAKE 22
#define SSL_MSG_APPLICATION_DATA 23
#define SSL_MSG_FIRST 20
#define SSL_MSG_LAST 23
/* Special-case expected packet-type values that are passed to readPacketSSL()
to handle situations where more than one return value is valid. The
client handshake is supposed to be a v3 handshake but is often a hacked v2
one with forwards-compatibility kludges, since this looks nothing like a
normal v3 packet we have to treat it specially */
#define SSL_MSG_SPECIAL_HANDSHAKE 0xFF
#define SSL_MSG_V2HANDSHAKE 0x80
/* SSL handshake message subtypes */
#define SSL_HAND_CLIENT_HELLO 0x01
#define SSL_HAND_SERVER_HELLO 0x02
#define SSL_HAND_CERTIFICATE 0x0B
#define SSL_HAND_SERVER_CERTREQUEST 0x0D
#define SSL_HAND_SERVER_HELLODONE 0x0E
#define SSL_HAND_CLIENT_CERTVERIFY 0x0F
#define SSL_HAND_CLIENT_KEYEXCHANGE 0x10
#define SSL_HAND_FINISHED 0x14
/* SSL alert levels and types */
#define SSL_ALERTLEVEL_WARNING 1
#define SSL_ALERTLEVEL_FATAL 2
#define SSL_ALERT_CLOSE_NOTIFY 0
#define SSL_ALERT_UNEXPECTED_MESSAGE 10
#define SSL_ALERT_BAD_RECORD_MAC 20
#define TLS_ALERT_DECRYPTION_FAILED 21
#define TLS_ALERT_RECORD_OVERFLOW 22
#define SSL_ALERT_DECOMPRESSION_FAILURE 30
#define SSL_ALERT_HANDSHAKE_FAILURE 40
#define SSL_ALERT_NO_CERTIFICATE 41
#define SSL_ALERT_BAD_CERTIFICATE 42
#define SSL_ALERT_UNSUPPORTED_CERTIFICATE 43
#define SSL_ALERT_CERTIFICATE_REVOKED 44
#define SSL_ALERT_CERTIFICATE_EXPIRED 45
#define SSL_ALERT_CERTIFICATE_UNKNOWN 46
#define SSL_ALERT_ILLEGAL_PARAMETER 47
#define TLS_ALERT_UNKNOWN_CA 48
#define TLS_ALERT_ACCESS_DENIED 49
#define TLS_ALERT_DECODE_ERROR 50
#define TLS_ALERT_DECRYPT_ERROR 51
#define TLS_ALERT_EXPORT_RESTRICTION 60
#define TLS_ALERT_PROTOCOL_VERSION 70
#define TLS_ALERT_INSUFFICIENT_SECURITY 71
#define TLS_ALERT_INTERNAL_ERROR 80
#define TLS_ALERT_USER_CANCELLED 90
#define TLS_ALERT_NO_RENEGOTIATION 100
#define TLS_ALERT_UNSUPPORTED_EXTENSION 110
#define TLS_ALERT_CERTIFICATE_UNOBTAINABLE 111
#define TLS_ALERT_UNRECOGNIZED_NAME 112
#define TLS_ALERT_BAD_CERTIFICATE_STATUS_RESPONSE 113
#define TLS_ALERT_BAD_CERTIFICATE_HASH_VALUE 114
/* SSL cipher suites */
typedef enum {
/* SSLv3 cipher suites (0-10) */
SSL_NULL_WITH_NULL, SSL_RSA_WITH_NULL_MD5, SSL_RSA_WITH_NULL_SHA,
SSL_RSA_EXPORT_WITH_RC4_40_MD5, SSL_RSA_WITH_RC4_128_MD5,
SSL_RSA_WITH_RC4_128_SHA, SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5,
SSL_RSA_WITH_IDEA_CBC_SHA, SSL_RSA_EXPORT_WITH_DES40_CBC_SHA,
SSL_RSA_WITH_DES_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA,
/* TLS (RFC 2246) DH cipher suites (11-22) */
TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA, TLS_DH_DSS_WITH_DES_CBC_SHA,
TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA, TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA,
TLS_DH_RSA_WITH_DES_CBC_SHA, TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA,
TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA, TLS_DHE_DSS_WITH_DES_CBC_SHA,
TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA,
TLS_DHE_RSA_WITH_DES_CBC_SHA, TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA,
/* TLS (RFC 2246) anon-DH cipher suites (23-27) */
TLS_DH_anon_EXPORT_WITH_RC4_40_MD5, TLS_DH_anon_WITH_RC4_128_MD5,
TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA, TLS_DH_anon_WITH_DES_CBC_SHA,
TLS_DH_anon_WITH_3DES_EDE_CBC_SHA,
/* TLS (RFC 2246) reserved cipher suites (28-29, used for Fortezza in
SSLv3) */
TLS_reserved_1, TLS_reserved_2,
/* TLS with Kerberos (RFC 2712) suites (30-43) */
TLS_KRB5_WITH_DES_CBC_SHA, TLS_KRB5_WITH_3DES_EDE_CBC_SHA,
TLS_KRB5_WITH_RC4_128_SHA, TLS_KRB5_WITH_IDEA_CBC_SHA,
TLS_KRB5_WITH_DES_CBC_MD5, TLS_KRB5_WITH_3DES_EDE_CBC_MD5,
TLS_KRB5_WITH_RC4_128_MD5, TLS_KRB5_WITH_IDEA_CBC_MD5,
TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA, TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA,
TLS_KRB5_EXPORT_WITH_RC4_40_SHA, TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5,
TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5, TLS_KRB5_EXPORT_WITH_RC4_40_MD5,
/* Unknown suites (44-46) */
/* TLS (post-2246) cipher suites (47-58) */
TLS_RSA_WITH_AES_128_CBC_SHA = 0x2F, TLS_DH_DSS_WITH_AES_128_CBC_SHA,
TLS_DH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA,
TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DH_anon_WITH_AES_128_CBC_SHA,
TLS_RSA_WITH_AES_256_CBC_SHA, TLS_DH_DSS_WITH_AES_256_CBC_SHA,
TLS_DH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA,
TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DH_anon_WITH_AES_256_CBC_SHA,
SSL_LAST } SSL_CIPHERSUITE_TYPE;
/* TLS extension types */
typedef enum {
TLS_EXT_SERVER_NAME, TLS_EXT_MAX_FRAGMENT_LENTH,
TLS_EXT_CLIENT_CERTIFICATE_URL, TLS_EXT_TRUSTED_CA_KEYS,
TLS_EXT_TRUNCATED_HMAC, TLS_EXT_STATUS_REQUEST
} TLS_EXT_TYPE;
/* SSL and TLS major and minor version numbers */
#define SSL_MAJOR_VERSION 3
#define SSL_MINOR_VERSION_SSL 0
#define SSL_MINOR_VERSION_TLS 1
#define SSL_MINOR_VERSION_TLS11 2
/* SSL sender label values for the finished message MAC */
#define SSL_SENDER_CLIENTLABEL "CLNT"
#define SSL_SENDER_SERVERLABEL "SRVR"
#define SSL_SENDERLABEL_SIZE 4
/* Proto-HMAC padding data */
#define PROTOHMAC_PAD1 "\x36\x36\x36\x36\x36\x36\x36\x36" \
"\x36\x36\x36\x36\x36\x36\x36\x36" \
"\x36\x36\x36\x36\x36\x36\x36\x36" \
"\x36\x36\x36\x36\x36\x36\x36\x36" \
"\x36\x36\x36\x36\x36\x36\x36\x36" \
"\x36\x36\x36\x36\x36\x36\x36\x36"
#define PROTOHMAC_PAD2 "\x5C\x5C\x5C\x5C\x5C\x5C\x5C\x5C" \
"\x5C\x5C\x5C\x5C\x5C\x5C\x5C\x5C" \
"\x5C\x5C\x5C\x5C\x5C\x5C\x5C\x5C" \
"\x5C\x5C\x5C\x5C\x5C\x5C\x5C\x5C" \
"\x5C\x5C\x5C\x5C\x5C\x5C\x5C\x5C" \
"\x5C\x5C\x5C\x5C\x5C\x5C\x5C\x5C"
/* Fixed-format message templates for SSL, TLS 1.0, and TLS 1.1. The second
subscript is a worst-case, unfortunately this is the only way we can
statically initialise a two-dimensional array of chars */
typedef BYTE SSL_MESSAGE_TEMPLATE[ 3 ][ 8 ];
/* SSL handshake state information. This is passed around various
subfunctions that handle individual parts of the handshake */
typedef struct SL {
/* Client and server proto-HMAC/dual-hash contexts */
CRYPT_CONTEXT clientMD5context, clientSHA1context;
CRYPT_CONTEXT serverMD5context, serverSHA1context;
/* Client and server nonces and session ID */
BYTE clientNonce[ SSL_NONCE_SIZE ], serverNonce[ SSL_NONCE_SIZE ];
BYTE sessionID[ MAX_SESSIONID_SIZE ];
int sessionIDlength;
/* Premaster/master secret */
BYTE premasterSecret[ SSL_SECRET_SIZE ];
/* Other info */
int cipherSuite; /* Selected cipher suite */
int cryptKeysize; /* Size of session key */
int clientOfferedVersion; /* Prot.vers.originally offered by client */
/* Function pointers to handshaking functions. These are set up as
required depending on whether the session is client or server */
int ( *beginHandshake )( SESSION_INFO *sessionInfoPtr,
struct SL *handshakeInfo );
int ( *exchangeKeys )( SESSION_INFO *sessionInfoPtr,
struct SL *handshakeInfo );
} SSL_HANDSHAKE_INFO;
/* Session cache management functions */
int findSessionCacheEntryID( const void *sessionID,
const int sessionIDlength );
int addSessionCacheEntry( const void *sessionID, const int sessionIDlength,
const void *masterSecret,
const BOOLEAN isFixedEntry );
void deleteSessionCacheEntry( const int uniqueID );
/* Prototypes for functions in ssl.c */
int readPacketSSL( SESSION_INFO *sessionInfoPtr,
SSL_HANDSHAKE_INFO *handshakeInfo, const int packetType );
int checkPacketHeader( SESSION_INFO *sessionInfoPtr, BYTE **bufPtrPtr,
const int type, const int minSize,
const int nextByte );
void wrapHandshakePacket( void *data, const int length,
const int protocolVersion );
int createSharedMasterSecret( BYTE *masterSecret,
const SESSION_INFO *sessionInfoPtr );
int initCiphersuiteInfo( SESSION_INFO *sessionInfoPtr,
SSL_HANDSHAKE_INFO *handshakeInfo,
const int cipherSuite );
int writeSSLCertChain( SESSION_INFO *sessionInfoPtr, BYTE *buffer );
int processVersionInfo( SESSION_INFO *sessionInfoPtr, const int version );
int processCertVerify( const SESSION_INFO *sessionInfoPtr,
const SSL_HANDSHAKE_INFO *handshakeInfo,
void *signature, const int signatureLength,
const int signatureMaxLength );
int dualMacData( const SSL_HANDSHAKE_INFO *handshakeInfo, const void *data,
const int dataLength );
/* Prototypes for session mapping functions */
void initSSLclientProcessing( SSL_HANDSHAKE_INFO *handshakeInfo );
void initSSLserverProcessing( SSL_HANDSHAKE_INFO *handshakeInfo );
#endif /* _SSL_DEFINED */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -