Skip to content

Commit 5e3c051

Browse files
authored
Merge pull request #75 from ColtonWilley/wp_openvpn_fixes
Changes for openvpn tests to run successfully
2 parents fc822c5 + ffee404 commit 5e3c051

File tree

6 files changed

+179
-27
lines changed

6 files changed

+179
-27
lines changed

.github/workflows/openvpn.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: OpenVPN Tests
2+
3+
# START OF COMMON SECTION
4+
on:
5+
push:
6+
branches: [ 'master', 'main', 'release/**' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
# END OF COMMON SECTION
14+
15+
jobs:
16+
build_wolfprovider:
17+
name: Build wolfProvider
18+
runs-on: ubuntu-22.04
19+
timeout-minutes: 20
20+
strategy:
21+
matrix:
22+
wolfssl_ref: [ 'master', 'v5.7.4-stable' ]
23+
steps:
24+
- name: Checkout wolfProvider
25+
uses: actions/checkout@v4
26+
27+
# Check if this version of wolfssl/wolfprovider has already been built,
28+
# mark to cache these items on post if we do end up building
29+
- name: Checking wolfSSL/wolfProvider in cache
30+
uses: actions/cache@v4
31+
id: wolfprov-cache
32+
with:
33+
path: |
34+
wolfssl-source
35+
wolfssl-install
36+
wolfprov-install
37+
provider.conf
38+
39+
key: wolfprov-${{ matrix.wolfssl_ref }}-${{ github.sha }}
40+
lookup-only: true
41+
42+
# If wolfssl/wolfprovider have not yet been built, pull ossl from cache
43+
- name: Checking OpenSSL in cache
44+
if: steps.wolfprov-${{ matrix.wolfssl_ref }}-cache.hit != 'true'
45+
uses: actions/cache@v4
46+
id: openssl-cache
47+
with:
48+
path: |
49+
openssl-source
50+
openssl-install
51+
52+
key: ossl-depends
53+
54+
# If not yet built this version, build it now
55+
- name: Build wolfProvider
56+
if: steps.wolfprov-${{ matrix.wolfssl_ref }}-cache.hit != 'true'
57+
run: |
58+
WOLFSSL_TAG=${{ matrix.wolfssl_ref }} ./scripts/build-wolfprovider.sh
59+
make check
60+
61+
- name: Print errors
62+
if: ${{ failure() }}
63+
run: |
64+
if [ -f test-suite.log ] ; then
65+
cat test-suite.log
66+
fi
67+
68+
test_openvpn:
69+
runs-on: ubuntu-22.04
70+
needs: build_wolfprovider
71+
# This should be a safe limit for the tests to run.
72+
timeout-minutes: 20
73+
strategy:
74+
matrix:
75+
openvpn_ref: [ 'master' ]
76+
wolfssl_ref: [ 'master', 'v5.7.4-stable' ]
77+
steps:
78+
- name: Retrieving OpenSSL from cache
79+
uses: actions/cache/restore@v4
80+
id: openssl-cache
81+
with:
82+
path: |
83+
openssl-source
84+
openssl-install
85+
86+
key: ossl-depends
87+
fail-on-cache-miss: true
88+
89+
- name: Retrieving wolfSSL/wolfProvider from cache
90+
uses: actions/cache/restore@v4
91+
id: wolfprov-cache
92+
with:
93+
path: |
94+
wolfssl-source
95+
wolfssl-install
96+
wolfprov-install
97+
provider.conf
98+
99+
key: wolfprov-${{ matrix.wolfssl_ref }}-${{ github.sha }}
100+
fail-on-cache-miss: true
101+
102+
- name: Install test dependencies
103+
run: |
104+
sudo apt-get update
105+
sudo apt-get install liblzo2-dev libpam0g-dev liblz4-dev libcap-ng-dev \
106+
linux-libc-dev man2html libcmocka-dev python3-docutils \
107+
libtool automake autoconf libnl-genl-3-dev libnl-genl-3-200
108+
109+
- name: Build and test OpenVPN
110+
uses: wolfSSL/actions-build-autotools-project@v1
111+
with:
112+
repository: OpenVPN/openvpn
113+
path: openvpn
114+
ref: ${{ matrix.openvpn_ref }}
115+
configure:
116+
check: false
117+
118+
- name: Test OpenVPN with wolfProvider
119+
working-directory: openvpn
120+
run: |
121+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/wolfssl-install/lib:$GITHUB_WORKSPACE/openssl-install/lib64
122+
export OPENSSL_CONF=$GITHUB_WORKSPACE/provider.conf
123+
export OPENSSL_MODULES=$GITHUB_WORKSPACE/wolfprov-install/lib
124+
make check

scripts/utils-openssl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ install_openssl() {
7070
if [ ! -d ${OPENSSL_INSTALL_DIR} ]; then
7171
printf "\tConfigure OpenSSL ${OPENSSL_TAG} ... "
7272
if [ "$WOLFPROV_DEBUG" = "1" ]; then
73-
./config shared --prefix=${OPENSSL_INSTALL_DIR} --debug >>$LOG_FILE 2>&1
73+
./config shared enable-trace --prefix=${OPENSSL_INSTALL_DIR} --debug >>$LOG_FILE 2>&1
7474
RET=$?
7575
else
7676
./config shared --prefix=${OPENSSL_INSTALL_DIR} >>$LOG_FILE 2>&1

src/wp_dh_kmgmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,7 @@ static int wp_dh_decode(wp_DhEncDecCtx* ctx, OSSL_CORE_BIO *cBio,
21192119
ok = 0;
21202120
}
21212121
if (ok && (ctx->format == WP_ENC_FORMAT_TYPE_SPECIFIC)) {
2122-
if (selection == OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) {
2122+
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) {
21232123
if (!wp_dh_decode_params(dh, data, len)) {
21242124
ok = 0;
21252125
decoded = 0;

src/wp_ecc_kmgmt.c

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,12 @@ static wp_Ecc* wp_ecc_gen(wp_EccGenCtx *ctx, OSSL_CALLBACK *cb, void *cbArg)
16441644
}
16451645
}
16461646
}
1647+
if (ok && ((ctx->selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)) {
1648+
rc = wc_ecc_set_curve(&ecc->key, 0, ecc->curveId);
1649+
if (rc != 0) {
1650+
ok = 0;
1651+
}
1652+
}
16471653
if (!ok) {
16481654
wp_ecc_free(ecc);
16491655
ecc = NULL;
@@ -2131,11 +2137,19 @@ static int wp_ecc_decode(wp_EccEncDecCtx* ctx, OSSL_CORE_BIO *cBio,
21312137
*/
21322138
static int wp_ecc_encode_params_size(const wp_Ecc *ecc, size_t* keyLen)
21332139
{
2134-
/* ASN.1 type, len and data. */
2135-
*keyLen = ecc->key.dp->oidSz + 2;
2140+
int ok = 1;
2141+
word32 len = 0;
21362142

2137-
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
2138-
return 1;
2143+
if (wc_ecc_get_oid(ecc->key.dp->oidSum, NULL, &len) <= 0) {
2144+
ok = 0;
2145+
}
2146+
if (ok) {
2147+
/* ASN.1 type, len and data. */
2148+
*keyLen = len + 2;
2149+
}
2150+
2151+
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2152+
return ok;
21392153
}
21402154

21412155
/**
@@ -2151,14 +2165,22 @@ static int wp_ecc_encode_params_size(const wp_Ecc *ecc, size_t* keyLen)
21512165
static int wp_ecc_encode_params(const wp_Ecc *ecc, unsigned char* keyData,
21522166
size_t* keyLen)
21532167
{
2154-
keyData[0] = 0x06;
2155-
keyData[1] = ecc->key.dp->oidSz;
2156-
XMEMCPY(keyData + 2, ecc->key.dp->oid, ecc->key.dp->oidSz);
2168+
int ok = 1;
2169+
word32 len;
2170+
const byte *oid;
21572171

2158-
*keyLen = ecc->key.dp->oidSz + 2;
2172+
if (wc_ecc_get_oid(ecc->key.dp->oidSum, &oid, &len) <= 0) {
2173+
ok = 0;
2174+
}
2175+
if (ok) {
2176+
keyData[0] = 0x06;
2177+
keyData[1] = len;
2178+
XMEMCPY(keyData + 2, oid, len);
2179+
*keyLen = len + 2;
2180+
}
21592181

2160-
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
2161-
return 1;
2182+
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
2183+
return ok;
21622184
}
21632185

21642186
/**
@@ -2442,14 +2464,14 @@ static int wp_ecc_encode(wp_EccEncDecCtx* ctx, OSSL_CORE_BIO *cBio,
24422464

24432465
if (ok && ((ctx->format == WP_ENC_FORMAT_TYPE_SPECIFIC) ||
24442466
(ctx->format == WP_ENC_FORMAT_X9_62))) {
2445-
if (selection == OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) {
2446-
if (!wp_ecc_encode_params_size(key, &derLen)) {
2467+
if (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) {
2468+
private = 1;
2469+
if (!wp_ecc_encode_priv_size(key, &derLen)) {
24472470
ok = 0;
24482471
}
24492472
}
2450-
else {
2451-
private = 1;
2452-
if (!wp_ecc_encode_priv_size(key, &derLen)) {
2473+
else if (selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) {
2474+
if (!wp_ecc_encode_params_size(key, &derLen)) {
24532475
ok = 0;
24542476
}
24552477
}
@@ -2484,13 +2506,7 @@ static int wp_ecc_encode(wp_EccEncDecCtx* ctx, OSSL_CORE_BIO *cBio,
24842506

24852507
if (ok && ((ctx->format == WP_ENC_FORMAT_TYPE_SPECIFIC) ||
24862508
(ctx->format == WP_ENC_FORMAT_X9_62))) {
2487-
if (selection == OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) {
2488-
pemType = DH_PARAM_TYPE;
2489-
if (!wp_ecc_encode_params(key, derData, &derLen)) {
2490-
ok = 0;
2491-
}
2492-
}
2493-
else {
2509+
if (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) {
24942510
if (ctx->format == WP_ENC_FORMAT_X9_62) {
24952511
pemType = ECC_PRIVATEKEY_TYPE;
24962512
}
@@ -2499,6 +2515,12 @@ static int wp_ecc_encode(wp_EccEncDecCtx* ctx, OSSL_CORE_BIO *cBio,
24992515
ok = 0;
25002516
}
25012517
}
2518+
else if (selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) {
2519+
pemType = DH_PARAM_TYPE;
2520+
if (!wp_ecc_encode_params(key, derData, &derLen)) {
2521+
ok = 0;
2522+
}
2523+
}
25022524
}
25032525
else if (ok && (ctx->format == WP_ENC_FORMAT_SPKI)) {
25042526
pemType = PUBLICKEY_TYPE;
@@ -2551,7 +2573,8 @@ static int wp_ecc_encode(wp_EccEncDecCtx* ctx, OSSL_CORE_BIO *cBio,
25512573
}
25522574
if (ok && ((ctx->format == WP_ENC_FORMAT_TYPE_SPECIFIC) ||
25532575
(ctx->format == WP_ENC_FORMAT_X9_62)) &&
2554-
(selection == OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS)) {
2576+
((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0) &&
2577+
(selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS)) {
25552578
pemData[11] = 'E';
25562579
pemData[12] = 'C';
25572580
pemData[pemLen - 19] = 'E';

src/wp_file_store.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ static wp_FileCtx* wp_file_open(WOLFPROV_CTX* provCtx, const char* uri)
109109
if (ctx != NULL) {
110110
int ok = 1;
111111

112-
/* TODO: support URI form 'file:'. */
112+
if (OPENSSL_strncasecmp(uri, "file:", 5) == 0) {
113+
uri += 5;
114+
if (OPENSSL_strncasecmp(uri, "//", 2) == 0) {
115+
/* TODO: may need more uri processing for windows cases */
116+
uri += 2;
117+
}
118+
}
113119
ctx->uri = OPENSSL_strdup(uri);
114120
if (ctx->uri == NULL) {
115121
ok = 0;

src/wp_wolfprov.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,6 @@ static const OSSL_ALGORITHM wolfprov_encoder[] = {
723723
wp_rsa_kp_pem_encoder_functions,
724724
"" },
725725
#ifdef WOLFSSL_RSA_PSS_ENCODING
726-
/* TODO: RSA-PSS encoding isn't supported in wolfSSL */
727726
{ WP_NAMES_RSA_PSS, WP_ENCODER_PROPERTIES(SubjectPublicKeyInfo, der),
728727
wp_rsapss_spki_der_encoder_functions,
729728
"" },

0 commit comments

Comments
 (0)