Skip to content

Commit 6c8b905

Browse files
authored
Merge pull request #9443 from holtrop/report-rsa_pss_pss-sig-algo
TLSv1.3 certificate verify: report rsa_pss_pss_* signature algorithm when supported
2 parents 6a5e29e + 36418ac commit 6c8b905

6 files changed

Lines changed: 129 additions & 4 deletions

File tree

scripts/include.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ EXTRA_DIST += scripts/sniffer-static-rsa.pcap \
116116

117117
# leave openssl.test as extra until non bash works
118118
EXTRA_DIST += scripts/openssl.test
119+
EXTRA_DIST += scripts/rsapss.test
119120

120121
EXTRA_DIST += scripts/dertoc.pl
121122

scripts/rsapss.test

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env bash
2+
3+
# rsapss.test
4+
5+
if ! ./examples/client/client -V | grep -q 4; then
6+
echo "skipping because TLS 1.3 not enabled in this build"
7+
exit 0
8+
fi
9+
if ! grep -q -- -DWC_RSA_PSS config.log 2>/dev/null; then
10+
echo "skipping because WC_RSA_PSS not enabled in this build"
11+
exit 0
12+
fi
13+
if ! grep -q -- '-DHAVE_ECC\>' config.log 2>/dev/null; then
14+
echo "skipping because HAVE_ECC not enabled in this build"
15+
exit 0
16+
fi
17+
if grep -q -- '-DNO_CODING' config.log 2>/dev/null; then
18+
echo "skipping because NO_CODING is defined in this build"
19+
exit 0
20+
fi
21+
22+
CERT_DIR="$PWD/$(dirname "$0")/../certs"
23+
if [ "$OPENSSL" = "" ]; then
24+
OPENSSL=openssl
25+
fi
26+
27+
# if we can, isolate the network namespace to eliminate port collisions.
28+
if [[ -n "$NETWORK_UNSHARE_HELPER" ]]; then
29+
if [[ -z "$NETWORK_UNSHARE_HELPER_CALLED" ]]; then
30+
export NETWORK_UNSHARE_HELPER_CALLED=yes
31+
exec "$NETWORK_UNSHARE_HELPER" "$0" "$@" || exit $?
32+
fi
33+
elif [ "${AM_BWRAPPED-}" != "yes" ]; then
34+
bwrap_path="$(command -v bwrap)"
35+
if [ -n "$bwrap_path" ]; then
36+
export AM_BWRAPPED=yes
37+
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
38+
fi
39+
unset AM_BWRAPPED
40+
fi
41+
42+
# need a unique port since may run the same time as testsuite
43+
generate_port() {
44+
#-------------------------------------------------------------------------#
45+
# Generate a random port number
46+
#-------------------------------------------------------------------------#
47+
48+
if [[ "$OSTYPE" == "linux"* ]]; then
49+
port=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
50+
elif [[ "$OSTYPE" == "darwin"* ]]; then
51+
port=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
52+
else
53+
echo "skipping due to unsupported OS"
54+
exit 0
55+
fi
56+
}
57+
58+
WOLFSSL_SERVER=./examples/server/server
59+
60+
start_wolfssl_server() {
61+
generate_port
62+
server_port=$port
63+
$WOLFSSL_SERVER -p $server_port -v 4 -c $CERT_DIR/rsapss/server-rsapss.pem -k $CERT_DIR/rsapss/server-rsapss-priv.pem -A $CERT_DIR/rsapss/root-rsapss.pem -d &
64+
}
65+
66+
#
67+
# Run OpenSSL client against wolfSSL server
68+
#
69+
do_openssl_client() {
70+
echo "test connection" | $OPENSSL s_client -connect 127.0.0.1:$server_port -cert $CERT_DIR/rsapss/client-rsapss.pem -key $CERT_DIR/rsapss/client-rsapss-priv.pem -CAfile $CERT_DIR/rsapss/root-rsapss.pem > rsapss.test.log
71+
result=$?
72+
cat rsapss.test.log
73+
if [ $result != 0 ]
74+
then
75+
echo "$OPENSSL s_client command failed"
76+
exit 1
77+
fi
78+
grep -q "Peer signature type:.*rsa_pss_rsae_sha256" rsapss.test.log
79+
result=$?
80+
rm -f rsapss.test.log
81+
if [ $result == 0 ]
82+
then
83+
echo "Test failed: Peer signature type identified as rsa_pss_rsae_sha256"
84+
exit 1
85+
fi
86+
}
87+
88+
start_wolfssl_server
89+
sleep 1
90+
do_openssl_client
91+
echo -e "\nSuccess!\n\n"
92+
exit 0

src/internal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7005,6 +7005,9 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
70057005
#endif
70067006
#ifndef NO_RSA
70077007
ssl->options.minRsaKeySz = ctx->minRsaKeySz;
7008+
#ifdef WC_RSA_PSS
7009+
ssl->useRsaPss = ctx->useRsaPss;
7010+
#endif
70087011
#endif
70097012
#ifdef HAVE_ECC
70107013
ssl->options.minEccKeySz = ctx->minEccKeySz;

src/ssl_load.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,14 @@ 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->useRsaPss = cert->keyOID == RSAPSSk;
1630+
}
1631+
if (ctx) {
1632+
ctx->useRsaPss = cert->keyOID == RSAPSSk;
1633+
}
1634+
#endif
16271635
break;
16281636
#endif /* !NO_RSA */
16291637
#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->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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3914,6 +3914,9 @@ struct WOLFSSL_CTX {
39143914
#endif
39153915
#ifndef NO_RSA
39163916
short minRsaKeySz; /* minimum RSA key size */
3917+
#ifdef WC_RSA_PSS
3918+
word8 useRsaPss; /* cert supports RSA-PSS */
3919+
#endif
39173920
#endif
39183921
#if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
39193922
short minEccKeySz; /* minimum ECC key size */
@@ -5944,6 +5947,9 @@ struct WOLFSSL {
59445947
byte* peerSceTsipEncRsaKeyIndex;
59455948
#endif
59465949
byte peerRsaKeyPresent;
5950+
#ifdef WC_RSA_PSS
5951+
word8 useRsaPss; /* cert supports RSA-PSS */
5952+
#endif
59475953
#endif
59485954
#if defined(WOLFSSL_TLS13) || defined(HAVE_FFDHE)
59495955
word16 namedGroup;

0 commit comments

Comments
 (0)