Skip to content

Commit 268b81c

Browse files
TLSv1.3 certificate verify: report rsa_pss_pss_* signature algorithm when supported
1 parent 50c5028 commit 268b81c

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/ssl_load.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,12 @@ static int ProcessBufferCertPublicKey(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
16241624
ret = CHECK_KEY_SZ(ssl ? ssl->options.minRsaKeySz :
16251625
ctx->minRsaKeySz, RSA_MAX_SIZE / 8, keySz, RSA_KEY_SIZE_E);
16261626
}
1627+
#ifdef WC_RSA_PSS
1628+
if (ssl)
1629+
ssl->ctx->useRsaPss = (cert->keyOID == RSAPSSk) ? 1u : 0u;
1630+
else
1631+
ctx->useRsaPss = (cert->keyOID == RSAPSSk) ? 1u : 0u;
1632+
#endif
16271633
break;
16281634
#endif /* !NO_RSA */
16291635
#ifdef HAVE_ECC

src/tls13.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7867,8 +7867,9 @@ static int SendTls13CertificateRequest(WOLFSSL* ssl, byte* reqCtx,
78677867
* hsType The signature type.
78687868
* output The buffer to encode into.
78697869
*/
7870-
static WC_INLINE void EncodeSigAlg(byte hashAlgo, byte hsType, byte* output)
7870+
static WC_INLINE void EncodeSigAlg(const WOLFSSL * ssl, byte hashAlgo, byte hsType, byte* output)
78717871
{
7872+
(void)ssl;
78727873
switch (hsType) {
78737874
#ifdef HAVE_ECC
78747875
case ecc_dsa_sa_algo:
@@ -7899,10 +7900,24 @@ static WC_INLINE void EncodeSigAlg(byte hashAlgo, byte hsType, byte* output)
78997900
break;
79007901
#endif
79017902
#ifndef NO_RSA
7902-
/* PSS signatures: 0x080[4-6] */
7903+
/* PSS signatures: 0x080[4-6] or 0x080[9-B] */
79037904
case rsa_pss_sa_algo:
79047905
output[0] = rsa_pss_sa_algo;
7905-
output[1] = hashAlgo;
7906+
#ifdef WC_RSA_PSS
7907+
/* If the private key uses the RSA-PSS OID, and the peer supports
7908+
* the rsa_pss_pss_* signature algorithm in use, then report
7909+
* rsa_pss_pss_* rather than rsa_pss_rsae_*. */
7910+
if (ssl->ctx->useRsaPss &&
7911+
((ssl->pssAlgo & (1u << hashAlgo)) != 0u) &&
7912+
(sha256_mac <= hashAlgo) && (hashAlgo <= sha512_mac))
7913+
{
7914+
output[1] = PSS_RSAE_TO_PSS_PSS(hashAlgo);
7915+
}
7916+
else
7917+
#endif
7918+
{
7919+
output[1] = hashAlgo;
7920+
}
79067921
break;
79077922
#endif
79087923
#ifdef HAVE_FALCON
@@ -9361,7 +9376,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
93619376
}
93629377
else
93639378
#endif /* WOLFSSL_DUAL_ALG_CERTS */
9364-
EncodeSigAlg(ssl->options.hashAlgo, args->sigAlgo,
9379+
EncodeSigAlg(ssl, ssl->options.hashAlgo, args->sigAlgo,
93659380
args->verify);
93669381

93679382
if (args->sigData == NULL) {

wolfssl/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3907,6 +3907,9 @@ struct WOLFSSL_CTX {
39073907
#endif
39083908
#ifndef NO_RSA
39093909
short minRsaKeySz; /* minimum RSA key size */
3910+
#ifdef WC_RSA_PSS
3911+
word8 useRsaPss;
3912+
#endif
39103913
#endif
39113914
#if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
39123915
short minEccKeySz; /* minimum ECC key size */

0 commit comments

Comments
 (0)