⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 session.h

📁 提供了很多种加密算法和CA认证及相关服务如CMP、OCSP等的开发
💻 H
字号:
/****************************************************************************
*																			*
*						Secure Session Routines Header File					*
*						 Copyright Peter Gutmann 1998-2002					*
*																			*
****************************************************************************/

#ifndef _SES_DEFINED

#define _SES_DEFINED

/* Session information flags.  The isSecure flag indicates that the session 
   has passed the initial handshake stage and all data is now being 
   encrypted/MACd/whatever.  The isCryptlib flag indicates that the peer is 
   also running cryptlib, which means we can apply cryptlib-specific 
   optimistions and security enhancements */

#define SESSION_ISSERVER				0x01	/* Session is server session */
#define SESSION_ISSECURE				0x02	/* Session has entered secure state */
#define SESSION_ISCRYPTLIB				0x04	/* Peer is running cryptlib */

/* Needed-information flags used by protocol-specific handlers to indicate 
   that the caller must set the given attributes in the session information 
   before the session can be activated.  This allows it to be checked at the 
   general cryptses.c level rather than at the per-protocol level */

#define SESSION_CLIENT_NEEDSUSERID		0x0001	/* Must have userID */
#define SESSION_CLIENT_NEEDSPASSWORD	0x0002	/* Must have password */
#define SESSION_CLIENT_NEEDSPRIVATEKEY	0x0004	/* Must have private key */
#define SESSION_CLIENT_NEEDSPRIVKEYCERT	0x0008	/* Priv.key must have cert */
#define SESSION_SERVER_NEEDSPRIVATEKEY	0x0010	/* Must have priv.key if svr.*/
#define SESSION_SERVER_NEEDSPRIVKEYCERT	0x0020	/* Svr.priv.key must have cert */
#define SESSION_SERVER_NEEDSPRIVKEYCACERT 0x0040/* Svr.priv key must have CA cert */
#define SESSION_SERVER_NEEDSCERTSTORE	0x0080	/* Must have cert store */

/* The structure which stores the information on a session */

typedef struct SI {
	/* Control and status information */
	CRYPT_SESSION_TYPE type;			/* Session type */
	int version;						/* Protocol version/subtype */
	BOOLEAN sessionOpen;				/* Whether session is active */
	CRYPT_ALGO cryptAlgo;				/* Negotiated encryption algo */
	CRYPT_ALGO integrityAlgo;			/* Negotiated integrity prot.algo */
	int flags;							/* Session information flags */

	/* When we add generic attributes to the session, we occasionally need to
	   perform protocol-specific checking of the attributes being added.  The
	   following values are used to tell the generic cryptses.c code which
	   checks need to be performed */
	int requiredAttributeFlags;			/* Required attributes */
	CRYPT_ATTRIBUTE_TYPE requiredCertAttribute;	/* Required attribute in cert */
	int requiredPrivateKeySize;			/* Min.allowed size for private key */

	/* The overall session status.  If we run into a nonrecoverable error
	   (which for the encrypted session types means just about anything,
	   once we lose sync we're toast) we remember the status here so that 
	   any further attempts to work with the session will return this 
	   status.  In many cases there'll still be data in the internal
	   buffer which the user can read without triggering an error response
	   so before we set the error state we set the pending error state and
	   only move the pending state into the current state once all data still
	   present in the buffer has been read */
	int errorState;						/* Current error state */
	int pendingErrorState;				/* Error state when buffer emptied */

	/* Data buffer information.  In protocols which consist of single 
	   messages sent back and forth only the receive buffer is used for
	   sending and receiving data, this buffer is somewhat more flexible 
	   since it's associated with extra variables for handling the current 
	   position in the buffer (bufPos) vs the total amount of data present 
	   (bufEnd) */
	BYTE *sendBuffer, *receiveBuffer;	/* Data buffer */
	int sendBufSize, receiveBufSize;	/* Total buffer size */
	int sendBufPos, receiveBufPos;		/* Current position in buffer */
	int receiveBufEnd;					/* Total data in buffer */

	/* When reading encrypted data packets we typically end up with a partial
	   packet in the read buffer which we can't process until the remainder
	   arrives, the following variables holds the eventual length of the 
	   pending data packet, the amount of data at the start of the packet 
	   which has already been MACd and decrypted (for protocols which require
	   processing of the packet header which is normally discarded as out-of-
	   band data), and the amount of data remaining to be read */
	int pendingPacketLength;			/* Lending of pending data packet */
	int pendingPacketPartialLength;		/* Length of data already processed */
	int pendingPacketRemaining;			/* Bytes remaining to be read */

	/* The session generally has various ephemeral contexts associated with 
	   it, some short-term (eg public-key contexts used to establish the 
	   session) and some long-term (eg encryption contexts used to perform 
	   bulk data encryption).  These contexts are ephemeral ones which are 
	   created as part of the session, long-term ones (eg signature keys 
	   used for authentication) are held elsewhere */
	CRYPT_CONTEXT iKeyexCryptContext;	/* Key exchange encryption */
	CRYPT_CONTEXT iKeyexAuthContext;	/* Key exchange authentication */
	CRYPT_CONTEXT iCryptInContext, iCryptOutContext;
										/* In/outgoing data encryption */
	CRYPT_CONTEXT iAuthInContext, iAuthOutContext;
										/* In/outgoing auth/integrity */
	CRYPT_CERTIFICATE iCertRequest, iCertResponse;
										/* Cert request/response */
	int cryptBlocksize, authBlocksize;	/* Block size of crypt, auth.algos */

	/* Other session state information.  The incoming and outgoing packet
	   sequence number, for detecting insertion/deletion attacks */
	long readSeqNo, writeSeqNo;			/* Packet sequence number */

	/* User name and password or private key, which are required to 
	   authenticate the client or server in some protocols */
	char userName[ CRYPT_MAX_TEXTSIZE ], password[ CRYPT_MAX_TEXTSIZE ];
	int userNameLength, passwordLength;
	CRYPT_CONTEXT privateKey;			/* Authentication private key */

	/* Certificate store for cert management protocols like OCSP and CMP */
	CRYPT_KEYSET cryptKeyset;			/* Certificate store */

	/* SSL protocol-specific information.  The SSL MAC read/write secrets 
	   are required because SSL 3.0 uses a proto-HMAC which isn't handled 
	   by cryptlib.  We leave the data in normal memory because it's only
	   usable for an active attack which means recovering it from swap
	   afterwards isn't a problem */
	BYTE sslMacReadSecret[ CRYPT_MAX_HASHSIZE ],
		 sslMacWriteSecret[ CRYPT_MAX_HASHSIZE ];	/* Proto-HMAC keys */

	/* TSP protocol-specific information.  The message imprint (hash) 
	   algorithm and hash value */
	CRYPT_ALGO tspImprintAlgo;			/* Imprint (hash) algorithm */
	BYTE tspImprint[ CRYPT_MAX_HASHSIZE ];
	int tspImprintSize;					/* Message imprint (hash) */

	/* CMP protocol-specific information.  The request subtype */
	int requestType;					/* CMP request subtype */

	/* Network connection information */
	STREAM stream;						/* Network I/O stream */
	char serverName[ MAX_URL_SIZE + 1 ];/* Server name */
	int serverPort;						/* Port on server */
	char clientName[ MAX_URL_SIZE + 1 ];/* Client name */
	int clientPort;						/* Port on client */

	/* Last-error information.  To help developers in debugging, we store
	   the error code and error text (if available) */
	int errorCode;
	char errorMessage[ MAX_ERRMSG_SIZE + 1 ];

	/* Pointers to session access methods */
	int ( *initFunction )( struct SI *sessionInfoPtr );
	void ( *shutdownFunction )( struct SI *sessionInfoPtr );
	int ( *connectFunction )( struct SI *sessionInfoPtr );
	int ( *getAttributeFunction )( struct SI *sessionInfoPtr, void *data,
								   const CRYPT_ATTRIBUTE_TYPE type );
	int ( *setAttributeFunction )( struct SI *sessionInfoPtr, const void *data,
								   const CRYPT_ATTRIBUTE_TYPE type );
	int ( *readHeaderFunction )( struct SI *sessionInfoPtr );
	int ( *processBodyFunction )( struct SI *sessionInfoPtr );
	int ( *writeDataFunction )( struct SI *sessionInfoPtr );

	/* Error information */
	CRYPT_ATTRIBUTE_TYPE errorLocus;/* Error locus */
	CRYPT_ERRTYPE_TYPE errorType;	/* Error type */

	/* When we clone an object, there are certain per-instance fields which
	   don't get cloned.  These fields are located after the following
	   member, and must be initialised by the cloning function */
	int _sharedEnd;					/* Dummy used for end of shared fields */

	/* The object's handle and the handle of the user who owns this object.
	   The former is used when sending messages to the object when only the 
	   xxx_INFO is available, the latter is used to avoid having to fetch the
	   same information from the system object table */
	CRYPT_HANDLE objectHandle;
	CRYPT_USER ownerHandle;

	/* In multithreaded environments we need to protect the information from
	   access by other threads while we use it.  The following macro declares
	   the actual variables required to handle the resource locking (the
	   actual values are defined in cryptos.h) */
	DECLARE_OBJECT_LOCKING_VARS
	} SESSION_INFO;

/* Prototypes for session mapping functions */

int setAccessMethodCMP( SESSION_INFO *sessionInfoPtr );
int setAccessMethodSSL( SESSION_INFO *sessionInfoPtr );
int setAccessMethodSSH( SESSION_INFO *sessionInfoPtr );
int setAccessMethodOCSP( SESSION_INFO *sessionInfoPtr );
int setAccessMethodTSP( SESSION_INFO *sessionInfoPtr );

#endif /* _SES_DEFINED */

⌨️ 快捷键说明

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