Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ EXTRA_DIST += scripts/sniffer-static-rsa.pcap \

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

EXTRA_DIST += scripts/dertoc.pl

Expand Down
92 changes: 92 additions & 0 deletions scripts/rsapss.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env bash

# rsapss.test

if ! ./examples/client/client -V | grep -q 4; then
echo "skipping because TLS 1.3 not enabled in this build"
exit 0
fi
if ! grep -q -- -DWC_RSA_PSS config.log 2>/dev/null; then
echo "skipping because WC_RSA_PSS not enabled in this build"
exit 0
fi
if ! grep -q -- '-DHAVE_ECC\>' config.log 2>/dev/null; then
echo "skipping because HAVE_ECC not enabled in this build"
exit 0
fi
if grep -q -- '-DNO_CODING' config.log 2>/dev/null; then
echo "skipping because NO_CODING is defined in this build"
exit 0
fi

CERT_DIR="$PWD/$(dirname "$0")/../certs"
if [ "$OPENSSL" = "" ]; then
OPENSSL=openssl
fi

# if we can, isolate the network namespace to eliminate port collisions.
if [[ -n "$NETWORK_UNSHARE_HELPER" ]]; then
if [[ -z "$NETWORK_UNSHARE_HELPER_CALLED" ]]; then
export NETWORK_UNSHARE_HELPER_CALLED=yes
exec "$NETWORK_UNSHARE_HELPER" "$0" "$@" || exit $?
fi
elif [ "${AM_BWRAPPED-}" != "yes" ]; then
bwrap_path="$(command -v bwrap)"
if [ -n "$bwrap_path" ]; then
export AM_BWRAPPED=yes
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
fi
unset AM_BWRAPPED
fi

# need a unique port since may run the same time as testsuite
generate_port() {
#-------------------------------------------------------------------------#
# Generate a random port number
#-------------------------------------------------------------------------#

if [[ "$OSTYPE" == "linux"* ]]; then
port=$(($(od -An -N2 /dev/urandom) % (65535-49512) + 49512))
elif [[ "$OSTYPE" == "darwin"* ]]; then
port=$(($(od -An -N2 /dev/random) % (65535-49512) + 49512))
else
echo "skipping due to unsupported OS"
exit 0
fi
}

WOLFSSL_SERVER=./examples/server/server

start_wolfssl_server() {
generate_port
server_port=$port
$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 &
}

#
# Run OpenSSL client against wolfSSL server
#
do_openssl_client() {
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
result=$?
cat rsapss.test.log
if [ $result != 0 ]
then
echo "$OPENSSL s_client command failed"
exit 1
fi
grep -q "Peer signature type:.*rsa_pss_rsae_sha256" rsapss.test.log
result=$?
rm -f rsapss.test.log
if [ $result == 0 ]
then
echo "Test failed: Peer signature type identified as rsa_pss_rsae_sha256"
exit 1
fi
}

start_wolfssl_server
sleep 1
do_openssl_client
echo -e "\nSuccess!\n\n"
exit 0
3 changes: 3 additions & 0 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -6983,6 +6983,9 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
#endif
#ifndef NO_RSA
ssl->options.minRsaKeySz = ctx->minRsaKeySz;
#ifdef WC_RSA_PSS
ssl->useRsaPss = ctx->useRsaPss;
#endif
#endif
#ifdef HAVE_ECC
ssl->options.minEccKeySz = ctx->minEccKeySz;
Expand Down
8 changes: 8 additions & 0 deletions src/ssl_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,14 @@ static int ProcessBufferCertPublicKey(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
ret = CHECK_KEY_SZ(ssl ? ssl->options.minRsaKeySz :
ctx->minRsaKeySz, RSA_MAX_SIZE / 8, keySz, RSA_KEY_SIZE_E);
}
#ifdef WC_RSA_PSS
if (ssl) {
ssl->useRsaPss = cert->keyOID == RSAPSSk;
}
if (ctx) {
ctx->useRsaPss = cert->keyOID == RSAPSSk;
}
#endif
break;
#endif /* !NO_RSA */
#ifdef HAVE_ECC
Expand Down
23 changes: 19 additions & 4 deletions src/tls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -7867,8 +7867,9 @@ static int SendTls13CertificateRequest(WOLFSSL* ssl, byte* reqCtx,
* hsType The signature type.
* output The buffer to encode into.
*/
static WC_INLINE void EncodeSigAlg(byte hashAlgo, byte hsType, byte* output)
static WC_INLINE void EncodeSigAlg(const WOLFSSL * ssl, byte hashAlgo, byte hsType, byte* output)
{
(void)ssl;
switch (hsType) {
#ifdef HAVE_ECC
case ecc_dsa_sa_algo:
Expand Down Expand Up @@ -7899,10 +7900,24 @@ static WC_INLINE void EncodeSigAlg(byte hashAlgo, byte hsType, byte* output)
break;
#endif
#ifndef NO_RSA
/* PSS signatures: 0x080[4-6] */
/* PSS signatures: 0x080[4-6] or 0x080[9-B] */
case rsa_pss_sa_algo:
output[0] = rsa_pss_sa_algo;
output[1] = hashAlgo;
#ifdef WC_RSA_PSS
/* If the private key uses the RSA-PSS OID, and the peer supports
* the rsa_pss_pss_* signature algorithm in use, then report
* rsa_pss_pss_* rather than rsa_pss_rsae_*. */
if (ssl->useRsaPss &&
((ssl->pssAlgo & (1U << hashAlgo)) != 0U) &&
(sha256_mac <= hashAlgo) && (hashAlgo <= sha512_mac))
{
output[1] = PSS_RSAE_TO_PSS_PSS(hashAlgo);
}
else
#endif
{
output[1] = hashAlgo;
}
break;
#endif
#ifdef HAVE_FALCON
Expand Down Expand Up @@ -9361,7 +9376,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
}
else
#endif /* WOLFSSL_DUAL_ALG_CERTS */
EncodeSigAlg(ssl->options.hashAlgo, args->sigAlgo,
EncodeSigAlg(ssl, ssl->options.hashAlgo, args->sigAlgo,
args->verify);

if (args->sigData == NULL) {
Expand Down
6 changes: 6 additions & 0 deletions wolfssl/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3907,6 +3907,9 @@ struct WOLFSSL_CTX {
#endif
#ifndef NO_RSA
short minRsaKeySz; /* minimum RSA key size */
#ifdef WC_RSA_PSS
word8 useRsaPss; /* cert supports RSA-PSS */
#endif
#endif
#if defined(HAVE_ECC) || defined(HAVE_ED25519) || defined(HAVE_ED448)
short minEccKeySz; /* minimum ECC key size */
Expand Down Expand Up @@ -5938,6 +5941,9 @@ struct WOLFSSL {
byte* peerSceTsipEncRsaKeyIndex;
#endif
byte peerRsaKeyPresent;
#ifdef WC_RSA_PSS
word8 useRsaPss; /* cert supports RSA-PSS */
#endif
#endif
#if defined(WOLFSSL_TLS13) || defined(HAVE_FFDHE)
word16 namedGroup;
Expand Down