📄 session.h
字号:
/* The message imprint (hash) algorithm and hash value */
CRYPT_ALGO_TYPE imprintAlgo;
BYTE imprint[ CRYPT_MAX_HASHSIZE ];
int imprintSize;
} TSP_INFO;
typedef struct {
/* CMP request subtype, user info and protocol flags */
int requestType; /* CMP request subtype */
CRYPT_CERTIFICATE userInfo; /* PKI user info */
int flags; /* Protocl flags */
/* The saved MAC context from a previous transaction (if any) */
CRYPT_CONTEXT savedMacContext; /* MAC context from prev.trans */
} CMP_INFO;
/* Defines to make access to the union fields less messy */
#define sessionSSH sessionInfo.sshInfo
#define sessionSSL sessionInfo.sslInfo
#define sessionTSP sessionInfo.tspInfo
#define sessionCMP sessionInfo.cmpInfo
/* The structure that stores the information on a session */
typedef struct SI {
/* Control and status information */
CRYPT_SESSION_TYPE type; /* Session type */
const PROTOCOL_INFO *protocolInfo; /* Session subtype information */
int version; /* Protocol version/subtype */
CRYPT_ALGO_TYPE cryptAlgo; /* Negotiated encryption algo */
CRYPT_ALGO_TYPE integrityAlgo; /* Negotiated integrity prot.algo */
int flags, protocolFlags; /* Session info, protocol-specific flags */
int authResponse; /* Response to user-auth request */
/* Session type-specific information */
union {
SSL_INFO *sslInfo;
SSH_INFO *sshInfo;
TSP_INFO *tspInfo;
CMP_INFO *cmpInfo;
} sessionInfo;
/* 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 clientReqAttrFlags, serverReqAttrFlags; /* Required attributes */
/* 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. Since an error on one side of the channel (e.g. bad data on
read) doesn't necessarily affect the operation of the other side, we
keep track of the two sides independantly, and only set the error
state for both sides for network-related errors.
In many cases there'll still be data in the internal buffer that the
user can read/write 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 readErrorState, writeErrorState;/* Current error state */
int pendingReadErrorState, pendingWriteErrorState;
/* Error state when buffer emptied */
/* Data buffer information. In protocols that 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 sendBufStartOfs, receiveBufStartOfs; /* Space for header in buffer */
int receiveBufEnd; /* Total data in buffer */
int maxPacketSize; /* Maximum packet (payload data) size */
/* When reading encrypted data packets we typically end up with a partial
packet in the read buffer that 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
that has already been MACd and decrypted (for protocols that 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 */
/* Unlike payload data, the packet header can't be read in sections but
must be read atomically since all of the header information needs to
be processed at once. The following value is usually zero, if it's
nonzero it records how much of the header has been read so far */
int partialHeaderLength; /* Header bytes read so far */
/* When sending data we can also end up with partially-processed packets
in the send buffer, but for sending we prevent further packets from
being added until the current one is flushed. To handle this all we
need is a simple high-water-mark indicator that indicates the start
position of any yet-to-be-written data */
BOOLEAN partialWrite; /* Unwritten data remains in buffer */
int sendBufPartialBufPos; /* Progress point of partial write */
/* The session generally has various ephemeral contexts associated with
it, some short-term (e.g.public-key contexts used to establish the
session) and some long-term (e.g.encryption contexts used to perform
bulk data encryption). These contexts are ephemeral ones that are
created as part of the session, long-term ones (e.g.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 */
/* The private key, which is required to authenticate the client or
server in some protocols */
CRYPT_CONTEXT privateKey; /* Authentication private key */
/* Certificate store for cert management protocols like OCSP and CMP
and private-key keyset for PnP PKI protocols */
CRYPT_KEYSET cryptKeyset; /* Certificate store */
CRYPT_HANDLE privKeyset; /* Private-key keyset/device */
/* Session-related attributes such as username and password */
ATTRIBUTE_LIST *attributeList, *attributeListCurrent;
/* Network connection information. The reason why the client and server
info require separate storage is that (on the server) we may be
binding to a specific interface (requiring a server name) and we need
to record where the remote system's connection is coming from
(requiring a client name) */
CRYPT_SESSION transportSession; /* Transport mechanism */
int networkSocket; /* User-supplied network socket */
int readTimeout, writeTimeout, connectTimeout;
/* Connect and data xfer.timeouts */
STREAM stream; /* Network I/O stream */
/* 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. Stateful sessions use the read/
write functions, stateless ones use the transact function */
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 ( *checkAttributeFunction )( struct SI *sessionInfoPtr,
const CRYPT_HANDLE cryptHandle,
const CRYPT_ATTRIBUTE_TYPE type );
int ( *transactFunction )( struct SI *sessionInfoPtr );
int ( *readHeaderFunction )( struct SI *sessionInfoPtr,
READSTATE_INFO *readInfo );
int ( *processBodyFunction )( struct SI *sessionInfoPtr,
READSTATE_INFO *readInfo );
int ( *preparePacketFunction )( struct SI *sessionInfoPtr );
/* Error information */
CRYPT_ATTRIBUTE_TYPE errorLocus;/* Error locus */
CRYPT_ERRTYPE_TYPE errorType; /* Error type */
/* 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;
/* Variable-length storage for the type-specific data */
DECLARE_VARSTRUCT_VARS;
} SESSION_INFO;
/****************************************************************************
* *
* Session Functions *
* *
****************************************************************************/
/* Prototypes for utility functions in cryptses.c. retExt() returns after
setting extended error information for the session. We use a macro to
make it match the standard return statement, the slightly unusual form is
required to handle the fact that the helper function is a varargs
function.
In addition to the standard retExt() we also have an extended-form version
of the function that takes an additional parameter, a handle to an object
that may provide additional error information. This is used when (for
example) an operation references a keyset, where the keyset also contains
extended error information */
int retExtFnSession( SESSION_INFO *sessionInfoPtr, const int status,
const char *format, ... ) PRINTF_FN;
#define retExt return retExtFnSession
int retExtExFnSession( SESSION_INFO *sessionInfoPtr,
const int status, const CRYPT_HANDLE extErrorObject,
const char *format, ... ) PRINTF_FN_EX;
#define retExtEx return retExtExFnSession
/* Session attribute management functions */
int addSessionAttribute( ATTRIBUTE_LIST **listHeadPtr,
const CRYPT_ATTRIBUTE_TYPE attributeType,
const void *data, const int dataLength );
int addSessionAttributeEx( ATTRIBUTE_LIST **listHeadPtr,
const CRYPT_ATTRIBUTE_TYPE attributeType,
const void *data, const int dataLength,
const ATTRACCESSFUNCTION accessFunction,
const int flags );
int updateSessionAttribute( ATTRIBUTE_LIST **listHeadPtr,
const CRYPT_ATTRIBUTE_TYPE attributeType,
const void *data, const int dataLength,
const int dataMaxLength, const int flags );
const ATTRIBUTE_LIST *findSessionAttribute( const ATTRIBUTE_LIST *attributeListPtr,
const CRYPT_ATTRIBUTE_TYPE attributeType );
void resetSessionAttribute( ATTRIBUTE_LIST *attributeListPtr,
const CRYPT_ATTRIBUTE_TYPE attributeType );
void deleteSessionAttribute( ATTRIBUTE_LIST **attributeListHead,
ATTRIBUTE_LIST *attributeListPtr );
/* Prototypes for functions in session.c */
int initSessionIO( SESSION_INFO *sessionInfoPtr );
void initSessionNetConnectInfo( const SESSION_INFO *sessionInfoPtr,
NET_CONNECT_INFO *connectInfo );
int activateSession( SESSION_INFO *sessionInfoPtr );
int getSessionData( SESSION_INFO *sessionInfoPtr, void *data,
const int length, int *bytesCopied );
int putSessionData( SESSION_INFO *sessionInfoPtr, const void *data,
const int length, int *bytesCopied );
int readFixedHeader( SESSION_INFO *sessionInfoPtr, const int headerSize );
int readPkiDatagram( SESSION_INFO *sessionInfoPtr );
int writePkiDatagram( SESSION_INFO *sessionInfoPtr );
int sendCloseNotification( SESSION_INFO *sessionInfoPtr,
const void *data, const int length );
/* Prototypes for session mapping functions */
#ifdef USE_CERTSTORE
int setAccessMethodCertstore( SESSION_INFO *sessionInfoPtr );
#else
#define setAccessMethodCertstore( x ) CRYPT_ARGERROR_NUM1
#endif /* USE_CERTSTORE */
#ifdef USE_CMP
int setAccessMethodCMP( SESSION_INFO *sessionInfoPtr );
#else
#define setAccessMethodCMP( x ) CRYPT_ARGERROR_NUM1
#endif /* USE_CMP */
#ifdef USE_RTCS
int setAccessMethodRTCS( SESSION_INFO *sessionInfoPtr );
#else
#define setAccessMethodRTCS( x ) CRYPT_ARGERROR_NUM1
#endif /* USE_RTCS */
#ifdef USE_OCSP
int setAccessMethodOCSP( SESSION_INFO *sessionInfoPtr );
#else
#define setAccessMethodOCSP( x ) CRYPT_ARGERROR_NUM1
#endif /* USE_OCSP */
#ifdef USE_SCEP
int setAccessMethodSCEP( SESSION_INFO *sessionInfoPtr );
#else
#define setAccessMethodSCEP( x ) CRYPT_ARGERROR_NUM1
#endif /* USE_SCEP */
#if defined( USE_SSH1 ) || defined( USE_SSH2 )
int setAccessMethodSSH( SESSION_INFO *sessionInfoPtr );
#else
#define setAccessMethodSSH( x ) CRYPT_ARGERROR_NUM1
#endif /* USE_SSH1 || USE_SSH2 */
#ifdef USE_SSL
int setAccessMethodSSL( SESSION_INFO *sessionInfoPtr );
int initSessionCache( void );
void endSessionCache( void );
#else
#define setAccessMethodSSL( x ) CRYPT_ARGERROR_NUM1
#define initSessionCache() CRYPT_OK
#define endSessionCache()
#endif /* USE_SSL */
#ifdef USE_TSP
int setAccessMethodTSP( SESSION_INFO *sessionInfoPtr );
#else
#define setAccessMethodTSP( x ) CRYPT_ARGERROR_NUM1
#endif /* USE_TCP */
#endif /* _SES_DEFINED */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -