OpenSC / pkcs11-helper

Library that simplifies the interaction with PKCS#11 providers for end-user applications using a simple API and optional OpenSSL engine
Other
66 stars 43 forks source link

Error building static windows builds using vcpkg #63

Closed vimalraj-adikesavan closed 1 year ago

vimalraj-adikesavan commented 1 year ago

I am trying to build openvpn with static linking setting. Modified vcpkg-triplets\x64-windows-ovpn.cmake file as below

`set(VCPKG_TARGET_ARCHITECTURE x64) set(VCPKG_CRT_LINKAGE static) set(VCPKG_LIBRARY_LINKAGE static)

set(STATIC_PORTS lz4 lzo) if(PORT IN_LIST STATIC_PORTS) set(VCPKG_LIBRARY_LINKAGE static) endif()`

It is able to build all the dependencies except pkcs11-helper. It failed with linker error "unresolved external symbol". Complete build output is given below. Please let me know how to build pkcs11-helper with static linking.

` echo LIBRARY libpkcs11-helper-1 > pkcs11-helper-1.dll.def echo EXPORTS >> pkcs11-helper-1.dll.def type core.exports >> pkcs11-helper-1.dll.def type certificate.exports >> pkcs11-helper-1.dll.def type data.exports >> pkcs11-helper-1.dll.def type slotevent.exports >> pkcs11-helper-1.dll.def type token.exports >> pkcs11-helper-1.dll.def type openssl.exports >> pkcs11-helper-1.dll.def echo /c -I../include -IC:/vcpkg/packages/pkcs11-helper_x64-windows-ovpn/../openssl_x64-windows-ovpn\include -DENABLE_PKCS11H_OPENSSL -DWIN32 -DWIN32_LEAN_AND_MEAN -D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_WIN32_WINNT=0x0400 > C:\Users...\AppData\Local\Temp\nmA3EF.tmp echo pkcs11h-core.c pkcs11h-certificate.c pkcs11h-crypto.c _pkcs11h-crypto-cryptoapi.c pkcs11h-data.c pkcs11h-mem.c pkcs11h-openssl.c pkcs11h-serialization.c pkcs11h-session.c pkcs11h-slotevent.c pkcs11h-sys.c pkcs11h-threading.c pkcs11h-token.c pkcs11h-util.c >> C:\Users...\AppData\Local\Temp\nmA3EF.tmp cl.exe @C:\Users...\AppData\Local\Temp\nmA3EF.tmp pkcs11h-core.c pkcs11h-certificate.c pkcs11h-crypto.c _pkcs11h-crypto-cryptoapi.c pkcs11h-data.c pkcs11h-mem.c pkcs11h-openssl.c pkcs11h-serialization.c pkcs11h-certificate.c(250): warning C4267: '=': conversion from 'size_t' to 'unsigned long', possible loss of data pkcs11h-certificate.c(930): warning C4267: 'function': conversion from 'size_t' to 'unsigned long', possible loss of data pkcs11h-certificate.c(980): warning C4267: '=': conversion from 'size_t' to 'CK_ULONG', possible loss of data pkcs11h-certificate.c(987): warning C4267: 'function': conversion from 'size_t' to 'unsigned long', possible loss of data pkcs11h-certificate.c(996): warning C4267: 'function': conversion from 'size_t' to 'unsigned long', possible loss of data pkcs11h-certificate.c(1005): warning C4267: 'function': conversion from 'size_t' to 'unsigned long', possible loss of data pkcs11h-data.c(70): warning C4267: 'initializing': conversion from 'size_t' to 'unsigned long', possible loss of data pkcs11h-data.c(71): warning C4267: 'initializing': conversion from 'size_t' to 'unsigned long', possible loss of data pkcs11h-data.c(315): warning C4267: 'initializing': conversion from 'size_t' to 'unsigned long', possible loss of data pkcs11h-data.c(316): warning C4267: 'initializing': conversion from 'size_t' to 'unsigned long', possible loss of data pkcs11h-data.c(317): warning C4267: 'initializing': conversion from 'size_t' to 'unsigned long', possible loss of data pkcs11h-session.c _pkcs11h-crypto-cryptoapi.c(191): warning C4267: 'function': conversion from 'size_t' to 'DWORD', possible loss of data _pkcs11h-crypto-cryptoapi.c(250): warning C4267: 'function': conversion from 'size_t' to 'DWORD', possible loss of data _pkcs11h-crypto-cryptoapi.c(281): warning C4267: 'function': conversion from 'size_t' to 'int', possible loss of data pkcs11h-slotevent.c _pkcs11h-crypto-cryptoapi.c(328): warning C4267: 'function': conversion from 'size_t' to 'DWORD', possible loss of data _pkcs11h-crypto-cryptoapi.c(333): warning C4267: 'function': conversion from 'size_t' to 'DWORD', possible loss of data pkcs11h-sys.c pkcs11h-threading.c pkcs11h-serialization.c(71): warning C4114: same type qualifier used more than once pkcs11h-serialization.c(76): warning C4311: 'type cast': pointer truncation from 'char ()[17]' to 'unsigned long' pkcs11h-serialization.c(77): warning C4311: 'type cast': pointer truncation from 'char ()[33]' to 'unsigned long' pkcs11h-serialization.c(78): warning C4311: 'type cast': pointer truncation from 'char ()[33]' to 'unsigned long' pkcs11h-serialization.c(79): warning C4311: 'type cast': pointer truncation from 'char ()[17]' to 'unsigned long' pkcs11h-token.c pkcs11h-util.c pkcs11h-openssl.c(421): warning C4996: 'RSA_get_ex_data': Since OpenSSL 3.0 pkcs11h-openssl.c(583): warning C4996: 'RSA_size': Since OpenSSL 3.0 pkcs11h-openssl.c(645): warning C4996: 'EVP_PKEY_get1_RSA': Since OpenSSL 3.0 pkcs11h-openssl.c(651): warning C4996: 'RSA_set_method': Since OpenSSL 3.0 pkcs11h-openssl.c(652): warning C4996: 'RSA_set_ex_data': Since OpenSSL 3.0 pkcs11h-openssl.c(656): warning C4996: 'EVP_PKEY_set1_RSA': Since OpenSSL 3.0 pkcs11h-openssl.c(675): warning C4996: 'RSA_free': Since OpenSSL 3.0 pkcs11h-openssl.c(701): warning C4996: 'DSA_get_ex_data': Since OpenSSL 3.0 pkcs11h-openssl.c(781): warning C4267: 'function': conversion from 'size_t' to 'int', possible loss of data pkcs11h-openssl.c(786): warning C4267: 'function': conversion from 'size_t' to 'int', possible loss of data pkcs11h-openssl.c(847): warning C4996: 'EVP_PKEY_get1_DSA': Since OpenSSL 3.0 pkcs11h-openssl.c(853): warning C4996: 'DSA_set_method': Since OpenSSL 3.0 pkcs11h-openssl.c(854): warning C4996: 'DSA_set_ex_data': Since OpenSSL 3.0 pkcs11h-openssl.c(856): warning C4996: 'EVP_PKEY_set1_DSA': Since OpenSSL 3.0 pkcs11h-openssl.c(866): warning C4996: 'DSA_free': Since OpenSSL 3.0 pkcs11h-openssl.c(892): warning C4996: 'EC_KEY_get_ex_data': Since OpenSSL 3.0 pkcs11h-openssl.c(978): warning C4267: 'function': conversion from 'size_t' to 'int', possible loss of data pkcs11h-openssl.c(983): warning C4267: 'function': conversion from 'size_t' to 'int', possible loss of data pkcs11h-openssl.c(1050): warning C4996: 'EVP_PKEY_get1_EC_KEY': Since OpenSSL 3.0 pkcs11h-openssl.c(1056): warning C4996: 'EC_KEY_set_method': Since OpenSSL 3.0 pkcs11h-openssl.c(1057): warning C4996: 'EC_KEY_set_ex_data': Since OpenSSL 3.0 pkcs11h-openssl.c(1059): warning C4996: 'EVP_PKEY_set1_EC_KEY': Since OpenSSL 3.0 pkcs11h-openssl.c(1069): warning C4996: 'EC_KEY_free': Since OpenSSL 3.0 pkcs11h-openssl.c(1095): warning C4996: 'RSA_meth_free': Since OpenSSL 3.0 pkcs11h-openssl.c(1097): warning C4996: 'RSA_meth_dup': Since OpenSSL 3.0 pkcs11h-openssl.c(1100): warning C4996: 'RSA_meth_set1_name': Since OpenSSL 3.0 pkcs11h-openssl.c(1101): warning C4996: 'RSA_meth_set_priv_dec': Since OpenSSL 3.0 pkcs11h-openssl.c(1102): warning C4996: 'RSA_meth_set_priv_enc': Since OpenSSL 3.0 pkcs11h-openssl.c(1103): warning C4996: 'RSA_meth_set_flags': Since OpenSSL 3.0 pkcs11h-openssl.c(1114): warning C4996: 'DSA_meth_free': Since OpenSSL 3.0 pkcs11h-openssl.c(1116): warning C4996: 'DSA_meth_dup': Since OpenSSL 3.0 pkcs11h-openssl.c(1117): warning C4996: 'DSA_meth_set1_name': Since OpenSSL 3.0 pkcs11h-openssl.c(1118): warning C4996: 'DSA_meth_set_sign': Since OpenSSL 3.0 pkcs11h-openssl.c(1129): warning C4996: 'EC_KEY_METHOD_free': Since OpenSSL 3.0 pkcs11h-openssl.c(1131): warning C4996: 'EC_KEY_METHOD_new': Since OpenSSL 3.0 pkcs11h-openssl.c(1144): warning C4996: 'EC_KEY_METHOD_get_sign': Since OpenSSL 3.0 pkcs11h-openssl.c(1145): warning C4996: 'EC_KEY_METHOD_set_sign': Since OpenSSL 3.0 pkcs11h-openssl.c(1174): warning C4996: 'RSA_meth_free': Since OpenSSL 3.0 pkcs11h-openssl.c(1180): warning C4996: 'DSA_meth_free': Since OpenSSL 3.0 pkcs11h-openssl.c(1186): warning C4996: 'EC_KEY_METHOD_free': Since OpenSSL 3.0 pkcs11h-openssl.c(1242): warning C4267: 'function': conversion from 'size_t' to 'long', possible loss of data pkcs11h-openssl.c(1428): warning C4996: 'EVP_PKEY_get1_RSA': Since OpenSSL 3.0 pkcs11h-openssl.c(1444): warning C4996: 'RSA_free': Since OpenSSL 3.0 pkcs11h-session.c(796): warning C4267: 'initializing': conversion from 'size_t' to 'unsigned long', possible loss of data pkcs11h-session.c(1095): warning C4267: '=': conversion from 'size_t' to 'CK_ULONG', possible loss of data pkcs11h-token.c(356): warning C4267: '=': conversion from 'size_t' to 'CK_ULONG', possible loss of data rc.exe -I../include -IC:/vcpkg/packages/pkcs11-helper_x64-windows-ovpn/../openssl_x64-windows-ovpn\include -DENABLE_PKCS11H_OPENSSL -DWIN32 -DWIN32_LEAN_AND_MEAN -D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_WIN32_WINNT=0x0400 versioninfo.rc Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Copyright (C) Microsoft Corporation. All rights reserved.

echo    /dll > C:\Users\...\AppData\Local\Temp\nmA73C.tmp
echo    /out:"libpkcs11-helper-1.dll" /def:pkcs11-helper-1.dll.def >> C:\Users\...\AppData\Local\Temp\nmA73C.tmp
echo    kernel32.lib gdi32.lib -LIBPATH:C:/vcpkg/packages/pkcs11-helper_x64-windows-ovpn/../openssl_x64-windows-ovpn\lib user32.lib advapi32.lib libcrypto.lib >> C:\Users\...\AppData\Local\Temp\nmA73C.tmp
echo    pkcs11h-core.obj  pkcs11h-certificate.obj  pkcs11h-crypto.obj  _pkcs11h-crypto-cryptoapi.obj  pkcs11h-data.obj  pkcs11h-mem.obj  pkcs11h-openssl.obj  pkcs11h-serialization.obj  pkcs11h-session.obj  pkcs11h-slotevent.obj  pkcs11h-sys.obj  pkcs11h-threading.obj  pkcs11h-token.obj  pkcs11h-util.obj >> C:\Users\...\AppData\Local\Temp\nmA73C.tmp
echo    versioninfo.res >> C:\Users\...\AppData\Local\Temp\nmA73C.tmp
link.exe @C:\Users\ADIKES~1\AppData\Local\Temp\nmA73C.tmp

Creating library libpkcs11-helper-1.lib and object libpkcs11-helper-1.exp libcrypto.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol imp_ioctlsocket referenced in function BIO_socket_ioctl libcrypto.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol imp_getsockname referenced in function BIO_sock_info libcrypto.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol imp_getsockopt referenced in function BIO_sock_error libcrypto.lib(libcrypto-lib-bio_sock2.obj) : error LNK2001: unresolved external symbol imp_getsockopt libcrypto.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol imp_ntohs referenced in function BIO_get_port libcrypto.lib(libcrypto-lib-bio_addr.obj) : error LNK2001: unresolved external symbol imp_ntohs libcrypto.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol imp_select referenced in function BIO_socket_wait libcrypto.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol imp_gethostbyname referenced in function BIO_gethostbyname libcrypto.lib(libcrypto-lib-bio_addr.obj) : error LNK2001: unresolved external symbol imp_gethostbyname libcrypto.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol imp_WSAStartup referenced in function BIO_sock_init libcrypto.lib(libcrypto-lib-bio_sock.obj) : error LNK2019: unresolved external symbol imp_WSACleanup referenced in function bio_sock_cleanup_int libcrypto.lib(libcrypto-lib-bss_conn.obj) : error LNK2001: unresolved external symbol imp_WSAGetLastError libcrypto.lib(libcrypto-lib-bio_sock.obj) : error LNK2001: unresolved external symbol imp_WSAGetLastError libcrypto.lib(libcrypto-lib-bio_addr.obj) : error LNK2001: unresolved external symbol imp_WSAGetLastError libcrypto.lib(libcrypto-lib-bss_sock.obj) : error LNK2001: unresolved external symbol imp_WSAGetLastError libcrypto.lib(libcrypto-lib-bio_sock2.obj) : error LNK2001: unresolved external symbol imp_WSAGetLastError libcrypto.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol imp_htonl referenced in function WspiapiLegacyGetAddrInfo libcrypto.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol imp_htons referenced in function WspiapiLegacyGetAddrInfo libcrypto.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol imp_inet_addr referenced in function WspiapiLegacyGetAddrInfo libcrypto.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol imp_inet_ntoa referenced in function WspiapiLegacyGetAddrInfo libcrypto.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol imp_gethostbyaddr referenced in function WspiapiLegacyGetNameInfo libcrypto.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol imp_getservbyport referenced in function WspiapiLegacyGetNameInfo libcrypto.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol imp_getservbyname referenced in function WspiapiLegacyGetAddrInfo libcrypto.lib(libcrypto-lib-bio_addr.obj) : error LNK2019: unresolved external symbol imp_WSASetLastError referenced in function BIO_lookup libcrypto.lib(libcrypto-lib-bss_sock.obj) : error LNK2001: unresolved external symbol imp_WSASetLastError libcrypto.lib(libcrypto-lib-bss_conn.obj) : error LNK2001: unresolved external symbol imp_WSASetLastError libcrypto.lib(libcrypto-lib-bss_sock.obj) : error LNK2019: unresolved external symbol imp_recv referenced in function sock_read libcrypto.lib(libcrypto-lib-bss_conn.obj) : error LNK2001: unresolved external symbol imp_recv libcrypto.lib(libcrypto-lib-bss_sock.obj) : error LNK2019: unresolved external symbol imp_send referenced in function sock_write libcrypto.lib(libcrypto-lib-bss_conn.obj) : error LNK2001: unresolved external symbol imp_send libcrypto.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol imp_accept referenced in function BIO_accept_ex libcrypto.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol imp_bind referenced in function BIO_bind libcrypto.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol imp_closesocket referenced in function BIO_accept_ex libcrypto.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol imp_connect referenced in function BIO_connect libcrypto.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol imp_listen referenced in function BIO_listen libcrypto.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol __imp_setsockopt referenced in function BIO_connect libcrypto.lib(libcrypto-lib-bio_sock2.obj) : error LNK2019: unresolved external symbol imp_socket referenced in function BIO_socket libcrypto.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol imp_CertOpenStore referenced in function capi_open_store libcrypto.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol imp_CertCloseStore referenced in function capi_find_key libcrypto.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol imp_CertEnumCertificatesInStore referenced in function capi_find_cert libcrypto.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol imp_CertFindCertificateInStore referenced in function capi_find_cert libcrypto.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol imp_CertDuplicateCertificateContext referenced in function capi_load_ssl_client_cert libcrypto.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol imp_CertFreeCertificateContext referenced in function capi_dsa_free libcrypto.lib(libcrypto-lib-e_capi.obj) : error LNK2019: unresolved external symbol __imp_CertGetCertificateContextProperty referenced in function capi_cert_get_fname libcrypto.lib(libcrypto-lib-bss_conn.obj) : error LNK2019: unresolved external symbol __imp_shutdown referenced in function conn_free libpkcs11-helper-1.dll : fatal error LNK1120: 34 unresolved externals `

alonbl commented 1 year ago

Please try the following patch

diff --git a/lib/Makefile.w32-vc b/lib/Makefile.w32-vc
index 96f1f89..1a7f554 100644
--- a/lib/Makefile.w32-vc
+++ b/lib/Makefile.w32-vc
@@ -145,7 +145,7 @@ libpkcs11-helper-1.dll: pkcs11-helper-1.dll.def $(OBJS) $(RES)
        $(LINK32) @<<
        $(LINK32_FLAGS)
        /out:"libpkcs11-helper-1.dll" /def:pkcs11-helper-1.dll.def
-       kernel32.lib gdi32.lib $(OPENSSL_LIBS)
+       ws2_32.lib kernel32.lib gdi32.lib $(OPENSSL_LIBS)
        $(OBJS)
        $(RES)
 <<
vimalraj-adikesavan commented 1 year ago

Thanks! it worked with minor change. I added crypt32.lib as well along with ws2_32.lib