Skip to content

Commit 8d7c600

Browse files
authored
Merge pull request #8263 from JacobBarthelmeh/rsa_pss
account for rsa_pss_rsae vs rsa_pss_pss type
2 parents 2e8f017 + af4b5c2 commit 8d7c600

4 files changed

Lines changed: 110 additions & 6 deletions

File tree

scripts/openssl.test

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ anon_wolfssl_pid=$no_pid
6464
wolf_cases_tested=0
6565
wolf_cases_total=0
6666
counter=0
67+
wolfssl_no_resume=""
6768
testing_summary="OpenSSL Interop Testing Summary:\nVersion\tTested\t#Found\t#wolf\t#Found\t#OpenSSL\n"
6869
versionName="Invalid"
6970
if [ "$OPENSSL" = "" ]; then
@@ -328,6 +329,10 @@ do_wolfssl_client() {
328329
then
329330
wolfssl_resume=
330331
fi
332+
if [ "$wolfssl_no_resume" = "yes" ]
333+
then
334+
wolfssl_resume=
335+
fi
331336
if [ "$version" != "5" -a "$version" != "" ]
332337
then
333338
echo "#"
@@ -516,6 +521,19 @@ then
516521
if [ "$wolf_rsa" != "" ]; then
517522
echo "wolfSSL supports RSA"
518523
fi
524+
# Check if RSA-PSS certificates supported in wolfSSL
525+
wolf_rsapss=`$WOLFSSL_CLIENT -A "${CERT_DIR}/rsapss/ca-rsapss.pem" 2>&1`
526+
case $wolf_rsapss in
527+
*"ca file"*)
528+
echo "wolfSSL does not support RSA-PSS"
529+
wolf_rsapss=""
530+
;;
531+
*)
532+
;;
533+
esac
534+
if [ "$wolf_rsapss" != "" ]; then
535+
echo "wolfSSL supports RSA-PSS"
536+
fi
519537
# Check if ECC certificates supported in wolfSSL
520538
wolf_ecc=`$WOLFSSL_CLIENT -A "${CERT_DIR}/ca-ecc-cert.pem" 2>&1`
521539
case $wolf_ecc in
@@ -1228,6 +1246,49 @@ do
12281246
done
12291247
IFS="$OIFS" #restore separator
12301248

1249+
# Skip RSA-PSS interop test when RSA-PSS is not supported
1250+
if [ "$wolf_rsapss" != "" -a "$ecdhe_avail" = "yes" -a "$wolf_rsa" = "yes" ]
1251+
then
1252+
# Test for RSA-PSS certs interop
1253+
# Was running into alert sent by openssl server with version 1.1.1 released
1254+
# in Sep 2018. To avoid this issue check that openssl version 3.0.0 or later
1255+
# is used.
1256+
1257+
$OPENSSL version | awk '{print $2}' | \
1258+
awk -F. '{if ($1 >= 3) exit 1; else exit 0;}'
1259+
RESULT=$?
1260+
if [ "$RESULT" = "0" ]; then
1261+
echo -e "Old version of openssl detected, skipping interop RSA-PSS test"
1262+
else
1263+
echo -e "Doing interop RSA-PSS test"
1264+
1265+
key_file=${CERT_DIR}/rsapss/server-rsapss-priv.pem
1266+
cert_file=${CERT_DIR}/rsapss/server-rsapss.pem
1267+
ca_file=${CERT_DIR}/client-cert.pem
1268+
openssl_suite="RSAPSS"
1269+
start_openssl_server
1270+
1271+
cert="${CERT_DIR}/client-cert.pem"
1272+
key="${CERT_DIR}/client-key.pem"
1273+
caCert="${CERT_DIR}/rsapss/ca-rsapss.pem"
1274+
crl="-C"
1275+
wolfSuite="ALL"
1276+
wolfssl_no_resume="yes"
1277+
port=$server_port
1278+
1279+
if [ "$wolf_tls13" != "" ]
1280+
then
1281+
version="4"
1282+
do_wolfssl_client
1283+
fi
1284+
1285+
if [ "$wolf_tls" != "" ]
1286+
then
1287+
version="3"
1288+
do_wolfssl_client
1289+
fi
1290+
fi
1291+
fi
12311292
do_cleanup
12321293

12331294
echo -e "wolfSSL total cases $wolf_cases_total"

src/internal.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5142,7 +5142,7 @@ int RsaVerify(WOLFSSL* ssl, byte* in, word32 inSz, byte** out, int sigAlgo,
51425142
#endif
51435143

51445144
#if defined(WC_RSA_PSS)
5145-
if (sigAlgo == rsa_pss_sa_algo) {
5145+
if (sigAlgo == rsa_pss_sa_algo || sigAlgo == rsa_pss_pss_algo) {
51465146
enum wc_HashType hashType = WC_HASH_TYPE_NONE;
51475147
int mgf = 0;
51485148

@@ -32292,6 +32292,13 @@ static int DoServerKeyExchange(WOLFSSL* ssl, const byte* input,
3229232292
}
3229332293
else
3229432294
#endif
32295+
#ifdef WC_RSA_PSS
32296+
if (sigAlgo == rsa_pss_pss_algo &&
32297+
ssl->options.peerSigAlgo == rsa_sa_algo) {
32298+
ssl->options.peerSigAlgo = sigAlgo;
32299+
}
32300+
else
32301+
#endif
3229532302
#if defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3)
3229632303
if (sigAlgo == sm2_sa_algo &&
3229732304
ssl->options.peerSigAlgo == ecc_dsa_sa_algo) {
@@ -32358,6 +32365,7 @@ static int DoServerKeyExchange(WOLFSSL* ssl, const byte* input,
3235832365
#ifndef NO_RSA
3235932366
#ifdef WC_RSA_PSS
3236032367
case rsa_pss_sa_algo:
32368+
case rsa_pss_pss_algo:
3236132369
#endif
3236232370
case rsa_sa_algo:
3236332371
{
@@ -32458,6 +32466,7 @@ static int DoServerKeyExchange(WOLFSSL* ssl, const byte* input,
3245832466
#ifndef NO_RSA
3245932467
#ifdef WC_RSA_PSS
3246032468
case rsa_pss_sa_algo:
32469+
case rsa_pss_pss_algo:
3246132470
#endif
3246232471
case rsa_sa_algo:
3246332472
{
@@ -32669,6 +32678,7 @@ static int DoServerKeyExchange(WOLFSSL* ssl, const byte* input,
3266932678
#ifndef NO_RSA
3267032679
#ifdef WC_RSA_PSS
3267132680
case rsa_pss_sa_algo:
32681+
case rsa_pss_pss_algo:
3267232682
#ifdef HAVE_SELFTEST
3267332683
ret = wc_RsaPSS_CheckPadding(
3267432684
ssl->buffers.digest.buffer,

src/tls13.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7938,6 +7938,27 @@ static void EncodeDualSigAlg(byte sigAlg, byte altSigAlg, byte* output)
79387938
}
79397939
#endif /* WOLFSSL_DUAL_ALG_CERTS */
79407940

7941+
static enum wc_MACAlgorithm GetNewSAHashAlgo(int typeIn)
7942+
{
7943+
switch (typeIn) {
7944+
case RSA_PSS_RSAE_SHA256_MINOR:
7945+
case RSA_PSS_PSS_SHA256_MINOR:
7946+
return sha256_mac;
7947+
7948+
case RSA_PSS_RSAE_SHA384_MINOR:
7949+
case RSA_PSS_PSS_SHA384_MINOR:
7950+
return sha384_mac;
7951+
7952+
case RSA_PSS_RSAE_SHA512_MINOR:
7953+
case RSA_PSS_PSS_SHA512_MINOR:
7954+
case ED25519_SA_MINOR:
7955+
case ED448_SA_MINOR:
7956+
return sha512_mac;
7957+
default:
7958+
return no_mac;
7959+
}
7960+
}
7961+
79417962
/* Decode the signature algorithm.
79427963
*
79437964
* input The encoded signature algorithm.
@@ -7962,25 +7983,30 @@ static WC_INLINE int DecodeTls13SigAlg(byte* input, byte* hashAlgo,
79627983
break;
79637984
#endif
79647985
case NEW_SA_MAJOR:
7965-
/* PSS signatures: 0x080[4-6] */
7966-
if (input[1] >= sha256_mac && input[1] <= sha512_mac) {
7986+
*hashAlgo = GetNewSAHashAlgo(input[1]);
7987+
7988+
/* PSS encryption: 0x080[4-6] */
7989+
if (input[1] >= RSA_PSS_RSAE_SHA256_MINOR &&
7990+
input[1] <= RSA_PSS_RSAE_SHA512_MINOR) {
7991+
*hsType = input[0];
7992+
}
7993+
/* PSS signature: 0x080[9-B] */
7994+
else if (input[1] >= RSA_PSS_PSS_SHA256_MINOR &&
7995+
input[1] <= RSA_PSS_PSS_SHA512_MINOR) {
79677996
*hsType = input[0];
7968-
*hashAlgo = input[1];
79697997
}
79707998
#ifdef HAVE_ED25519
79717999
/* ED25519: 0x0807 */
79728000
else if (input[1] == ED25519_SA_MINOR) {
79738001
*hsType = ed25519_sa_algo;
79748002
/* Hash performed as part of sign/verify operation. */
7975-
*hashAlgo = sha512_mac;
79768003
}
79778004
#endif
79788005
#ifdef HAVE_ED448
79798006
/* ED448: 0x0808 */
79808007
else if (input[1] == ED448_SA_MINOR) {
79818008
*hsType = ed448_sa_algo;
79828009
/* Hash performed as part of sign/verify operation. */
7983-
*hashAlgo = sha512_mac;
79848010
}
79858011
#endif
79868012
else

wolfssl/internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,13 @@ enum Misc {
18131813
MAX_CURVE_NAME_SZ = 18, /* Maximum size of curve name string */
18141814

18151815
NEW_SA_MAJOR = 8, /* Most significant byte used with new sig algos */
1816+
RSA_PSS_RSAE_SHA256_MINOR = 0x04,
1817+
RSA_PSS_RSAE_SHA384_MINOR = 0x05,
1818+
RSA_PSS_RSAE_SHA512_MINOR = 0x06,
1819+
RSA_PSS_PSS_SHA256_MINOR = 0x09,
1820+
RSA_PSS_PSS_SHA384_MINOR = 0x0A,
1821+
RSA_PSS_PSS_SHA512_MINOR = 0x0B,
1822+
18161823
ED25519_SA_MAJOR = 8, /* Most significant byte for ED25519 */
18171824
ED25519_SA_MINOR = 7, /* Least significant byte for ED25519 */
18181825
ED448_SA_MAJOR = 8, /* Most significant byte for ED448 */

0 commit comments

Comments
 (0)