@@ -707,6 +707,56 @@ static void test_pubkey_auth_ecc(void)
707707
708708 run_pubkey_test (& sCtx , & cCtx , WS_SUCCESS );
709709}
710+
711+ /* Negative test: correct ECC public key presented (passes the authorized-key
712+ * hash check) but the client signs with a corrupted private key. The wrong
713+ * signature must reach and be rejected by DoUserAuthRequestEcc rather than
714+ * failing on the earlier key-type mismatch path.
715+ */
716+ static void test_pubkey_auth_ecc_bad_sig (void )
717+ {
718+ PubkeyServerCtx sCtx ;
719+ PubkeyClientCtx cCtx ;
720+ byte pubKeyBuf [256 ];
721+ byte * p = pubKeyBuf ;
722+ word32 pubKeySz = sizeof (pubKeyBuf );
723+ const byte * pubKeyType = NULL ;
724+ word32 pubKeyTypeSz = 0 ;
725+ /* Flip one byte inside the private scalar of the DER blob.
726+ * Byte 10 lands in the scalar for all three NIST curves:
727+ * P-256 scalar starts at DER byte 7; P-384/P-521 start at byte 8.
728+ * So the value remains within the curve order
729+ * and the key remains signable */
730+ byte badPrivDer [sizeof (hanselPrivateEcc )];
731+ byte badPrivBuf [256 ];
732+ byte * badPrivPtr = badPrivBuf ;
733+ word32 badPrivSz = sizeof (badPrivBuf );
734+ const byte * badPrivType = NULL ;
735+ word32 badPrivTypeSz = 0 ;
736+
737+ printf ("Testing ECC pubkey auth rejection with tampered signature\n" );
738+
739+ AssertIntEQ (wolfSSH_ReadKey_buffer ((const byte * )hanselPublicEcc ,
740+ (word32 )WSTRLEN (hanselPublicEcc ), WOLFSSH_FORMAT_SSH ,
741+ & p , & pubKeySz , & pubKeyType , & pubKeyTypeSz , NULL ), WS_SUCCESS );
742+ AssertIntEQ (wc_Sha256Hash (pubKeyBuf , pubKeySz , sCtx .hash ), 0 );
743+
744+ WMEMCPY (badPrivDer , hanselPrivateEcc , hanselPrivateEccSz );
745+ badPrivDer [10 ] ^= 0xFF ;
746+ AssertIntEQ (wolfSSH_ReadKey_buffer (badPrivDer , hanselPrivateEccSz ,
747+ WOLFSSH_FORMAT_ASN1 ,
748+ & badPrivPtr , & badPrivSz , & badPrivType , & badPrivTypeSz , NULL ),
749+ WS_SUCCESS );
750+
751+ cCtx .publicKeyType = pubKeyType ;
752+ cCtx .publicKeyTypeSz = pubKeyTypeSz ;
753+ cCtx .publicKey = pubKeyBuf ;
754+ cCtx .publicKeySz = pubKeySz ;
755+ cCtx .privateKey = badPrivBuf ;
756+ cCtx .privateKeySz = badPrivSz ;
757+
758+ run_pubkey_test (& sCtx , & cCtx , WS_FATAL_ERROR );
759+ }
710760#endif /* WOLFSSH_NO_ECC */
711761
712762#if !defined(WOLFSSH_NO_RSA ) && !defined(WOLFSSH_NO_ECC )
@@ -1511,6 +1561,7 @@ int wolfSSH_AuthTest(int argc, char** argv)
15111561#endif
15121562#ifndef WOLFSSH_NO_ECC
15131563 test_pubkey_auth_ecc ();
1564+ test_pubkey_auth_ecc_bad_sig ();
15141565#endif
15151566#if !defined(WOLFSSH_NO_RSA ) && !defined(WOLFSSH_NO_ECC )
15161567 test_pubkey_auth_wrong_key ();
0 commit comments