sslimpl.h
来自「支持SSL v2/v3, TLS, PKCS #5, PKCS #7, PKCS」· C头文件 代码 · 共 1,251 行 · 第 1/3 页
H
1,251 行
*/typedef struct SSL3HandshakeStateStr { SSL3Random server_random; SSL3Random client_random; SSL3WaitState ws; PK11Context * md5; /* handshake running hashes */ PK11Context * sha;const ssl3KEADef * kea_def; ssl3CipherSuite cipher_suite;const ssl3CipherSuiteDef *suite_def; SSL3CompressionMethod compression; sslBuffer msg_body; /* protected by recvBufLock */ /* partial handshake message from record layer */ unsigned int header_bytes; /* number of bytes consumed from handshake */ /* message for message type and header length */ SSL3HandshakeType msg_type; unsigned long msg_len; SECItem ca_list; /* used only by client */ PRBool isResuming; /* are we resuming a session */ PRBool rehandshake; /* immediately start another handshake * when this one finishes */ PRBool usedStepDownKey; /* we did a server key exchange. */ sslBuffer msgState; /* current state for handshake messages*/ /* protected by recvBufLock */} SSL3HandshakeState;struct SSL3FortezzaKEAParamsStr { unsigned char R_s[128]; /* server's "random" public key */ PK11SymKey * tek;};typedef struct SSL3FortezzaKEAParamsStr SSL3FortezzaKEAParams;/*** This is the "ssl3" struct, as in "ss->ssl3".** note:** usually, crSpec == cwSpec and prSpec == pwSpec. ** Sometimes, crSpec == pwSpec and prSpec == cwSpec.** But there are never more than 2 actual specs. ** No spec must ever be modified if either "current" pointer points to it.*/struct ssl3StateStr { /* ** The following Specs and Spec pointers must be protected using the ** Spec Lock. */ ssl3CipherSpec * crSpec; /* current read spec. */ ssl3CipherSpec * prSpec; /* pending read spec. */ ssl3CipherSpec * cwSpec; /* current write spec. */ ssl3CipherSpec * pwSpec; /* pending write spec. */ ssl3CipherSpec specs[2]; /* one is current, one is pending. */ SSL3HandshakeState hs; CERTCertificate * clientCertificate; /* used by client */ SECKEYPrivateKey * clientPrivateKey; /* used by client */ CERTCertificateList *clientCertChain; /* used by client */ PRBool sendEmptyCert; /* used by client */ int policy; /* This says what cipher suites we can do, and should * be either SSL_ALLOWED or SSL_RESTRICTED */ PRArenaPool * peerCertArena; /* These are used to keep track of the peer CA */ void * peerCertChain; /* chain while we are trying to validate it. */ CERTDistNames * ca_list; /* used by server. trusted CAs for this socket. */ SSL3FortezzaKEAParams fortezza;};typedef struct { SSL3ContentType type; SSL3ProtocolVersion version; sslBuffer * buf;} SSL3Ciphertext;struct ssl3KeyPairStr { SECKEYPrivateKey * privKey; /* RSA step down key */ SECKEYPublicKey * pubKey; /* RSA step down key */ PRInt32 refCount; /* use PR_Atomic calls for this. */};typedef struct SSLWrappedSymWrappingKeyStr { SSL3Opaque wrappedSymmetricWrappingkey[512]; SSL3Opaque wrapIV[24]; CK_MECHANISM_TYPE symWrapMechanism; /* unwrapped symmetric wrapping key uses this mechanism */ CK_MECHANISM_TYPE asymWrapMechanism; /* mechanism used to wrap the SymmetricWrappingKey using * server's public and/or private keys. */ SSL3KEAType exchKeyType; /* type of keys used to wrap SymWrapKey*/ PRInt32 symWrapMechIndex; PRUint16 wrappedSymKeyLen; PRUint16 wrapIVLen;} SSLWrappedSymWrappingKey;/* All the global data items declared here should be protected using the ** ssl_global_data_lock, which is a reader/writer lock.*/extern NSSRWLock * ssl_global_data_lock;extern char ssl_debug;extern char ssl_trace;extern CERTDistNames * ssl3_server_ca_list;extern PRUint32 ssl_sid_timeout;extern PRUint32 ssl3_sid_timeout;extern PRBool ssl3_global_policy_some_restricted;extern const char * const ssl_cipherName[];extern const char * const ssl3_cipherName[];extern sslSessionIDLookupFunc ssl_sid_lookup;extern sslSessionIDCacheFunc ssl_sid_cache;extern sslSessionIDUncacheFunc ssl_sid_uncache;/************************************************************************/SEC_BEGIN_PROTOS/* Implementation of ops for default (non socks, non secure) case */extern int ssl_DefConnect(sslSocket *ss, const PRNetAddr *addr);extern PRFileDesc *ssl_DefAccept(sslSocket *ss, PRNetAddr *addr);extern int ssl_DefBind(sslSocket *ss, const PRNetAddr *addr);extern int ssl_DefListen(sslSocket *ss, int backlog);extern int ssl_DefShutdown(sslSocket *ss, int how);extern int ssl_DefClose(sslSocket *ss);extern int ssl_DefRecv(sslSocket *ss, unsigned char *buf, int len, int flags);extern int ssl_DefSend(sslSocket *ss, const unsigned char *buf, int len, int flags);extern int ssl_DefRead(sslSocket *ss, unsigned char *buf, int len);extern int ssl_DefWrite(sslSocket *ss, const unsigned char *buf, int len);extern int ssl_DefGetpeername(sslSocket *ss, PRNetAddr *name);extern int ssl_DefGetsockname(sslSocket *ss, PRNetAddr *name);extern int ssl_DefGetsockopt(sslSocket *ss, PRSockOption optname, void *optval, PRInt32 *optlen);extern int ssl_DefSetsockopt(sslSocket *ss, PRSockOption optname, const void *optval, PRInt32 optlen);/* Implementation of ops for socks only case */extern int ssl_SocksConnect(sslSocket *ss, const PRNetAddr *addr);extern PRFileDesc *ssl_SocksAccept(sslSocket *ss, PRNetAddr *addr);extern int ssl_SocksBind(sslSocket *ss, const PRNetAddr *addr);extern int ssl_SocksListen(sslSocket *ss, int backlog);extern int ssl_SocksGetsockname(sslSocket *ss, PRNetAddr *name);extern int ssl_SocksRecv(sslSocket *ss, unsigned char *buf, int len, int flags);extern int ssl_SocksSend(sslSocket *ss, const unsigned char *buf, int len, int flags);extern int ssl_SocksRead(sslSocket *ss, unsigned char *buf, int len);extern int ssl_SocksWrite(sslSocket *ss, const unsigned char *buf, int len);/* Implementation of ops for secure only case */extern int ssl_SecureConnect(sslSocket *ss, const PRNetAddr *addr);extern PRFileDesc *ssl_SecureAccept(sslSocket *ss, PRNetAddr *addr);extern int ssl_SecureRecv(sslSocket *ss, unsigned char *buf, int len, int flags);extern int ssl_SecureSend(sslSocket *ss, const unsigned char *buf, int len, int flags);extern int ssl_SecureRead(sslSocket *ss, unsigned char *buf, int len);extern int ssl_SecureWrite(sslSocket *ss, const unsigned char *buf, int len);extern int ssl_SecureShutdown(sslSocket *ss, int how);extern int ssl_SecureClose(sslSocket *ss);/* Implementation of ops for secure socks case */extern int ssl_SecureSocksConnect(sslSocket *ss, const PRNetAddr *addr);extern PRFileDesc *ssl_SecureSocksAccept(sslSocket *ss, PRNetAddr *addr);extern PRFileDesc *ssl_FindTop(sslSocket *ss);/* Gather funcs. */extern sslGather * ssl_NewGather(void);extern void ssl_DestroyGather(sslGather *gs);extern int ssl2_GatherData(sslSocket *ss, sslGather *gs, int flags);extern int ssl2_GatherRecord(sslSocket *ss, int flags);extern SECStatus ssl_GatherRecord1stHandshake(sslSocket *ss);extern SECStatus ssl2_HandleClientHelloMessage(sslSocket *ss);extern SECStatus ssl2_HandleServerHelloMessage(sslSocket *ss);extern int ssl2_StartGatherBytes(sslSocket *ss, sslGather *gs, unsigned int count);extern SECStatus ssl_CreateSecurityInfo(sslSocket *ss);extern SECStatus ssl_CopySecurityInfo(sslSocket *ss, sslSocket *os);extern void ssl_DestroySecurityInfo(sslSecurityInfo *sec);extern SECStatus ssl_CreateSocksInfo(sslSocket *ss);extern SECStatus ssl_CopySocksInfo(sslSocket *ss, sslSocket *os);extern void ssl_DestroySocksInfo(sslSocksInfo *si);extern sslSocket * ssl_DupSocket(sslSocket *old);extern void ssl_PrintBuf(sslSocket *ss, const char *msg, const void *cp, int len);extern void ssl_DumpMsg(sslSocket *ss, unsigned char *bp, unsigned len);extern int ssl_SendSavedWriteData(sslSocket *ss, sslBuffer *buf, sslSendFunc fp);extern SECStatus ssl_SaveWriteData(sslSocket *ss, sslBuffer *buf, const void* p, unsigned int l);extern SECStatus ssl2_BeginClientHandshake(sslSocket *ss);extern SECStatus ssl2_BeginServerHandshake(sslSocket *ss);extern int ssl_Do1stHandshake(sslSocket *ss);extern SECStatus sslBuffer_Grow(sslBuffer *b, unsigned int newLen);extern void ssl2_UseClearSendFunc(sslSocket *ss);extern void ssl_ChooseSessionIDProcs(sslSecurityInfo *sec);extern sslSessionID *ssl_LookupSID(const PRIPv6Addr *addr, PRUint16 port, const char *peerID, const char *urlSvrName);extern void ssl_FreeSID(sslSessionID *sid);extern int ssl3_SendApplicationData(sslSocket *ss, const PRUint8 *in, int len, int flags);extern PRBool ssl_FdIsBlocking(PRFileDesc *fd);extern PRBool ssl_SocketIsBlocking(sslSocket *ss);extern void ssl_SetAlwaysBlock(sslSocket *ss);#define SSL_LOCK_READER(ss) if (ss->recvLock) PR_Lock(ss->recvLock)#define SSL_UNLOCK_READER(ss) if (ss->recvLock) PR_Unlock(ss->recvLock)#define SSL_LOCK_WRITER(ss) if (ss->sendLock) PR_Lock(ss->sendLock)#define SSL_UNLOCK_WRITER(ss) if (ss->sendLock) PR_Unlock(ss->sendLock)#define ssl_Get1stHandshakeLock(ss) PR_EnterMonitor((ss)->firstHandshakeLock)#define ssl_Release1stHandshakeLock(ss) PR_ExitMonitor((ss)->firstHandshakeLock)#define ssl_Have1stHandshakeLock(ss) PR_InMonitor( (ss)->firstHandshakeLock)#define ssl_GetSSL3HandshakeLock(ss) PR_EnterMonitor((ss)->ssl3HandshakeLock)#define ssl_ReleaseSSL3HandshakeLock(ss) PR_ExitMonitor((ss)->ssl3HandshakeLock)#define ssl_HaveSSL3HandshakeLock(ss) PR_InMonitor( (ss)->ssl3HandshakeLock)#define ssl_GetSpecReadLock(ss) NSSRWLock_LockRead( (ss)->specLock)#define ssl_ReleaseSpecReadLock(ss) NSSRWLock_UnlockRead( (ss)->specLock)#define ssl_GetSpecWriteLock(ss) NSSRWLock_LockWrite( (ss)->specLock)#define ssl_ReleaseSpecWriteLock(ss) NSSRWLock_UnlockWrite((ss)->specLock)#define ssl_HaveSpecWriteLock(ss) NSSRWLock_HaveWriteLock((ss)->specLock)#define ssl_GetRecvBufLock(ss) PR_EnterMonitor((ss)->recvBufLock)#define ssl_ReleaseRecvBufLock(ss) PR_ExitMonitor( (ss)->recvBufLock)#define ssl_HaveRecvBufLock(ss) PR_InMonitor( (ss)->recvBufLock)#define ssl_GetXmitBufLock(ss) PR_EnterMonitor((ss)->xmitBufLock)#define ssl_ReleaseXmitBufLock(ss) PR_ExitMonitor( (ss)->xmitBufLock)#define ssl_HaveXmitBufLock(ss) PR_InMonitor( (ss)->xmitBufLock)/* These functions are called from secnav, even though they're "private". */extern int ssl2_SendErrorMessage(struct sslSocketStr *ss, int error);extern int SSL_RestartHandshakeAfterServerCert(struct sslSocketStr *ss);extern int SSL_RestartHandshakeAfterCertReq(struct sslSocketStr *ss, CERTCertificate *cert, SECKEYPrivateKey *key, CERTCertificateList *certChain);extern sslSocket *ssl_FindSocket(PRFileDesc *fd);extern void ssl_FreeSocket(struct sslSocketStr *ssl);extern SECStatus SSL3_SendAlert(sslSocket *ss, SSL3AlertLevel level, SSL3AlertDescription desc);extern int ssl2_RestartHandshakeAfterCertReq(sslSocket * ss, CERTCertificate * cert, SECKEYPrivateKey * key);extern SECStatus ssl3_RestartHandshakeAfterCertReq(sslSocket * ss, CERTCertificate * cert, SECKEYPrivateKey * key, CERTCertificateList *certChain);extern int ssl2_RestartHandshakeAfterServerCert(sslSocket *ss);extern int ssl3_RestartHandshakeAfterServerCert(sslSocket *ss);/* * for dealing with SSL 3.0 clients sending SSL 2.0 format hellos */extern SECStatus ssl3_HandleV2ClientHello( sslSocket *ss, unsigned char *buffer, int length);extern SECStatus ssl3_StartHandshakeHash( sslSocket *ss, unsigned char *buf, int length);/* * SSL3 specific routines */SECStatus ssl3_SendClientHello(sslSocket *ss);/* * input into the SSL3 machinery from the actualy network reading code */SECStatus ssl3_HandleRecord( sslSocket *ss, SSL3Ciphertext *cipher, sslBuffer *out);int ssl3_GatherAppDataRecord(sslSocket *ss, int flags);int ssl3_GatherCompleteHandshake(sslSocket *ss, int flags);/* * When talking to export clients or using export cipher suites, servers * with public RSA keys larger than 512 bits need to use a 512-bit public * key, signed by the larger key. The smaller key is a "step down" key. * Generate that key pair and keep it around. */extern SECStatus ssl3_CreateRSAStepDownKeys(sslSocket *ss);extern SECStatus ssl3_CipherPrefSetDefault(ssl3CipherSuite which, PRBool on);extern SECStatus ssl3_CipherPrefGetDefault(ssl3CipherSuite which, PRBool *on);extern SECStatus ssl2_CipherPrefSetDefault(PRInt32 which, PRBool enabled);extern SECStatus ssl2_CipherPrefGetDefault(PRInt32 which, PRBool *enabled);extern SECStatus ssl3_CipherPrefSet(sslSocket *ss, ssl3CipherSuite which, PRBool on);extern SECStatus ssl3_CipherPrefGet(sslSocket *ss, ssl3CipherSuite which, PRBool *on);extern SECStatus ssl2_CipherPrefSet(sslSocket *ss, PRInt32 which, PRBool enabled);extern SECStatus ssl2_CipherPrefGet(sslSocket *ss, PRInt32 which, PRBool *enabled);extern SECStatus ssl3_SetPolicy(ssl3CipherSuite which, PRInt32 policy);extern SECStatus ssl3_GetPolicy(ssl3CipherSuite which, PRInt32 *policy);extern SECStatus ssl2_SetPolicy(PRInt32 which, PRInt32 policy);extern SECStatus ssl2_GetPolicy(PRInt32 which, PRInt32 *policy);extern void ssl2_InitSocketPolicy(sslSocket *ss);extern void ssl3_InitSocketPolicy(sslSocket *ss);extern SECStatus ssl3_ConstructV2CipherSpecsHack(sslSocket *ss, unsigned char *cs, int *size);extern SECStatus ssl3_RedoHandshake(sslSocket *ss, PRBool flushCache);extern void ssl3_DestroySSL3Info(ssl3State *ssl3);extern SECStatus ssl3_NegotiateVersion(sslSocket *ss, SSL3ProtocolVersion peerVersion);extern SECStatus ssl_GetPeerInfo(sslSocket *ss);/* Construct a new NSPR socket for the app to use */extern PRFileDesc *ssl_NewPRSocket(sslSocket *ss, PRFileDesc *fd);extern void ssl_FreePRSocket(PRFileDesc *fd);/* Internal config function so SSL2 can initialize the present state of * various ciphers */extern int ssl3_config_match_init(sslSocket *);/* Create a new ref counted key pair object from two keys. */extern ssl3KeyPair * ssl3_NewKeyPair( SECKEYPrivateKey * privKey, SECKEYPublicKey * pubKey);/* get a new reference (bump ref count) to an ssl3KeyPair. */extern ssl3KeyPair * ssl3_GetKeyPairRef(ssl3KeyPair * keyPair);/* Decrement keypair's ref count and free if zero. */extern void ssl3_FreeKeyPair(ssl3KeyPair * keyPair);/* calls for accessing wrapping keys across processes. */extern PRBoolssl_GetWrappingKey( PRInt32 symWrapMechIndex, SSL3KEAType exchKeyType, SSLWrappedSymWrappingKey *wswk);/* The caller passes in the new value it wants * to set. This code tests the wrapped sym key entry in the file on disk. * If it is uninitialized, this function writes the caller's value into * the disk entry, and returns false. * Otherwise, it overwrites the caller's wswk with the value obtained from * the disk, and returns PR_TRUE. * This is all done while holding the locks/semaphores necessary to make * the operation atomic. */extern PRBoolssl_SetWrappingKey(SSLWrappedSymWrappingKey *wswk);/********************** misc calls *********************/extern int ssl_MapLowLevelError(int hiLevelError);extern PRUint32 ssl_Time(void);/* emulation of NSPR routines. */extern PRInt32 ssl_EmulateAcceptRead( PRFileDesc * sd, PRFileDesc ** nd, PRNetAddr ** raddr, void * buf, PRInt32 amount, PRIntervalTime timeout);extern PRInt32 ssl_EmulateTransmitFile( PRFileDesc * sd, PRFileDesc * fd, const void * headers, PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime timeout);extern PRInt32 ssl_EmulateSendFile( PRFileDesc * sd, PRSendFileData * sfd, PRTransmitFileFlags flags, PRIntervalTime timeout);#ifdef TRACE#define SSL_TRACE(msg) ssl_Trace msg#else#define SSL_TRACE(msg)#endifvoid ssl_Trace(const char *format, ...);SEC_END_PROTOS#ifdef XP_UNIX#define SSL_GETPID() getpid()#else#define SSL_GETPID() 0#endif#endif /* __sslimpl_h_ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?