Skip to contentSkip to conversation

contrib/vcpkg-ports: add pkcs11-helper port

PATCH Superseded Lev Stipakov 3 participants 11 messages May 13, 2021 – Jun 15, 2021

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 contrib/vcpkg-ports: add pkcs11-helper port

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

pkcs11-helper is a dependency library used by OpenVPN. So far it has been built only by mingw.

Since we're making MSVC build system a first class citizen, we need to build depencencies with MSVC, which we do with vcpkg. All dependencies are in vcpkg official repo, expect pkcs11-helper.

This provides vcpkg port for building pkcs11-helper.

Example usage:

vcpkg --overlay-ports=<openvpn>\contrib\vcpkg-ports install pkcs11-helper

---
 .../0001-nmake-openssl-1.1.1-support.patch    |  89 +++
 contrib/vcpkg-ports/pkcs11-helper/CONTROL     |   4 +
 .../pkcs11-helper-001-RFC7512.patch           | 686 ++++++++++++++++++
 .../vcpkg-ports/pkcs11-helper/portfile.cmake  |  34 +
 4 files changed, 813 insertions(+)
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/0001-nmake-openssl-1.1.1-support.patch
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/CONTROL
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/pkcs11-helper-001-RFC7512.patch
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/portfile.cmake
contrib/vcpkg-ports/pkcs11-helper/0001-nmake-openssl-1.1.1-support.patch new file +89 -0
new file mode 100644
index 00000000..8a6750b9
@@ -0,0 +1,89 @@
+From 324026ce179468fcea348e59259dbc5456438ead Mon Sep 17 00:00:00 2001
+From: Lev Stipakov <[email protected]...>
+Date: Fri, 14 May 2021 14:35:53 +0300
+Subject: [PATCH] nmake: openssl 1.1.1 support
+
+Starting from version 1.1.1, OpenSSL includes routines
+like RSA_meth_xxx and DSA_meth_xxx. pkcs11-helper includes
+implementation of those routines. That code is compiled if
+they're missing from OpenSSL.
+
+nmake build uses pre-generated config-w32-vc.h, which lacks
+defines which indicate that OpenSSL includes above routines,
+which causes pkcs11's own implementaion to be compiled. However,
+pkcs11-helper implementation is not compatible with OpenSSL 1.1.1 -
+for example, it takes size of opaque struct RSA_METHOD, which
+has become internal in OpenSSL.
+
+This adds necessary defines to config header used by nmake build
+so that pkcs11-helper code, which is not compatible with OpenSSL 1.1.1,
+is not compiled.
+
+Also libeay is changed to libcrypto.
+
+Signed-off-by: Lev Stipakov <[email protected]...>
+---
+ config-w32-vc.h.in  | 33 +++++++++++++++++++++++++++++++++
+ lib/Makefile.w32-vc |  4 ++--
+ 2 files changed, 35 insertions(+), 2 deletions(-)
+
+diff --git a/config-w32-vc.h b/config-w32-vc.h
+index 6346f02..102b2e3 100644
+--- a/config-w32-vc.h
++++ b/config-w32-vc.h
+@@ -185,3 +185,36 @@
+ #if _MSC_VER >= 1400
+ #define HAVE_CPP_VARARG_MACRO_ISO 1
+ #endif
++
++/* Define to 1 if you have the `RSA_meth_dup' function. */
++#define HAVE_RSA_METH_DUP 1
++
++/* Define to 1 if you have the `RSA_meth_free' function. */
++#define HAVE_RSA_METH_FREE 1
++
++/* Define to 1 if you have the `RSA_meth_set1_name' function. */
++#define HAVE_RSA_METH_SET1_NAME 1
++
++/* Define to 1 if you have the `RSA_meth_set_flags' function. */
++#define HAVE_RSA_METH_SET_FLAGS 1
++
++/* Define to 1 if you have the `RSA_meth_set_priv_dec' function. */
++#define HAVE_RSA_METH_SET_PRIV_DEC 1
++
++/* Define to 1 if you have the `RSA_meth_set_priv_enc' function. */
++#define HAVE_RSA_METH_SET_PRIV_ENC 1
++
++/* Define to 1 if you have the `DSA_meth_dup' function. */
++#define HAVE_DSA_METH_DUP 1
++
++/* Define to 1 if you have the `DSA_meth_free' function. */
++#define HAVE_DSA_METH_FREE 1
++
++/* Define to 1 if you have the `DSA_meth_set1_name' function. */
++#define HAVE_DSA_METH_SET1_NAME 1
++
++/* Define to 1 if you have the `DSA_meth_set_sign' function. */
++#define HAVE_DSA_METH_SET_SIGN 1
++
++/* Define to 1 if you have the `DSA_SIG_set0' function. */
++#define HAVE_DSA_SIG_SET0 1
+diff --git a/lib/Makefile.w32-vc b/lib/Makefile.w32-vc
+index 2edab39..b2ac746 100644
+--- a/lib/Makefile.w32-vc
++++ b/lib/Makefile.w32-vc
+@@ -60,9 +60,9 @@ OPENSSL_HOME = ..\..\openssl-0.9.8a
+ !endif
+ 
+ !ifdef OPENSSL
+-OPENSSL_STATIC = libeay32.lib
++OPENSSL_STATIC = libcrypto.lib
+ #OPENSSL_STATIC = libeay32sd.lib
+-OPENSSL_DYNAMIC = libeay32.lib
++OPENSSL_DYNAMIC = libcrypto.lib
+ #OPENSSL_DYNAMIC = libeay32d.lib
+ 
+ OPENSSL_INC=$(OPENSSL_HOME)\include
+-- 
+2.23.0.windows.1
+
contrib/vcpkg-ports/pkcs11-helper/CONTROL new file +4 -0
new file mode 100644
index 00000000..01831802
@@ -0,0 +1,4 @@
+Source: pkcs11-helper
+Version: 1.27-1
+Homepage: https://github.com/OpenSC/pkcs11-helper
+Description: pkcs11-helper is a library that simplifies the interaction with PKCS#11 providers for end-user applications.
contrib/vcpkg-ports/pkcs11-helper/pkcs11-helper-001-RFC7512.patch new file +686 -0

686 lines not on this page · raw message

contrib/vcpkg-ports/pkcs11-helper/portfile.cmake new file +34 -0
new file mode 100644
index 00000000..01cc8666
@@ -0,0 +1,34 @@
+include(vcpkg_common_functions)
+
+set(VERSION 1.27)
+
+vcpkg_download_distfile(ARCHIVE
+    URLS "https://github.com/OpenSC/pkcs11-helper/releases/download/pkcs11-helper-${VERSION}/pkcs11-helper-${VERSION}.0.tar.bz2"
+    FILENAME "pkcs11-helper-${VERSION}.tar.bz2"
+    SHA512 5799342cb755dae8b7ba0880d652e9d4b4f1e52a74043015e1185e1e059326cb2689bb51957db98060ac2257dee34e2f047dcf3d52ad59fd49b91fedcfc5332b
+)
+
+vcpkg_extract_source_archive_ex(
+    OUT_SOURCE_PATH SOURCE_PATH
+    ARCHIVE ${ARCHIVE}
+    REF ${VERSION}
+    PATCHES
+        0001-nmake-openssl-1.1.1-support.patch
+        pkcs11-helper-001-RFC7512.patch
+)
+
+vcpkg_build_nmake(
+    SOURCE_PATH ${SOURCE_PATH}
+    NO_DEBUG
+    PROJECT_SUBPATH lib
+    PROJECT_NAME Makefile.w32-vc
+    OPTIONS
+        OPENSSL=1
+        OPENSSL_HOME=${CURRENT_PACKAGES_DIR}/../openssl-windows_${TARGET_TRIPLET}
+)
+
+file(INSTALL ${SOURCE_PATH}/include/pkcs11-helper-1.0 DESTINATION ${CURRENT_PACKAGES_DIR}/include/)
+file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/lib/pkcs11-helper.dll.lib DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
+file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/lib/pkcs11-helper.dll.lib DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
+
+file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
Signature · 1 line
2.23.0.windows.1
#1 lore raw

PATCH v2 1/1 contrib/vcpkg-ports: add pkcs11-helper port

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

pkcs11-helper is a dependency library used by OpenVPN. So far it has been built only by mingw.

Since we're making MSVC build system a first class citizen, we need to build depencencies with MSVC, which we do with vcpkg. All dependencies are in vcpkg official repo, expect pkcs11-helper.

This provides vcpkg port for building pkcs11-helper.

Example usage:

vcpkg --overlay-ports=<openvpn>\contrib\vcpkg-ports install pkcs11-helper

---

v2: add missing dll installation commands to port file

 .../0001-nmake-openssl-1.1.1-support.patch    |  89 +++
 contrib/vcpkg-ports/pkcs11-helper/CONTROL     |   4 +
 .../pkcs11-helper-001-RFC7512.patch           | 686 ++++++++++++++++++
 .../vcpkg-ports/pkcs11-helper/portfile.cmake  |  37 +
 4 files changed, 816 insertions(+)
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/0001-nmake-openssl-1.1.1-support.patch
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/CONTROL
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/pkcs11-helper-001-RFC7512.patch
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/portfile.cmake
contrib/vcpkg-ports/pkcs11-helper/0001-nmake-openssl-1.1.1-support.patch new file +89 -0
new file mode 100644
index 00000000..8a6750b9
@@ -0,0 +1,89 @@
+From 324026ce179468fcea348e59259dbc5456438ead Mon Sep 17 00:00:00 2001
+From: Lev Stipakov <[email protected]...>
+Date: Fri, 14 May 2021 14:35:53 +0300
+Subject: [PATCH] nmake: openssl 1.1.1 support
+
+Starting from version 1.1.1, OpenSSL includes routines
+like RSA_meth_xxx and DSA_meth_xxx. pkcs11-helper includes
+implementation of those routines. That code is compiled if
+they're missing from OpenSSL.
+
+nmake build uses pre-generated config-w32-vc.h, which lacks
+defines which indicate that OpenSSL includes above routines,
+which causes pkcs11's own implementaion to be compiled. However,
+pkcs11-helper implementation is not compatible with OpenSSL 1.1.1 -
+for example, it takes size of opaque struct RSA_METHOD, which
+has become internal in OpenSSL.
+
+This adds necessary defines to config header used by nmake build
+so that pkcs11-helper code, which is not compatible with OpenSSL 1.1.1,
+is not compiled.
+
+Also libeay is changed to libcrypto.
+
+Signed-off-by: Lev Stipakov <[email protected]...>
+---
+ config-w32-vc.h.in  | 33 +++++++++++++++++++++++++++++++++
+ lib/Makefile.w32-vc |  4 ++--
+ 2 files changed, 35 insertions(+), 2 deletions(-)
+
+diff --git a/config-w32-vc.h b/config-w32-vc.h
+index 6346f02..102b2e3 100644
+--- a/config-w32-vc.h
++++ b/config-w32-vc.h
+@@ -185,3 +185,36 @@
+ #if _MSC_VER >= 1400
+ #define HAVE_CPP_VARARG_MACRO_ISO 1
+ #endif
++
++/* Define to 1 if you have the `RSA_meth_dup' function. */
++#define HAVE_RSA_METH_DUP 1
++
++/* Define to 1 if you have the `RSA_meth_free' function. */
++#define HAVE_RSA_METH_FREE 1
++
++/* Define to 1 if you have the `RSA_meth_set1_name' function. */
++#define HAVE_RSA_METH_SET1_NAME 1
++
++/* Define to 1 if you have the `RSA_meth_set_flags' function. */
++#define HAVE_RSA_METH_SET_FLAGS 1
++
++/* Define to 1 if you have the `RSA_meth_set_priv_dec' function. */
++#define HAVE_RSA_METH_SET_PRIV_DEC 1
++
++/* Define to 1 if you have the `RSA_meth_set_priv_enc' function. */
++#define HAVE_RSA_METH_SET_PRIV_ENC 1
++
++/* Define to 1 if you have the `DSA_meth_dup' function. */
++#define HAVE_DSA_METH_DUP 1
++
++/* Define to 1 if you have the `DSA_meth_free' function. */
++#define HAVE_DSA_METH_FREE 1
++
++/* Define to 1 if you have the `DSA_meth_set1_name' function. */
++#define HAVE_DSA_METH_SET1_NAME 1
++
++/* Define to 1 if you have the `DSA_meth_set_sign' function. */
++#define HAVE_DSA_METH_SET_SIGN 1
++
++/* Define to 1 if you have the `DSA_SIG_set0' function. */
++#define HAVE_DSA_SIG_SET0 1
+diff --git a/lib/Makefile.w32-vc b/lib/Makefile.w32-vc
+index 2edab39..b2ac746 100644
+--- a/lib/Makefile.w32-vc
++++ b/lib/Makefile.w32-vc
+@@ -60,9 +60,9 @@ OPENSSL_HOME = ..\..\openssl-0.9.8a
+ !endif
+ 
+ !ifdef OPENSSL
+-OPENSSL_STATIC = libeay32.lib
++OPENSSL_STATIC = libcrypto.lib
+ #OPENSSL_STATIC = libeay32sd.lib
+-OPENSSL_DYNAMIC = libeay32.lib
++OPENSSL_DYNAMIC = libcrypto.lib
+ #OPENSSL_DYNAMIC = libeay32d.lib
+ 
+ OPENSSL_INC=$(OPENSSL_HOME)\include
+-- 
+2.23.0.windows.1
+
contrib/vcpkg-ports/pkcs11-helper/CONTROL new file +4 -0
new file mode 100644
index 00000000..01831802
@@ -0,0 +1,4 @@
+Source: pkcs11-helper
+Version: 1.27-1
+Homepage: https://github.com/OpenSC/pkcs11-helper
+Description: pkcs11-helper is a library that simplifies the interaction with PKCS#11 providers for end-user applications.
contrib/vcpkg-ports/pkcs11-helper/pkcs11-helper-001-RFC7512.patch new file +686 -0

686 lines not on this page · raw message

contrib/vcpkg-ports/pkcs11-helper/portfile.cmake new file +37 -0
new file mode 100644
index 00000000..813e0939
@@ -0,0 +1,37 @@
+include(vcpkg_common_functions)
+
+set(VERSION 1.27)
+
+vcpkg_download_distfile(ARCHIVE
+    URLS "https://github.com/OpenSC/pkcs11-helper/releases/download/pkcs11-helper-${VERSION}/pkcs11-helper-${VERSION}.0.tar.bz2"
+    FILENAME "pkcs11-helper-${VERSION}.tar.bz2"
+    SHA512 5799342cb755dae8b7ba0880d652e9d4b4f1e52a74043015e1185e1e059326cb2689bb51957db98060ac2257dee34e2f047dcf3d52ad59fd49b91fedcfc5332b
+)
+
+vcpkg_extract_source_archive_ex(
+    OUT_SOURCE_PATH SOURCE_PATH
+    ARCHIVE ${ARCHIVE}
+    REF ${VERSION}
+    PATCHES
+        0001-nmake-openssl-1.1.1-support.patch
+        pkcs11-helper-001-RFC7512.patch
+)
+
+vcpkg_build_nmake(
+    SOURCE_PATH ${SOURCE_PATH}
+    NO_DEBUG
+    PROJECT_SUBPATH lib
+    PROJECT_NAME Makefile.w32-vc
+    OPTIONS
+        OPENSSL=1
+        OPENSSL_HOME=${CURRENT_PACKAGES_DIR}/../openssl-windows_${TARGET_TRIPLET}
+)
+
+file(INSTALL ${SOURCE_PATH}/include/pkcs11-helper-1.0 DESTINATION ${CURRENT_PACKAGES_DIR}/include/)
+file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/lib/pkcs11-helper.dll.lib DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
+file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/lib/pkcs11-helper.dll.lib DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
+
+file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/lib/libpkcs11-helper-1.dll DESTINATION ${CURRENT_PACKAGES_DIR}/bin)
+file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/lib/libpkcs11-helper-1.dll DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)
+
+file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
Signature · 1 line
2.23.0.windows.1
#4 lore raw
In reply to Lev Stipakov

Hi,

Quoted 10 lines · Lev Stipakov

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

pkcs11-helper is a dependency library used by OpenVPN. So far it has been built only by mingw.

Since we're making MSVC build system a first class citizen, we need to build depencencies with MSVC, which we do with vcpkg. All dependencies are in vcpkg official repo, expect pkcs11-helper.

Quoted 5 lines

This provides vcpkg port for building pkcs11-helper.

Example usage:

vcpkg --overlay-ports=<openvpn>\contrib\vcpkg-ports install pkcs11-helper

Part of the changes here -- especially that of config-win32-vc.h should go upstream to pkcs11-helper isn't it? In fact it may have to be added to config-win32-vc.h.in as the former is a generated file.

Was it rejected upstream and we have to maintain this ourselves?

Also the patch adding the RFC 7512 (pkcs11: URI) serialization is applied in openvpn-build as well. Adding a patch inside a patch already makes it so hard to read/review and keep current, and now having the same in two places would add to that burden.

Is there any real advantage of building openvpn.exe directly from here as opposed to from openvpn-build? Anyway, for Windows releases we need more than openvpn.exe.

Selva

#5 lore raw

Hi,

Quoted 5 lines

Part of the changes here -- especially that of config-win32-vc.h should go upstream to pkcs11-helper isn't it? In fact it may have to be added to config-win32-vc.h.in as the former is a generated file.

Was it rejected upstream and we have to maintain this ourselves?

it was accepted to upstream:

https://github.com/OpenSC/pkcs11-helper/commit/1d33a743bc67cfeb62293bc75f1bf2949c8115bb

However the latest release 1.27 was tagged in November, 2020. Either we switch to
using master or maintain this change ourselves until 1.28 is out. Or politely ask Alon
to tag 1.28, for the sake of his good contributions to openvpn :)

Quoted 4 lines

Also the patch adding the RFC 7512 (pkcs11: URI) serialization is applied in openvpn-build as well. Adding a patch inside a patch already makes it so hard to read/review and keep current, and now having the same in two places would add to that burden.

I agree. Does anybody know if that patch is required (on Windows), why wasn't it merged (submitted?) to upstream and shall we try to submit it to upstream now?

Quoted 3 lines

Is there any real advantage of building openvpn.exe directly from here as opposed to from openvpn-build? Anyway, for Windows releases we need more than openvpn.exe.

IMO yes, at least from developers' perspective. While you need openvpn-build to make installers,
it is not required (not when "standalone msvc build" patch is merged) for openvpn Windows development.

pkcs11-helper is not a separate tool like, say, openvpn-gui or EasyRSA, but a real dependency of
openvpn.exe, same as openssl. So I don't see reasons not to include it into build process,
especially when it doesn't require much effort (and will require even less with 1.28).

Maybe I should submit this port to vcpkg upstream, but currently it won't work on non-Windows
systems. Not sure if this is an obstacle, though.

Signature · 1 line
-Lev
#7 lore raw
In reply to Lev Stipakov
Quoted 9 lines · Lev Stipakov

Hi,

Quoted 5 lines

Part of the changes here -- especially that of config-win32-vc.h should go upstream to pkcs11-helper isn't it? In fact it may have to be added to config-win32-vc.h.in as the former is a generated file.

Was it rejected upstream and we have to maintain this ourselves?

Quoted 7 lines

it was accepted to upstream:

https://github.com/OpenSC/pkcs11-helper/commit/1d33a743bc67cfeb62293bc75f1bf2949c8115bb

However the latest release 1.27 was tagged in November, 2020. Either we switch to
using master or maintain this change ourselves until 1.28 is out.

That's good to know. We can live with that I suppose.

Quoted 11 lines

Or politely ask Alon
to tag 1.28, for the sake of his good contributions to openvpn :)

Quoted 4 lines

Also the patch adding the RFC 7512 (pkcs11: URI) serialization is applied in openvpn-build as well. Adding a patch inside a patch already makes it so hard to read/review and keep current, and now having the same in two places would add to that burden.

I agree. Does anybody know if that patch is required (on Windows), why wasn't it merged (submitted?) to upstream and shall we try to submit it to upstream now?

It has a long (6 years and counting) history and may never get merged...

https://github.com/OpenSC/pkcs11-helper/pull/4

We could look into incorporating it into our own pkcs11 glue code (pkcs11.c etc.). Not sure whether it really needs access to any innards of pkcs11-helper.

Quoted 10 lines
Quoted 4 lines

Is there any real advantage of building openvpn.exe directly from here as opposed to from openvpn-build? Anyway, for Windows releases we need more than openvpn.exe.

IMO yes, at least from developers' perspective. While you need openvpn-build to make installers,
it is not required (not when "standalone msvc build" patch is merged) for openvpn Windows development.

Quoted 6 lines

pkcs11-helper is not a separate tool like, say, openvpn-gui or EasyRSA, but a real dependency of
openvpn.exe, same as openssl. So I don't see reasons not to include it into build process,
especially when it doesn't require much effort (and will require even less with 1.28).

At the same time, pkcs11-helper is a separate library so anything required to build it doesn't belong to openvpn repo, does it? Ideally native (msvc) build on Windows it should work like on Linux/Unix platforms -- have all dependencies satisfied independently and then just "configure" and build. Too much to ask?

Selva

#8 lore raw

Hi,

Quoted 7 lines

It has a long (6 years and counting) history and may never get merged...

https://github.com/OpenSC/pkcs11-helper/pull/4

We could look into incorporating it into our own pkcs11 glue code (pkcs11.c etc.). Not sure whether it really needs access to any innards of pkcs11-helper.

Sounds reasonable. I don't know much about pkcs11 so let's wait for volunteers.

Quoted 5 lines

At the same time, pkcs11-helper is a separate library so anything required to build it doesn't belong to openvpn repo, does it? Ideally native (msvc) build on Windows it should work like on Linux/Unix platforms -- have all dependencies satisfied independently and then just "configure" and build.

I agree. In 2.6 we're going to have vcpkg manifest with the list of dependencies:

https://github.com/schwabe/openvpn/blob/dco/vcpkg.json

"dependencies": [

    "cmocka",
    "lz4",
    "openssl",
    "lzo",
    "tap-windows6",
    "ovpn-dco-win"

]

All those dependendencies (except ovpn-dco-win) have ports in vcpkg upstream, so we just list those and let vcpkg do the rest.

Since pkcs11-helper (and ovpn-dco-win) have no support in vcpkg upstream, we have to maintain ports ourselves.

We could:

1) move ports to openvpn-build. I don't think this is a good
solution, because that would
require Windows developers to clone another repo, which is needed for building installers.
This looks like a wrong thing for me to do.

2) move ports and the rest of Windows-specific stuff, such as
openvpnmsica, into openvpn-windows
repo. This is something to consider, assuming that this repo also would take care about MSI (and NSIS?)
stuff and have openvpn as a submodule.

3) do nothing and have those ports as part of openvpn repo. vcpkg
supports "ports-overlay" , so
I see nothing wrong or "hacky" with this approach. I see you point about having dependencies build scripts
as part of openvpn repo. However in this case script is fairly trivial and mostly consists of boilerplate code:

https://github.com/lstipakov/openvpn/blob/dco180521/contrib/vcpkg-ports/pkcs11-helper/portfile.cmake

To my understanding this part of openvpn is fairly static, so I don't expect much maintenance burden for it, if any. In any case I volunteer to take care of it.

4) submit pkcs11-helper and ovpn-dco-win ports to vcpkg upstream and
then remove those from openvpn.

We could do that after doing release with vcpkg as dependencies manager, so we'll have a good use case.
I can volunteer for that.

Signature · 1 line
-Lev
#9 lore raw

Hi,

Quoted 7 lines · Lev Stipakov

3) do nothing and have those ports as part of openvpn repo. vcpkg
supports "ports-overlay" , so
I see nothing wrong or "hacky" with this approach. I see you point about having dependencies build scripts
as part of openvpn repo. However in this case script is fairly trivial and mostly consists of boilerplate code:

Quoted 5 lines

https://github.com/lstipakov/openvpn/blob/dco180521/contrib/vcpkg-ports/pkcs11-helper/portfile.cmake

To my understanding this part of openvpn is fairly static, so I don't expect much maintenance burden for it, if any. In any case I volunteer to take care of it.

For now, this sounds like the easiest way forward...

Quoted 2 lines

4) submit pkcs11-helper and ovpn-dco-win ports to vcpkg upstream and
then remove those from openvpn.

... and when the dust has settled, move here...

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#2 lore raw

PATCH v3 1/1 contrib/vcpkg-ports: add pkcs11-helper port

In reply to Lev Stipakov

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

pkcs11-helper is a dependency library used by OpenVPN. So far it has been built only by mingw.

Since we're making MSVC build system a first class citizen, we need to build depencencies with MSVC, which we do with vcpkg. All dependencies are in vcpkg official repo, expect pkcs11-helper.

This provides vcpkg port for building pkcs11-helper.

Example usage:

vcpkg --overlay-ports=<openvpn>\contrib\vcpkg-ports install pkcs11-helper

---

v3:
- use correct OPENSSL_HOME (remove -windows suffix)
- remove deprecated "include(vcpkg_common_functions)"

v2:
- add missing dll installation commands to port file

 .../0001-nmake-openssl-1.1.1-support.patch    |  89 +++
 contrib/vcpkg-ports/pkcs11-helper/CONTROL     |   4 +
 .../pkcs11-helper-001-RFC7512.patch           | 686 ++++++++++++++++++
 .../vcpkg-ports/pkcs11-helper/portfile.cmake  |  35 +
 4 files changed, 814 insertions(+)
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/0001-nmake-openssl-1.1.1-support.patch
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/CONTROL
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/pkcs11-helper-001-RFC7512.patch
 create mode 100644 contrib/vcpkg-ports/pkcs11-helper/portfile.cmake
contrib/vcpkg-ports/pkcs11-helper/0001-nmake-openssl-1.1.1-support.patch new file +89 -0
new file mode 100644
index 00000000..8a6750b9
@@ -0,0 +1,89 @@
+From 324026ce179468fcea348e59259dbc5456438ead Mon Sep 17 00:00:00 2001
+From: Lev Stipakov <[email protected]...>
+Date: Fri, 14 May 2021 14:35:53 +0300
+Subject: [PATCH] nmake: openssl 1.1.1 support
+
+Starting from version 1.1.1, OpenSSL includes routines
+like RSA_meth_xxx and DSA_meth_xxx. pkcs11-helper includes
+implementation of those routines. That code is compiled if
+they're missing from OpenSSL.
+
+nmake build uses pre-generated config-w32-vc.h, which lacks
+defines which indicate that OpenSSL includes above routines,
+which causes pkcs11's own implementaion to be compiled. However,
+pkcs11-helper implementation is not compatible with OpenSSL 1.1.1 -
+for example, it takes size of opaque struct RSA_METHOD, which
+has become internal in OpenSSL.
+
+This adds necessary defines to config header used by nmake build
+so that pkcs11-helper code, which is not compatible with OpenSSL 1.1.1,
+is not compiled.
+
+Also libeay is changed to libcrypto.
+
+Signed-off-by: Lev Stipakov <[email protected]...>
+---
+ config-w32-vc.h.in  | 33 +++++++++++++++++++++++++++++++++
+ lib/Makefile.w32-vc |  4 ++--
+ 2 files changed, 35 insertions(+), 2 deletions(-)
+
+diff --git a/config-w32-vc.h b/config-w32-vc.h
+index 6346f02..102b2e3 100644
+--- a/config-w32-vc.h
++++ b/config-w32-vc.h
+@@ -185,3 +185,36 @@
+ #if _MSC_VER >= 1400
+ #define HAVE_CPP_VARARG_MACRO_ISO 1
+ #endif
++
++/* Define to 1 if you have the `RSA_meth_dup' function. */
++#define HAVE_RSA_METH_DUP 1
++
++/* Define to 1 if you have the `RSA_meth_free' function. */
++#define HAVE_RSA_METH_FREE 1
++
++/* Define to 1 if you have the `RSA_meth_set1_name' function. */
++#define HAVE_RSA_METH_SET1_NAME 1
++
++/* Define to 1 if you have the `RSA_meth_set_flags' function. */
++#define HAVE_RSA_METH_SET_FLAGS 1
++
++/* Define to 1 if you have the `RSA_meth_set_priv_dec' function. */
++#define HAVE_RSA_METH_SET_PRIV_DEC 1
++
++/* Define to 1 if you have the `RSA_meth_set_priv_enc' function. */
++#define HAVE_RSA_METH_SET_PRIV_ENC 1
++
++/* Define to 1 if you have the `DSA_meth_dup' function. */
++#define HAVE_DSA_METH_DUP 1
++
++/* Define to 1 if you have the `DSA_meth_free' function. */
++#define HAVE_DSA_METH_FREE 1
++
++/* Define to 1 if you have the `DSA_meth_set1_name' function. */
++#define HAVE_DSA_METH_SET1_NAME 1
++
++/* Define to 1 if you have the `DSA_meth_set_sign' function. */
++#define HAVE_DSA_METH_SET_SIGN 1
++
++/* Define to 1 if you have the `DSA_SIG_set0' function. */
++#define HAVE_DSA_SIG_SET0 1
+diff --git a/lib/Makefile.w32-vc b/lib/Makefile.w32-vc
+index 2edab39..b2ac746 100644
+--- a/lib/Makefile.w32-vc
++++ b/lib/Makefile.w32-vc
+@@ -60,9 +60,9 @@ OPENSSL_HOME = ..\..\openssl-0.9.8a
+ !endif
+ 
+ !ifdef OPENSSL
+-OPENSSL_STATIC = libeay32.lib
++OPENSSL_STATIC = libcrypto.lib
+ #OPENSSL_STATIC = libeay32sd.lib
+-OPENSSL_DYNAMIC = libeay32.lib
++OPENSSL_DYNAMIC = libcrypto.lib
+ #OPENSSL_DYNAMIC = libeay32d.lib
+ 
+ OPENSSL_INC=$(OPENSSL_HOME)\include
+-- 
+2.23.0.windows.1
+
contrib/vcpkg-ports/pkcs11-helper/CONTROL new file +4 -0
new file mode 100644
index 00000000..01831802
@@ -0,0 +1,4 @@
+Source: pkcs11-helper
+Version: 1.27-1
+Homepage: https://github.com/OpenSC/pkcs11-helper
+Description: pkcs11-helper is a library that simplifies the interaction with PKCS#11 providers for end-user applications.
contrib/vcpkg-ports/pkcs11-helper/pkcs11-helper-001-RFC7512.patch new file +686 -0

686 lines not on this page · raw message

contrib/vcpkg-ports/pkcs11-helper/portfile.cmake new file +35 -0
new file mode 100644
index 00000000..54a0009d
@@ -0,0 +1,35 @@
+set(VERSION 1.27)
+
+vcpkg_download_distfile(ARCHIVE
+    URLS "https://github.com/OpenSC/pkcs11-helper/releases/download/pkcs11-helper-${VERSION}/pkcs11-helper-${VERSION}.0.tar.bz2"
+    FILENAME "pkcs11-helper-${VERSION}.tar.bz2"
+    SHA512 5799342cb755dae8b7ba0880d652e9d4b4f1e52a74043015e1185e1e059326cb2689bb51957db98060ac2257dee34e2f047dcf3d52ad59fd49b91fedcfc5332b
+)
+
+vcpkg_extract_source_archive_ex(
+    OUT_SOURCE_PATH SOURCE_PATH
+    ARCHIVE ${ARCHIVE}
+    REF ${VERSION}
+    PATCHES
+        0001-nmake-openssl-1.1.1-support.patch
+        pkcs11-helper-001-RFC7512.patch
+)
+
+vcpkg_build_nmake(
+    SOURCE_PATH ${SOURCE_PATH}
+    NO_DEBUG
+    PROJECT_SUBPATH lib
+    PROJECT_NAME Makefile.w32-vc
+    OPTIONS
+        OPENSSL=1
+        OPENSSL_HOME=${CURRENT_PACKAGES_DIR}/../openssl_${TARGET_TRIPLET}
+)
+
+file(INSTALL ${SOURCE_PATH}/include/pkcs11-helper-1.0 DESTINATION ${CURRENT_PACKAGES_DIR}/include/)
+file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/lib/pkcs11-helper.dll.lib DESTINATION ${CURRENT_PACKAGES_DIR}/lib)
+file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/lib/pkcs11-helper.dll.lib DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib)
+
+file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/lib/libpkcs11-helper-1.dll DESTINATION ${CURRENT_PACKAGES_DIR}/bin)
+file(INSTALL ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/lib/libpkcs11-helper-1.dll DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin)
+
+file(INSTALL ${SOURCE_PATH}/COPYING DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
Signature · 1 line
2.23.0.windows.1
#10 lore raw
In reply to Lev Stipakov

Hi

Quoted 53 lines · Lev Stipakov

Hi,

Quoted 7 lines

It has a long (6 years and counting) history and may never get merged...

https://github.com/OpenSC/pkcs11-helper/pull/4

We could look into incorporating it into our own pkcs11 glue code (pkcs11.c etc.). Not sure whether it really needs access to any innards of pkcs11-helper.

Sounds reasonable. I don't know much about pkcs11 so let's wait for volunteers.

Quoted 5 lines

At the same time, pkcs11-helper is a separate library so anything required to build it doesn't belong to openvpn repo, does it? Ideally native (msvc) build on Windows it should work like on Linux/Unix platforms -- have all dependencies satisfied independently and then just "configure" and build.

I agree. In 2.6 we're going to have vcpkg manifest with the list of dependencies:

https://github.com/schwabe/openvpn/blob/dco/vcpkg.json

"dependencies": [

    "cmocka",
    "lz4",
    "openssl",
    "lzo",
    "tap-windows6",
    "ovpn-dco-win"

]

All those dependendencies (except ovpn-dco-win) have ports in vcpkg upstream, so we just list those and let vcpkg do the rest.

Since pkcs11-helper (and ovpn-dco-win) have no support in vcpkg upstream, we have to maintain ports ourselves.

We could:

1) move ports to openvpn-build. I don't think this is a good
solution, because that would
require Windows developers to clone another repo, which is needed for building installers.
This looks like a wrong thing for me to do.

2) move ports and the rest of Windows-specific stuff, such as
openvpnmsica, into openvpn-windows
repo. This is something to consider, assuming that this repo also would take care about MSI (and NSIS?)
stuff and have openvpn as a submodule.

Quoted 6 lines

3) do nothing and have those ports as part of openvpn repo. vcpkg
supports "ports-overlay" , so
I see nothing wrong or "hacky" with this approach. I see you point about having dependencies build scripts
as part of openvpn repo. However in this case script is fairly trivial and mostly consists of boilerplate code:

Once the next pkcs11-helper is out (with config-win32-vc changes) and if we eventually manage to get rid of the serialization patch, this would indeed become minor and fairly static.

Quoted 6 lines

https://github.com/lstipakov/openvpn/blob/dco180521/contrib/vcpkg-ports/pkcs11-helper/portfile.cmake

To my understanding this part of openvpn is fairly static, so I don't expect much maintenance burden for it, if any. In any case I volunteer to take care of it.

I agree that this looks the most expedient.

Selva

Selva

Acked-by on v3 1/1
#3 lore raw
In reply to Lev Stipakov

The ACK is based on the discussion on the list for v1/v2 of the patch, and the agreement to go this way - do a local port including this patch to pkcs11-helper, and as soon as upstream does a new release with the patch, we get rid of it again.

This patch does not touch OpenVPN code, just build environment, and looks reasonable enough (though I have not tested it and have no idea if this is "best practice" or not).

Your patch has been applied to the master and release/2.5 branch.

commit 36b9aa0c1e40f3e4bd021b2fbd2a479ef148bc90 (master) commit 73fbeed493c6320e0e93fc7569c5c22e3fe9413e (release/2.5)

Author: Lev Stipakov
Date:   Mon Jun 7 13:42:13 2021 +0300
     contrib/vcpkg-ports: add pkcs11-helper port

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

--
kind regards,

Gert Doering