Skip to content

Commit b4f1abe

Browse files
committed
SM2 TLS1.3: Fix certificate verify
Code to verify with SM2/SM3 was not able to be reached. The check of hsType (which was ECC for both ECC and SM2/SM3) was replaced with a check of peerSigAlgo for ecc_dsa_sa_algo which is different for ECDSA and SM2/SM3.
1 parent 342c37d commit b4f1abe

1 file changed

Lines changed: 28 additions & 22 deletions

File tree

src/tls13.c

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10537,28 +10537,17 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
1053710537
#endif /* !NO_RSA */
1053810538
#ifdef HAVE_ECC
1053910539
if ((ssl->options.peerSigAlgo == ecc_dsa_sa_algo) &&
10540-
(ssl->peerEccDsaKeyPresent)) {
10541-
#if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
10542-
if (ssl->options.peerSigAlgo == sm2_sa_algo) {
10543-
ret = Sm2wSm3Verify(ssl, TLS13_SM2_SIG_ID,
10544-
TLS13_SM2_SIG_ID_SZ, sig, args->sigSz,
10545-
args->sigData, args->sigDataSz,
10546-
ssl->peerEccDsaKey, NULL);
10547-
}
10548-
else
10549-
#endif
10550-
{
10551-
WOLFSSL_MSG("Doing ECC peer cert verify");
10552-
ret = EccVerify(ssl, sig, args->sigSz,
10553-
args->sigData, args->sigDataSz,
10554-
ssl->peerEccDsaKey,
10555-
#ifdef HAVE_PK_CALLBACKS
10556-
&ssl->buffers.peerEccDsaKey
10557-
#else
10558-
NULL
10559-
#endif
10560-
);
10561-
}
10540+
ssl->peerEccDsaKeyPresent) {
10541+
WOLFSSL_MSG("Doing ECC peer cert verify");
10542+
ret = EccVerify(ssl, sig, args->sigSz,
10543+
args->sigData, args->sigDataSz,
10544+
ssl->peerEccDsaKey,
10545+
#ifdef HAVE_PK_CALLBACKS
10546+
&ssl->buffers.peerEccDsaKey
10547+
#else
10548+
NULL
10549+
#endif
10550+
);
1056210551

1056310552
if (ret >= 0) {
1056410553
/* CLIENT/SERVER: data verified with public key from
@@ -10570,6 +10559,23 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
1057010559
}
1057110560
}
1057210561
#endif /* HAVE_ECC */
10562+
#if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
10563+
if ((ssl->options.peerSigAlgo == sm2_sa_algo) &&
10564+
ssl->peerEccDsaKeyPresent) {
10565+
WOLFSSL_MSG("Doing SM2/SM3 peer cert verify");
10566+
ret = Sm2wSm3Verify(ssl, TLS13_SM2_SIG_ID, TLS13_SM2_SIG_ID_SZ,
10567+
sig, args->sigSz, args->sigData, args->sigDataSz,
10568+
ssl->peerEccDsaKey, NULL);
10569+
if (ret >= 0) {
10570+
/* CLIENT/SERVER: data verified with public key from
10571+
* certificate. */
10572+
ssl->options.peerAuthGood = 1;
10573+
10574+
FreeKey(ssl, DYNAMIC_TYPE_ECC, (void**)&ssl->peerEccDsaKey);
10575+
ssl->peerEccDsaKeyPresent = 0;
10576+
}
10577+
}
10578+
#endif
1057310579
#ifdef HAVE_ED25519
1057410580
if ((ssl->options.peerSigAlgo == ed25519_sa_algo) &&
1057510581
(ssl->peerEd25519KeyPresent)) {

0 commit comments

Comments
 (0)