27 #define FINISHED_TEMPLATE_SIZE 4
29 static const BYTE finishedTemplateSSL[] = \
31 static const BYTE finishedTemplateTLS[] = \
78 const int macValueLength = \
84 assert(
isReadPtr( hashValues, hashValuesLength ) );
86 REQUIRES( hashValuesLength == macValueLength );
94 status = readHSPacketSSL( sessionInfoPtr, NULL, &length,
102 if( !
isServer( sessionInfoPtr ) && \
107 ", probably due to missing client "
108 "authentication" ) );
112 sMemConnect( &stream, sessionInfoPtr->receiveBuffer, length );
113 value = sgetc( &stream );
114 sMemDisconnect( &stream );
119 "Invalid change cipher spec packet payload, expected "
120 "0x01, got 0x%02X", value ) );
131 sessionInfoPtr->cryptBlocksize > 1 )
133 sessionInfoPtr->sessionSSL->ivSize = sessionInfoPtr->cryptBlocksize;
134 sessionInfoPtr->receiveBufStartOfs += sessionInfoPtr->sessionSSL->ivSize;
140 sessionInfoPtr->sessionSSL->ivSize = \
141 GCM_IV_SIZE - sessionInfoPtr->sessionSSL->gcmSaltSize;
142 sessionInfoPtr->receiveBufStartOfs += sessionInfoPtr->sessionSSL->ivSize;
160 status = readHSPacketSSL( sessionInfoPtr, NULL, &length,
164 status = unwrapPacketSSL( sessionInfoPtr, sessionInfoPtr->receiveBuffer,
174 "Decrypted data was corrupt, probably due to "
175 "incorrect encryption keys being negotiated "
176 "during the handshake: " ) );
180 sMemConnect( &stream, sessionInfoPtr->receiveBuffer, length );
181 status = checkHSPacketHeader( sessionInfoPtr, &stream, &length,
185 if( length != macValueLength )
192 status = sread( &stream, macBuffer, macValueLength );
194 sMemDisconnect( &stream );
201 "Invalid handshake finished packet, probably due to "
202 "incorrect encryption keys being negotiated during "
210 if( !compareDataConstTime( hashValues, macBuffer, macValueLength ) )
214 "Bad MAC for handshake messages, handshake messages were "
215 "corrupted/modified" ) );
225 const BYTE *hashValues,
227 const BOOLEAN continuedStream )
229 STREAM *stream = &handshakeInfo->stream;
234 assert(
isReadPtr( hashValues, hashValuesLength ) );
248 if( continuedStream )
250 status = continuePacketStreamSSL( stream, sessionInfoPtr,
256 status = openPacketStreamSSL( stream, sessionInfoPtr,
262 status = sputc( stream, 1 );
264 status = completePacketStreamSSL( stream, offset );
267 sMemDisconnect( stream );
279 sessionInfoPtr->cryptBlocksize > 1 )
281 sessionInfoPtr->sessionSSL->ivSize = sessionInfoPtr->cryptBlocksize;
282 sessionInfoPtr->sendBufStartOfs += sessionInfoPtr->sessionSSL->ivSize;
288 sessionInfoPtr->sessionSSL->ivSize = \
289 GCM_IV_SIZE - sessionInfoPtr->sessionSSL->gcmSaltSize;
290 sessionInfoPtr->sendBufStartOfs += sessionInfoPtr->sessionSSL->ivSize;
304 status = continuePacketStreamSSL( stream, sessionInfoPtr,
310 status = swrite( stream, hashValues, hashValuesLength );
312 status = completeHSPacketStream( stream, offset );
314 status = wrapPacketSSL( sessionInfoPtr, stream, ccsEndPos );
316 status = sendPacketSSL( sessionInfoPtr, stream,
318 sMemDisconnect( stream );
362 const CRYPT_CONTEXT initiatorMD5context = handshakeInfo->md5context;
363 const CRYPT_CONTEXT initiatorSHA1context = handshakeInfo->sha1context;
364 const CRYPT_CONTEXT initiatorSHA2context = handshakeInfo->sha2context;
371 const void *sslInitiatorString, *sslResponderString;
372 const void *tlsInitiatorString, *tlsResponderString;
374 int initiatorHashLength, responderHashLength;
375 int sslLabelLength, tlsLabelLength,
status;
381 handshakeInfo->cryptKeysize +
382 sessionInfoPtr->cryptBlocksize ) * 2 );
384 (
isEccAlgo( handshakeInfo->keyexAlgo ) && \
386 ( !
isEccAlgo( handshakeInfo->keyexAlgo ) && \
391 if( isResumedSession )
396 tlsInitiatorString =
"server finished";
397 tlsResponderString =
"client finished";
404 tlsInitiatorString =
"client finished";
405 tlsResponderString =
"server finished";
411 status = initCryptoSSL( sessionInfoPtr, handshakeInfo, masterSecret,
425 status = cloneHashContext( initiatorMD5context,
426 &responderMD5context );
429 status = cloneHashContext( initiatorSHA1context,
430 &responderSHA1context );
437 status = cloneHashContext( initiatorSHA2context,
438 &responderSHA2context );
451 status = completeSSLDualMAC( initiatorMD5context, initiatorSHA1context,
453 &initiatorHashLength, sslInitiatorString,
460 status = completeTLSHashedMAC( initiatorMD5context,
461 initiatorSHA1context, initiatorHashes,
463 tlsInitiatorString, tlsLabelLength, masterSecret,
468 status = completeTLS12HashedMAC( initiatorSHA2context,
470 &initiatorHashLength, tlsInitiatorString,
476 status = readHandshakeCompletionData( sessionInfoPtr,
478 initiatorHashLength );
483 destroyHashContexts( responderMD5context, responderSHA1context,
484 responderSHA2context );
496 (
MESSAGE_CAST ) finishedTemplateTLS, FINISHED_TEMPLATE_SIZE );
499 initiatorHashes, initiatorHashLength );
503 const BYTE *finishedTemplate = \
505 finishedTemplateSSL : finishedTemplateTLS;
508 (
MESSAGE_CAST ) finishedTemplate, FINISHED_TEMPLATE_SIZE );
512 (
MESSAGE_CAST ) finishedTemplate, FINISHED_TEMPLATE_SIZE );
516 initiatorHashes, initiatorHashLength );
519 initiatorHashes, initiatorHashLength );
524 destroyHashContexts( responderMD5context, responderSHA1context,
525 responderSHA2context );
530 status = completeSSLDualMAC( responderMD5context, responderSHA1context,
532 &responderHashLength, sslResponderString,
539 status = completeTLSHashedMAC( responderMD5context,
540 responderSHA1context, responderHashes,
542 tlsResponderString, tlsLabelLength, masterSecret,
547 status = completeTLS12HashedMAC( responderSHA2context,
549 &responderHashLength, tlsResponderString,
554 destroyHashContexts( responderMD5context, responderSHA1context,
555 responderSHA2context );
563 status = writeHandshakeCompletionData( sessionInfoPtr, handshakeInfo,
564 isInitiator ? initiatorHashes : \
568 ( isClient && !isResumedSession ) || \
569 ( !isClient && isResumedSession ) );
572 return( readHandshakeCompletionData( sessionInfoPtr, responderHashes,
573 initiatorHashLength ) );