@@ -784,6 +784,40 @@ static const char *ssh_find_aead_hmac(const char *cipher)
784784 return NULL ;
785785}
786786
787+ static enum ssh_key_exchange_e
788+ kex_select_kex_type (const char * kex )
789+ {
790+ if (strcmp (kex , "diffie-hellman-group1-sha1" ) == 0 ) {
791+ return SSH_KEX_DH_GROUP1_SHA1 ;
792+ } else if (strcmp (kex , "diffie-hellman-group14-sha1" ) == 0 ) {
793+ return SSH_KEX_DH_GROUP14_SHA1 ;
794+ } else if (strcmp (kex , "diffie-hellman-group14-sha256" ) == 0 ) {
795+ return SSH_KEX_DH_GROUP14_SHA256 ;
796+ } else if (strcmp (kex , "diffie-hellman-group16-sha512" ) == 0 ) {
797+ return SSH_KEX_DH_GROUP16_SHA512 ;
798+ } else if (strcmp (kex , "diffie-hellman-group18-sha512" ) == 0 ) {
799+ return SSH_KEX_DH_GROUP18_SHA512 ;
800+ #ifdef WITH_GEX
801+ } else if (strcmp (kex , "diffie-hellman-group-exchange-sha1" ) == 0 ) {
802+ return SSH_KEX_DH_GEX_SHA1 ;
803+ } else if (strcmp (kex , "diffie-hellman-group-exchange-sha256" ) == 0 ) {
804+ return SSH_KEX_DH_GEX_SHA256 ;
805+ #endif /* WITH_GEX */
806+ } else if (strcmp (kex , "ecdh-sha2-nistp256" ) == 0 ) {
807+ return SSH_KEX_ECDH_SHA2_NISTP256 ;
808+ } else if (strcmp (kex , "ecdh-sha2-nistp384" ) == 0 ) {
809+ return SSH_KEX_ECDH_SHA2_NISTP384 ;
810+ } else if (strcmp (kex , "ecdh-sha2-nistp521" ) == 0 ) {
811+ return SSH_KEX_ECDH_SHA2_NISTP521 ;
812+ } else if (strcmp (kex , "curve25519-sha256@libssh.org" ) == 0 ) {
813+ return SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG ;
814+ } else if (strcmp (kex , "curve25519-sha256" ) == 0 ) {
815+ return SSH_KEX_CURVE25519_SHA256 ;
816+ }
817+ /* should not happen. We should be getting only valid names at this stage */
818+ return 0 ;
819+ }
820+
787821/** @brief Select the different methods on basis of client's and
788822 * server's kex messages, and watches out if a match is possible.
789823 */
@@ -825,34 +859,9 @@ int ssh_kex_select_methods (ssh_session session)
825859 crypto -> kex_methods [i ] = strdup ("" );
826860 }
827861 }
828- kex = session -> next_crypto -> kex_methods [SSH_KEX ];
829- if (strcmp (kex , "diffie-hellman-group1-sha1" ) == 0 ) {
830- session -> next_crypto -> kex_type = SSH_KEX_DH_GROUP1_SHA1 ;
831- } else if (strcmp (kex , "diffie-hellman-group14-sha1" ) == 0 ) {
832- session -> next_crypto -> kex_type = SSH_KEX_DH_GROUP14_SHA1 ;
833- } else if (strcmp (kex , "diffie-hellman-group14-sha256" ) == 0 ) {
834- session -> next_crypto -> kex_type = SSH_KEX_DH_GROUP14_SHA256 ;
835- } else if (strcmp (kex , "diffie-hellman-group16-sha512" ) == 0 ) {
836- session -> next_crypto -> kex_type = SSH_KEX_DH_GROUP16_SHA512 ;
837- } else if (strcmp (kex , "diffie-hellman-group18-sha512" ) == 0 ) {
838- session -> next_crypto -> kex_type = SSH_KEX_DH_GROUP18_SHA512 ;
839- #ifdef WITH_GEX
840- } else if (strcmp (kex , "diffie-hellman-group-exchange-sha1" ) == 0 ) {
841- session -> next_crypto -> kex_type = SSH_KEX_DH_GEX_SHA1 ;
842- } else if (strcmp (kex , "diffie-hellman-group-exchange-sha256" ) == 0 ) {
843- session -> next_crypto -> kex_type = SSH_KEX_DH_GEX_SHA256 ;
844- #endif /* WITH_GEX */
845- } else if (strcmp (kex , "ecdh-sha2-nistp256" ) == 0 ) {
846- session -> next_crypto -> kex_type = SSH_KEX_ECDH_SHA2_NISTP256 ;
847- } else if (strcmp (kex , "ecdh-sha2-nistp384" ) == 0 ) {
848- session -> next_crypto -> kex_type = SSH_KEX_ECDH_SHA2_NISTP384 ;
849- } else if (strcmp (kex , "ecdh-sha2-nistp521" ) == 0 ) {
850- session -> next_crypto -> kex_type = SSH_KEX_ECDH_SHA2_NISTP521 ;
851- } else if (strcmp (kex , "curve25519-sha256@libssh.org" ) == 0 ) {
852- session -> next_crypto -> kex_type = SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG ;
853- } else if (strcmp (kex , "curve25519-sha256" ) == 0 ) {
854- session -> next_crypto -> kex_type = SSH_KEX_CURVE25519_SHA256 ;
855- }
862+ kex = crypto -> kex_methods [SSH_KEX ];
863+ crypto -> kex_type = kex_select_kex_type (kex );
864+
856865 SSH_LOG (SSH_LOG_INFO , "Negotiated %s,%s,%s,%s,%s,%s,%s,%s,%s,%s" ,
857866 session -> next_crypto -> kex_methods [SSH_KEX ],
858867 session -> next_crypto -> kex_methods [SSH_HOSTKEYS ],
0 commit comments