41 handshakeInfo->md5context = \
42 handshakeInfo->sha1context = \
47 handshakeInfo->dhContext = \
69 handshakeInfo->sha1context = createInfo.
cryptHandle;
86 handshakeInfo->sha384context = createInfo.
cryptHandle;
104 handshakeInfo->sha2context = createInfo.
cryptHandle;
110 destroyHandshakeCryptInfo( handshakeInfo );
154 if( handshakeInfo->certVerifyContext !=
CRYPT_ERROR )
186 sessionInfoPtr->iAuthInContext = createInfo.
cryptHandle;
194 destroySecurityContextsSSL( sessionInfoPtr );
197 sessionInfoPtr->iAuthOutContext = createInfo.
cryptHandle;
200 handshakeInfo->integrityAlgoParam ==
bitsToBytes( 384 ) )
217 destroySecurityContextsSSL( sessionInfoPtr );
231 sessionInfoPtr->iCryptInContext = createInfo.
cryptHandle;
239 destroySecurityContextsSSL( sessionInfoPtr );
242 sessionInfoPtr->iCryptOutContext = createInfo.
cryptHandle;
263 destroySecurityContextsSSL( sessionInfoPtr );
277 if( sessionInfoPtr->iKeyexCryptContext !=
CRYPT_ERROR )
283 if( sessionInfoPtr->iAuthInContext !=
CRYPT_ERROR )
289 if( sessionInfoPtr->iAuthOutContext !=
CRYPT_ERROR )
295 if( sessionInfoPtr->iCryptInContext !=
CRYPT_ERROR )
301 if( sessionInfoPtr->iCryptOutContext !=
CRYPT_ERROR )
364 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
365 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
366 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
367 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
368 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
369 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
370 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
371 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
372 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
373 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
374 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B,
375 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
376 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5,
377 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
378 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81,
379 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
387 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
388 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
389 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
390 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
391 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
392 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
393 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
394 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
395 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
396 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
397 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B,
398 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
399 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5,
400 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
401 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
402 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
403 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A,
404 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
405 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96,
406 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
407 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
408 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
409 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C,
410 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
411 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03,
412 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F,
413 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
414 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18,
415 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5,
416 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
417 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68,
418 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
448 static const ECCCURVE_SSL_INFO eccCurveMapTbl[] = {
471 assert( ( keyData == NULL && keyDataLength == 0 ) || \
474 REQUIRES( ( keyData == NULL && keyDataLength == 0 ) || \
475 ( keyData != NULL && \
491 if( keyData == NULL && iServerKeyTemplate !=
CRYPT_UNUSED && \
520 if( keyData != NULL )
532 const ECCCURVE_SSL_INFO *eccCurveInfoPtr = NULL;
540 if( eccCurveMapTbl[ i ].curveType == eccParams )
542 eccCurveInfoPtr = &eccCurveMapTbl[ i ];
547 ECCCURVE_SSL_INFO ) );
548 ENSURES( eccCurveInfoPtr != NULL );
560 sizeof( dh2048SSL ) ); }
563 sizeof( dh1024SSL ) ); }
568 CRYPT_IATTRIBUTE_KEY_SSL );
572 if( keyData == NULL )
596 const void *sharedSecret,
604 assert(
isWritePtr( premasterSecret, premasterSecretMaxLength ) );
605 assert(
isWritePtr( premasterSecretLength,
sizeof(
int ) ) );
606 assert(
isReadPtr( sharedSecret, sharedSecretLength ) );
608 REQUIRES( premasterSecretMaxLength > 0 && \
610 REQUIRES( sharedSecretLength > 0 && \
614 *premasterSecretLength = 0;
632 sMemOpen( &stream, premasterSecret, premasterSecretMaxLength );
635 BYTE decodedValue[ 64 + 8 ];
636 int decodedValueLength;
640 status = decodePKIUserValue( decodedValue, 64, &decodedValueLength,
641 sharedSecret, sharedSecretLength );
644 DEBUG_DIAG((
"Couldn't decode supposedly valid PKI user "
649 writeUint16( &stream, decodedValueLength );
650 swrite( &stream, zeroes, decodedValueLength );
651 writeUint16( &stream, decodedValueLength );
652 status = swrite( &stream, decodedValue, decodedValueLength );
653 zeroise( decodedValue, decodedValueLength );
657 writeUint16( &stream, sharedSecretLength );
658 swrite( &stream, zeroes, sharedSecretLength );
659 writeUint16( &stream, sharedSecretLength );
660 status = swrite( &stream, sharedSecret, sharedSecretLength );
664 *premasterSecretLength = stell( &stream );
665 sMemDisconnect( &stream );
686 assert(
isWritePtr( dataLength,
sizeof(
int ) ) );
691 memset( data, 0,
min( 16, dataMaxLength ) );
702 handshakeInfo->premasterSecret[ 1 ] = \
703 intToByte( handshakeInfo->clientOfferedVersion );
709 CRYPT_IATTRIBUTE_RANDOM );
713 handshakeInfo->premasterSecret,
715 sessionInfoPtr->iKeyexCryptContext );
728 IN_BUFFER( dataLength )
const void *data,
763 handshakeInfo->premasterSecret,
765 sessionInfoPtr->privateKey );
769 mechanismInfo.
keyDataLength != handshakeInfo->premasterSecretSize )
780 handshakeInfo->premasterSecret[ 1 ] != handshakeInfo->clientOfferedVersion )
794 "Warning: Accepting invalid premaster secret "
795 "version 3.0 (MSIE bug)", 66 );
801 "Invalid premaster secret version data 0x%02X 0x%02X, "
802 "expected 0x03 0x%02X",
803 handshakeInfo->premasterSecret[ 0 ],
804 handshakeInfo->premasterSecret[ 1 ],
805 handshakeInfo->clientOfferedVersion ) );
822 static
int premasterToMaster(
const SESSION_INFO *sessionInfoPtr,
833 assert(
isReadPtr( masterSecret, masterSecretLength ) );
835 REQUIRES( masterSecretLength > 0 && \
843 memcpy( nonceBuffer, handshakeInfo->clientNonce,
SSL_NONCE_SIZE );
848 handshakeInfo->premasterSecret,
856 memcpy( nonceBuffer,
"master secret", 13 );
857 memcpy( nonceBuffer + 13, handshakeInfo->clientNonce,
SSL_NONCE_SIZE );
858 memcpy( nonceBuffer + 13 +
SSL_NONCE_SIZE, handshakeInfo->serverNonce,
864 handshakeInfo->premasterSecret,
874 handshakeInfo->premasterSecret,
883 static
int masterToKeys(
const SESSION_INFO *sessionInfoPtr,
886 const void *masterSecret,
896 assert(
isReadPtr( masterSecret, masterSecretLength ) );
897 assert(
isWritePtr( keyBlock, keyBlockLength ) );
899 REQUIRES( masterSecretLength > 0 && \
908 memcpy( nonceBuffer, handshakeInfo->serverNonce,
SSL_NONCE_SIZE );
912 masterSecret, masterSecretLength,
919 memcpy( nonceBuffer,
"key expansion", 13 );
920 memcpy( nonceBuffer + 13, handshakeInfo->serverNonce,
SSL_NONCE_SIZE );
921 memcpy( nonceBuffer + 13 +
SSL_NONCE_SIZE, handshakeInfo->clientNonce,
926 masterSecret, masterSecretLength,
935 masterSecret, masterSecretLength,
953 IN_BUFFER( masterSecretSize )
void *masterSecret,
957 SSL_INFO *sslInfo = sessionInfoPtr->sessionSSL;
962 assert(
isWritePtr( masterSecret, masterSecretSize ) );
976 ENSURES( attributeListPtr != NULL );
977 status = cachedID = \
979 handshakeInfo->sessionID,
980 handshakeInfo->sessionIDlength,
981 attributeListPtr->value,
983 masterSecret, masterSecretSize );
991 status = cachedID = \
993 handshakeInfo->sessionID,
994 handshakeInfo->sessionIDlength,
995 masterSecret, masterSecretSize );
1006 IN_BUFFER( keyBlockLength )
const void *keyBlock,
1010 SSL_INFO *sslInfo = sessionInfoPtr->sessionSSL;
1012 BYTE *keyBlockPtr = (
BYTE * ) keyBlock;
1017 assert(
isReadPtr( keyBlock, keyBlockLength ) );
1019 REQUIRES( keyBlockLength >= ( sessionInfoPtr->authBlocksize * 2 ) + \
1021 ( sessionInfoPtr->cryptBlocksize * 2 ) && \
1041 memcpy( isClient ? sslInfo->macWriteSecret : sslInfo->macReadSecret,
1042 keyBlockPtr, sessionInfoPtr->authBlocksize );
1043 memcpy( isClient ? sslInfo->macReadSecret : sslInfo->macWriteSecret,
1044 keyBlockPtr + sessionInfoPtr->authBlocksize,
1045 sessionInfoPtr->authBlocksize );
1050 sessionInfoPtr->authBlocksize );
1052 sessionInfoPtr->iAuthOutContext : \
1053 sessionInfoPtr->iAuthInContext,
1059 keyBlockPtr + sessionInfoPtr->authBlocksize,
1060 sessionInfoPtr->authBlocksize );
1062 sessionInfoPtr->iAuthInContext: \
1063 sessionInfoPtr->iAuthOutContext,
1069 keyBlockPtr += sessionInfoPtr->authBlocksize * 2;
1075 sessionInfoPtr->iCryptOutContext : \
1076 sessionInfoPtr->iCryptInContext,
1084 sessionInfoPtr->iCryptInContext : \
1085 sessionInfoPtr->iCryptOutContext,
1101 memcpy( isClient ? sessionInfoPtr->sessionSSL->gcmWriteSalt : \
1102 sessionInfoPtr->sessionSSL->gcmReadSalt,
1104 memcpy( isClient ? sessionInfoPtr->sessionSSL->gcmReadSalt : \
1105 sessionInfoPtr->sessionSSL->gcmWriteSalt,
1116 sessionInfoPtr->cryptBlocksize );
1118 sessionInfoPtr->iCryptInContext,
1121 keyBlockPtr += sessionInfoPtr->cryptBlocksize;
1123 sessionInfoPtr->cryptBlocksize );
1124 return(
krnlSendMessage( isClient ? sessionInfoPtr->iCryptInContext : \
1125 sessionInfoPtr->iCryptOutContext,
1143 assert(
isWritePtr( masterSecret, masterSecretSize ) );
1145 REQUIRES( masterSecretSize > 0 && \
1149 status = initSecurityContextsSSL( sessionInfoPtr, handshakeInfo );
1155 if( !isResumedSession )
1157 status = premasterToMaster( sessionInfoPtr, handshakeInfo,
1158 masterSecret, masterSecretSize );
1164 if( handshakeInfo->sessionIDlength > 0 )
1166 status = updateSessionCache( sessionInfoPtr, handshakeInfo,
1167 masterSecret, masterSecretSize,
1171 zeroise( masterSecret, masterSecretSize );
1181 masterSecretSize ) );
1182 memcpy( masterSecret, handshakeInfo->premasterSecret,
1183 handshakeInfo->premasterSecretSize );
1189 status = masterToKeys( sessionInfoPtr, handshakeInfo, masterSecret,
1193 zeroise( masterSecret, masterSecretSize );
1198 status = loadKeys( sessionInfoPtr, handshakeInfo, keyBlock,
1203 zeroise( masterSecret, masterSecretSize );
1218 SSL_INFO *sslInfo = sessionInfoPtr->sessionSSL;
1225 assert(
isWritePtr( ivLength,
sizeof(
int ) ) );
1231 status = sread( stream, iv, sslInfo->
ivSize );
1240 memcpy( iv, sslInfo->gcmReadSalt, sslInfo->
gcmSaltSize );
1254 "Packet IV read/load failed" ) );
1258 *ivLength = sslInfo->
ivSize;