Skip to content

Commit 8aa3142

Browse files
committed
Merge branch 'master' of github.com:ColtonWilley/wolfProvider into add-debug-silent-option
2 parents d98a90a + 4eeea87 commit 8aa3142

File tree

7 files changed

+608
-157
lines changed

7 files changed

+608
-157
lines changed

.github/workflows/debian-package.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,36 @@ jobs:
6262
name: debian-packages-${{ matrix.fips_ref }}${{ matrix.replace_default && '-replace-default' || '' }}-${{ matrix.wolfssl_ref }}-${{ matrix.openssl_ref }}
6363
path: /tmp
6464

65-
- name: Install wolfSSL/OpenSSL/wolfprov packages
65+
- name: Install OpenSSL packages
6666
run: |
67-
apt install --reinstall -y --allow-downgrades --allow-change-held-packages \
68-
${{ env.WOLFSSL_PACKAGES_PATH }}/libwolfssl_*.deb
67+
if [ "${{ matrix.replace_default }}" = "true" ]; then
68+
# Install OpenSSL packages for replace-default mode
69+
apt install --reinstall -y --allow-downgrades --allow-change-held-packages \
70+
${{ env.OPENSSL_PACKAGES_PATH }}/openssl_*.deb \
71+
${{ env.OPENSSL_PACKAGES_PATH }}/libssl3_*.deb \
72+
${{ env.OPENSSL_PACKAGES_PATH }}/libssl-dev_*.deb
73+
else
74+
# Install standard OpenSSL packages
75+
apt-get update
76+
apt-get install -y \
77+
openssl libssl3 libssl-dev
78+
fi
6979
80+
- name: Install wolfSSL and wolfProvider packages
81+
run: |
7082
apt install --reinstall -y --allow-downgrades --allow-change-held-packages \
71-
${{ env.OPENSSL_PACKAGES_PATH }}/openssl_*.deb \
72-
${{ env.OPENSSL_PACKAGES_PATH }}/libssl3_*.deb \
73-
${{ env.OPENSSL_PACKAGES_PATH }}/libssl-dev_*.deb
83+
${{ env.WOLFSSL_PACKAGES_PATH }}/libwolfssl_*.deb
7484
7585
apt install --reinstall -y --allow-downgrades --allow-change-held-packages \
7686
${{ env.WOLFPROV_PACKAGES_PATH }}/libwolfprov_*.deb
7787
88+
# In standalone mode, use OPENSSL_CONF to enable wolfProvider.
89+
if [ "${{ matrix.replace_default }}" = "false" ]; then
90+
echo "Setting OPENSSL_CONF to /etc/ssl/openssl.cnf.d/wolfprovider.conf"
91+
# export OPENSSL_CONF=/etc/ssl/openssl.cnf.d/wolfprovider.conf
92+
echo "OPENSSL_CONF=/etc/ssl/openssl.cnf.d/wolfprovider.conf" >> "$GITHUB_ENV"
93+
fi
94+
7895
- name: Verify wolfProvider is properly installed
7996
run: |
8097
$GITHUB_WORKSPACE/scripts/verify-install.sh \

debian/install-wolfprov.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ main() {
189189
fi
190190

191191
if [ -n "$output_dir" ]; then
192-
output_dir=$(realpath $output_dir)
192+
output_dir=$(realpath "$output_dir")
193193
fi
194194

195195
work_dir=$(mktemp -d)

debian/libwolfprov.postinst

Lines changed: 97 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#!/bin/sh
22
set -e
33

4-
# Define the include line to add to the openssl.cnf file
5-
INCLUDE_LINE=".include /etc/ssl/openssl.cnf.d/wolfprovider.conf"
6-
7-
# Search for the openssl.cnf file in /usr, /lib and /etc
8-
CONF_FILES=$(find /usr /lib /etc -name openssl.cnf 2>/dev/null)
9-
104
# Check if we are in replace-default mode by reading the openssl version
115
REPLACE_DEFAULT=0
126
if command -v openssl >/dev/null 2>&1; then
@@ -16,29 +10,104 @@ if command -v openssl >/dev/null 2>&1; then
1610
fi
1711
fi
1812

19-
if [ $REPLACE_DEFAULT -eq 1 ]; then
20-
# Remove INCLUDE_LINE from each CONF_FILE
21-
# Replace default mode should automatically find wolfProvider.
22-
# Using the config file or OPENSSL_CONF will cause:
23-
# 1. the provider name to be 'libwolfprov' instead of 'default'
24-
# 2. the provider init call to happen twice
25-
# Neither of these is harmful, but it's not ideal.
26-
for CONF_FILE in $CONF_FILES; do
27-
# Remove any line containing both ".include" and "wolfprovider.conf"
28-
sed -i '/\.include/ { /wolfprovider\.conf/ d; }' "$CONF_FILE"
29-
printf "Removed wolfprovider include line(s) from %s\n" "$CONF_FILE"
30-
done
31-
else
32-
# For each CONF_FILE, apply the include line to the openssl.cnf file, if not already applied
33-
for CONF_FILE in $CONF_FILES; do
34-
if grep -qF "$INCLUDE_LINE" "$CONF_FILE"; then
35-
echo "Include line already exists in $CONF_FILE"
36-
else
37-
echo "Adding include for wolfprovider to $CONF_FILE..."
38-
echo "$INCLUDE_LINE" >> "$CONF_FILE"
39-
fi
40-
done
13+
if [ "$1" = "configure" ]; then
14+
if [ $REPLACE_DEFAULT -eq 1 ]; then
15+
cat <<'EOF'
16+
============================================================
17+
wolfProvider Installation Notes
18+
============================================================
19+
20+
wolfProvider is installed in replace-default mode with a
21+
patched version of OpenSSL that uses wolfProvider as the
22+
crypto backend. wolfProvider will appear as the 'default'
23+
provider.
24+
25+
No other conf file modifications or environment variables
26+
are required.
27+
28+
To verify installation, run:
29+
openssl version
30+
openssl list -providers
31+
32+
wolfProvider configuration file installed at:
33+
/etc/ssl/openssl.cnf.d/wolfprovider.conf
34+
35+
============================================================
36+
EOF
37+
else
38+
cat <<'EOF'
39+
============================================================
40+
wolfProvider Installation Notes
41+
============================================================
42+
43+
To use wolfProvider with OpenSSL, choose ONE of the options
44+
below depending on your use case.
45+
46+
1) System-wide enable:
47+
48+
Add the following line to your /etc/ssl/openssl.cnf:
49+
50+
.include /etc/ssl/openssl.cnf.d/wolfprovider.conf
51+
52+
This makes wolfProvider available to applications that
53+
execute with the standard system OpenSSL configuration.
54+
Note that many applications, such as anything executing
55+
from systemd, will ignore the global configuration
56+
entirely and will not use wolfProvider.
57+
58+
59+
2) Per-command enable (no system-wide changes)
60+
61+
Set OPENSSL_CONF environment variable when running applications:
62+
63+
OPENSSL_CONF=/etc/ssl/openssl.cnf.d/wolfprovider.conf <your-application>
64+
65+
Most applications with standard environment variable handling will
66+
be able to use this method, not just the openssl binary. For example:
67+
68+
OPENSSL_CONF=/etc/ssl/openssl.cnf.d/wolfprovider.conf openssl <command>
69+
70+
This enables use of wolfProvider whenever the environment variable
71+
is set for the current shell.
72+
73+
74+
3) Application-level integration (for developers)
75+
76+
In your application, you can create a dedicated OpenSSL
77+
library context and explicitly load wolfProvider, e.g.:
78+
79+
OSSL_LIB_CTX *wpLibCtx = OSSL_LIB_CTX_new();
80+
OSSL_PROVIDER *wpProv = OSSL_PROVIDER_load(wpLibCtx, "wolfprovider");
81+
/* Use wpLibCtx with EVP, etc. */
82+
EVP_function(wpLibCtx, ...);
83+
OSSL_PROVIDER_unload(wpProv);
84+
OSSL_LIB_CTX_free(wpLibCtx);
85+
86+
This keeps wolfProvider usage scoped to specific code paths
87+
without requiring any system-wide configuration changes.
88+
89+
To verify installation and configuration, run:
90+
openssl version
91+
openssl list -providers
92+
93+
wolfProvider configuration file installed at:
94+
/etc/ssl/openssl.cnf.d/wolfprovider.conf
95+
96+
============================================================
97+
EOF
98+
fi
4199
fi
42100

101+
# Search for the openssl.cnf file in /usr, /lib and /etc
102+
CONF_FILES=$(find /usr /lib /etc -name openssl.cnf 2>/dev/null)
103+
104+
# Warn user on install or removal if our config file is already included.
105+
for CONF_FILE in $CONF_FILES; do
106+
if grep '.include' "$CONF_FILE" | grep -q "wolfprovider.conf"; then
107+
echo "WARNING: wolfprovider.conf is already included in $CONF_FILE"
108+
fi
109+
done
110+
111+
43112
#DEBHELPER#
44113
exit 0

src/wp_rsa_kmgmt.c

Lines changed: 113 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,72 @@ static int wp_rsa_get_params_key_data(wp_Rsa* rsa, OSSL_PARAM params[])
909909
return ok;
910910
}
911911

912+
/**
913+
* Convert a wolfCrypt hashType to the equivalent OpenSSL digest name.
914+
*
915+
* @param [in] hashType WolfProvider digest id.
916+
* @param [out] osslDigest Corresponding OpenSSL digest name.
917+
* @return 1 on success.
918+
* @return 0 on failure.
919+
*/
920+
static int wp_digest_to_ossl_digest(enum wc_HashType hashType,
921+
const char** osslDigest)
922+
{
923+
int ok = 1;
924+
925+
switch (hashType) {
926+
case WC_HASH_TYPE_MD5:
927+
*osslDigest = OSSL_DIGEST_NAME_MD5;
928+
break;
929+
930+
case WC_HASH_TYPE_SHA:
931+
*osslDigest = OSSL_DIGEST_NAME_SHA1;
932+
break;
933+
934+
case WC_HASH_TYPE_SHA256:
935+
*osslDigest = OSSL_DIGEST_NAME_SHA2_256;
936+
break;
937+
938+
case WC_HASH_TYPE_SHA384:
939+
*osslDigest = OSSL_DIGEST_NAME_SHA2_384;
940+
break;
941+
942+
case WC_HASH_TYPE_SHA512:
943+
*osslDigest = OSSL_DIGEST_NAME_SHA2_512;
944+
break;
945+
946+
case WC_HASH_TYPE_NONE:
947+
case WC_HASH_TYPE_MD2:
948+
case WC_HASH_TYPE_MD4:
949+
case WC_HASH_TYPE_SHA224:
950+
case WC_HASH_TYPE_MD5_SHA:
951+
case WC_HASH_TYPE_SHA3_224:
952+
case WC_HASH_TYPE_SHA3_256:
953+
case WC_HASH_TYPE_SHA3_384:
954+
case WC_HASH_TYPE_SHA3_512:
955+
case WC_HASH_TYPE_BLAKE2B:
956+
case WC_HASH_TYPE_BLAKE2S:
957+
#ifndef WOLFSSL_NOSHA512_224
958+
case WC_HASH_TYPE_SHA512_224:
959+
#endif
960+
#ifndef WOLFSSL_NOSHA512_256
961+
case WC_HASH_TYPE_SHA512_256:
962+
#endif
963+
#ifdef WOLFSSL_SHAKE128
964+
case WC_HASH_TYPE_SHAKE128:
965+
#endif
966+
#ifdef WOLFSSL_SHAKE256
967+
case WC_HASH_TYPE_SHAKE256:
968+
#endif
969+
#ifdef WOLFSSL_SM3
970+
case WC_HASH_TYPE_SM3:
971+
#endif
972+
ok = 0;
973+
}
974+
975+
return ok;
976+
}
977+
912978
/**
913979
* Get the PSS parameters into the parameters array.
914980
*
@@ -921,19 +987,22 @@ static int wp_rsa_get_params_pss(wp_RsaPssParams* pss, OSSL_PARAM params[])
921987
{
922988
int ok = 1;
923989
OSSL_PARAM* p;
990+
const char* osslDigest = NULL;
924991

925992
WOLFPROV_ENTER(WP_LOG_COMP_RSA, "wp_rsa_get_params_pss");
926993

927994
if (pss->hashType != WP_RSA_PSS_DIGEST_DEF) {
928995
p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_RSA_DIGEST);
929-
if ((p != NULL) && !OSSL_PARAM_set_utf8_string(p, pss->mdName)) {
996+
if ((p != NULL) && wp_digest_to_ossl_digest(pss->hashType, &osslDigest)
997+
&& !OSSL_PARAM_set_utf8_string(p, osslDigest)) {
930998
ok = 0;
931999
}
9321000
}
9331001
/* MGF is default so don't set. */
9341002
if (ok && (pss->mgf != WP_RSA_PSS_MGF_DEF)) {
9351003
p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_RSA_MGF1_DIGEST);
936-
if ((p != NULL) && !OSSL_PARAM_set_utf8_string(p, pss->mgfMdName)) {
1004+
if ((p != NULL) && wp_digest_to_ossl_digest(pss->hashType, &osslDigest)
1005+
&& !OSSL_PARAM_set_utf8_string(p, osslDigest)) {
9371006
ok = 0;
9381007
}
9391008
}
@@ -1144,7 +1213,7 @@ static int wp_rsa_import_key_data(wp_Rsa* rsa, const OSSL_PARAM params[],
11441213

11451214
/* N and E params are the only ones required by OSSL, so match that.
11461215
* See ossl_rsa_fromdata() and RSA_set0_key() in OpenSSL. */
1147-
if (OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_N) == NULL ||
1216+
if (OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_N) == NULL ||
11481217
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E) == NULL) {
11491218
WOLFPROV_MSG(WP_LOG_COMP_RSA, "Param N or E is missing");
11501219
ok = 0;
@@ -1160,7 +1229,7 @@ static int wp_rsa_import_key_data(wp_Rsa* rsa, const OSSL_PARAM params[],
11601229
index = -1;
11611230
for (j = 0; j < (int)ARRAY_SIZE(wp_rsa_param_key); j++) {
11621231
if (XSTRNCMP(p->key, wp_rsa_param_key[j], XSTRLEN(p->key)) == 0) {
1163-
index = j;
1232+
index = j;
11641233
break;
11651234
}
11661235
}
@@ -2374,7 +2443,7 @@ static int wp_rsa_decode_enc_pki(wp_Rsa* rsa, unsigned char* data, word32 len,
23742443
size_t passwordSz = sizeof(password);
23752444

23762445
WOLFPROV_ENTER_SILENT(WP_LOG_COMP_RSA, WOLFPROV_FUNC_NAME);
2377-
2446+
23782447
if (!wolfssl_prov_is_running()) {
23792448
ok = 0;
23802449
}
@@ -2567,7 +2636,7 @@ int wp_rsa_pss_encode_alg_id(const wp_Rsa* rsa, const char* mdName,
25672636
WOLFPROV_ENTER(WP_LOG_COMP_RSA, "wp_rsa_pss_encode_alg_id");
25682637

25692638
if (pssAlgId == NULL) {
2570-
/* Length opf header without optional parts. */
2639+
/* Length of header without optional parts. */
25712640
i = 2 + sizeof(rsa_pss_oid) + 2;
25722641
}
25732642
else {
@@ -2928,6 +2997,14 @@ static int wp_rsa_encode_pki_size(const wp_Rsa* rsa, size_t* keyLen, int algoId)
29282997
if (ok) {
29292998
*keyLen = len;
29302999
}
3000+
if (ok && (rsa->type == RSA_FLAG_TYPE_RSASSAPSS)) {
3001+
word32 pssLen = 0;
3002+
ok = wp_rsa_pss_encode_alg_id(rsa, rsa->pssParams.mdName,
3003+
rsa->pssParams.mgfMdName, rsa->pssParams.saltLen, NULL, &pssLen);
3004+
if (ok) {
3005+
*keyLen += pssLen;
3006+
}
3007+
}
29313008

29323009
WOLFPROV_LEAVE(WP_LOG_COMP_RSA, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
29333010
return ok;
@@ -2981,6 +3058,36 @@ static int wp_rsa_encode_pki(const wp_Rsa* rsa, unsigned char* keyData,
29813058
ok = 0;
29823059
}
29833060
}
3061+
if (ok && rsa->type == RSA_FLAG_TYPE_RSASSAPSS) {
3062+
word32 pssLen = 0;
3063+
word32 i;
3064+
3065+
/* Find where Algorithm ID is by looking for RSA PKCS#1 OID. */
3066+
ok = wp_rsa_find_oid(keyData, ret, rsa_pkcs1_oid, RSA_PKCS1_OID_SZ,
3067+
&i);
3068+
if (ok) {
3069+
i += 11;
3070+
/* Get length of encoded RSA-PSS Algorithm ID. */
3071+
ok = wp_rsa_pss_encode_alg_id(rsa, rsa->pssParams.mdName,
3072+
rsa->pssParams.mgfMdName, rsa->pssParams.saltLen, NULL,
3073+
&pssLen);
3074+
}
3075+
if (ok) {
3076+
/* Move rest of key to after RSA-PSS Algorithm ID. */
3077+
XMEMMOVE(keyData + 7 + pssLen, keyData + i, ret - i);
3078+
/* Encode RSA-PSS Algorithm ID. */
3079+
ok = wp_rsa_pss_encode_alg_id(rsa, rsa->pssParams.mdName,
3080+
rsa->pssParams.mgfMdName, rsa->pssParams.saltLen,
3081+
keyData + 7, &pssLen);
3082+
}
3083+
if (ok) {
3084+
/* Update return length. */
3085+
ret += pssLen - 13;
3086+
/* Update first sequence. */
3087+
keyData[2] = (byte)((ret - 4) >> 8);
3088+
keyData[3] = (byte)((ret - 4) & 0xff);
3089+
}
3090+
}
29843091
if (ok) {
29853092
*keyLen = ret;
29863093
}

0 commit comments

Comments
 (0)