Skip to contentSkip to conversation

*** msvc: switch to openssl3 ***

PATCH Superseded Lev Stipakov 4 participants 8 messages Jan 21, 2022 – Feb 2, 2022

lore
Share & tools
lore
#0 lore raw

cover *** msvc: switch to openssl3 ***

From: Lev Stipakov <[email protected]...>

These two patches add openssl3 support for msvc build. The first one contains fixes to xkey code to make it compilable by msvc. Second one adds openssl3 port.

Lev Stipakov (2):
xkey: fix msvc build
msvc: switch to openssl3

 .github/workflows/build.yaml                  |   2 +-
 .../openssl3/detect_platform.cmake            |  86 ++++++++
 contrib/vcpkg-ports/openssl3/portfile.cmake   | 204 ++++++++++++++++++
 contrib/vcpkg-ports/openssl3/usage            |  11 +
 contrib/vcpkg-ports/openssl3/vcpkg.json       |   7 +
 .../vcpkg-ports/pkcs11-helper/portfile.cmake  |   2 +-
 src/openvpn/xkey_helper.c                     |   4 +-
 src/openvpn/xkey_provider.c                   |  13 +-
 8 files changed, 317 insertions(+), 12 deletions(-)
 create mode 100644 contrib/vcpkg-ports/openssl3/detect_platform.cmake
 create mode 100644 contrib/vcpkg-ports/openssl3/portfile.cmake
 create mode 100644 contrib/vcpkg-ports/openssl3/usage
 create mode 100644 contrib/vcpkg-ports/openssl3/vcpkg.json
Signature · 1 line
2.23.0.windows.1
#1 lore raw

PATCH 1/2 xkey: fix msvc build

From: Lev Stipakov <[email protected]...>

- use sizeof(void *) since msvc doesn't support sizeof of function ptr

- use XKEY_PROV_PROPS macro instead of props since msvc requires constant expression in aggregate initializers

---
 src/openvpn/xkey_helper.c   |  4 ++--
 src/openvpn/xkey_provider.c | 13 +++++--------
 2 files changed, 7 insertions(+), 10 deletions(-)
src/openvpn/xkey_helper.c +2 -2
index c667f7be..50231335 100644
@@ -125,8 +125,8 @@ xkey_load_generic_key(OSSL_LIB_CTX *libctx, void *handle, EVP_PKEY *pubkey,
         {"xkey-origin", OSSL_PARAM_UTF8_STRING, (char *) origin, 0, 0},
         {"pubkey", OSSL_PARAM_OCTET_STRING, &pubkey, sizeof(pubkey), 0},
         {"handle", OSSL_PARAM_OCTET_PTR, &handle, sizeof(handle), 0},
-        {"sign_op", OSSL_PARAM_OCTET_PTR, (void **) &sign_op, sizeof(sign_op), 0},
-        {"free_op", OSSL_PARAM_OCTET_PTR, (void **) &free_op, sizeof(free_op), 0},
+        {"sign_op", OSSL_PARAM_OCTET_PTR, (void **) &sign_op, sizeof(void *), 0},
+        {"free_op", OSSL_PARAM_OCTET_PTR, (void **) &free_op, sizeof(void *), 0},
         {NULL, 0, NULL, 0, 0}};
 
     /* Do not use EVP_PKEY_new_from_pkey as that will take keymgmt from pubkey */
src/openvpn/xkey_provider.c +5 -8
index c2d560c5..115b9931 100644
@@ -44,9 +44,6 @@
 #include <openssl/evp.h>
 #include <openssl/err.h>
 
-/* propq set all on all ops we implement */
-static const char *const props = XKEY_PROV_PROPS;
-
 /* A descriptive name */
 static const char *provname = "OpenVPN External Key Provider";
 
@@ -592,9 +589,9 @@ static const OSSL_DISPATCH ec_keymgmt_functions[] = {
 };
 
 const OSSL_ALGORITHM keymgmts[] = {
-    {"RSA:rsaEncryption", props, rsa_keymgmt_functions, "OpenVPN xkey RSA Key Manager"},
-    {"RSA-PSS:RSASSA-PSS", props, rsa_keymgmt_functions, "OpenVPN xkey RSA-PSS Key Manager"},
-    {"EC:id-ecPublicKey", props, ec_keymgmt_functions, "OpenVPN xkey EC Key Manager"},
+    {"RSA:rsaEncryption", XKEY_PROV_PROPS, rsa_keymgmt_functions, "OpenVPN xkey RSA Key Manager"},
+    {"RSA-PSS:RSASSA-PSS", XKEY_PROV_PROPS, rsa_keymgmt_functions, "OpenVPN xkey RSA-PSS Key Manager"},
+    {"EC:id-ecPublicKey", XKEY_PROV_PROPS, ec_keymgmt_functions, "OpenVPN xkey EC Key Manager"},
     {NULL, NULL, NULL, NULL}
 };
 
@@ -1074,8 +1071,8 @@ static const OSSL_DISPATCH signature_functions[] = {
 };
 
 const OSSL_ALGORITHM signatures[] = {
-    {"RSA:rsaEncryption", props, signature_functions, "OpenVPN xkey RSA Signature"},
-    {"ECDSA", props, signature_functions, "OpenVPN xkey ECDSA Signature"},
+    {"RSA:rsaEncryption", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey RSA Signature"},
+    {"ECDSA", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey ECDSA Signature"},
     {NULL, NULL, NULL, NULL}
 };
 
Signature · 1 line
2.23.0.windows.1
Acked-by on v1 1/2
#2 lore raw

Re: [Openvpn-devel] [PATCH 1/2] xkey: fix msvc build

Quoted 4 lines · Lev Stipakov

From: Lev Stipakov <[email protected]...>

- use sizeof(void *) since msvc doesn't support sizeof of function ptr

This is not just an msvc problem, but signals a bigger issue it seems. In retrospect, passing function pointers pickled this was probably a bad design decision on my part though we are forced by OpenSSL 3's design of using OSSL_PARAMs to pass data to providers.

For now, The proposed fix (i.e., to use void*) looks okay to me especially since its handled like a normal pointer during key import. But we may have to find a better way for passing these function pointers if this comes back to bite us.

Quoted 4 lines

- use XKEY_PROV_PROPS macro instead of props since msvc requires constant expression in aggregate initializers

Makes sense.

Quoted 72 lines
---
 src/openvpn/xkey_helper.c   |  4 ++--
 src/openvpn/xkey_provider.c | 13 +++++--------
 2 files changed, 7 insertions(+), 10 deletions(-)
src/openvpn/xkey_helper.c +1 -2
index c667f7be..50231335 100644
@@ -125,8 +125,8 @@ xkey_load_generic_key(OSSL_LIB_CTX *libctx, void
 *handle, EVP_PKEY *pubkey,
         {"xkey-origin", OSSL_PARAM_UTF8_STRING, (char *) origin, 0, 0},
         {"pubkey", OSSL_PARAM_OCTET_STRING, &pubkey, sizeof(pubkey), 0},
         {"handle", OSSL_PARAM_OCTET_PTR, &handle, sizeof(handle), 0},
-        {"sign_op", OSSL_PARAM_OCTET_PTR, (void **) &sign_op,
 sizeof(sign_op), 0},
-        {"free_op", OSSL_PARAM_OCTET_PTR, (void **) &free_op,
 sizeof(free_op), 0},
+        {"sign_op", OSSL_PARAM_OCTET_PTR, (void **) &sign_op, sizeof(void

*), 0},
+ {"free_op", OSSL_PARAM_OCTET_PTR, (void **) &free_op, sizeof(void
*), 0},

         {NULL, 0, NULL, 0, 0}};

     /* Do not use EVP_PKEY_new_from_pkey as that will take keymgmt from

pubkey */

src/openvpn/xkey_provider.c +1 -6
index c2d560c5..115b9931 100644
@@ -44,9 +44,6 @@
 #include <openssl/evp.h>
 #include <openssl/err.h>
 
-/* propq set all on all ops we implement */
-static const char *const props = XKEY_PROV_PROPS;
-
 /* A descriptive name */
 static const char *provname = "OpenVPN External Key Provider";
 
@@ -592,9 +589,9 @@ static const OSSL_DISPATCH ec_keymgmt_functions[] = {
 };
 
 const OSSL_ALGORITHM keymgmts[] = {
-    {"RSA:rsaEncryption", props, rsa_keymgmt_functions, "OpenVPN xkey RSA
 Key Manager"},
-    {"RSA-PSS:RSASSA-PSS", props, rsa_keymgmt_functions, "OpenVPN xkey
 RSA-PSS Key Manager"},
-    {"EC:id-ecPublicKey", props, ec_keymgmt_functions, "OpenVPN xkey EC
 Key Manager"},
+    {"RSA:rsaEncryption", XKEY_PROV_PROPS, rsa_keymgmt_functions,

"OpenVPN xkey RSA Key Manager"},
+ {"RSA-PSS:RSASSA-PSS", XKEY_PROV_PROPS, rsa_keymgmt_functions,
"OpenVPN xkey RSA-PSS Key Manager"},
+ {"EC:id-ecPublicKey", XKEY_PROV_PROPS, ec_keymgmt_functions, "OpenVPN
xkey EC Key Manager"},

     {NULL, NULL, NULL, NULL}

};

src/openvpn/xkey_provider.c +2 -2
@@ -1074,8 +1071,8 @@ static const OSSL_DISPATCH signature_functions[] = {
 };
 
 const OSSL_ALGORITHM signatures[] = {
-    {"RSA:rsaEncryption", props, signature_functions, "OpenVPN xkey RSA
 Signature"},
-    {"ECDSA", props, signature_functions, "OpenVPN xkey ECDSA Signature"},
+    {"RSA:rsaEncryption", XKEY_PROV_PROPS, signature_functions, "OpenVPN
 xkey RSA Signature"},
+    {"ECDSA", XKEY_PROV_PROPS, signature_functions, "OpenVPN xkey ECDSA
 Signature"},
     {NULL, NULL, NULL, NULL}
Quoted 1 line

};

#3 lore raw

[Openvpn-devel] [PATCH applied] Re: xkey: fix msvc build

In reply to Lev Stipakov

This time I'm sure I have an ACK :-) - and the changes look reasonable.

Compile tested on linux/3.0.1, just to avoid typos that went unnoticed (all fine).

Your patch has been applied to the master branch.

commit 627d1a3d286386067a93b755def308ea70060310

Author: Lev Stipakov
Date:   Fri Jan 21 07:22:58 2022 +0200
     xkey: fix msvc build

     Signed-off-by: Lev Stipakov <[email protected]...>
     Acked-by: Selva Nair <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg23643.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#4 lore raw

PATCH 2/2 msvc: switch to openssl3

In reply to Lev Stipakov

From: Lev Stipakov <[email protected]...>

Add openssl3 vcpkg port from https://github.com/microsoft/vcpkg/pull/20428/files
with some changes:

- switch to openssl 3.0.1
- add install_runtime make target to build openssl.exe
- create tools/openssl and copy there openssl.exe with dependency dlls

---
 .github/workflows/build.yaml                  |   2 +-
 .../openssl3/detect_platform.cmake            |  86 ++++++++
 contrib/vcpkg-ports/openssl3/portfile.cmake   | 204 ++++++++++++++++++
 contrib/vcpkg-ports/openssl3/usage            |  11 +
 contrib/vcpkg-ports/openssl3/vcpkg.json       |   7 +
 .../vcpkg-ports/pkcs11-helper/portfile.cmake  |   2 +-
 6 files changed, 310 insertions(+), 2 deletions(-)
 create mode 100644 contrib/vcpkg-ports/openssl3/detect_platform.cmake
 create mode 100644 contrib/vcpkg-ports/openssl3/portfile.cmake
 create mode 100644 contrib/vcpkg-ports/openssl3/usage
 create mode 100644 contrib/vcpkg-ports/openssl3/vcpkg.json
.github/workflows/build.yaml +1 -1
index 9f884ac2..f1a75736 100644
@@ -294,7 +294,7 @@ jobs:
         uses: lukka/[email protected]...
         with:
           vcpkgGitCommitId: 'a2fcb03749ff5897b5985092934dc6057680c789'
-          vcpkgArguments: 'openssl lz4 lzo pkcs11-helper tap-windows6'
+          vcpkgArguments: 'openssl3 lz4 lzo pkcs11-helper tap-windows6'
           vcpkgTriplet: '${{ matrix.triplet }}-windows-ovpn'
           cleanAfterBuild: false
 
contrib/vcpkg-ports/openssl3/detect_platform.cmake new file +86 -0

86 lines not on this page · raw message

contrib/vcpkg-ports/openssl3/portfile.cmake new file +204 -0

204 lines not on this page · raw message

contrib/vcpkg-ports/openssl3/usage new file +11 -0
new file mode 100644
index 00000000..1f4298f7
@@ -0,0 +1,11 @@
+The package openssl3 can be imported via CMake FindOpenSSL module:
+
+    find_package(OpenSSL REQUIRED)
+    target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)
+
+Also, FindPkgConfig module can be used if pkg-config(.pc) files are installed:
+
+    find_package(PkgConfig REQUIRED)
+    pkg_check_modules(openssl REQUIRED IMPORTED_TARGET GLOBAL openssl>=3.0)
+    
+    target_link_libraries(main PRIVATE PkgConfig::openssl)
contrib/vcpkg-ports/openssl3/vcpkg.json new file +7 -0
new file mode 100644
index 00000000..93db84b9
@@ -0,0 +1,7 @@
+{
+  "name": "openssl3",
+  "version-semver": "3.0.1",
+  "description": "TLS/SSL and crypto library",
+  "homepage": "https://www.openssl.org/",
+  "license": "Apache-2.0"
+}
contrib/vcpkg-ports/pkcs11-helper/portfile.cmake +1 -1
index 532aa69b..0723344e 100644
@@ -23,7 +23,7 @@ vcpkg_build_nmake(
     PROJECT_NAME Makefile.w32-vc
     OPTIONS
         OPENSSL=1
-        OPENSSL_HOME=${CURRENT_PACKAGES_DIR}/../openssl_${TARGET_TRIPLET}
+        OPENSSL_HOME=${CURRENT_PACKAGES_DIR}/../openssl3_${TARGET_TRIPLET}
 )
 
 file(INSTALL ${SOURCE_PATH}/include/pkcs11-helper-1.0 DESTINATION ${CURRENT_PACKAGES_DIR}/include/)
Signature · 1 line
2.23.0.windows.1
#5 lore raw

PATCH v2 2/2 msvc: switch to openssl3

From: Lev Stipakov <[email protected]...>

Add openssl3 vcpkg port, which is slightly modified version of openssl1.1.1 port from official vcpkg repo.

---

v2:
- rewrite openssl3 port based on upstream's openssl1.1.1 port
and statically link legacy provider into it

 .github/workflows/build.yaml                  |   2 +-
 contrib/vcpkg-ports/openssl3/portfile.cmake   | 168 ++++++++++++++++++
 contrib/vcpkg-ports/openssl3/usage            |   4 +
 contrib/vcpkg-ports/openssl3/vcpkg.json       |   7 +
 .../vcpkg-ports/pkcs11-helper/portfile.cmake  |   2 +-
 5 files changed, 181 insertions(+), 2 deletions(-)
 create mode 100644 contrib/vcpkg-ports/openssl3/portfile.cmake
 create mode 100644 contrib/vcpkg-ports/openssl3/usage
 create mode 100644 contrib/vcpkg-ports/openssl3/vcpkg.json
.github/workflows/build.yaml +1 -1
index 9f884ac2..f1a75736 100644
@@ -294,7 +294,7 @@ jobs:
         uses: lukka/[email protected]...
         with:
           vcpkgGitCommitId: 'a2fcb03749ff5897b5985092934dc6057680c789'
-          vcpkgArguments: 'openssl lz4 lzo pkcs11-helper tap-windows6'
+          vcpkgArguments: 'openssl3 lz4 lzo pkcs11-helper tap-windows6'
           vcpkgTriplet: '${{ matrix.triplet }}-windows-ovpn'
           cleanAfterBuild: false
 
contrib/vcpkg-ports/openssl3/portfile.cmake new file +168 -0

168 lines not on this page · raw message

contrib/vcpkg-ports/openssl3/usage new file +4 -0
new file mode 100644
index 00000000..97e7760e
@@ -0,0 +1,4 @@
+The package openssl3 is compatible with built-in CMake targets:
+
+    find_package(OpenSSL REQUIRED)
+    target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)
contrib/vcpkg-ports/openssl3/vcpkg.json new file +7 -0
new file mode 100644
index 00000000..93db84b9
@@ -0,0 +1,7 @@
+{
+  "name": "openssl3",
+  "version-semver": "3.0.1",
+  "description": "TLS/SSL and crypto library",
+  "homepage": "https://www.openssl.org/",
+  "license": "Apache-2.0"
+}
contrib/vcpkg-ports/pkcs11-helper/portfile.cmake +1 -1
index 532aa69b..0723344e 100644
@@ -23,7 +23,7 @@ vcpkg_build_nmake(
     PROJECT_NAME Makefile.w32-vc
     OPTIONS
         OPENSSL=1
-        OPENSSL_HOME=${CURRENT_PACKAGES_DIR}/../openssl_${TARGET_TRIPLET}
+        OPENSSL_HOME=${CURRENT_PACKAGES_DIR}/../openssl3_${TARGET_TRIPLET}
 )
 
 file(INSTALL ${SOURCE_PATH}/include/pkcs11-helper-1.0 DESTINATION ${CURRENT_PACKAGES_DIR}/include/)
Signature · 1 line
2.23.0.windows.1
Acked-by on v2 2/2
#6 lore raw

Re: [Openvpn-devel] [PATCH v2 2/2] msvc: switch to openssl3

Hi,

Quoted 6 lines · Lev Stipakov

From: Lev Stipakov <[email protected]...>

Add openssl3 vcpkg port, which is slightly modified version of openssl1.1.1 port from official vcpkg repo.

Built this branch using GH actions and it worked for all archs. I also smoke tested the x64 build on Win11 and it worked as expected. Reported openssl version is 3.0.1, as expected.

I could establish a connection and have a working tunnel.

FWIW:

Signature · 1 line
Antonio Quartulli
#7 lore raw

[Openvpn-devel] [PATCH applied] Re: msvc: switch to openssl3

In reply to Lev Stipakov

Haven't tested anything. If you and Antonio say this works, good enough :)

Your patch has been applied to the master branch.

commit 225893ef7d06cdaf145436c54bd1070266a1d1da

Author: Lev Stipakov
Date:   Wed Jan 26 14:35:02 2022 +0200
     msvc: switch to openssl3

     Signed-off-by: Lev Stipakov <[email protected]...>
     Acked-by: Antonio Quartulli <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg23662.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering