39 #ifdef PREFER_ECC_SUITES
43 #if !defined( PREFER_ECC_SUITES )
65 IN_RANGE( 1, 16 )
const int algoListLength )
68 int availAlgoIndex[ 16 + 8 ];
69 int noAlgos = 0,
length = 0, algoIndex, noAlgoStringInfoEntries,
status;
75 REQUIRES( algoListLength >= 1 && algoListLength <= 16 );
84 algoIndex < algoListLength && \
103 algoStringInfoTbl[ i ].algo != cryptAlgo && \
104 i < noAlgoStringInfoEntries; i++ );
105 ENSURES( i < noAlgoStringInfoEntries );
107 noAlgos >= 0 && noAlgos < 16 );
108 algoStringInfo = &algoStringInfoTbl[ i ];
123 availAlgoIndex[ noAlgos++ ] = i;
128 ENSURES( algoIndex < FAILSAFE_ITERATIONS_SMALL );
131 status = writeUint32( stream,
length );
132 for( algoIndex = 0;
cryptStatusOK( status ) && algoIndex < noAlgos;
136 &algoStringInfoTbl[ availAlgoIndex[ algoIndex ] ];
139 sputc( stream,
',' );
140 status = swrite( stream, algoStringInfo->name,
184 handshakeInfo->pubkeyAlgo = pubKeyAlgo;
190 handshakeInfo->algoStringPubkeyTbl = algoStringPubkeyRSATbl;
191 handshakeInfo->algoStringPubkeyTblNoEntries = \
197 handshakeInfo->algoStringPubkeyTbl = algoStringPubkeyDSATbl;
198 handshakeInfo->algoStringPubkeyTblNoEntries = \
215 handshakeInfo->algoStringPubkeyTbl = algoStringPubkeyECDSATbl;
216 handshakeInfo->algoStringPubkeyTblNoEntries = \
221 handshakeInfo->algoStringPubkeyTbl = algoStringPubkeyECDSA384Tbl;
222 handshakeInfo->algoStringPubkeyTblNoEntries = \
227 handshakeInfo->algoStringPubkeyTbl = algoStringPubkeyECDSA521Tbl;
228 handshakeInfo->algoStringPubkeyTblNoEntries = \
276 sMemConnect( &stream, sessionInfoPtr->receiveBuffer, length );
282 readUint32( &stream );
283 keySize = readUint32( &stream );
284 status = readUint32( &stream );
289 status = keySize = readUint32( &stream );
292 status = streamBookmarkComplete( &stream, &keyexInfoPtr,
293 &keyexInfoLength, keyexInfoLength );
294 sMemDisconnect( &stream );
299 "Invalid ephemeral DH key data request packet" ) );
307 "Client requested invalid ephemeral DH key size %d bits, "
308 "should be %d...%d", keySize,
313 memcpy( handshakeInfo->encodedReqKeySizes, keyexInfoPtr,
315 handshakeInfo->encodedReqKeySizesLength = keyexInfoLength;
316 handshakeInfo->requestedServerKeySize =
bitsToBytes( keySize );
344 if( handshakeInfo->requestedServerKeySize < \
346 handshakeInfo->requestedServerKeySize > \
352 status = initDHcontextSSH( &handshakeInfo->iServerCryptContext,
353 &handshakeInfo->serverKeySize, NULL, 0,
354 handshakeInfo->requestedServerKeySize );
379 CRYPT_IATTRIBUTE_KEY_SSH );
383 readUint32( &stream );
384 status = readUniversal32( &stream );
386 keyDataStart = stell( &stream );
387 keyDataLength = sMemDataLeft( &stream );
388 sMemDisconnect( &stream );
392 status = openPacketStreamSSH( &stream, sessionInfoPtr,
396 status = swrite( &stream,
keyData + keyDataStart, keyDataLength );
398 status = sendPacketSSH2( sessionInfoPtr, &stream,
FALSE );
399 sMemDisconnect( &stream );
418 int length, serverHelloLength, clientHelloLength,
status;
426 status = initPubkeyAlgo( sessionInfoPtr, handshakeInfo );
437 status = hashAsString( handshakeInfo->iExchangeHashContext,
438 sessionInfoPtr->receiveBuffer,
439 strlen( sessionInfoPtr->receiveBuffer ) );
441 status = hashAsString( handshakeInfo->iExchangeHashContext,
444 handshakeInfo->iExchangeHashAltContext !=
CRYPT_ERROR )
446 status = hashAsString( handshakeInfo->iExchangeHashAltContext,
447 sessionInfoPtr->receiveBuffer,
448 strlen( sessionInfoPtr->receiveBuffer ) );
450 status = hashAsString( handshakeInfo->iExchangeHashAltContext,
518 status = openPacketStreamSSH( &stream, sessionInfoPtr,
SSH_MSG_KEXINIT );
523 CRYPT_IATTRIBUTE_RANDOM_NONCE,
538 status = writeAlgoList( &stream, algoKeyexEccList,
544 status = writeAlgoList( &stream, algoKeyexList,
550 status = writeAlgoString( &stream, handshakeInfo->pubkeyAlgo );
552 status = writeAlgoList( &stream, algoEncrList,
556 status = writeAlgoList( &stream, algoEncrList,
560 status = writeAlgoList( &stream, algoMACList,
564 status = writeAlgoList( &stream, algoMACList,
573 writeUint32( &stream, 0 );
574 writeUint32( &stream, 0 );
576 status = writeUint32( &stream, 0 );
580 status = streamBookmarkComplete( &stream, &serverHelloPtr,
585 status = sendPacketSSH2( sessionInfoPtr, &stream,
FALSE );
586 sMemDisconnect( &stream );
593 status = initDHcontextSSH( &handshakeInfo->iServerCryptContext,
594 &handshakeInfo->serverKeySize, NULL, 0,
603 status = processHelloSSH( sessionInfoPtr, handshakeInfo,
604 &clientHelloLength,
TRUE );
613 skipGuessedKeyex =
TRUE;
616 sessionInfoPtr->receiveBufSize ) );
617 memmove( sessionInfoPtr->receiveBuffer + 1,
618 sessionInfoPtr->receiveBuffer, clientHelloLength );
620 status = hashAsString( handshakeInfo->iExchangeHashContext,
621 sessionInfoPtr->receiveBuffer,
622 clientHelloLength + 1 );
627 status = readHSPacketSSH2( sessionInfoPtr,
628 ( handshakeInfo->requestedServerKeySize > 0 ) ? \
633 status = hashAsString( handshakeInfo->iExchangeHashContext,
634 serverHelloPtr, serverHelloLength );
640 if( handshakeInfo->requestedServerKeySize > 0 )
642 status = processDHE( sessionInfoPtr, handshakeInfo );
650 if( handshakeInfo->isECDH )
655 status = initECDHcontextSSH( &handshakeInfo->iServerCryptContext,
656 &handshakeInfo->serverKeySize,
657 handshakeInfo->keyexAlgo );
660 sMemDisconnect( &stream );
675 readHSPacketSSH2( sessionInfoPtr,
676 ( handshakeInfo->requestedServerKeySize > 0 ) ? \
678 ID_SIZE + ( handshakeInfo->isECDH ? \
683 sMemConnect( &stream, sessionInfoPtr->receiveBuffer, length );
684 status = readRawObject32( &stream, handshakeInfo->clientKeyexValue,
686 &handshakeInfo->clientKeyexValueLength );
687 sMemDisconnect( &stream );
690 if( handshakeInfo->isECDH )
707 "Invalid %s phase 1 keyex value",
708 handshakeInfo->isECDH ?
"ECDH" :
"DH" ) );
734 sMemOpen( &stream, handshakeInfo->serverKeyexValue,
736 if( handshakeInfo->isECDH )
738 status = writeString32( &stream, keyAgreeParams.publicValue,
743 status = writeInteger32( &stream, keyAgreeParams.publicValue,
747 handshakeInfo->serverKeyexValueLength = stell( &stream );
748 sMemDisconnect( &stream );
785 status = openPacketStreamSSH( &stream, sessionInfoPtr,
786 handshakeInfo->requestedServerKeySize ? \
792 status = exportAttributeToStream( &stream, sessionInfoPtr->privateKey,
793 CRYPT_IATTRIBUTE_KEY_SSH );
795 status = streamBookmarkComplete( &stream, &keyPtr, &keyLength,
802 sMemDisconnect( &stream );
805 swrite( &stream, handshakeInfo->serverKeyexValue,
806 handshakeInfo->serverKeyexValueLength );
810 status = completeKeyex( sessionInfoPtr, handshakeInfo,
TRUE );
818 status = sMemGetDataBlockRemaining( &stream, &dataPtr, &dataLength );
821 status = iCryptCreateSignature( dataPtr,
823 &sigLength, CRYPT_IFORMAT_SSH,
824 sessionInfoPtr->privateKey,
825 handshakeInfo->iExchangeHashContext, NULL );
830 if( handshakeInfo->iExchangeHashAltContext !=
CRYPT_ERROR )
834 handshakeInfo->iExchangeHashAltContext =
CRYPT_ERROR;
837 status = sSkip( &stream, sigLength );
839 status = wrapPacketSSH2( sessionInfoPtr, &stream, 0,
FALSE,
TRUE );
842 sMemDisconnect( &stream );
851 status = initSecurityInfo( sessionInfoPtr, handshakeInfo );
864 status = wrapPacketSSH2( sessionInfoPtr, &stream, packetOffset,
867 status = sendPacketSSH2( sessionInfoPtr, &stream,
TRUE );
868 sMemDisconnect( &stream );
901 userInfoPresent =
TRUE;
929 sMemConnect( &stream, sessionInfoPtr->receiveBuffer, length );
932 sMemDisconnect( &stream );
934 stringLength != 12 || memcmp( stringBuffer,
"ssh-userauth", 12 ) )
938 "Invalid service request packet" ) );
940 status = openPacketStreamSSH( &stream, sessionInfoPtr,
944 status = writeString32( &stream,
"ssh-userauth", 12 );
946 status = sendPacketSSH2( sessionInfoPtr, &stream,
FALSE );
947 sMemDisconnect( &stream );
953 status = processServerAuth( sessionInfoPtr, userInfoPresent );
964 sMemConnect( &stream, sessionInfoPtr->receiveBuffer, length );
965 status = processChannelOpen( sessionInfoPtr, &stream );
966 sMemDisconnect( &stream );
991 sMemConnect( &stream, sessionInfoPtr->receiveBuffer, length );
992 status = processChannelControlMessage( sessionInfoPtr, &stream );
993 sMemDisconnect( &stream );
1014 handshakeInfo->beginHandshake = beginServerHandshake;
1015 handshakeInfo->exchangeKeys = exchangeServerKeys;
1016 handshakeInfo->completeHandshake = completeServerHandshake;