Skip to content

Commit cf77626

Browse files
committed
Initial draft of option to replace openssl default provider
1 parent 0de5133 commit cf77626

File tree

13 files changed

+334
-16
lines changed

13 files changed

+334
-16
lines changed

Makefile.am

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
SUFFIXES =
2+
SUFFIXES =
33
TESTS =
44
noinst_PROGRAMS =
55
noinst_HEADERS =
@@ -14,6 +14,13 @@ AM_CPPFLAGS = -I$(top_srcdir)/include
1414

1515
lib_LTLIBRARIES = libwolfprov.la
1616

17+
# Conditionally build libdefault.so when --replace-default is enabled
18+
if BUILD_REPLACE_DEFAULT
19+
lib_LTLIBRARIES += libdefault.la
20+
libdefault_la_SOURCES = src/wp_default_replace.c
21+
libdefault_la_LIBADD = libwolfprov.la
22+
endif
23+
1724
EXTRA_DIST+=ChangeLog.md
1825
EXTRA_DIST+=README.md
1926
EXTRA_DIST+=IDE

configure.ac

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@ AS_IF([ test "x$ENABLED_SINGLETHREADED" = "xno" ],[
123123
])
124124
])
125125

126+
# Replace default provider
127+
AC_ARG_ENABLE([replace-default],
128+
[AS_HELP_STRING([--enable-replace-default],[Build real libdefault.so from wp_default_replace.c (default: disabled).])],
129+
[ ENABLED_REPLACE_DEFAULT=$enableval ],
130+
[ ENABLED_REPLACE_DEFAULT=no ]
131+
)
126132

127-
133+
AM_CONDITIONAL([BUILD_REPLACE_DEFAULT], [test "x$ENABLED_REPLACE_DEFAULT" = "xyes"])
128134

129135

130136
AX_HARDEN_CC_COMPILER_FLAGS
@@ -170,6 +176,7 @@ echo
170176
echo " Features "
171177
echo " * User settings: $ENABLED_USERSETTINGS"
172178
echo " * Dynamic provider: $ENABLED_DYNAMIC_PROVIDER"
179+
echo " * Replace default: $ENABLED_REPLACE_DEFAULT"
173180
echo ""
174181
echo "---"
175182

default_stub/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Makefile
2+
Makefile.in
3+
.deps/
4+
.libs/
5+
*.la
6+
*.lo
7+
*.o
8+
aclocal.m4
9+
autom4te.cache/
10+
config.log
11+
config.status
12+
configure
13+
libtool
14+
*.so
15+
*.so.*

default_stub/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib_LTLIBRARIES = libdefault.la
2+
libdefault_la_SOURCES = wp_default_stub.c

default_stub/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# libdefault - Default Provider Stub Library
2+
3+
Minimal autotools build for a stub version of the default provider.
4+
5+
## Building
6+
7+
```bash
8+
# Generate build system
9+
./autogen.sh
10+
11+
# Configure and build
12+
./configure
13+
make
14+
15+
# Clean build artifacts
16+
make clean
17+
```
18+
19+
## Output
20+
21+
The build produces `libdefault.so` in the `.libs/` directory.

default_stub/autogen.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
autoreconf -fiv

default_stub/configure.ac

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
AC_INIT([libdefault], [1.0], [support@wolfssl.com])
2+
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
3+
AC_PROG_CC
4+
AM_PROG_AR
5+
LT_INIT
6+
AC_CONFIG_FILES([Makefile])
7+
AC_OUTPUT

default_stub/wp_default_stub.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2006-2024 wolfSSL Inc.
3+
*
4+
* This file is part of wolfProvider.
5+
*
6+
* wolfProvider is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* wolfProvider is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <openssl/provider.h>
21+
22+
/* Prototype of public function that initializes the wolfSSL provider. */
23+
OSSL_provider_init_fn wolfssl_provider_init;
24+
25+
/* Prototype for the wolfprov_provider_init function */
26+
int wolfprov_provider_init(const OSSL_CORE_HANDLE* handle,
27+
const OSSL_DISPATCH* in,
28+
const OSSL_DISPATCH** out,
29+
void** provCtx);
30+
31+
/*
32+
* Provider implementation stub
33+
*/
34+
int wolfprov_provider_init(const OSSL_CORE_HANDLE* handle,
35+
const OSSL_DISPATCH* in,
36+
const OSSL_DISPATCH** out,
37+
void** provCtx)
38+
{
39+
return 0;
40+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/crypto/provider_predefined.c b/crypto/provider_predefined.c
2+
index 068e0b7..499a9ca 100644
3+
--- a/crypto/provider_predefined.c
4+
+++ b/crypto/provider_predefined.c
5+
@@ -10,21 +10,15 @@
6+
#include <openssl/core.h>
7+
#include "provider_local.h"
8+
9+
-OSSL_provider_init_fn ossl_default_provider_init;
10+
+OSSL_provider_init_fn wolfprov_provider_init;
11+
OSSL_provider_init_fn ossl_base_provider_init;
12+
OSSL_provider_init_fn ossl_null_provider_init;
13+
-OSSL_provider_init_fn ossl_fips_intern_provider_init;
14+
-#ifdef STATIC_LEGACY
15+
-OSSL_provider_init_fn ossl_legacy_provider_init;
16+
-#endif
17+
const OSSL_PROVIDER_INFO ossl_predefined_providers[] = {
18+
#ifdef FIPS_MODULE
19+
- { "fips", NULL, ossl_fips_intern_provider_init, NULL, 1 },
20+
+ { "fips", NULL, wolfprov_provider_init, NULL, 1 },
21+
#else
22+
- { "default", NULL, ossl_default_provider_init, NULL, 1 },
23+
-# ifdef STATIC_LEGACY
24+
- { "legacy", NULL, ossl_legacy_provider_init, NULL, 0 },
25+
-# endif
26+
+ { "default", NULL, wolfprov_provider_init, NULL, 1 },
27+
+ { "legacy", NULL, wolfprov_provider_init, NULL, 0 },
28+
{ "base", NULL, ossl_base_provider_init, NULL, 0 },
29+
{ "null", NULL, ossl_null_provider_init, NULL, 0 },
30+
#endif

scripts/build-wolfprovider.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ show_help() {
2020
echo " --fips-version=VER Choose the wolfSSL FIPS version"
2121
echo " --debian Build a Debian package"
2222
echo " --quicktest Disable some tests for a faster testing suite"
23+
echo " --replace-default Patch OpenSSL and build it so that wolfProvider is the default provider"
2324
echo ""
2425
echo "Environment Variables:"
2526
echo " OPENSSL_TAG OpenSSL tag to use (e.g., openssl-3.5.0)"
@@ -81,7 +82,6 @@ for arg in "$@"; do
8182
WOLFSSL_ISFIPS=1
8283
;;
8384
--fips-bundle=*)
84-
unset WOLFSSL_ISFIPS
8585
unset WOLFSSL_FIPS_CHECK_TAG
8686
IFS='=' read -r trash fips_bun <<< "$arg"
8787
if [ -z "$fips_bun" ]; then
@@ -113,6 +113,9 @@ for arg in "$@"; do
113113
--quicktest)
114114
WOLFPROV_QUICKTEST=1
115115
;;
116+
--replace-default)
117+
WOLFPROV_REPLACE_DEFAULT=1
118+
;;
116119
*)
117120
args_wrong+="$arg, "
118121
;;
@@ -144,6 +147,10 @@ source ${SCRIPT_DIR}/utils-wolfprovider.sh
144147

145148
echo "Using openssl: $OPENSSL_TAG, wolfssl: $WOLFSSL_TAG"
146149

150+
if [ "$WOLFPROV_REPLACE_DEFAULT" = "1" ]; then
151+
build_default_stub
152+
fi
153+
147154
init_wolfprov
148155

149156
exit $?

0 commit comments

Comments
 (0)