25 #if defined( __WINDOWS__ ) && defined( _MSC_VER ) && ( _MSC_VER == 1200 ) && \
26 !defined( NDEBUG ) && 1
27 #define NO_SESSION_CACHE
105 int availableSuites[ 32 + 8 ], cipherSuiteCount = 0, suiteIndex;
106 int cipherSuiteInfoSize,
status;
126 suiteIndex < cipherSuiteInfoSize && \
128 cipherSuiteCount < 32;
136 const int suiteFlags = cipherSuiteInfoPtr->
flags;
141 if( suiteNo == 0 || suiteNo == 1 )
143 if( !checkSuiteBSelection( cipherSuiteInfoPtr->
cipherSuite,
144 ( suiteBinfo == 0 ) ? \
171 while( cipherSuiteInfo[ suiteIndex ]->keyexAlgo == keyexAlgo && \
172 suiteIndex < cipherSuiteInfoSize )
174 ENSURES( suiteIndex < cipherSuiteInfoSize );
183 while( cipherSuiteInfo[ suiteIndex ]->cryptAlgo == cryptAlgo && \
184 suiteIndex < cipherSuiteInfoSize )
186 ENSURES( suiteIndex < cipherSuiteInfoSize );
191 while( cipherSuiteInfo[ suiteIndex ]->macAlgo == macAlgo && \
192 suiteIndex < cipherSuiteInfoSize )
194 ENSURES( suiteIndex < cipherSuiteInfoSize );
203 while( cipherSuiteInfo[ suiteIndex ]->keyexAlgo == keyexAlgo && \
204 cipherSuiteInfo[ suiteIndex ]->authAlgo == authAlgo && \
205 cipherSuiteInfo[ suiteIndex ]->cryptAlgo == cryptAlgo && \
206 cipherSuiteInfo[ suiteIndex ]->macAlgo == macAlgo && \
207 cipherSuiteCount < 32 && suiteIndex < cipherSuiteInfoSize )
209 availableSuites[ cipherSuiteCount++ ] = \
210 cipherSuiteInfo[ suiteIndex++ ]->cipherSuite;
212 if( suiteNo == 0 || suiteNo == 1 )
216 ENSURES( suiteIndex < cipherSuiteInfoSize );
217 ENSURES( cipherSuiteCount < 32 );
219 ENSURES( suiteIndex < cipherSuiteInfoSize );
220 ENSURES( cipherSuiteCount > 0 && cipherSuiteCount < 32 );
223 status = writeUint16( stream, cipherSuiteCount *
UINT16_SIZE );
227 status = writeUint16( stream, availableSuites[ suiteIndex ] );
248 static
int processServerKeyex(
INOUT STREAM *stream,
254 const int keyDataOffset = stell( stream );
268 ( void ) sgetc( stream );
269 status = readUint16( stream );
273 status = readInteger16UChecked( stream, NULL, &dummy,
277 status = readInteger16U( stream, NULL, &dummy, 1,
286 keyDataLength = stell( stream ) - keyDataOffset;
287 status = sMemGetDataBlockAbs( stream, keyDataOffset, &keyData,
291 status = initDHcontextSSL( dhContextPtr, keyData, keyDataLength,
302 return( readEcdhValue( stream, keyAgreeParams->publicValue,
304 &keyAgreeParams->publicValueLen ) );
306 return( readInteger16UChecked( stream, keyAgreeParams->publicValue,
307 &keyAgreeParams->publicValueLen,
324 #ifndef NO_SESSION_CACHE
327 STREAM *stream = &handshakeInfo->stream;
343 #ifndef NO_SESSION_CACHE
346 if( attributeListPtr != NULL )
355 status = attributeCopyParams( handshakeInfo->sessionID,
357 &handshakeInfo->sessionIDlength,
368 memcpy( sentSessionID, handshakeInfo->sessionID,
369 handshakeInfo->sessionIDlength );
370 sentSessionIDlength = handshakeInfo->sessionIDlength;
378 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
415 sMemDisconnect( stream );
419 sputc( stream, sessionInfoPtr->version );
420 handshakeInfo->clientOfferedVersion = sessionInfoPtr->version;
422 sputc( stream, handshakeInfo->sessionIDlength );
423 if( handshakeInfo->sessionIDlength > 0 )
425 swrite( stream, handshakeInfo->sessionID,
426 handshakeInfo->sessionIDlength );
427 sessionIDsent =
TRUE;
429 status = writeCipherSuiteList( stream,
435 isServer( sessionInfoPtr ),
440 status = sputc( stream, 0 );
447 status = writeClientExtensions( stream, sessionInfoPtr );
450 status = completeHSPacketStream( stream, packetOffset );
452 status = sendPacketSSL( sessionInfoPtr, stream, FALSE );
455 sMemDisconnect( stream );
461 status = hashHSPacketWrite( handshakeInfo, stream, 0 );
462 sMemDisconnect( stream );
486 status = readHSPacketSSL( sessionInfoPtr, handshakeInfo, &length,
490 sMemConnect( stream, sessionInfoPtr->receiveBuffer, length );
491 status = processHelloSSL( sessionInfoPtr, handshakeInfo, stream, FALSE );
494 int resumedSessionID;
498 sMemDisconnect( stream );
508 lookupScoreboardEntry( sessionInfoPtr->sessionSSL->scoreboardInfoPtr,
510 handshakeInfo->sessionIDlength,
512 #ifdef CONFIG_SUITEB_TESTS
517 sMemDisconnect( stream );
521 if( !sessionIDsent || \
522 ( handshakeInfo->sessionIDlength != sentSessionIDlength || \
523 memcmp( handshakeInfo->sessionID, sentSessionID,
524 sentSessionIDlength ) ) )
531 "Server indicated that a non-valid session should "
537 status = attributeCopyParams( handshakeInfo->premasterSecret,
539 &handshakeInfo->premasterSecretSize,
545 DEBUG_PRINT((
"Resuming session with server based on "
548 handshakeInfo->sessionIDlength );
562 STREAM *stream = &handshakeInfo->stream;
588 status = refreshHSStream( sessionInfoPtr, handshakeInfo );
593 status = checkHSPacketHeader( sessionInfoPtr, stream, &length,
598 sMemDisconnect( stream );
601 readUint16( stream );
602 status = readUniversal16( stream );
605 sMemDisconnect( stream );
608 "Invalid supplemental data" ) );
620 status = refreshHSStream( sessionInfoPtr, handshakeInfo );
623 status = readSSLCertChain( sessionInfoPtr, handshakeInfo,
624 stream, &sessionInfoPtr->iKeyexCryptContext,
628 sMemDisconnect( stream );
662 int keyDataOffset, keyDataLength =
DUMMY_INIT;
664 status = refreshHSStream( sessionInfoPtr, handshakeInfo );
674 status = checkHSPacketHeader( sessionInfoPtr, stream, &length,
686 sMemDisconnect( stream );
691 keyDataOffset = stell( stream );
692 status = processServerKeyex( stream, &keyAgreeParams,
693 &handshakeInfo->dhContext, isECC );
696 keyDataLength = stell( stream ) - keyDataOffset;
697 status = sMemGetDataBlockAbs( stream, keyDataOffset, &keyData,
702 sMemDisconnect( stream );
711 "Insecure key used in key exchange" ) );
718 "Invalid server key agreement parameters" ) );
723 status = checkKeyexSignature( sessionInfoPtr, handshakeInfo,
724 stream, keyData, keyDataLength,
728 sMemDisconnect( stream );
731 "Invalid server key agreement parameter signature" ) );
746 sMemDisconnect( stream );
751 memcpy( keyexPublicValue, tempKeyAgreeParams.publicValue,
763 sMemDisconnect( stream );
768 const int xCoordLen = ( keyAgreeParams.
wrappedKeyLen - 1 ) / 2;
783 keyAgreeParams.wrappedKey[ 0 ] == 0x04 );
784 memmove( keyAgreeParams.wrappedKey,
785 keyAgreeParams.wrappedKey + 1, xCoordLen );
790 memcpy( handshakeInfo->premasterSecret, keyAgreeParams.wrappedKey,
792 handshakeInfo->premasterSecretSize = keyAgreeParams.
wrappedKeyLen;
826 status = refreshHSStream( sessionInfoPtr, handshakeInfo );
835 status = checkHSPacketHeader( sessionInfoPtr, stream, &length,
838 ( ( sessionInfoPtr->version >= \
844 sMemDisconnect( stream );
847 status = length = sgetc( stream );
850 if( length < 1 || length > 64 )
854 status = sSkip( stream, length );
857 sMemDisconnect( stream );
860 "Invalid certificate request certificate-type "
865 status = length = readUint16( stream );
868 if( length < UINT16_SIZE || length > 64 || \
873 status = sSkip( stream, length );
876 sMemDisconnect( stream );
879 "Invalid certificate request signature/hash "
880 "algorithm information" ) );
883 status = readUniversal16( stream );
886 sMemDisconnect( stream );
889 "Invalid certificate request CA name list" ) );
891 needClientCert =
TRUE;
898 status = refreshHSStream( sessionInfoPtr, handshakeInfo );
901 status = checkHSPacketHeader( sessionInfoPtr, stream, &length,
905 sMemDisconnect( stream );
928 static const BYTE FAR_BSS noCertAlertSSLTemplate[] = {
938 swrite( &sessionInfoPtr->stream, noCertAlertSSLTemplate, 7 );
947 needClientCert =
FALSE;
955 status = writeSSLCertChain( sessionInfoPtr, stream );
958 sMemDisconnect( stream );
984 sMemDisconnect( stream );
991 if(
isEccAlgo( handshakeInfo->keyexAlgo ) )
993 sputc( stream, keyexPublicValueLen );
994 status = swrite( stream, keyexPublicValue,
995 keyexPublicValueLen );
999 status = writeInteger16U( stream, keyexPublicValue,
1000 keyexPublicValueLen );
1008 findSessionInfo( sessionInfoPtr->attributeList,
1011 findSessionInfo( sessionInfoPtr->attributeList,
1018 status = createSharedPremasterSecret( \
1019 handshakeInfo->premasterSecret,
1021 &handshakeInfo->premasterSecretSize,
1028 sMemDisconnect( stream );
1031 "Couldn't create master secret from shared "
1032 "secret/password value" ) );
1037 status = swrite( stream, userNamePtr->value,
1043 int wrappedKeyLength;
1045 status = wrapPremasterSecret( sessionInfoPtr, handshakeInfo,
1047 &wrappedKeyLength );
1050 sMemDisconnect( stream );
1061 status = swrite( stream, wrappedKey, wrappedKeyLength );
1065 status = writeInteger16U( stream, wrappedKey,
1071 status = completeHSPacketStream( stream, packetOffset );
1074 sMemDisconnect( stream );
1081 if( needClientCert )
1086 status = completePacketStreamSSL( stream, 0 );
1088 status = hashHSPacketWrite( handshakeInfo, stream, 0 );
1090 status = createCertVerifyHash( sessionInfoPtr, handshakeInfo );
1093 sMemDisconnect( stream );
1100 status = continuePacketStreamSSL( stream, sessionInfoPtr,
1102 &packetStreamOffset );
1108 status = createCertVerify( sessionInfoPtr, handshakeInfo,
1111 status = completeHSPacketStream( stream, packetOffset );
1114 sMemDisconnect( stream );
1123 status = completePacketStreamSSL( stream, packetStreamOffset );
1125 status = hashHSPacketWrite( handshakeInfo, stream,
1126 packetStreamOffset );
1141 handshakeInfo->beginHandshake = beginClientHandshake;
1142 handshakeInfo->exchangeKeys = exchangeClientKeys;