From 053bf08d7947c1dda24da9861f3db95b46dfac97 Mon Sep 17 00:00:00 2001 From: Vladimir Stoiakin Date: Thu, 25 Apr 2024 20:36:52 +0300 Subject: [PATCH] build: add support for meson Co-authored-by: Frank Morgner Co-authored-by: Jussi Pakkanen --- .clang-tidy | 4 + MacOSX/meson.build | 0 configure.ac | 2 + doc/files/meson.build | 76 +++ doc/tools/generate_completion.sh | 38 ++ doc/tools/meson.build | 93 ++++ etc/meson.build | 40 ++ meson.build | 507 +++++++++++++++++ meson_options.txt | 29 + src/common/meson.build | 29 + src/libopensc/apdu.c | 2 +- src/libopensc/card-iasecc.c | 2 +- src/libopensc/iso7816.c | 2 +- src/libopensc/libopensc.def.in | 3 + src/libopensc/meson.build | 201 +++++++ src/libopensc/sc.c | 6 +- src/minidriver/meson.build | 43 ++ src/minidriver/minidriver.def.in | 3 + src/pkcs11/meson.build | 150 +++++ src/pkcs11/opensc-pkcs11.pc.in | 2 +- src/pkcs11/opensc.module.in | 1 + src/pkcs11/pkcs11-global.c | 3 +- src/pkcs11/pkcs11.def.in | 3 + src/pkcs15init/meson.build | 58 ++ src/scconf/meson.build | 9 + src/sm/meson.build | 22 + src/smm/meson.build | 24 + src/smm/smm-local.def.in | 3 + src/tests/meson.build | 348 ++++++++++++ src/tests/p11test/p11test_case_common.c | 2 +- src/tests/p11test/runtest.sh | 55 +- src/tests/regression/functions | 72 ++- src/tools/Makefile.am | 1 - src/tools/meson.build | 520 ++++++++++++++++++ src/tools/npa-tool.c | 1 - src/tools/pkcs11-tool.c | 8 + src/ui/meson.build | 11 + subprojects/dutil.wrap | 7 + subprojects/glib.wrap | 11 + subprojects/openpace.wrap | 10 + subprojects/openssl.wrap | 15 + subprojects/packagefiles/dutil/meson.build | 21 + subprojects/packagefiles/openpace/meson.build | 42 ++ .../packagefiles/openpace/meson_options.txt | 2 + subprojects/packagefiles/wcautil/meson.build | 21 + subprojects/wcautil.wrap | 7 + subprojects/zlib.wrap | 13 + tests/common.sh | 10 +- tests/test-duplicate-symbols.sh | 8 +- tests/test-fuzzing.sh | 12 +- tests/test-manpage.sh | 13 +- tests/test-p11test.sh | 19 +- tests/test-pkcs11-tool-allowed-mechanisms.sh | 11 +- tests/test-pkcs11-tool-import.sh | 13 +- tests/test-pkcs11-tool-sign-verify.sh | 30 +- tests/test-pkcs11-tool-sym-crypt-test.sh | 10 +- tests/test-pkcs11-tool-test-threads.sh | 18 +- tests/test-pkcs11-tool-test.sh | 11 +- tests/test-pkcs11-tool-unwrap-wrap-test.sh | 11 +- win32/OpenSC.iss.in | 2 +- win32/OpenSC.wxs.in | 4 +- win32/meson.build | 32 ++ win32/winconfig.h.in | 1 - 63 files changed, 2629 insertions(+), 98 deletions(-) create mode 100644 .clang-tidy create mode 100644 MacOSX/meson.build create mode 100644 doc/files/meson.build create mode 100755 doc/tools/generate_completion.sh create mode 100644 doc/tools/meson.build create mode 100644 etc/meson.build create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 src/common/meson.build create mode 100644 src/libopensc/libopensc.def.in create mode 100644 src/libopensc/meson.build create mode 100644 src/minidriver/meson.build create mode 100644 src/minidriver/minidriver.def.in create mode 100644 src/pkcs11/meson.build create mode 100644 src/pkcs11/opensc.module.in create mode 100644 src/pkcs11/pkcs11.def.in create mode 100644 src/pkcs15init/meson.build create mode 100644 src/scconf/meson.build create mode 100644 src/sm/meson.build create mode 100644 src/smm/meson.build create mode 100644 src/smm/smm-local.def.in create mode 100644 src/tests/meson.build create mode 100644 src/tools/meson.build create mode 100644 src/ui/meson.build create mode 100644 subprojects/dutil.wrap create mode 100644 subprojects/glib.wrap create mode 100644 subprojects/openpace.wrap create mode 100644 subprojects/openssl.wrap create mode 100644 subprojects/packagefiles/dutil/meson.build create mode 100644 subprojects/packagefiles/openpace/meson.build create mode 100644 subprojects/packagefiles/openpace/meson_options.txt create mode 100644 subprojects/packagefiles/wcautil/meson.build create mode 100644 subprojects/wcautil.wrap create mode 100644 subprojects/zlib.wrap create mode 100644 win32/meson.build diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000000..cda100bce2 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,4 @@ +Checks: '-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling' +WarningsAsErrors: '-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling' +HeaderFilterRegex: '.*' +UseColor: 'true' diff --git a/MacOSX/meson.build b/MacOSX/meson.build new file mode 100644 index 0000000000..e69de29bb2 diff --git a/configure.ac b/configure.ac index b8224b5de7..145f380981 100644 --- a/configure.ac +++ b/configure.ac @@ -980,6 +980,8 @@ if test "${enable_sm}" = "yes"; then esac fi +AC_DEFINE([ENABLE_PKCS11], [1], [Enable building of PKCS#11 library]) + if test "${with_pkcs11_provider}" = "detect"; then if test "${WIN32}" != "yes"; then DEFAULT_PKCS11_PROVIDER="${libdir}/opensc-pkcs11${DYN_LIB_EXT}" diff --git a/doc/files/meson.build b/doc/files/meson.build new file mode 100644 index 0000000000..d9dce8b3c4 --- /dev/null +++ b/doc/files/meson.build @@ -0,0 +1,76 @@ +if progxsltproc.found() and stylesheets_path != '' + xml1 = configure_file( + configuration: { + 'sysconfdir': absolute_sysconfdir, + 'docdir': absolute_docdir, + 'libdir': absolute_libdir / '', + 'DYN_LIB_EXT': '.' + extension_of_libraries, + 'DEFAULT_PCSC_PROVIDER': conf.get_unquoted('DEFAULT_PCSC_PROVIDER'), + 'PROFILE_DIR_DEFAULT': (host_machine.system() == 'windows' or host_machine.system() == 'cygwin')? + 'obtained from windows registers' : absolute_pkgdir, + 'DEFAULT_SM_MODULE': conf.get_unquoted('DEFAULT_SM_MODULE') + }, + input: 'opensc.conf.5.xml.in', + output: 'opensc.conf.5.xml' + ) + + custom_target( + command: [progxsltproc, + '--nonet', + '--path', meson.project_source_root() / 'doc' + ':' + stylesheets_path / 'manpages', + '--xinclude', + '-o', '@OUTPUT@', + 'man.xsl', + '@INPUT@' + ], + input: xml1, + output: modfs.stem(xml1), + build_by_default: get_option('man'), + install: get_option('man'), + install_dir: get_option('mandir') / 'man5' + ) + + xml2 = configure_file( + configuration: {'pkgdatadir': absolute_pkgdir}, + input: 'pkcs15-profile.5.xml.in', + output: 'pkcs15-profile.5.xml' + ) + + custom_target( + command: [progxsltproc, + '--nonet', + '--path', meson.project_source_root() / 'doc' + ':' + stylesheets_path / 'manpages', + '--xinclude', + '-o', '@OUTPUT@', + 'man.xsl', + '@INPUT@' + ], + input: xml2, + output: modfs.stem(xml2), + build_by_default: get_option('man'), + install: get_option('man'), + install_dir: get_option('mandir') / 'man5' + ) + + custom_target( + command: [progxsltproc, + '--nonet', + '--path', meson.project_build_root() / 'doc' / 'files' + ':' + + meson.project_source_root() / 'doc' + ':' + + stylesheets_path / 'html', + '--xinclude', + '-o', '@OUTPUT@', + 'html.xsl', + '@INPUT@' + ], + input: 'files.xml', + output: 'files.html', + depend_files: [xml1, xml2], + build_by_default: get_option('doc'), + install: get_option('doc'), + install_dir: absolute_docdir + ) + + unset_variable('xml1') + unset_variable('xml2') +endif diff --git a/doc/tools/generate_completion.sh b/doc/tools/generate_completion.sh new file mode 100755 index 0000000000..4c541d9f60 --- /dev/null +++ b/doc/tools/generate_completion.sh @@ -0,0 +1,38 @@ +if [ ! $# -eq 3 ]; then + echo "Usage: template description.1.xml generated_completion" + exit 1 +fi +if [ ! -r "$1" ]; then + echo "The file \"$1\" does not exist or is not readable" + exit 2 +fi +if [ ! -r "$2" ]; then + echo "The file \"$2\" does not exist or is not readable" + exit 3 +fi + +ALLOPTS=$(sed -n 's,.*.*,\1,pg' "$2" | sort -u | grep '^-' | tr '\n' ' ') + +OPTSWITHARGS=$(sed -n 's,.*.*.*,\1,pg' "$2" | sort -u | grep '^-' | tr '\n' '|' | sed 's,|$$,,' | grep ^ || echo "!*") + +FILEOPTS=$(sed -n 's,.*.*.*filename.*,\1,pg' "$2" | sort -u | grep '^-' | tr '\n' '|' | sed 's,|$$,,' | grep ^ || echo "!*") + +PINOPTS=$(sed -En 's,.*.*\s*(newpin|pin|puk|sopin|sopuk)\s*<.*,\1,pg' "$2" | sort -u | grep '^-' | tr '\n' '|' | sed 's,|$$,,' | grep ^ || echo "!*") + +MODULEOPTS=$(sed -n 's,.*.*.*mod.*,\1,pg' "$2" | sort -u | grep '^-' | tr '\n' '|' | sed 's,|$$,,' | grep ^ || echo "!*") + +FUNCTION_NAME=$(basename "$3" | sed s,-,_,g) + +PROGRAM_NAME=$(basename "$3") + +cat "$1" \ + | sed "s,ALLOPTS,${ALLOPTS}," \ + | sed "s,OPTSWITHARGS,${OPTSWITHARGS}," \ + | sed "s,FILEOPTS,${FILEOPTS}," \ + | sed "s,PINOPTS,${PINOPTS}," \ + | sed "s,MODULEOPTS,${MODULEOPTS}," \ + | sed "s,FUNCTION_NAME,${FUNCTION_NAME}," \ + | sed "s,PROGRAM_NAME,${PROGRAM_NAME}," \ +> "$3" + +exit 0 diff --git a/doc/tools/meson.build b/doc/tools/meson.build new file mode 100644 index 0000000000..87665602f7 --- /dev/null +++ b/doc/tools/meson.build @@ -0,0 +1,93 @@ +sources = [ + 'cardos-tool.1.xml', + 'dnie-tool.1.xml', + 'dtrust-tool.1.xml', + 'egk-tool.1.xml', + 'eidenv.1.xml', + 'goid-tool.1.xml', + 'iasecc-tool.1.xml', + 'openpgp-tool.1.xml', + 'opensc-asn1.1.xml', + 'opensc-explorer.1.xml', + 'opensc-tool.1.xml', + 'pkcs11-register.1.xml', + 'pkcs11-tool.1.xml', + 'pkcs15-crypt.1.xml', + 'pkcs15-tool.1.xml' +] + +if conf.get('ENABLE_OPENSSL') + sources += [ + 'cryptoflex-tool.1.xml', + 'gids-tool.1.xml', + 'netkey-tool.1.xml', + 'piv-tool.1.xml', + 'pkcs15-init.1.xml', + 'sc-hsm-tool.1.xml', + 'westcos-tool.1.xml' + ] + + if conf.get('ENABLE_OPENPACE') + sources += [ + 'npa-tool.1.xml' + ] + endif +endif + +if conf.get('ENABLE_NOTIFY') + sources += [ + 'opensc-notify.1.xml' + ] +endif + +if progxsltproc.found() and stylesheets_path != '' + foreach xml : sources + custom_target( + command: [progxsltproc, + '--nonet', + '--path', meson.project_source_root() / 'doc' + ':' + stylesheets_path / 'manpages', + '--xinclude', + '-o', '@OUTPUT@', + 'man.xsl', + '@INPUT@' + ], + input: xml, + output: modfs.replace_suffix(xml, ''), + build_by_default: get_option('man'), + install: get_option('man'), + install_dir: get_option('mandir') / 'man1' + ) + endforeach + + custom_target( + command: [progxsltproc, + '--nonet', + '--path', meson.project_source_root() / 'doc' + ':' + stylesheets_path / 'html', + '--xinclude', + '-o', '@OUTPUT@', + 'html.xsl', + '@INPUT@' + ], + input: 'tools.xml', + output: 'tools.html', + depend_files: sources, + build_by_default: get_option('doc'), + install: get_option('doc'), + install_dir: absolute_docdir + ) +endif + +if bash_completion_path != '' + foreach xml : sources + custom_target( + command: ['generate_completion.sh', '@INPUT0@', '@INPUT1@', '@OUTPUT@'], + input: ['completion-template', xml], + output: modfs.replace_suffix(modfs.replace_suffix(xml, ''), ''), + build_by_default: get_option('bash_completion'), + install: get_option('bash_completion'), + install_dir: bash_completion_path + ) + endforeach +endif + +unset_variable('sources') diff --git a/etc/meson.build b/etc/meson.build new file mode 100644 index 0000000000..714b5a2146 --- /dev/null +++ b/etc/meson.build @@ -0,0 +1,40 @@ +install_data( + 'opensc.conf', + install_dir: get_option('sysconfdir') +) + +if conf.get('ENABLE_OPENPACE') + install_data( + 'DESRCACC100001', + 'DESCHSMCVCA00001', + install_dir: conf.get_unquoted('CVCDIR') + ) +endif + +if get_option('doc') + conf_etc = configuration_data() + conf_etc.set('LIBDIR', absolute_libdir / '') + conf_etc.set('DEFAULT_PCSC_PROVIDER', conf.get_unquoted('DEFAULT_PCSC_PROVIDER')) + conf_etc.set('DEFAULT_SM_MODULE', conf.get_unquoted('DEFAULT_SM_MODULE')) + conf_etc.set('DEFAULT_SM_MODULE_PATH', conf.get_unquoted('DEFAULT_SM_MODULE_PATH')) + conf_etc.set('DYN_LIB_EXT', '.' + extension_of_libraries) + conf_etc.set('LIB_PRE', prefix_of_libraries) + + if host_machine.system() == 'windows' or host_machine.system() == 'cygwin' + conf_etc.set('DEBUG_FILE', '%TEMP%\\opensc-debug.log') + conf_etc.set('PROFILE_DIR_DEFAULT', 'obtained from windows registers') + conf_etc.set('PROFILE_DIR', '') + else + conf_etc.set('DEBUG_FILE', '/tmp/opensc-debug.log') + conf_etc.set('PROFILE_DIR_DEFAULT', absolute_pkgdir) + conf_etc.set('PROFILE_DIR', absolute_pkgdir) + endif + + configure_file( + configuration: conf_etc, + input: 'opensc.conf.example.in', + output: 'opensc.conf', + install: true, + install_dir: absolute_docdir + ) +endif diff --git a/meson.build b/meson.build new file mode 100644 index 0000000000..ff4a1add11 --- /dev/null +++ b/meson.build @@ -0,0 +1,507 @@ +project('opensc', 'c', + version: '0.25.1', + license: 'LGPLv2.1+', + default_options: 'c_winlibs=advapi32.lib, comctl32.lib, gdi32.lib, shell32.lib, shlwapi.lib, user32.lib, ws2_32.lib', + meson_version: '>= 0.62' + ) + +modpkgconfig = import('pkgconfig') +modfs = import('fs') +modwindows = import('windows') + +all_languages = ['c'] +if host_machine.system() == 'windows' + add_languages('cpp', native: false) + all_languages += 'cpp' +elif host_machine.system() == 'darwin' + add_languages('objc', native: false) + all_languages += 'objc' +endif + +prefix_of_libraries = 'lib' +if host_machine.system() == 'cygwin' + prefix_of_libraries = 'cyg' +elif meson.get_compiler('c').get_id() == 'msvc' + prefix_of_libraries = '' +endif + +extension_of_libraries = 'so' +if host_machine.system() == 'windows' + extension_of_libraries = 'dll' +elif host_machine.system() == 'darwin' + extension_of_libraries = 'dylib' +endif + +absolute_bindir = (modfs.is_absolute(get_option('bindir'))? '' : get_option('prefix')) / get_option('bindir') +absolute_libdir = (modfs.is_absolute(get_option('libdir'))? '' : get_option('prefix')) / get_option('libdir') +absolute_sysconfdir = (modfs.is_absolute(get_option('sysconfdir'))? '' : get_option('prefix')) / get_option('sysconfdir') +absolute_datadir = (modfs.is_absolute(get_option('datadir'))? '' : get_option('prefix')) / get_option('datadir') + +absolute_pkgdir = absolute_datadir / 'opensc' +absolute_docdir = absolute_datadir / 'doc' / 'opensc' + +################################################# +# Dependencies and configuration +################################################# +conf = configuration_data() +conf.set_quoted('PACKAGE_NAME', 'OpenSC') +conf.set_quoted('PACKAGE_VERSION', meson.project_version()) +conf.set_quoted('PACKAGE_BUGREPORT', 'https://github.com/OpenSC/OpenSC/issues') +conf.set_quoted('PACKAGE_TARNAME', 'opensc') +conf.set_quoted('PACKAGE_URL', 'https://github.com/OpenSC/OpenSC') +conf.set_quoted('PACKAGE_SUMMARY', '') + +conf.set_quoted('OPENSC_VS_FF_COMPANY_NAME', 'OpenSC project') +conf.set_quoted('OPENSC_VS_FF_COMPANY_URL', 'https://github.com/OpenSC') +conf.set_quoted('OPENSC_VS_FF_PRODUCT_NAME', 'OpenSC smartcard framework') +conf.set_quoted('OPENSC_VS_FF_PRODUCT_UPDATES', 'https://github.com/OpenSC/OpenSC/releases') +conf.set_quoted('OPENSC_VS_FF_PRODUCT_URL', 'https://github.com/OpenSC/OpenSC') +conf.set_quoted('OPENSC_VS_FF_COMMENTS', 'Provided under the terms of the GNU Lesser General Public License (LGPLv2.1+).') +conf.set_quoted('OPENSC_VS_FF_LEGAL_COMPANY_NAME', 'OpenSC project') +conf.set_quoted('OPENSC_VS_FF_LEGAL_COMPANY_URL', 'https://github.com/OpenSC') +conf.set_quoted('OPENSC_VS_FF_LEGAL_COPYRIGHT', 'OpenSC Project') + +conf.set_quoted('OPENSC_CONF_PATH', absolute_sysconfdir / 'opensc.conf') +conf.set_quoted('DEFAULT_SM_MODULE', prefix_of_libraries + 'smm-local.' + extension_of_libraries) + +project_version = meson.project_version().split('.') +conf.set('OPENSC_VERSION_MAJOR', project_version[0]) +conf.set('OPENSC_VERSION_MINOR', project_version[1]) +conf.set('OPENSC_VERSION_FIX', project_version[2]) + +if host_machine.system() == 'windows' or host_machine.system() == 'cygwin' + conf.set_quoted('DEFAULT_PCSC_PROVIDER', 'winscard.dll') + conf.set_quoted('SC_PKCS15_PROFILE_DIRECTORY', 'C:\\Program Files\\OpenSC Project\\OpenSC\\profiles') + conf.set_quoted('DEFAULT_SM_MODULE_PATH', '%PROGRAMFILES%\\OpenSC Project\\OpenSC\\tools') + conf.set('PKCS11_REGISTER_SKIP_FIREFOX', 'on') + +elif host_machine.system() == 'darwin' + conf.set_quoted('DEFAULT_PCSC_PROVIDER', '/System/Library/Frameworks/PCSC.framework/PCSC') + conf.set_quoted('SC_PKCS15_PROFILE_DIRECTORY', absolute_pkgdir) + conf.set_quoted('DEFAULT_SM_MODULE_PATH', absolute_libdir) + conf.set('PKCS11_REGISTER_SKIP_FIREFOX', 'on') + +else + conf.set_quoted('DEFAULT_PCSC_PROVIDER', 'libpcsclite.so.1') + conf.set_quoted('SC_PKCS15_PROFILE_DIRECTORY', absolute_pkgdir) + conf.set_quoted('DEFAULT_SM_MODULE_PATH', absolute_libdir) + conf.set('PKCS11_REGISTER_SKIP_FIREFOX', 'off') +endif + +if meson.get_compiler('c').get_id() == 'msvc' + conf.set('PATH_MAX', 'FILENAME_MAX') + conf.set('strncasecmp', 'strnicmp') + conf.set('strcasecmp', 'stricmp') +endif + +conf.set('ENABLE_SHARED', get_option('default_library') != 'static') +conf.set('ENABLE_PKCS11', get_option('components').contains('pkcs11')) +conf.set('ENABLE_MINIDRIVER', get_option('components').contains('minidriver')) +conf.set('ENABLE_SM', get_option('components').contains('sm')) + +conf.set('ENABLE_PCSC', false) +conf.set('ENABLE_CRYPTOTOKENKIT', false) +conf.set('ENABLE_OPENCT', false) +conf.set('ENABLE_CTAPI', false) +conf.set('HAVE_WINSCARD_H', false) +conf.set('HAVE_PCSCLITE_H', false) + +if get_option('driver') == 'pcsc' + conf.set('ENABLE_PCSC', true) + if host_machine.system() == 'windows' + deppcsc = meson.get_compiler('c').find_library('winscard') + conf.set('HAVE_WINSCARD_H', meson.get_compiler('c').has_header('winscard.h')) + else + deppcsc = dependency('libpcsclite', version: '>= 1.8.22') + conf.set('HAVE_WINSCARD_H', meson.get_compiler('c').has_header('winscard.h', dependencies: deppcsc)) + conf.set('HAVE_PCSCLITE_H', meson.get_compiler('c').has_header('pcsclite.h', dependencies: deppcsc)) + endif +elif get_option('driver') == 'crypttokenkit' + conf.set('ENABLE_CRYPTOTOKENKIT', true) + depcryptotokenkit = dependency('appleframeworks', modules: 'CryptoTokenKit') + +elif get_option('driver') == 'openct' + conf.set('ENABLE_OPENCT', true) + depopenct = dependency('openct') + +elif get_option('driver') == 'ctapi' + conf.set('ENABLE_CTAPI', true) + +else + error('The option "driver" has unknown value') +endif + +depopenpace = dependency('libeac', version: '>= 0.9', required: get_option('openpace')) +conf.set('ENABLE_OPENPACE', depopenpace.found()) +if depopenpace.found() + conf.set_quoted('CVCDIR', depopenpace.get_variable('cvcdir')) + conf.set_quoted('X509DIR', depopenpace.get_variable('x509dir')) +else + conf.set_quoted('CVCDIR', '') + conf.set_quoted('X509DIR', '') +endif + +depopenssl = dependency('openssl', version: '>= 1.1.1', required: get_option('openssl'), default_options: 'default_library=static') +conf.set('ENABLE_OPENSSL', depopenssl.found()) +if depopenssl.found() and get_option('openssl-secure-malloc') != 0 + conf.set('OPENSSL_SECURE_MALLOC_SIZE', get_option('openssl-secure-malloc')) +endif + +depreadline = dependency('readline', required: get_option('readline')) +conf.set('ENABLE_READLINE', depreadline.found()) + +depzlib = dependency('zlib', required: get_option('zlib'), default_options: 'default_library=static') +conf.set('ENABLE_ZLIB', depzlib.found()) + +depcorefoundation = dependency('appleframeworks', modules: 'CoreFoundation', required: get_option('dnie_ui')) +conf.set('ENABLE_DNIE_UI', depcorefoundation.found()) + +depgio2 = dependency('gio-2.0', required: false, default_options: 'default_library=static') +conf.set('ENABLE_GIO2', depgio2.found()) + +conf.set('ENABLE_NOTIFY', get_option('notify')) +conf.set('PKCS11_THREAD_LOCKING', get_option('thread_locking')) +conf.set('ENABLE_PIV_SM', get_option('piv_sm')) + +depthreads = dependency('threads', required: false) +depdl = dependency('dl', required: false) + +conf.set_quoted('DEFAULT_PKCS11_PROVIDER', '') +conf.set_quoted('DEFAULT_ONEPIN_PKCS11_PROVIDER', '') +if get_option('components').contains('pkcs11') + depp11kit = dependency('p11-kit-1', required: get_option('p11kit')) + conf.set('HAVE_P11KIT', depp11kit.found()) + if depp11kit.found() + p11kit_modules_path = depp11kit.get_variable('p11_module_path') + p11kit_configs_path = depp11kit.get_variable('p11_module_configs') + + conf.set_quoted('DEFAULT_PKCS11_PROVIDER', p11kit_modules_path / 'opensc-pkcs11.' + extension_of_libraries) + conf.set_quoted('DEFAULT_ONEPIN_PKCS11_PROVIDER', p11kit_modules_path / 'opensc-pkcs11.' + extension_of_libraries) + else + if get_option('default_library') != 'static' + conf.set_quoted('DEFAULT_PKCS11_PROVIDER', absolute_libdir / prefix_of_libraries + 'opensc-pkcs11.' + extension_of_libraries) + conf.set_quoted('DEFAULT_ONEPIN_PKCS11_PROVIDER', absolute_libdir / prefix_of_libraries + 'opensc-pkcs11.' + extension_of_libraries) + endif + endif +endif + +conf.set('HAVE_INTTYPES_H', meson.get_compiler('c').has_header('inttypes.h')) +conf.set('HAVE_STRING_H', meson.get_compiler('c').has_header('string.h')) +conf.set('HAVE_STRINGS_H', meson.get_compiler('c').has_header('strings.h')) +conf.set('HAVE_SYS_TIME_H', meson.get_compiler('c').has_header('sys' / 'time.h')) +conf.set('HAVE_SYS_MMAN_H', meson.get_compiler('c').has_header('sys' / 'mman.h')) +conf.set('HAVE_SYS_ENDIAN_H', meson.get_compiler('c').has_header('sys' / 'endian.h')) +conf.set('HAVE_UNISTD_H', meson.get_compiler('c').has_header('unistd.h')) +conf.set('HAVE_ENDIAN_H', meson.get_compiler('c').has_header('endian.h')) +conf.set('HAVE_PTHREAD', meson.get_compiler('c').has_header('pthread.h')) + +conf.set('HAVE_GETPASS', meson.get_compiler('c').has_function('getpass')) +conf.set('HAVE_GETTIMEOFDAY', meson.get_compiler('c').has_function('gettimeofday')) +conf.set('HAVE_GETLINE', meson.get_compiler('c').has_function('getline')) +conf.set('HAVE_MEMSET_S', meson.get_compiler('c').has_function('memset_s')) +conf.set('HAVE_EXPLICIT_BZERO', meson.get_compiler('c').has_function('explicit_bzero')) +conf.set('HAVE_STRNLEN', meson.get_compiler('c').has_function('strnlen')) +conf.set('HAVE_SIGACTION', meson.get_compiler('c').has_function('sigaction')) +conf.set('HAVE_BUILTIN_OVERFLOW', meson.get_compiler('c').has_function('__builtin_uadd_overflow')) + +opensc_features = '' +opensc_features += conf.get('PKCS11_THREAD_LOCKING')? ' locking' : '' +opensc_features += conf.get('ENABLE_OPENPACE')? ' openpace' : '' +opensc_features += conf.get('ENABLE_OPENSSL')? ' openssl' : '' +opensc_features += conf.get('ENABLE_READLINE')? ' readline' : '' +opensc_features += conf.get('ENABLE_ZLIB')? ' zlib' : '' +opensc_features += conf.get('ENABLE_PCSC')? ' pcsc(@0@)'.format(conf.get_unquoted('DEFAULT_PCSC_PROVIDER')) : '' +opensc_features += conf.get('ENABLE_CRYPTOTOKENKIT')? ' cryptotokenkit' : '' +opensc_features += conf.get('ENABLE_OPENCT')? ' openct' : '' +opensc_features += conf.get('ENABLE_CTAPI')? ' ctapi' : '' +conf.set_quoted('OPENSC_FEATURES', opensc_features.strip()) +unset_variable('opensc_features') + +proggit = find_program('git', required: false) +if proggit.found() + description = run_command(proggit, 'describe', check: true).stdout().strip() + if description == '' + description = run_command(proggit, 'describe', '--tags', check: true).stdout().strip() + endif + hash_commit_date = run_command(proggit, 'log', '-1', '--pretty=format:rev: %h, commit-time: %ci', check: true).stdout().strip() + tag_commit = run_command(proggit, 'rev-list', '--tags', '--no-walk', '--max-count=1', check: true).stdout().strip() + revision = run_command(proggit, 'rev-list', tag_commit + '..HEAD', '--count', check: true).stdout().strip() + + conf.set_quoted('OPENSC_SCM_REVISION', 'OpenSC-@0@, @1@'.format(description, hash_commit_date)) + conf.set('OPENSC_VERSION_REVISION', revision) + + unset_variable('description') + unset_variable('hash_commit_date') + unset_variable('tag_commit') + unset_variable('revision') +else + conf.set_quoted('OPENSC_SCM_REVISION', '') + conf.set('OPENSC_VERSION_REVISION', '0') +endif + +if get_option('components').contains('tools') + proggengetopt = find_program('gengetopt') +endif + +if get_option('tests') + depcmocka = dependency('cmocka', version: '>= 1.0.1') +endif + +configure_file( + output: 'config.h', + configuration: conf +) +add_project_arguments('-DHAVE_CONFIG_H', language: all_languages) + +# Additional configuration for compatibility with autotools and nmake +# TODO: unify quoting after migration +conf_aux = configuration_data() +conf_aux.set('PACKAGE_NAME', conf.get_unquoted('PACKAGE_NAME')) +conf_aux.set('PACKAGE_VERSION', conf.get_unquoted('PACKAGE_VERSION')) +conf_aux.set('PACKAGE_BUGREPORT', conf.get_unquoted('PACKAGE_BUGREPORT')) +conf_aux.set('PACKAGE_TARNAME', conf.get_unquoted('PACKAGE_TARNAME')) +conf_aux.set('PACKAGE_URL', conf.get_unquoted('PACKAGE_URL')) +conf_aux.set('PACKAGE_SUMMARY', conf.get_unquoted('PACKAGE_SUMMARY')) + +conf_aux.set('OPENSC_VS_FF_COMPANY_NAME', conf.get_unquoted('OPENSC_VS_FF_COMPANY_NAME')) +conf_aux.set('OPENSC_VS_FF_COMPANY_URL', conf.get_unquoted('OPENSC_VS_FF_COMPANY_URL')) +conf_aux.set('OPENSC_VS_FF_PRODUCT_NAME', conf.get_unquoted('OPENSC_VS_FF_PRODUCT_NAME')) +conf_aux.set('OPENSC_VS_FF_PRODUCT_UPDATES', conf.get_unquoted('OPENSC_VS_FF_PRODUCT_UPDATES')) +conf_aux.set('OPENSC_VS_FF_PRODUCT_URL', conf.get_unquoted('OPENSC_VS_FF_PRODUCT_URL')) +conf_aux.set('OPENSC_VS_FF_COMMENTS', conf.get_unquoted('OPENSC_VS_FF_COMMENTS')) +conf_aux.set('OPENSC_VS_FF_LEGAL_COMPANY_NAME', conf.get_unquoted('OPENSC_VS_FF_LEGAL_COMPANY_NAME')) +conf_aux.set('OPENSC_VS_FF_LEGAL_COMPANY_URL', conf.get_unquoted('OPENSC_VS_FF_LEGAL_COMPANY_URL')) +conf_aux.set('OPENSC_VS_FF_LEGAL_COPYRIGHT', conf.get_unquoted('OPENSC_VS_FF_LEGAL_COPYRIGHT')) + +conf_aux.set('OPENSC_VERSION_MAJOR', project_version[0]) +conf_aux.set('OPENSC_VERSION_MINOR', project_version[1]) +conf_aux.set('OPENSC_VERSION_FIX', project_version[2]) + +conf_aux.set('OPENSC_VERSION_REVISION', conf.get_unquoted('OPENSC_VERSION_REVISION')) + +################################################# +# Build targets +################################################# +core_inc = include_directories('.', 'src') + +subdir('src' / 'common') +subdir('src' / 'scconf') +subdir('src' / 'ui') +subdir('src' / 'pkcs15init') +subdir('src' / 'sm') +subdir('src' / 'libopensc') + +if get_option('components').contains('pkcs11') + subdir('src' / 'pkcs11') +endif + +if get_option('components').contains('tools') + subdir('src' / 'tools') +endif + +if get_option('components').contains('minidriver') + subdir('src' / 'minidriver') +endif + +if get_option('components').contains('sm') + subdir('src' / 'smm') +endif + +subdir('etc') + +if get_option('tests') + subdir('src' / 'tests') +endif + +if host_machine.system() == 'windows' + subdir('win32') +endif + +if host_machine.system() == 'darwin' + subdir('MacOSX') +endif + +################################################# +# Documentation and completion files +################################################# +progxsltproc = find_program('xsltproc', required: false) +if progxsltproc.found() + stylesheets_path = get_option('xsl_stylesheets_path') + if stylesheets_path == '' + foreach path : [ + '/usr/share/xml/docbook/stylesheet/nwalsh', + '/usr/share/xml/docbook/stylesheet/nwalsh/current', + '/opt/local/share/xsl/docbook-xsl', + '/sw/share/xml/xsl/docbook-xsl' ] + + if modfs.exists(path / 'html' / 'docbook.xsl') + stylesheets_path = path + break + endif + endforeach + else + if not modfs.exists(stylesheets_path / 'html' / 'docbook.xsl') + error('The file @0@ does not exist'.format(stylesheets_path / 'html' / 'docbook.xsl')) + endif + endif +endif + +bash_completion_path = get_option('bash_completion_path') +if bash_completion_path == '' + depbashcompletion = dependency('bash-completion', version: '>= 2.0', required: false) + if depbashcompletion.found() + bash_completion_path = depbashcompletion.get_variable('completionsdir') + endif +endif + +subdir('doc' / 'files') + +if get_option('components').contains('tools') + subdir('doc' / 'tools') +endif + +install_data('NEWS', install_dir: absolute_docdir) + +################################################# +# Automated code checks +################################################# +progclangtidy = find_program('clang-tidy', required: false) +if progclangtidy.found() + run_target('clang-tidy', + command: [progclangtidy, + '-p', meson.project_build_root(), + '--config-file', meson.project_source_root() / '.clang-tidy', + meson.project_source_root() / 'src' / 'common' / 'compat_dummy.c', + meson.project_source_root() / 'src' / 'common' / 'compat_getopt.c', + meson.project_source_root() / 'src' / 'common' / 'compat_getopt.h', + meson.project_source_root() / 'src' / 'common' / 'compat_getpass.c', + meson.project_source_root() / 'src' / 'common' / 'compat_getpass.h', + meson.project_source_root() / 'src' / 'common' / 'compat___iob_func.c', + meson.project_source_root() / 'src' / 'common' / 'compat_overflow.c', + meson.project_source_root() / 'src' / 'common' / 'compat_overflow.h', + meson.project_source_root() / 'src' / 'common' / 'compat_report_rangecheckfailure.c', + meson.project_source_root() / 'src' / 'common' / 'compat_strlcat.c', + meson.project_source_root() / 'src' / 'common' / 'compat_strlcat.h', + meson.project_source_root() / 'src' / 'common' / 'compat_strlcpy.c', + meson.project_source_root() / 'src' / 'common' / 'compat_strlcpy.h', + meson.project_source_root() / 'src' / 'common' / 'compat_strnlen.c', + meson.project_source_root() / 'src' / 'common' / 'compat_strnlen.h', + meson.project_source_root() / 'src' / 'common' / 'constant-time.h', + meson.project_source_root() / 'src' / 'common' / 'libpkcs11.c', + meson.project_source_root() / 'src' / 'common' / 'libscdl.c', + meson.project_source_root() / 'src' / 'common' / 'simclist.c', + meson.project_source_root() / 'src' / 'common' / 'simclist.h', + + meson.project_source_root() / 'src' / 'libopensc' / 'apdu.c', + meson.project_source_root() / 'src' / 'libopensc' / 'asn1.c', + meson.project_source_root() / 'src' / 'libopensc' / 'aux-data.c', + meson.project_source_root() / 'src' / 'libopensc' / 'base64.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-asepcos.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-atrust-acos.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-authentic.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-belpic.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-cac1.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-cac.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-cac-common.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-cardos.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-coolkey.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-default.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-dtrust.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-edo.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-entersafe.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-eoi.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-epass2003.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-esteid2018.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-flex.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-gemsafeV1.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-iasecc.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-idprime.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-isoApplet.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-itacns.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-jpki.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-masktech.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-mcrd.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-muscle.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-myeid.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-npa.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-nqApplet.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-oberthur.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-rtecp.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-rutoken.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-sc-hsm.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-setcos.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-skeid.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-starcos.c', + meson.project_source_root() / 'src' / 'libopensc' / 'card-tcos.c', + meson.project_source_root() / 'src' / 'libopensc' / 'compression.c', + meson.project_source_root() / 'src' / 'libopensc' / 'ctbcs.c', + meson.project_source_root() / 'src' / 'libopensc' / 'ctx.c', + meson.project_source_root() / 'src' / 'libopensc' / 'cwa14890.c', + meson.project_source_root() / 'src' / 'libopensc' / 'cwa-dnie.c', + meson.project_source_root() / 'src' / 'libopensc' / 'dir.c', + meson.project_source_root() / 'src' / 'libopensc' / 'ef-atr.c', + meson.project_source_root() / 'src' / 'libopensc' / 'ef-gdo.c', + meson.project_source_root() / 'src' / 'libopensc' / 'errors.c', + meson.project_source_root() / 'src' / 'libopensc' / 'gp.c', + meson.project_source_root() / 'src' / 'libopensc' / 'iasecc-sdo.c', + meson.project_source_root() / 'src' / 'libopensc' / 'iasecc-sm.c', + meson.project_source_root() / 'src' / 'libopensc' / 'iso7816.c', + meson.project_source_root() / 'src' / 'libopensc' / 'muscle.c', + meson.project_source_root() / 'src' / 'libopensc' / 'muscle-filesystem.c', + meson.project_source_root() / 'src' / 'libopensc' / 'padding.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-actalis.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-algo.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-atrust-acos.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-cac.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-cache.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-cardos.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-cert.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-coolkey.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-data.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-din-66291.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-dnie.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-emulator-filter.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-esinit.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-esteid2018.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-gids.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-iasecc.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-idprime.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-itacns.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-jpki.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-nqApplet.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-oberthur.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-openpgp.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-pin.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-prkey.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-pteid.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-pubkey.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-sc-hsm.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-sec.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-skeid.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-skey.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-starcos-esign.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-syn.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-tccardos.c', + meson.project_source_root() / 'src' / 'libopensc' / 'pkcs15-tcos.c', + meson.project_source_root() / 'src' / 'libopensc' / 'reader-ctapi.c', + meson.project_source_root() / 'src' / 'libopensc' / 'reader-openct.c', + meson.project_source_root() / 'src' / 'libopensc' / 'reader-pcsc.c', + meson.project_source_root() / 'src' / 'libopensc' / 'reader-tr03119.c', + meson.project_source_root() / 'src' / 'libopensc' / 'sc.c', + meson.project_source_root() / 'src' / 'libopensc' / 'sec.c', + meson.project_source_root() / 'src' / 'libopensc' / 'simpletlv.c', + meson.project_source_root() / 'src' / 'libopensc' / 'sm.c', + + meson.project_source_root() / 'src' / 'pkcs11' / 'debug.c', + meson.project_source_root() / 'src' / 'pkcs11' / 'framework-pkcs15.c', + meson.project_source_root() / 'src' / 'pkcs11' / 'framework-pkcs15init.c', + meson.project_source_root() / 'src' / 'pkcs11' / 'mechanism.c', + meson.project_source_root() / 'src' / 'pkcs11' / 'openssl.c', + meson.project_source_root() / 'src' / 'pkcs11' / 'pkcs11-global.c', + meson.project_source_root() / 'src' / 'pkcs11' / 'pkcs11-object.c', + meson.project_source_root() / 'src' / 'pkcs11' / 'pkcs11-session.c', + meson.project_source_root() / 'src' / 'pkcs11' / 'slot.c', + ] + ) +endif diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000000..357de760f3 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,29 @@ +option('components', type: 'array', choices: ['pkcs11', 'tools', 'minidriver', 'sm'], value: ['pkcs11', 'tools']) + +option('driver', type: 'combo', choices: ['pcsc', 'cryptotokenkit', 'openct', 'ctapi'], value: 'pcsc', description: 'A card reader API that OpenSC will use') + +option('libopensc', type: 'combo', choices: ['shared', 'static', 'both'], value: 'shared', description: 'The type of an internal library of OpenSC') + +option('openpace', type: 'feature', value: 'auto', description: 'Use OpenPACE') +option('openssl', type: 'feature', value: 'auto', description: 'Use OpenSSL') +option('readline', type: 'feature', value: 'auto', description: 'Use readline') +option('zlib', type: 'feature', value: 'auto', description: 'Use zlib') +option('dnie_ui', type: 'feature', value: 'auto', description: 'Enable to request DNIe user pin with an external program') +option('p11kit', type: 'feature', value: 'auto', description: 'Install PKCS#11 libraries as p11-kit modules') + +option('openssl-secure-malloc', type: 'integer', min: 0, value: 0, description: 'Size of OpenSSL secure memory in bytes (must be a power of 2)') + +option('notify', type: 'boolean', value: true, description: 'Notification support') +option('thread_locking', type: 'boolean', value: true, description: 'Serialize threads in PKCS#11 API') +option('piv_sm', type: 'boolean', value: true, description: 'Enable secure messages in PIV card driver') +option('autostart', type: 'boolean', value: false, description: 'Launch "pkcs11-register" on user login') + +option('doc', type: 'boolean', value: true, description: 'Install documentation') +option('man', type: 'boolean', value: true, description: 'Install manual pages') +option('bash_completion', type: 'boolean', value: true, description: 'Install bash completion scripts') + +option('xsl_stylesheets_path', type: 'string', value: '') +option('bash_completion_path', type: 'string', value: '') + +option('tests', type: 'boolean', value: false, description: 'Build tests') +option('fuzzing_libs', type: 'string', value: '', description: 'Additional link argument for fuzzing tests') diff --git a/src/common/meson.build b/src/common/meson.build new file mode 100644 index 0000000000..9586df2e74 --- /dev/null +++ b/src/common/meson.build @@ -0,0 +1,29 @@ +libcompat = static_library('compat', + include_directories: core_inc, + sources: files( + 'compat_dummy.c', + 'compat_getopt.c', + 'compat_getopt_main.c', + 'compat_getpass.c', + 'compat___iob_func.c', + 'compat_overflow.c', + 'compat_report_rangecheckfailure.c', + 'compat_strlcat.c', + 'compat_strlcpy.c', + 'compat_strnlen.c', + 'simclist.c' + ) +) + +libscdl = static_library('scdl', + include_directories: core_inc, + sources: files('libscdl.c'), + dependencies: depdl +) + +libpkcs11_common = static_library('pkcs11', + include_directories: core_inc, + sources: files('libpkcs11.c'), + link_with: libscdl +) + diff --git a/src/libopensc/apdu.c b/src/libopensc/apdu.c index 099d152aa8..23a65160ac 100644 --- a/src/libopensc/apdu.c +++ b/src/libopensc/apdu.c @@ -563,7 +563,7 @@ int sc_transmit_apdu(sc_card_t *card, sc_apdu_t *apdu) return r; } -#if ENABLE_SM +#ifdef ENABLE_SM if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT && (apdu->flags & SC_APDU_FLAGS_CHAINING) != 0 && (apdu->flags & SC_APDU_FLAGS_SM_CHAINING) != 0) { diff --git a/src/libopensc/card-iasecc.c b/src/libopensc/card-iasecc.c index 4ecadc8bfb..e241dec2e7 100644 --- a/src/libopensc/card-iasecc.c +++ b/src/libopensc/card-iasecc.c @@ -792,7 +792,7 @@ iasecc_erase_binary(struct sc_card *card, unsigned int offs, size_t count, unsig } -#if ENABLE_SM +#ifdef ENABLE_SM static int _iasecc_sm_read_binary(struct sc_card *card, unsigned int offs, unsigned char *buff, size_t count) diff --git a/src/libopensc/iso7816.c b/src/libopensc/iso7816.c index 73893e9416..6ca38171de 100644 --- a/src/libopensc/iso7816.c +++ b/src/libopensc/iso7816.c @@ -1398,7 +1398,7 @@ static int iso7816_get_data(struct sc_card *card, unsigned int tag, u8 *buf, si static int iso7816_init(struct sc_card *card) { -#if ENABLE_SM +#ifdef ENABLE_SM memset(&card->sm_ctx, 0, sizeof card->sm_ctx); #endif return SC_SUCCESS; diff --git a/src/libopensc/libopensc.def.in b/src/libopensc/libopensc.def.in new file mode 100644 index 0000000000..1dbf0ab48a --- /dev/null +++ b/src/libopensc/libopensc.def.in @@ -0,0 +1,3 @@ +LIBRARY +EXPORTS +@EXPORTS@ diff --git a/src/libopensc/meson.build b/src/libopensc/meson.build new file mode 100644 index 0000000000..0c0ff367ee --- /dev/null +++ b/src/libopensc/meson.build @@ -0,0 +1,201 @@ +libopensc_sources = files( + 'apdu.c', + 'asn1.c', + 'aux-data.c', + 'base64.c', + 'card-asepcos.c', + 'card-atrust-acos.c', + 'card-authentic.c', + 'card-belpic.c', + 'card.c', + 'card-cac1.c', + 'card-cac.c', + 'card-cac-common.c', + 'card-cardos.c', + 'card-coolkey.c', + 'card-default.c', + 'card-dnie.c', + 'card-dtrust.c', + 'card-edo.c', + 'card-entersafe.c', + 'card-eoi.c', + 'card-epass2003.c', + 'card-esteid2018.c', + 'card-flex.c', + 'card-gemsafeV1.c', + 'card-gids.c', + 'card-iasecc.c', + 'card-idprime.c', + 'card-isoApplet.c', + 'card-itacns.c', + 'card-jpki.c', + 'card-masktech.c', + 'card-mcrd.c', + 'card-muscle.c', + 'card-myeid.c', + 'card-npa.c', + 'card-nqApplet.c', + 'card-oberthur.c', + 'card-openpgp.c', + 'card-piv.c', + 'card-rtecp.c', + 'card-rutoken.c', + 'card-sc-hsm.c', + 'card-setcos.c', + 'card-skeid.c', + 'card-starcos.c', + 'card-tcos.c', + 'compression.c', + 'ctbcs.c', + 'ctx.c', + 'cwa14890.c', + 'cwa-dnie.c', + 'dir.c', + 'ef-atr.c', + 'ef-gdo.c', + 'errors.c', + 'gp.c', + 'iasecc-sdo.c', + 'iasecc-sm.c', + 'iso7816.c', + 'log.c', + 'muscle.c', + 'muscle-filesystem.c', + 'padding.c', + 'pkcs15-actalis.c', + 'pkcs15-algo.c', + 'pkcs15-atrust-acos.c', + 'pkcs15.c', + 'pkcs15-cac.c', + 'pkcs15-cache.c', + 'pkcs15-cardos.c', + 'pkcs15-cert.c', + 'pkcs15-coolkey.c', + 'pkcs15-data.c', + 'pkcs15-din-66291.c', + 'pkcs15-dnie.c', + 'pkcs15-emulator-filter.c', + 'pkcs15-eoi.c', + 'pkcs15-esinit.c', + 'pkcs15-esteid2018.c', + 'pkcs15-gemsafeV1.c', + 'pkcs15-gids.c', + 'pkcs15-iasecc.c', + 'pkcs15-idprime.c', + 'pkcs15-itacns.c', + 'pkcs15-jpki.c', + 'pkcs15-nqApplet.c', + 'pkcs15-oberthur.c', + 'pkcs15-openpgp.c', + 'pkcs15-pin.c', + 'pkcs15-piv.c', + 'pkcs15-prkey.c', + 'pkcs15-pteid.c', + 'pkcs15-pubkey.c', + 'pkcs15-sc-hsm.c', + 'pkcs15-sec.c', + 'pkcs15-skeid.c', + 'pkcs15-skey.c', + 'pkcs15-starcert.c', + 'pkcs15-starcos-esign.c', + 'pkcs15-syn.c', + 'pkcs15-tccardos.c', + 'pkcs15-tcos.c', + 'reader-tr03119.c', + 'sc.c', + 'sec.c', + 'simpletlv.c', + 'sm.c' +) + +libopensc_libraries = [ + libcompat, + libscdl, + libscconf, + libstrings, + libnotify, + libpkcs15init, + libsmeac, + libsmiso +] + +libopensc_dependencies = [ + depopenpace, + depopenssl, + depzlib +] + +libopensc_targets = [] +if host_machine.system() == 'windows' or host_machine.system() == 'cygwin' + libopensc_targets += modwindows.compile_resources( + configure_file( + configuration: conf_aux, + input: meson.project_source_root() / 'win32' / 'versioninfo.rc.in', + output: 'versioninfo.rc' + ) + ) +endif + +libopensc_vs_defs = configure_file( + configuration: {'EXPORTS': modfs.read('libopensc.exports')}, + input: 'libopensc.def.in', + output: 'libopensc.def' +) + +if conf.get('ENABLE_PCSC') + libopensc_sources += files('reader-pcsc.c') + libopensc_dependencies += deppcsc +endif + +if conf.get('ENABLE_CRYPTOTOKENKIT') + libopensc_sources += files('reader-cryptotokenkit.m') + libopensc_dependencies += depcryptotokenkit +endif + +if conf.get('ENABLE_OPENCT') + libopensc_sources += files('reader-openct.c') + libopensc_dependencies += depopenct +endif + +if conf.get('ENABLE_CTAPI') + libopensc_sources += files('reader-ctapi.c') +endif + +libopensc_version = '11.0.2' + +if get_option('libopensc') == 'shared' + libopensc = shared_library('opensc', + libopensc_targets, + version: libopensc_version, + include_directories: core_inc, + sources: libopensc_sources, + link_with: libopensc_libraries, + dependencies: libopensc_dependencies, + vs_module_defs: libopensc_vs_defs, + install: true + ) + +elif get_option('libopensc') == 'static' + libopensc = static_library('opensc', + include_directories: core_inc, + sources: libopensc_sources, + link_with: libopensc_libraries, + dependencies: libopensc_dependencies, + install: get_option('default_library') != 'shared' + ) + +elif get_option('libopensc') == 'both' + libopensc = both_libraries('opensc', + libopensc_targets, + version: libopensc_version, + include_directories: core_inc, + sources: libopensc_sources, + link_with: libopensc_libraries, + dependencies: libopensc_dependencies, + vs_module_defs: libopensc_vs_defs, + install: true + ) + +else + error('The option "libopensc" has unknown value') +endif diff --git a/src/libopensc/sc.c b/src/libopensc/sc.c index cf3d86a022..490208bf23 100644 --- a/src/libopensc/sc.c +++ b/src/libopensc/sc.c @@ -951,11 +951,11 @@ void sc_mem_clear(void *ptr, size_t len) if (len > 0) { #ifdef HAVE_MEMSET_S memset_s(ptr, len, 0, len); -#elif _WIN32 +#elif defined(_WIN32) SecureZeroMemory(ptr, len); -#elif HAVE_EXPLICIT_BZERO +#elif defined(HAVE_EXPLICIT_BZERO) explicit_bzero(ptr, len); -#elif ENABLE_OPENSSL +#elif defined(ENABLE_OPENSSL) OPENSSL_cleanse(ptr, len); #else memset(ptr, 0, len); diff --git a/src/minidriver/meson.build b/src/minidriver/meson.build new file mode 100644 index 0000000000..9b90e7282f --- /dev/null +++ b/src/minidriver/meson.build @@ -0,0 +1,43 @@ +if host_machine.system() != 'windows' + error('The minidriver is intended for Windows only. Please remove it from the "components" option.') +endif + +libminidriver = shared_library('opensc-minidriver', + modwindows.compile_resources( + configure_file( + configuration: conf_aux, + input: 'versioninfo-minidriver.rc.in', + output: 'versioninfo-minidriver.rc' + ), + depend_files: meson.project_source_root() / 'win32' / 'DDORes.dll_14_2302.ico' + ), + include_directories: core_inc, + sources: files('minidriver.c'), + link_with: [ + libcompat, + libnotify, + libopensc, + libpkcs15init, + libstrings + ], + dependencies: [ + depopenpace, + depopenssl + ], + vs_module_defs: configure_file( + configuration: {'EXPORTS': modfs.read('minidriver.exports')}, + input: 'minidriver.def.in', + output: 'minidriver.def' + ), + install: true +) + +configure_file( + configuration: { + 'OPENSC_VERSION_MAJOR': conf.get('OPENSC_VERSION_MAJOR'), + 'OPENSC_VERSION_MINOR': conf.get('OPENSC_VERSION_MINOR'), + 'OPENSC_VERSION_FIX': conf.get('OPENSC_VERSION_FIX') + }, + input: 'opensc-minidriver.inf.in', + output: 'opensc-minidriver.inf' +) diff --git a/src/minidriver/minidriver.def.in b/src/minidriver/minidriver.def.in new file mode 100644 index 0000000000..1dbf0ab48a --- /dev/null +++ b/src/minidriver/minidriver.def.in @@ -0,0 +1,3 @@ +LIBRARY +EXPORTS +@EXPORTS@ diff --git a/src/pkcs11/meson.build b/src/pkcs11/meson.build new file mode 100644 index 0000000000..fa962d7ecf --- /dev/null +++ b/src/pkcs11/meson.build @@ -0,0 +1,150 @@ +libpkcs11_sources = files( + 'debug.c', + 'framework-pkcs15.c', + 'framework-pkcs15init.c', + 'mechanism.c', + 'misc.c', + 'openssl.c', + 'pkcs11-display.c', + 'pkcs11-global.c', + 'pkcs11-object.c', + 'pkcs11-session.c', + 'slot.c' +) + +libpkcs11_libraries = [ + libnotify, + libopensc +] + +libpkcs11_dependencies = [ + depopenpace, + depopenssl, + depthreads +] + +libpkcs11_targets = [] +if host_machine.system() == 'windows' or host_machine.system() == 'cygwin' + libpkcs11_targets += modwindows.compile_resources( + configure_file( + configuration: conf_aux, + input: 'versioninfo-pkcs11.rc.in', + output: 'versioninfo-pkcs11.rc' + ) + ) +endif + +libpkcs11_vs_defs = configure_file( + configuration: {'EXPORTS': modfs.read('pkcs11.exports')}, + input: 'pkcs11.def.in', + output: 'pkcs11.def' +) + + +libpkcs11spy_sources = files( + 'pkcs11-display.c', + 'pkcs11-spy.c' +) + +libpkcs11spy_libraries = [ + libpkcs11_common +] + +libpkcs11spy_dependencies = [ + depopenssl, + depthreads +] + +libpkcs11spy_targets = [] +if host_machine.system() == 'windows' or host_machine.system() == 'cygwin' + libpkcs11spy_targets += modwindows.compile_resources( + configure_file( + configuration: conf_aux, + input: 'versioninfo-pkcs11-spy.rc.in', + output: 'versioninfo-pkcs11-spy.rc' + ) + ) +endif + + +if depp11kit.found() + libpkcs11 = shared_library('opensc-pkcs11', + libpkcs11_targets, + name_prefix: '', + include_directories: core_inc, + sources: libpkcs11_sources, + link_with: libpkcs11_libraries, + dependencies: libpkcs11_dependencies, + vs_module_defs: libpkcs11_vs_defs, + install: true, + install_dir: p11kit_modules_path + ) + + libpkcs11spy = shared_library('pkcs11-spy', + libpkcs11spy_targets, + name_prefix: '', + include_directories: core_inc, + sources: libpkcs11spy_sources, + link_with: libpkcs11spy_libraries, + dependencies: libpkcs11spy_dependencies, + install: true, + install_dir: p11kit_modules_path + ) + + configure_file( + configuration: {'EXTENSION': extension_of_libraries}, + input: 'opensc.module.in', + output: 'opensc.module', + install: true, + install_dir: p11kit_configs_path + ) + + install_symlink('onepin-opensc-pkcs11.' + extension_of_libraries, + install_dir: p11kit_modules_path, + pointing_to: 'opensc-pkcs11.' + extension_of_libraries + ) +else + libpkcs11 = library('opensc-pkcs11', + libpkcs11_targets, + include_directories: core_inc, + sources: libpkcs11_sources, + link_with: libpkcs11_libraries, + dependencies: libpkcs11_dependencies, + vs_module_defs: libpkcs11_vs_defs, + install: true + ) + + libpkcs11spy = library('pkcs11-spy', + libpkcs11spy_targets, + include_directories: core_inc, + sources: libpkcs11spy_sources, + link_with: libpkcs11spy_libraries, + dependencies: libpkcs11spy_dependencies, + install: true + ) + + modpkgconfig.generate( + libpkcs11, + name: 'OpenSC smartcard framework', + version: meson.project_version(), + description: 'OpenSC PKCS#11 module', + url: 'https://github.com/OpenSC/OpenSC', + filebase: 'opensc-pkcs11' + ) + + extension = get_option('default_library') == 'static'? 'a' : extension_of_libraries + + install_symlink('onepin-opensc-pkcs11.' + extension, + install_dir: get_option('libdir'), + pointing_to: prefix_of_libraries + 'opensc-pkcs11.' + extension + ) + + if prefix_of_libraries != '' + install_symlink('opensc-pkcs11.' + extension, + install_dir: get_option('libdir'), + pointing_to: prefix_of_libraries + 'opensc-pkcs11.' + extension + ) + endif + + unset_variable('extension') +endif diff --git a/src/pkcs11/opensc-pkcs11.pc.in b/src/pkcs11/opensc-pkcs11.pc.in index 49cf735b0d..a0afcb1569 100644 --- a/src/pkcs11/opensc-pkcs11.pc.in +++ b/src/pkcs11/opensc-pkcs11.pc.in @@ -5,5 +5,5 @@ includedir=@includedir@ Name: OpenSC smartcard framework Description: OpenSC PKCS#11 module -Version: @VERSION@ +Version: @PACKAGE_VERSION@ Libs: -L${libdir} -lopensc-pkcs11 diff --git a/src/pkcs11/opensc.module.in b/src/pkcs11/opensc.module.in new file mode 100644 index 0000000000..c7b0f3bbf9 --- /dev/null +++ b/src/pkcs11/opensc.module.in @@ -0,0 +1 @@ +module: opensc-pkcs11.@EXTENSION@ diff --git a/src/pkcs11/pkcs11-global.c b/src/pkcs11/pkcs11-global.c index 65fcee73c9..424a774ffb 100644 --- a/src/pkcs11/pkcs11-global.c +++ b/src/pkcs11/pkcs11-global.c @@ -25,6 +25,7 @@ #ifdef HAVE_SYS_TIME_H #include #endif +#include #ifdef PKCS11_THREAD_LOCKING #if defined(HAVE_PTHREAD) @@ -587,7 +588,7 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese static sc_timestamp_t get_current_time(void) { -#if HAVE_GETTIMEOFDAY +#ifdef HAVE_GETTIMEOFDAY struct timeval tv; struct timezone tz; sc_timestamp_t curr; diff --git a/src/pkcs11/pkcs11.def.in b/src/pkcs11/pkcs11.def.in new file mode 100644 index 0000000000..1dbf0ab48a --- /dev/null +++ b/src/pkcs11/pkcs11.def.in @@ -0,0 +1,3 @@ +LIBRARY +EXPORTS +@EXPORTS@ diff --git a/src/pkcs15init/meson.build b/src/pkcs15init/meson.build new file mode 100644 index 0000000000..87595196cb --- /dev/null +++ b/src/pkcs15init/meson.build @@ -0,0 +1,58 @@ +libpkcs15init = static_library('pkcs15init', + include_directories: core_inc, + sources: files( + 'pkcs15-asepcos.c', + 'pkcs15-authentic.c', + 'pkcs15-cardos.c', + 'pkcs15-cflex.c', + 'pkcs15-entersafe.c', + 'pkcs15-epass2003.c', + 'pkcs15-gids.c', + 'pkcs15-iasecc.c', + 'pkcs15-isoApplet.c', + 'pkcs15-lib.c', + 'pkcs15-muscle.c', + 'pkcs15-myeid.c', + 'pkcs15-oberthur-awp.c', + 'pkcs15-oberthur.c', + 'pkcs15-openpgp.c', + 'pkcs15-rtecp.c', + 'pkcs15-rutoken.c', + 'pkcs15-sc-hsm.c', + 'pkcs15-setcos.c', + 'pkcs15-starcos.c', + 'profile.c' + ), + dependencies: depopenssl +) + +install_data( + 'asepcos.profile', + 'authentic.profile', + 'cardos.profile', + 'cyberflex.profile', + 'entersafe.profile', + 'epass2003.profile', + 'flex.profile', + 'gids.profile', + 'ias_adele_admin1.profile', + 'ias_adele_admin2.profile', + 'ias_adele_common.profile', + 'iasecc_admin_eid.profile', + 'iasecc_generic_oberthur.profile', + 'iasecc_generic_pki.profile', + 'iasecc.profile', + 'isoApplet.profile', + 'muscle.profile', + 'myeid.profile', + 'oberthur.profile', + 'openpgp.profile', + 'pkcs15.profile', + 'rutoken_ecp.profile', + 'rutoken_lite.profile', + 'rutoken.profile', + 'sc-hsm.profile', + 'setcos.profile', + 'starcos.profile', + install_dir: conf.get_unquoted('SC_PKCS15_PROFILE_DIRECTORY') +) diff --git a/src/scconf/meson.build b/src/scconf/meson.build new file mode 100644 index 0000000000..150cefe63a --- /dev/null +++ b/src/scconf/meson.build @@ -0,0 +1,9 @@ +libscconf = static_library('scconf', + include_directories: core_inc, + sources: files( + 'parse.c', + 'scconf.c', + 'sclex.c', + 'write.c' + ) +) diff --git a/src/sm/meson.build b/src/sm/meson.build new file mode 100644 index 0000000000..753c389091 --- /dev/null +++ b/src/sm/meson.build @@ -0,0 +1,22 @@ +libsmiso = static_library('smiso', + include_directories: core_inc, + sources: files('sm-iso.c') +) + +libsmeac = static_library('smeac', + include_directories: core_inc, + sources: files('sm-eac.c'), + link_with: libsmiso, + dependencies: [ + depopenpace, + depopenssl + ] +) + +if conf.get('ENABLE_OPENSSL') + libsm = static_library('sm', + include_directories: core_inc, + sources: files('sm-common.c'), + dependencies: depopenssl + ) +endif diff --git a/src/smm/meson.build b/src/smm/meson.build new file mode 100644 index 0000000000..b9df407b23 --- /dev/null +++ b/src/smm/meson.build @@ -0,0 +1,24 @@ +if conf.get('ENABLE_OPENSSL') + libsmm = library('smm-local', + version: '11.0.2', + include_directories: core_inc, + sources: files( + 'sm-card-authentic.c', + 'sm-card-iasecc.c', + 'sm-cwa14890.c', + 'sm-global-platform.c', + 'smm-local.c' + ), + link_with: [ + libopensc, + libsm + ], + dependencies: depopenssl, + vs_module_defs: configure_file( + configuration: {'EXPORTS': modfs.read('smm-local.exports')}, + input: 'smm-local.def.in', + output: 'smm-local.def' + ), + install: true + ) +endif diff --git a/src/smm/smm-local.def.in b/src/smm/smm-local.def.in new file mode 100644 index 0000000000..1dbf0ab48a --- /dev/null +++ b/src/smm/smm-local.def.in @@ -0,0 +1,3 @@ +LIBRARY +EXPORTS +@EXPORTS@ diff --git a/src/tests/meson.build b/src/tests/meson.build new file mode 100644 index 0000000000..daa2fc879c --- /dev/null +++ b/src/tests/meson.build @@ -0,0 +1,348 @@ +libtest = static_library('common', + include_directories: core_inc, + sources: files('sc-test.c'), + link_with: libopensc +) + +tests_targets = [] +if host_machine.system() == 'windows' or host_machine.system() == 'cygwin' + tests_targets += modwindows.compile_resources( + configure_file( + configuration: conf_aux, + input: meson.project_source_root() / 'win32' / 'versioninfo.rc.in', + output: 'versioninfo.rc' + ) + ) +endif + + +executable('base64', + tests_targets, + include_directories: core_inc, + sources: files('base64.c'), + link_with: [ + libopensc, + libtest + ] +) + +executable('lottery', + tests_targets, + include_directories: core_inc, + sources: files('lottery.c'), + link_with: [ + libopensc, + libtest + ] +) + +executable('p15dump', + tests_targets, + include_directories: core_inc, + sources: files( + 'p15dump.c', + 'print.c' + ), + link_with: [ + libopensc, + libtest + ] +) + +executable('pintest', + tests_targets, + include_directories: core_inc, + sources: files( + 'pintest.c', + 'print.c' + ), + link_with: [ + libcompat, + libopensc, + libtest + ] +) + +executable('prngtest', + tests_targets, + include_directories: core_inc, + sources: files('prngtest.c'), + link_with: [ + libopensc, + libtest + ] +) + +################################################# +# Unit tests +################################################# +ut_asn1 = executable('asn1', + include_directories: core_inc, + sources: files('unittests' / 'asn1.c'), + link_with: [ + libopensc, + libopensc_libraries + ], + dependencies: [ + depcmocka, + libopensc_dependencies + ] +) +test('asn1', ut_asn1) + +ut_cachedir = executable('cachedir', + include_directories: core_inc, + sources: files('unittests' / 'cachedir.c'), + link_with: libopensc, + dependencies: depcmocka +) +test('cachedir', ut_cachedir) + +ut_check_macro_reference_loop = executable('check_macro_reference_loop', + include_directories: core_inc, + sources: files('unittests' / 'check_macro_reference_loop.c'), + link_with: [ + libopensc, + libopensc_libraries + ], + dependencies: [ + depcmocka, + libopensc_dependencies + ] +) +test('check_macro_reference_loop', ut_check_macro_reference_loop) + +ut_decode_ecdsa_signature = executable('decode_ecdsa_signature', + include_directories: core_inc, + sources: files('unittests' / 'decode_ecdsa_signature.c'), + link_with: [ + libopensc, + libopensc_libraries + ], + dependencies: [ + depcmocka, + libopensc_dependencies + ] +) +test('decode_ecdsa_signature', ut_decode_ecdsa_signature) + +ut_hextobin = executable('hextobin', + include_directories: core_inc, + sources: files('unittests' / 'hextobin.c'), + link_with: libopensc, + dependencies: depcmocka +) +test('hextobin', ut_hextobin) + +ut_openpgp_tool = executable('openpgp-tool', + include_directories: core_inc, + sources: files( + 'unittests' / 'openpgp-tool.c', + '../tools/openpgp-tool-helpers.c' + ), + link_with: [ + libopensc, + libopensc_libraries + ], + dependencies: [ + depcmocka, + libopensc_dependencies + ] +) +test('openpgp-tool', ut_openpgp_tool) + +ut_pkcs15filter = executable('pkcs15filter', + include_directories: core_inc, + sources: files('unittests' / 'pkcs15-emulator-filter.c'), + link_with: [ + libopensc, + libopensc_libraries + ], + dependencies: [ + depcmocka, + libopensc_dependencies + ] +) +test('pkcs15filter', ut_pkcs15filter) + +ut_simpletlv = executable('simpletlv', + include_directories: core_inc, + sources: files('unittests' / 'simpletlv.c'), + link_with: [ + libopensc, + libopensc_libraries + ], + dependencies: [ + depcmocka, + libopensc_dependencies + ] +) +test('simpletlv', ut_simpletlv) + +ut_strip_pkcs1_2_padding = executable('strip_pkcs1_2_padding', + include_directories: core_inc, + sources: files('unittests' / 'strip_pkcs1_2_padding.c'), + link_with: [ + libopensc, + libopensc_libraries + ], + dependencies: [ + depcmocka, + libopensc_dependencies + ] +) +test('strip_pkcs1_2_padding', ut_strip_pkcs1_2_padding) + +if conf.get('ENABLE_OPENSSL') + ut_sm = executable('sm', + include_directories: core_inc, + sources: files('unittests' / 'sm.c'), + link_with: [ + libopensc, + libopensc_libraries, + libsm + ], + dependencies: [ + depcmocka, + libopensc_dependencies + ] + ) + test('sm', ut_sm) +endif + +if conf.get('ENABLE_ZLIB') + ut_compression = executable('compression', + include_directories: core_inc, + sources: files('unittests' / 'compression.c'), + link_with: [ + libopensc, + libopensc_libraries + ], + dependencies: [ + depcmocka, + libopensc_dependencies + ] + ) + test('compression', ut_compression) +endif + +################################################# +# p11test +################################################# +if conf.get('ENABLE_OPENSSL') + executable('p11test', + tests_targets, + include_directories: core_inc, + sources: files( + 'p11test' / 'p11test.c', + 'p11test' / 'p11test_case_common.c', + 'p11test' / 'p11test_case_ec_derive.c', + 'p11test' / 'p11test_case_ec_sign.c', + 'p11test' / 'p11test_case_interface.c', + 'p11test' / 'p11test_case_mechs.c', + 'p11test' / 'p11test_case_multipart.c', + 'p11test' / 'p11test_case_pss_oaep.c', + 'p11test' / 'p11test_case_readonly.c', + 'p11test' / 'p11test_case_secret.c', + 'p11test' / 'p11test_case_usage.c', + 'p11test' / 'p11test_case_wait.c', + 'p11test' / 'p11test_case_wrap.c', + 'p11test' / 'p11test_helpers.c', + 'p11test' / 'p11test_loader.c', + ), + dependencies: [ + depcmocka, + depopenssl + ] + ) +endif + +################################################# +# Fuzzing tests +################################################# +fuzzer_main = get_option('fuzzing_libs') == ''? files('fuzzing' / 'fuzzer.c') : '' + +fuzzers = { + 'fuzz_asn1_print': files('fuzzing' / 'fuzz_asn1_print.c'), + 'fuzz_asn1_sig_value': files('fuzzing' / 'fuzz_asn1_sig_value.c'), + 'fuzz_card': files( + 'fuzzing' / 'fuzz_card.c', + 'fuzzing' / 'fuzzer_reader.c' + ), + 'fuzz_pkcs15_crypt': files( + 'fuzzing' / 'fuzz_pkcs15_crypt.c', + 'fuzzing' / 'fuzzer_reader.c', + 'fuzzing' / 'fuzzer_tool.c', + '..' / 'tools' / 'util.c' + ), + 'fuzz_pkcs15_decode': files( + 'fuzzing' / 'fuzz_pkcs15_decode.c', + 'fuzzing' / 'fuzzer_reader.c' + ), + 'fuzz_pkcs15_encode': files( + 'fuzzing' / 'fuzz_pkcs15_encode.c', + 'fuzzing' / 'fuzzer_reader.c' + ), + 'fuzz_pkcs15_reader': files( + 'fuzzing' / 'fuzz_pkcs15_reader.c', + 'fuzzing' / 'fuzzer_reader.c' + ), + 'fuzz_pkcs15_tool': files( + 'fuzzing' / 'fuzz_pkcs15_tool.c', + 'fuzzing' / 'fuzzer_reader.c', + 'fuzzing' / 'fuzzer_tool.c', + '..' / 'pkcs11' / 'pkcs11-display.c', + '..' / 'tools' / 'util.c' + ), + 'fuzz_pkcs15init': files( + 'fuzzing' / 'fuzz_pkcs15init.c', + 'fuzzing' / 'fuzzer_reader.c' + ), + 'fuzz_scconf_parse_string': files('fuzzing' / 'fuzz_scconf_parse_string.c') +} +if conf.get('ENABLE_OPENSSL') + fuzzers += { + 'fuzz_piv_tool': files( + 'fuzzing' / 'fuzz_piv_tool.c', + 'fuzzing' / 'fuzzer_reader.c', + 'fuzzing' / 'fuzzer_tool.c', + '..' / 'tools' / 'util.c' + ) + } +endif + +foreach fuzzer, sources : fuzzers + executable(fuzzer, + include_directories: core_inc, + sources: [ + sources, + fuzzer_main + ], + link_with: [ + libopensc, + libopensc_libraries + ], + link_args: get_option('fuzzing_libs'), + dependencies: libopensc_dependencies + ) +endforeach + +if get_option('components').contains('pkcs11') + executable('fuzz_pkcs11', + include_directories: core_inc, + sources: [ + files( + 'fuzzing' / 'fuzz_pkcs11.c', + 'fuzzing' / 'fuzzer_reader.c', + 'fuzzing' / 'fuzzer_tool.c' + ), + fuzzer_main + ], + link_with: [ + libpkcs11, + libpkcs11_libraries + ], + link_args: get_option('fuzzing_libs'), + dependencies: libpkcs11_dependencies + ) +endif diff --git a/src/tests/p11test/p11test_case_common.c b/src/tests/p11test/p11test_case_common.c index ed8c2526d3..b5ad91685f 100644 --- a/src/tests/p11test/p11test_case_common.c +++ b/src/tests/p11test/p11test_case_common.c @@ -20,7 +20,7 @@ */ #include "p11test_case_common.h" -#include "../../libopensc/sc-ossl-compat.h" +#include "libopensc/sc-ossl-compat.h" /* Unsigned long can be up to 16 B long. We print also leading "0x" and we need trailing NULL byte */ #define FLAG_BUFFER_LEN 19 diff --git a/src/tests/p11test/runtest.sh b/src/tests/p11test/runtest.sh index c0aa7f43d1..6910a68e1e 100755 --- a/src/tests/p11test/runtest.sh +++ b/src/tests/p11test/runtest.sh @@ -22,9 +22,31 @@ SOPIN="12345678" PIN="123456" GENERATE_KEYS=1 -PKCS11_TOOL="../../tools/pkcs11-tool"; -PKCS15_INIT="env OPENSC_CONF=p11test_opensc.conf ../../tools/pkcs15-init" -SC_HSM_TOOL="../../tools/sc-hsm-tool"; + +if [ -z "$MESON_BUILD_ROOT" ]; then + export OPENSC_CONF="p11test_opensc.conf" + PKCS11_TOOL="../../tools/pkcs11-tool"; + PKCS15_INIT="../../tools/pkcs15-init" + SC_HSM_TOOL="../../tools/sc-hsm-tool"; + P11TEST="./p11test" + PKCS11_MODULE="../../pkcs11/.libs/opensc-pkcs11.so" + PKCS11SPY_MODULE="../../pkcs11/.libs/pkcs11-spy.so" + CERT_TEMPLATE="cert.cfg" + + make p11test || exit +else + export OPENSC_CONF="$MESON_SOURCE_ROOT/src/tests/p11test/p11test_opensc.conf" + PKCS11_TOOL="$MESON_BUILD_ROOT/src/tools/pkcs11-tool"; + PKCS15_INIT="$MESON_BUILD_ROOT/src/tools/pkcs15-init" + SC_HSM_TOOL="$MESON_BUILD_ROOT/src/tools/sc-hsm-tool"; + P11TEST="$MESON_BUILD_ROOT/src/tests/p11test" + PKCS11_MODULE="$MESON_BUILD_ROOT/src/pkcs11/libopensc-pkcs11.so" + PKCS11SPY_MODULE="$MESON_BUILD_ROOT/src/pkcs11/libpkcs11-spy.so" + CERT_TEMPLATE="$MESON_SOURCE_ROOT/src/tests/p11test/cert.cfg" + + meson -C "$MESON_BUILD_ROOT" compile src/tests/p11tool || exit +fi + function generate_sym() { TYPE="$1" @@ -70,18 +92,16 @@ function generate_cert() { TYPE_KEY="object-type" # Generate certificate - certtool --generate-self-signed --outfile="$TYPE.cert" --template=cert.cfg \ + certtool --generate-self-signed --outder --outfile="$TYPE.cert" --template="$CERT_TEMPLATE" \ --provider="$P11LIB" --load-privkey "pkcs11:object=$LABEL;$TYPE_KEY=private" \ --load-pubkey "pkcs11:object=$LABEL;$TYPE_KEY=public" - # convert to DER: - openssl x509 -inform PEM -outform DER -in "$TYPE.cert" -out "$TYPE.cert.der" # Write certificate #p11tool --login --write --load-certificate="$TYPE.cert" --label="$LABEL" \ # --provider="$P11LIB" - $PKCS11_TOOL --write-object "$TYPE.cert.der" --type=cert --id=$ID \ + $PKCS11_TOOL --write-object "$TYPE.cert" --type=cert --id=$ID \ --label="$LABEL" --module="$P11LIB" - rm "$TYPE.cert" "$TYPE.cert.der" + rm "$TYPE.cert" fi p11tool --login --provider="$P11LIB" --list-all @@ -135,13 +155,12 @@ function card_setup() { if [[ ! -z "$2" && -f "$2" ]]; then P11LIB="$2" else - P11LIB="/usr/lib64/pkcs11/opensc-pkcs11.so" - P11LIB="../pkcs11/.libs/opensc-pkcs11.so" + P11LIB="$PKCS11_MODULE" fi ;; "myeid") GENERATE_KEYS=0 # we generate them directly here - P11LIB="../../pkcs11/.libs/opensc-pkcs11.so" + P11LIB="$PKCS11_MODULE" $PKCS15_INIT --erase-card $PKCS15_INIT -C --pin $PIN --puk $SOPIN --so-pin $SOPIN --so-puk $SOPIN $PKCS15_INIT -P -a 1 -l "Basic PIN" --pin $PIN --puk $PIN @@ -156,14 +175,14 @@ function card_setup() { GENERATE_KEYS=0 # we generate them directly here SOPIN="3537363231383830" PIN="648219" - P11LIB="../../pkcs11/.libs/opensc-pkcs11.so" + P11LIB="$PKCS11_MODULE" $SC_HSM_TOOL --initialize --so-pin $SOPIN --pin $PIN - $PKCS11_TOOL --module $P11LIB -l --pin $PIN --keypairgen --key-type rsa:2048 --id 10 --label="RSA key" - $PKCS11_TOOL --module $P11LIB -l --pin $PIN --keypairgen --key-type EC:prime256v1 --label "EC key" + $PKCS11_TOOL --module "$P11LIB" -l --pin $PIN --keypairgen --key-type rsa:2048 --id 10 --label="RSA key" + $PKCS11_TOOL --module "$P11LIB" -l --pin $PIN --keypairgen --key-type EC:prime256v1 --label "EC key" ;; "epass2003") GENERATE_KEYS=0 # we generate them directly here - P11LIB="../../pkcs11/.libs/opensc-pkcs11.so" + P11LIB="$PKCS11_MODULE" PIN="987654" SOPIN="1234567890" $PKCS15_INIT --erase-card -T @@ -225,13 +244,13 @@ function card_cleanup() { } card_setup "$@" -make p11test || exit + if [[ "$PKCS11SPY" != "" ]]; then export PKCS11SPY="$P11LIB" - $VALGRIND ./p11test -v -m ../../pkcs11/.libs/pkcs11-spy.so -p $PIN &> /tmp/spy.log + $VALGRIND "$P11TEST" -v -m "$PKCS11SPY_MODULE" -p $PIN &> /tmp/spy.log echo "Output stored in /tmp/spy.log" else - $VALGRIND ./p11test -v -m "$P11LIB" -o test.json -p $PIN + $VALGRIND "$P11TEST" -v -m "$P11LIB" -o test.json -p $PIN fi card_cleanup "$@" diff --git a/src/tests/regression/functions b/src/tests/regression/functions index 65189a1eb7..7dccd92ab7 100755 --- a/src/tests/regression/functions +++ b/src/tests/regression/functions @@ -9,35 +9,55 @@ if [ -z "$__p15init__" ]; then p15base=${P15_BASE:-../..} p15temp=${P15_TEMP:-./test-data} - if [ "$1" == "--installed" ] - then - osctool=opensc-tool - p15crypt=pkcs15-crypt - p15tool=pkcs15-tool - p15init=pkcs15-init - p11tool=pkcs11-tool - p11module=/usr/lib/opensc-pkcs11.so - p15log=$p15temp/test.log - terrlog=$p15temp/terror.log - shift + p15log="$p15temp/test.log" + terrlog="$p15temp/terror.log" + + if [ -z "$MESON_BUILD_ROOT" ]; then + if [ "$1" == "--installed" ] + then + osctool=opensc-tool + p15crypt=pkcs15-crypt + p15tool=pkcs15-tool + p15init=pkcs15-init + p11tool=pkcs11-tool + p11module=/usr/lib/opensc-pkcs11.so + shift + else + osctool="$p15base/tools/opensc-tool" + p15crypt="$p15base/tools/pkcs15-crypt" + p15tool="$p15base/tools/pkcs15-tool" + p15init="$p15base/tools/pkcs15-init" + p15dump="$p15base/tests/p15dump" + p11tool="$p15base/tools/pkcs11-tool" + p11module="$p15base/pkcs11/.libs/opensc-pkcs11.so" + fi else - osctool=$p15base/tools/opensc-tool - p15crypt=$p15base/tools/pkcs15-crypt - p15tool=$p15base/tools/pkcs15-tool - p15init=$p15base/tools/pkcs15-init - p15dump=$p15base/tests/p15dump - p11tool=$p15base/tools/pkcs11-tool - p11module=$p15base/pkcs11/.libs/opensc-pkcs11.so - p15log=$p15temp/test.log - terrlog=$p15temp/terror.log - - for bin in $osctool $p15tool $p15crypt $p15init $p11tool; do - test -x $bin && continue - echo "*** Missing binary $bin" >&2 - exit 1 - done + if [ "$1" == "--installed" ] + then + osctool=opensc-tool + p15crypt=pkcs15-crypt + p15tool=pkcs15-tool + p15init=pkcs15-init + p11tool=pkcs11-tool + p11module=/usr/lib/libopensc-pkcs11.so + shift + else + osctool="$MESON_BUILD_ROOT/src/tools/opensc-tool" + p15crypt="$MESON_BUILD_ROOT/src/tools/pkcs15-crypt" + p15tool="$MESON_BUILD_ROOT/src/tools/pkcs15-tool" + p15init="$MESON_BUILD_ROOT/src/tools/pkcs15-init" + p15dump="$MESON_BUILD_ROOT/src/tests/p15dump" + p11tool="$MESON_BUILD_ROOT/src/tools/pkcs11-tool" + p11module="$MESON_BUILD_ROOT/src/pkcs11/libopensc-pkcs11.so" + fi fi + for bin in $osctool $p15tool $p15crypt $p15init $p11tool; do + test -x $bin && continue + echo "*** Missing binary $bin" >&2 + exit 1 + done + # Eat any arguments given on the command line while [ $# -ne 0 ]; do case $1 in diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am index aab4a81163..1202420fbb 100644 --- a/src/tools/Makefile.am +++ b/src/tools/Makefile.am @@ -9,7 +9,6 @@ endif do_subst = $(SED) \ -e 's,[@]bindir[@],$(bindir),g' \ -e 's,[@]CVCDIR[@],$(CVCDIR),g' \ - -e 's,[@]PACKAGE[@],$(PACKAGE),g' \ -e 's,[@]PACKAGE_BUGREPORT[@],$(PACKAGE_BUGREPORT),g' \ -e 's,[@]PACKAGE_NAME[@],$(PACKAGE_NAME),g' \ -e 's,[@]PACKAGE_TARNAME[@],$(PACKAGE_TARNAME),g' \ diff --git a/src/tools/meson.build b/src/tools/meson.build new file mode 100644 index 0000000000..9469cbbac5 --- /dev/null +++ b/src/tools/meson.build @@ -0,0 +1,520 @@ +libutil = static_library('util', + include_directories: core_inc, + sources: files( + 'fread_to_eof.c', + 'util.c' + ), + link_with: [ + libcompat, + libnotify, + libopensc + ] +) + +conf_tools = configuration_data() +conf_tools.set('bindir', absolute_bindir) +conf_tools.set('CVCDIR', conf.get_unquoted('CVCDIR')) +conf_tools.set('X509DIR', conf.get_unquoted('X509DIR')) +conf_tools.set('PACKAGE_NAME', conf.get_unquoted('PACKAGE_NAME')) +conf_tools.set('PACKAGE_VERSION', conf.get_unquoted('PACKAGE_VERSION')) +conf_tools.set('PACKAGE_BUGREPORT', conf.get_unquoted('PACKAGE_BUGREPORT')) +conf_tools.set('PACKAGE_TARNAME', conf.get_unquoted('PACKAGE_TARNAME')) +conf_tools.set('PACKAGE_URL', conf.get_unquoted('PACKAGE_URL')) +conf_tools.set('PACKAGE_SUMMARY', conf.get_unquoted('PACKAGE_SUMMARY')) +conf_tools.set('DEFAULT_PKCS11_PROVIDER', conf.get_unquoted('DEFAULT_PKCS11_PROVIDER')) +conf_tools.set('PKCS11_REGISTER_SKIP_FIREFOX', conf.get_unquoted('PKCS11_REGISTER_SKIP_FIREFOX')) +conf_tools.set('VDFORMAT', conf.get('ENABLE_ZLIB')? 'XML' : 'GZIP') + +tools_args = meson.get_compiler('c').get_supported_arguments( + '-Wno-unknown-warning-option' +) + +tools_targets = [] +if host_machine.system() == 'windows' or host_machine.system() == 'cygwin' + tools_targets += modwindows.compile_resources( + configure_file( + configuration: conf_aux, + input: 'versioninfo-tools.rc.in', + output: 'versioninfo-tools.rc' + ) + ) +endif + + +executable('cardos-tool', + tools_targets, + include_directories: core_inc, + sources: files('cardos-tool.c'), + link_with: [ + libopensc, + libutil + ], + dependencies: depopenssl, + install: true +) + + +executable('dnie-tool', + tools_targets, + include_directories: core_inc, + sources: files('dnie-tool.c'), + link_with: [ + libopensc, + libutil + ], + install: true +) + + +executable('dtrust-tool', + tools_targets, + include_directories: core_inc, + sources: files('dtrust-tool.c'), + link_with: [ + libopensc, + libutil + ], + install: true +) + + +egk_tool_target = custom_target( + command:[proggengetopt, + '--input=@INPUT@', + '--set-version=' + meson.project_version(), + '--output-dir=@OUTDIR@', + '--file-name=egk-tool-cmdline' + ], + input: configure_file( + configuration: conf_tools, + input: 'egk-tool.ggo.in', + output: 'egk-tool.ggo' + ), + output: ['egk-tool-cmdline.h', 'egk-tool-cmdline.c'] +) + +executable('egk-tool', + tools_targets, + egk_tool_target, + c_args: tools_args, + include_directories: core_inc, + sources: files('egk-tool.c'), + link_with: [ + libopensc, + libutil + ], + dependencies: depzlib, + install: true +) + + +executable('eidenv', + tools_targets, + include_directories: core_inc, + sources: files('eidenv.c'), + link_with: [ + libopensc, + libutil + ], + install: true +) + + +goid_tool_target = custom_target( + command:[proggengetopt, + '--input=@INPUT@', + '--set-version=' + meson.project_version(), + '--output-dir=@OUTDIR@', + '--file-name=goid-tool-cmdline' + ], + input: configure_file( + configuration: conf_tools, + input: 'goid-tool.ggo.in', + output: 'goid-tool.ggo' + ), + output: ['goid-tool-cmdline.h', 'goid-tool-cmdline.c'] +) + +executable('goid-tool', + tools_targets, + goid_tool_target, + c_args: tools_args, + include_directories: core_inc, + sources: files('goid-tool.c'), + link_with: [ + libopensc, + libsmeac, + libutil + ], + dependencies: depopenpace, + install: true +) + + +executable('iasecc-tool', + tools_targets, + include_directories: core_inc, + sources: files('iasecc-tool.c'), + link_with: [ + libopensc, + libutil + ], + install: true +) + + +executable('openpgp-tool', + tools_targets, + include_directories: core_inc, + sources: files( + 'openpgp-tool.c', + 'openpgp-tool-helpers.c' + ), + link_with: [ + libcompat, + libopensc, + libutil + ], + install: true +) + + +opensc_asn1_target = custom_target( + command:[proggengetopt, + '--input=@INPUT@', + '--set-version=' + meson.project_version(), + '--output-dir=@OUTDIR@', + '--file-name=opensc-asn1-cmdline' + ], + input: configure_file( + configuration: conf_tools, + input: 'opensc-asn1.ggo.in', + output: 'opensc-asn1.ggo' + ), + output: ['opensc-asn1-cmdline.h', 'opensc-asn1-cmdline.c'] +) + +executable('opensc-asn1', + tools_targets, + opensc_asn1_target, + c_args: tools_args, + include_directories: core_inc, + sources: files('opensc-asn1.c'), + link_with: [ + libopensc, + libutil + ], + install: true +) + + +executable('opensc-explorer', + tools_targets, + include_directories: core_inc, + sources: files('opensc-explorer.c'), + link_with: [ + libcompat, + libopensc, + libutil + ], + dependencies: depreadline, + install: true +) + + +executable('opensc-tool', + tools_targets, + include_directories: core_inc, + sources: files('opensc-tool.c'), + link_with: [ + libopensc, + libscconf, + libutil + ], + install: true +) + + +pkcs11_register_target = custom_target( + command:[proggengetopt, + '--input=@INPUT@', + '--set-version=' + meson.project_version(), + '--output-dir=@OUTDIR@', + '--file-name=pkcs11-register-cmdline' + ], + input: configure_file( + configuration: conf_tools, + input: 'pkcs11-register.ggo.in', + output: 'pkcs11-register.ggo' + ), + output: ['pkcs11-register-cmdline.h', 'pkcs11-register-cmdline.c'] +) + +executable('pkcs11-register', + tools_targets, + pkcs11_register_target, + c_args: tools_args, + include_directories: core_inc, + sources: files('pkcs11-register.c'), + link_with: [ + libpkcs11_common, + libutil + ], + install: true +) + + +pkcs11_tool_libraries = [ + libcompat, + libopensc, + libpkcs11_common, + libutil +] +if conf.get('ENABLE_PKCS11') and not conf.get('HAVE_P11KIT') and not conf.get('ENABLE_SHARED') + pkcs11_tool_libraries += libpkcs11 +endif + +executable('pkcs11-tool', + tools_targets, + include_directories: core_inc, + sources: files('pkcs11-tool.c'), + link_with: pkcs11_tool_libraries, + dependencies: [ + depopenssl, + depthreads + ], + install: true +) + + +executable('pkcs15-crypt', + tools_targets, + include_directories: core_inc, + sources: files('pkcs15-crypt.c'), + link_with: [ + libcompat, + libopensc, + libutil + ], + dependencies: depopenssl, + install: true +) + + +executable('pkcs15-tool', + tools_targets, + include_directories: core_inc, + sources: files( + 'pkcs15-tool.c', + '../pkcs11/pkcs11-display.c' + ), + link_with: [ + libopensc, + libutil + ], + dependencies: depopenssl, + install: true +) + + +if conf.get('ENABLE_OPENSSL') + executable('cryptoflex-tool', + tools_targets, + include_directories: core_inc, + sources: files('cryptoflex-tool.c'), + link_with: [ + libcompat, + libopensc, + libutil + ], + dependencies: depopenssl, + install: true + ) + + + executable('gids-tool', + tools_targets, + include_directories: core_inc, + sources: files('gids-tool.c'), + link_with: [ + libopensc, + libutil + ], + dependencies: depopenssl, + install: true + ) + + + executable('netkey-tool', + tools_targets, + include_directories: core_inc, + sources: files('netkey-tool.c'), + link_with: libopensc, + dependencies: depopenssl, + install: true + ) + + + executable('piv-tool', + tools_targets, + include_directories: core_inc, + sources: files('piv-tool.c'), + link_with: [ + libopensc, + libutil + ], + dependencies: depopenssl, + install: true + ) + + + executable('pkcs15-init', + tools_targets, + include_directories: core_inc, + sources: files('pkcs15-init.c'), + link_with: [ + libcompat, + libopensc, + libpkcs15init, + libutil + ], + dependencies: depopenssl, + install: true + ) + + + executable('sc-hsm-tool', + tools_targets, + include_directories: core_inc, + sources: files('sc-hsm-tool.c'), + link_with: [ + libopensc, + libutil + ], + dependencies: depopenssl, + install: true + ) + + + executable('westcos-tool', + tools_targets, + include_directories: core_inc, + sources: files('westcos-tool.c'), + link_with: [ + libopensc, + libutil + ], + dependencies: depopenssl, + install: true + ) + + + if conf.get('ENABLE_OPENPACE') + npa_tool_target = custom_target( + command:[proggengetopt, + '--input=@INPUT@', + '--set-version=' + meson.project_version(), + '--output-dir=@OUTDIR@', + '--file-name=npa-tool-cmdline' + ], + input: configure_file( + configuration: conf_tools, + input: 'npa-tool.ggo.in', + output: 'npa-tool.ggo' + ), + output: ['npa-tool-cmdline.h', 'npa-tool-cmdline.c'] + ) + + executable('npa-tool', + tools_targets, + npa_tool_target, + c_args: tools_args, + include_directories: core_inc, + sources: files('npa-tool.c'), + link_with: [ + libopensc, + libsmeac, + libutil + ], + dependencies: [ + depopenpace, + depopenssl + ], + install: true + ) + endif +endif + + +if conf.get('ENABLE_NOTIFY') + opensc_notify_targets = [] + opensc_notify_targets += custom_target( + command:[proggengetopt, + '--input=@INPUT@', + '--set-version=' + meson.project_version(), + '--output-dir=@OUTDIR@', + '--file-name=opensc-notify-cmdline' + ], + input: configure_file( + configuration: conf_tools, + input: 'opensc-notify.ggo.in', + output: 'opensc-notify.ggo' + ), + output: ['opensc-notify-cmdline.h', 'opensc-notify-cmdline.c'] + ) + + if host_machine.system() == 'windows' + opensc_notify_targets += modwindows.compile_resources( + configure_file( + configuration: conf_aux, + input: 'versioninfo-opensc-notify.rc.in', + output: 'versioninfo-opensc-notify.rc' + ), + depend_files: meson.project_source_root() / 'win32' / 'DDORes.dll_14_2302.ico' + ) + endif + + executable('opensc-notify', + opensc_notify_targets, + c_args: tools_args, + include_directories: core_inc, + sources: files('opensc-notify.c'), + link_with: [ + libopensc, + libnotify + ], + dependencies: depthreads, + install: true + ) + + configure_file( + configuration: {'bindir': absolute_bindir}, + input: 'org.opensc.notify.desktop.in', + output: 'org.opensc.notify.desktop', + install: true, + install_dir: get_option('datadir') / 'applications' + ) +endif + + +if get_option('autostart') + configure_file( + configuration: {'bindir': absolute_bindir}, + input: 'pkcs11-register.desktop.in', + output: 'pkcs11-register.desktop', + install: true, + install_dir: get_option('sysconfdir') / 'xdg' / 'autostart' + ) +endif + + +executable('sceac-example.c', + include_directories: core_inc, + sources: files('sceac-example.c'), + link_with: [ + libopensc, + libsmeac, + libsmiso + ], + build_by_default: false +) diff --git a/src/tools/npa-tool.c b/src/tools/npa-tool.c index 81a90a749d..b8218485d2 100644 --- a/src/tools/npa-tool.c +++ b/src/tools/npa-tool.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include diff --git a/src/tools/pkcs11-tool.c b/src/tools/pkcs11-tool.c index 4e1668290f..5ea258dce0 100644 --- a/src/tools/pkcs11-tool.c +++ b/src/tools/pkcs11-tool.c @@ -88,9 +88,13 @@ #endif #endif +#ifdef ENABLE_PKCS11 +#ifndef HAVE_P11KIT #ifndef ENABLE_SHARED extern CK_FUNCTION_LIST_3_0 pkcs11_function_list_3_0; #endif +#endif +#endif #if defined(_WIN32) || defined(HAVE_PTHREAD) #define MAX_TEST_THREADS 10 @@ -1169,10 +1173,14 @@ int main(int argc, char * argv[]) opt_module = expanded_val; #endif +#ifdef ENABLE_PKCS11 +#ifndef HAVE_P11KIT #ifndef ENABLE_SHARED if (strcmp(opt_module, DEFAULT_PKCS11_PROVIDER) == 0) p11 = &pkcs11_function_list_3_0; else +#endif +#endif #endif { CK_FUNCTION_LIST_PTR p11_v2 = NULL; diff --git a/src/ui/meson.build b/src/ui/meson.build new file mode 100644 index 0000000000..96731fedfa --- /dev/null +++ b/src/ui/meson.build @@ -0,0 +1,11 @@ +libstrings = static_library('strings', + include_directories: core_inc, + sources: files('strings.c'), + dependencies: depopenssl +) + +libnotify = static_library('notify', + include_directories: core_inc, + sources: files('notify.c'), + dependencies: depgio2 +) diff --git a/subprojects/dutil.wrap b/subprojects/dutil.wrap new file mode 100644 index 0000000000..0bf4a629fc --- /dev/null +++ b/subprojects/dutil.wrap @@ -0,0 +1,7 @@ +[wrap-file] +source_url = https://www.nuget.org/api/v2/package/WixToolset.DUtil/5.0.0 +source_filename = dutil.5.0.0.zip +source_hash = 522cd2fb68bb29c7971721924abfe32e8926a703c57c1ffa1bcab46170c3e836 +lead_directory_missing = true + +patch_directory = dutil diff --git a/subprojects/glib.wrap b/subprojects/glib.wrap new file mode 100644 index 0000000000..6e7aee2f35 --- /dev/null +++ b/subprojects/glib.wrap @@ -0,0 +1,11 @@ +[wrap-file] +directory = glib-2.80.0 +source_url = https://download.gnome.org/sources/glib/2.80/glib-2.80.0.tar.xz +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/glib_2.80.0-1/glib-2.80.0.tar.xz +source_filename = glib-2.80.0.tar.xz +source_hash = 8228a92f92a412160b139ae68b6345bd28f24434a7b5af150ebe21ff587a561d +wrapdb_version = 2.80.0-1 + +[provide] +dependency_names = gthread-2.0, gobject-2.0, gmodule-no-export-2.0, gmodule-export-2.0, gmodule-2.0, glib-2.0, gio-2.0, gio-windows-2.0, gio-unix-2.0 +program_names = glib-genmarshal, glib-mkenums, glib-compile-schemas, glib-compile-resources, gio-querymodules, gdbus-codegen diff --git a/subprojects/openpace.wrap b/subprojects/openpace.wrap new file mode 100644 index 0000000000..0269dbfb9a --- /dev/null +++ b/subprojects/openpace.wrap @@ -0,0 +1,10 @@ +[wrap-file] +directory = openpace-1.1.3 +source_url = https://github.com/frankmorgner/openpace/releases/download/1.1.3/openpace-1.1.3.tar.gz +source_filename = openpace-1.1.3.tar.gz +source_hash = ef82a172d82e8300b91b4ec08df282292ac841f9233188e00554f56e97c2c089 + +patch_directory = openpace + +[provide] +dependency_names = libeac diff --git a/subprojects/openssl.wrap b/subprojects/openssl.wrap new file mode 100644 index 0000000000..873d55106e --- /dev/null +++ b/subprojects/openssl.wrap @@ -0,0 +1,15 @@ +[wrap-file] +directory = openssl-3.0.8 +source_url = https://www.openssl.org/source/openssl-3.0.8.tar.gz +source_filename = openssl-3.0.8.tar.gz +source_hash = 6c13d2bf38fdf31eac3ce2a347073673f5d63263398f1f69d0df4a41253e4b3e +patch_filename = openssl_3.0.8-3_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/openssl_3.0.8-3/get_patch +patch_hash = 300da189e106942347d61a4a4295aa2edbcf06184f8d13b4cee0bed9fb936963 +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/openssl_3.0.8-3/openssl-3.0.8.tar.gz +wrapdb_version = 3.0.8-3 + +[provide] +libcrypto = libcrypto_dep +libssl = libssl_dep +openssl = openssl_dep diff --git a/subprojects/packagefiles/dutil/meson.build b/subprojects/packagefiles/dutil/meson.build new file mode 100644 index 0000000000..e8eb8cc9c4 --- /dev/null +++ b/subprojects/packagefiles/dutil/meson.build @@ -0,0 +1,21 @@ +project('dutil', 'cpp') + +if meson.get_compiler('cpp', native: false).get_id() != 'msvc' + error('Unsuitable compiler: this subproject requires Microsoft Visual Studio only') +endif + +if host_machine.cpu_family() == 'x86_64' + folder = 'x64' +elif host_machine.cpu_family() == 'aarch64' + folder = 'ARM64' +elif host_machine.cpu_family() == 'x86' + folder = 'x86' +else + error('Unsuitable architecture: this subproject requires x86, x86_64 or aarch64 only') +endif + +depdutil = declare_dependency( + include_directories: 'build' / 'native' / 'include', + dependencies: meson.get_compiler('cpp').find_library('dutil', dirs: meson.project_source_root() / 'build' / 'native' / 'v14' / folder) +) + diff --git a/subprojects/packagefiles/openpace/meson.build b/subprojects/packagefiles/openpace/meson.build new file mode 100644 index 0000000000..c4dbd8bdec --- /dev/null +++ b/subprojects/packagefiles/openpace/meson.build @@ -0,0 +1,42 @@ +project('openpace', 'c', + version: '1.1.3', + meson_version : '>= 0.57.0' + ) + +modfs = import('fs') +modexternalproject = import('unstable-external_project') + +absolute_sysconfdir = (modfs.is_absolute(get_option('sysconfdir'))? '' : get_option('prefix')) / get_option('sysconfdir') + +cv_certificates_path = get_option('cv_certificates_path') +if cv_certificates_path == '' + cv_certificates_path = absolute_sysconfdir / 'eac' / 'cvc' +endif + +x509_certificates_path = get_option('x509_certificates_path') +if x509_certificates_path == '' + x509_certificates_path = absolute_sysconfdir / 'eac' / 'x509' +endif + +depopenpace = modexternalproject.add_project('configure', + configure_options: [ + '--enable-static', + '--enable-cvcdir=' + cv_certificates_path, + '--enable-x509dir=' + x509_certificates_path, + '--disable-shared', + '--disable-python', + '--disable-java', + '--disable-ruby', + '--disable-go', + '--with-pic' + ] +).dependency('eac') + +meson.override_dependency('libeac', declare_dependency( + dependencies: depopenpace, + variables: { + 'cvcdir': cv_certificates_path, + 'x509dir': x509_certificates_path + } +)) + diff --git a/subprojects/packagefiles/openpace/meson_options.txt b/subprojects/packagefiles/openpace/meson_options.txt new file mode 100644 index 0000000000..0f47a430b5 --- /dev/null +++ b/subprojects/packagefiles/openpace/meson_options.txt @@ -0,0 +1,2 @@ +option('cv_certificates_path', type: 'string', value: '') +option('x509_certificates_path', type: 'string', value: '') diff --git a/subprojects/packagefiles/wcautil/meson.build b/subprojects/packagefiles/wcautil/meson.build new file mode 100644 index 0000000000..9d74c82217 --- /dev/null +++ b/subprojects/packagefiles/wcautil/meson.build @@ -0,0 +1,21 @@ +project('wcautil', 'cpp') + +if meson.get_compiler('cpp', native: false).get_id() != 'msvc' + error('Unsuitable compiler: this subproject requires Microsoft Visual Studio only') +endif + +if host_machine.cpu_family() == 'x86_64' + folder = 'x64' +elif host_machine.cpu_family() == 'aarch64' + folder = 'ARM64' +elif host_machine.cpu_family() == 'x86' + folder = 'x86' +else + error('Unsuitable architecture: this subproject requires x86, x86_64 or aarch64 only') +endif + +depwcautil = declare_dependency( + include_directories: 'build' / 'native' / 'include', + dependencies: meson.get_compiler('cpp').find_library('wcautil', dirs: meson.project_source_root() / 'build' / 'native' / 'v14' / folder) +) + diff --git a/subprojects/wcautil.wrap b/subprojects/wcautil.wrap new file mode 100644 index 0000000000..a20c8b1c83 --- /dev/null +++ b/subprojects/wcautil.wrap @@ -0,0 +1,7 @@ +[wrap-file] +source_url = https://www.nuget.org/api/v2/package/WixToolset.WcaUtil/5.0.0 +source_filename = wcautil.5.0.0.zip +source_hash = 41822b81ca28f19a5599fa9a4af5f50de052ae94d04f705bcc9b6835d6cd2004 +lead_directory_missing = true + +patch_directory = wcautil diff --git a/subprojects/zlib.wrap b/subprojects/zlib.wrap new file mode 100644 index 0000000000..aa14de1774 --- /dev/null +++ b/subprojects/zlib.wrap @@ -0,0 +1,13 @@ +[wrap-file] +directory = zlib-1.3.1 +source_url = http://zlib.net/fossils/zlib-1.3.1.tar.gz +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/zlib_1.3.1-1/zlib-1.3.1.tar.gz +source_filename = zlib-1.3.1.tar.gz +source_hash = 9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23 +patch_filename = zlib_1.3.1-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/zlib_1.3.1-1/get_patch +patch_hash = e79b98eb24a75392009cec6f99ca5cdca9881ff20bfa174e8b8926d5c7a47095 +wrapdb_version = 1.3.1-1 + +[provide] +zlib = zlib_dep diff --git a/tests/common.sh b/tests/common.sh index b1a3bbf904..ec62e64e61 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -1,18 +1,24 @@ #!/bin/bash ## from OpenSC/src/tests/p11test/runtest.sh -BUILD_PATH=${BUILD_PATH:-..} # run valgrind with all the switches we are interested in if [ -n "$VALGRIND" -a -n "$LOG_COMPILER" ]; then VALGRIND="$LOG_COMPILER" fi +if [ -z "$MESON_BUILD_ROOT" ]; then + BUILD_PATH=${BUILD_PATH:-..} +else + BUILD_PATH="$MESON_BUILD_ROOT" +fi + SOPIN="12345678" PIN="123456" PKCS11_TOOL="$VALGRIND $BUILD_PATH/src/tools/pkcs11-tool" softhsm_paths="/usr/local/lib/softhsm/libsofthsm2.so \ - /usr/lib/softhsm/libsofthsm2.so + /usr/lib/softhsm/libsofthsm2.so \ + /usr/lib/pkcs11/libsofthsm2.so \ /usr/lib64/pkcs11/libsofthsm2.so \ /usr/lib/i386-linux-gnu/softhsm/libsofthsm2.so \ /usr/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so" diff --git a/tests/test-duplicate-symbols.sh b/tests/test-duplicate-symbols.sh index 6cecc51e4a..d015b7857f 100755 --- a/tests/test-duplicate-symbols.sh +++ b/tests/test-duplicate-symbols.sh @@ -1,7 +1,11 @@ #!/bin/bash -SOURCE_PATH=${SOURCE_PATH:-..} -EXPORTS=`find "${SOURCE_PATH}" -name "*exports"` +if [ -z "$MESON_BUILD_ROOT" ]; then + SOURCE_PATH=${SOURCE_PATH:-..} + EXPORTS=`find "${SOURCE_PATH}" -name "*exports"` +else + EXPORTS=`find "${MESON_BUILD_ROOT}" -name "*symbols"` +fi ERRORS=0 for E in $EXPORTS; do diff --git a/tests/test-fuzzing.sh b/tests/test-fuzzing.sh index 2f24f57c04..c91f33fbbf 100755 --- a/tests/test-fuzzing.sh +++ b/tests/test-fuzzing.sh @@ -2,15 +2,21 @@ set -ex +if [ -z "$MESON_BUILD_ROOT" ]; then + ROOT="" +else + ROOT="$MESON_BUILD_ROOT/" +fi + case "$1" in "pkcs11-tool") - CMD="src/tools/pkcs11-tool --test --login --pin 123456" + CMD="${ROOT}src/tools/pkcs11-tool --test --login --pin 123456" ;; "pkcs15-tool") - CMD="src/tools/pkcs15-tool --dump" + CMD="${ROOT}src/tools/pkcs15-tool --dump" ;; "eidenv") - CMD="src/tools/eidenv" + CMD="${ROOT}src/tools/eidenv" ;; *) echo "Unknown fuzzing target" diff --git a/tests/test-manpage.sh b/tests/test-manpage.sh index da36a88693..a44f4b6b9d 100755 --- a/tests/test-manpage.sh +++ b/tests/test-manpage.sh @@ -1,12 +1,19 @@ #!/bin/bash -x -SOURCE_PATH=${SOURCE_PATH:-..} + +if [ -z "$MESON_BUILD_ROOT" ]; then + SOURCE_PATH=${SOURCE_PATH:-..} + BUILD_PATH=${BUILD_PATH:-..} +else + SOURCE_PATH="$MESON_SOURCE_ROOT" + BUILD_PATH="$MESON_BUILD_ROOT" +fi # find all the manual pages in doc/tools TOOLS=`find "${SOURCE_PATH}/doc/tools" -name "*.1.xml" | sed -E -e "s|.*/([a-z0-9-]*).*|\1|"` ALL=1 for T in $TOOLS; do - SWITCHES=$( ${SOURCE_PATH}/src/tools/${T} --help 2>&1 \ + SWITCHES=$( ${BUILD_PATH}/src/tools/${T} --help 2>&1 \ | grep -v "unrecognized option '--help'" \ | awk '{if (match($0,"--[a-zA-Z0-9-]*",a) != 0) print a[0]} {if (match($0," -[a-zA-Z0-9]",a) != 0) print a[0]}' ) @@ -22,7 +29,7 @@ fi RES=0 # find all tools in src/tools (files without extension) -TOOLS=`find "${SOURCE_PATH}/src/tools" -maxdepth 1 -type f ! -name "*.*" | sed -E -e "s|.*/([a-z0-9-]*).*|\1|" | grep -v -- -example` +TOOLS=`find "${BUILD_PATH}/src/tools" -maxdepth 1 -type f ! -name "*.*" | sed -E -e "s|.*/([a-z0-9-]*).*|\1|" | grep -v -- -example` for T in $TOOLS; do if [[ ! -f "${SOURCE_PATH}/doc/tools/$T.1.xml" ]]; then echo "Missing manual page for '$T'" diff --git a/tests/test-p11test.sh b/tests/test-p11test.sh index a8eab0640e..e9d553338a 100755 --- a/tests/test-p11test.sh +++ b/tests/test-p11test.sh @@ -1,7 +1,18 @@ #!/bin/bash -SOURCE_PATH=${SOURCE_PATH:-..} -source $SOURCE_PATH/tests/common.sh +if [ -z "$MESON_BUILD_ROOT" ]; then + SOURCE_PATH=${SOURCE_PATH:-..} + BUILD_PATH=${BUILD_PATH:-..} + P11TEST="./../src/tests/p11test/p11test" + PKCS11SPY_MODULE="../src/pkcs11/.libs/pkcs11-spy.so" +else + SOURCE_PATH="$MESON_SOURCE_ROOT" + BUILD_PATH="$MESON_BUILD_ROOT" + P11TEST="$MESON_BUILD_ROOT/src/tests/p11test" + PKCS11SPY_MODULE="$MESON_BUILD_ROOT/src/pkcs11/libpkcs11-spy.so" +fi + +source "$SOURCE_PATH/tests/common.sh" echo "=======================================================" echo "Setup SoftHSM" @@ -20,7 +31,7 @@ assert $? "Failed to set up card" echo "=======================================================" echo "Run p11test" echo "=======================================================" -$VALGRIND ./../src/tests/p11test/p11test -v -m $P11LIB -o softhsm.json -p $PIN +$VALGRIND "$P11TEST" -v -m $P11LIB -o softhsm.json -p $PIN assert $? "Failed running tests" # Run the input shrough sed to skip the mechanism part: @@ -39,7 +50,7 @@ echo "=======================================================" echo "Run p11test with PKCS11SPY" echo "=======================================================" export PKCS11SPY="$P11LIB" -$VALGRIND ./../src/tests/p11test/p11test -v -m ../src/pkcs11/.libs/pkcs11-spy.so -o softhsm.json -p $PIN +$VALGRIND "$P11TEST" -v -m "$PKCS11SPY_MODULE" -o softhsm.json -p $PIN assert $? "Failed running tests" diff -U3 <(filter_log $SOURCE_PATH/tests/softhsm_ref.json) <(filter_log softhsm.json) diff --git a/tests/test-pkcs11-tool-allowed-mechanisms.sh b/tests/test-pkcs11-tool-allowed-mechanisms.sh index f9bb0dabd4..7471fbeb32 100755 --- a/tests/test-pkcs11-tool-allowed-mechanisms.sh +++ b/tests/test-pkcs11-tool-allowed-mechanisms.sh @@ -1,7 +1,14 @@ #!/bin/bash -SOURCE_PATH=${SOURCE_PATH:-..} -source $SOURCE_PATH/tests/common.sh +if [ -z "$MESON_BUILD_ROOT" ]; then + SOURCE_PATH=${SOURCE_PATH:-..} + BUILD_PATH=${BUILD_PATH:-..} +else + SOURCE_PATH="$MESON_SOURCE_ROOT" + BUILD_PATH="$MESON_BUILD_ROOT" +fi + +source "$SOURCE_PATH/tests/common.sh" echo "=======================================================" echo "Setup SoftHSM" diff --git a/tests/test-pkcs11-tool-import.sh b/tests/test-pkcs11-tool-import.sh index 653d0491ae..58897c5a35 100755 --- a/tests/test-pkcs11-tool-import.sh +++ b/tests/test-pkcs11-tool-import.sh @@ -1,7 +1,14 @@ #!/bin/bash -SOURCE_PATH=${SOURCE_PATH:-..} -source $SOURCE_PATH/tests/common.sh +if [ -z "$MESON_BUILD_ROOT" ]; then + SOURCE_PATH=${SOURCE_PATH:-..} + BUILD_PATH=${BUILD_PATH:-..} +else + SOURCE_PATH="$MESON_SOURCE_ROOT" + BUILD_PATH="$MESON_BUILD_ROOT" +fi + +source "$SOURCE_PATH/tests/common.sh" echo "=======================================================" echo "Setup SoftHSM" @@ -32,7 +39,7 @@ for KEYTYPE in "RSA" "EC"; do openssl pkey -in "${KEYTYPE}_private.der" -out "${KEYTYPE}_public.der" -pubout -inform DER -outform DER assert $? "Failed to convert private $KEYTYPE key to public" $PKCS11_TOOL --write-object "${KEYTYPE}_public.der" --id "$ID" --type pubkey --label "$KEYTYPE" \ - -p $PIN --module $P11LIB + -p $PIN --module "$P11LIB" assert $? "Failed to write public $KEYTYPE key" # certificate import already tested in all other tests diff --git a/tests/test-pkcs11-tool-sign-verify.sh b/tests/test-pkcs11-tool-sign-verify.sh index 8f8df6dd3c..c110fb5d8e 100755 --- a/tests/test-pkcs11-tool-sign-verify.sh +++ b/tests/test-pkcs11-tool-sign-verify.sh @@ -1,7 +1,13 @@ #!/bin/bash -SOURCE_PATH=${SOURCE_PATH:-..} +if [ -z "$MESON_BUILD_ROOT" ]; then + SOURCE_PATH=${SOURCE_PATH:-..} + BUILD_PATH=${BUILD_PATH:-..} +else + SOURCE_PATH="$MESON_SOURCE_ROOT" + BUILD_PATH="$MESON_BUILD_ROOT" +fi -source $SOURCE_PATH/tests/common.sh +source "$SOURCE_PATH/tests/common.sh" echo "=======================================================" echo "Setup SoftHSM" @@ -38,7 +44,7 @@ for HASH in "" "SHA1" "SHA224" "SHA256" "SHA384" "SHA512"; do echo "=======================================================" echo "$METHOD: Sign & Verify (KEY $SIGN_KEY)" echo "=======================================================" - $PKCS11_TOOL --id $SIGN_KEY -s -p $PIN -m $METHOD --module $P11LIB \ + $PKCS11_TOOL --id $SIGN_KEY -s -p $PIN -m $METHOD --module "$P11LIB" \ --input-file data --output-file data.sig assert $? "Failed to Sign data" @@ -58,7 +64,7 @@ for HASH in "" "SHA1" "SHA224" "SHA256" "SHA384" "SHA512"; do fi # pkcs11-tool verification - $PKCS11_TOOL --id $SIGN_KEY --verify -m $METHOD --module $P11LIB \ + $PKCS11_TOOL --id $SIGN_KEY --verify -m $METHOD --module "$P11LIB" \ --input-file data --signature-file data.sig assert $? "Failed to Verify signature using pkcs11-tool" rm data.sig @@ -90,7 +96,7 @@ for HASH in "" "SHA1" "SHA224" "SHA256" "SHA384" "SHA512"; do VERIFY_DGEST="-${HASH,,*}" VERIFY_OPTS="-sigopt rsa_mgf1_md:${HASH,,*}" fi - $PKCS11_TOOL --id $SIGN_KEY -s -p $PIN -m $METHOD --module $P11LIB \ + $PKCS11_TOOL --id $SIGN_KEY -s -p $PIN -m $METHOD --module "$P11LIB" \ $HASH_ALGORITM --salt-len=-1 \ --input-file data.hash --output-file data.sig assert $? "Failed to Sign data" @@ -106,7 +112,7 @@ for HASH in "" "SHA1" "SHA224" "SHA256" "SHA384" "SHA512"; do fi # pkcs11-tool verification - $PKCS11_TOOL --id $SIGN_KEY --verify -m $METHOD --module $P11LIB \ + $PKCS11_TOOL --id $SIGN_KEY --verify -m $METHOD --module "$P11LIB" \ $HASH_ALGORITM --salt-len=-1 \ --input-file data.hash --signature-file data.sig assert $? "Failed to Verify signature using pkcs11-tool" @@ -133,7 +139,7 @@ for HASH in "" "SHA1" "SHA224" "SHA256" "SHA384" "SHA512"; do # -pubin -out data.crypt assert $? "Failed to encrypt data using OpenSSL" $PKCS11_TOOL --id $ENC_KEY --decrypt -p $PIN -m $METHOD \ - --module $P11LIB --input-file data.crypt > data.decrypted + --module "$P11LIB" --input-file data.crypt > data.decrypted diff data{,.decrypted} assert $? "The decrypted data do not match the original" rm data.{crypt,decrypted} @@ -155,10 +161,10 @@ for SIGN_KEY in "03" "04"; do echo "$METHOD: Sign & Verify (KEY $SIGN_KEY)" echo "=======================================================" openssl dgst -binary -sha256 data > data.hash - $PKCS11_TOOL --id $SIGN_KEY -s -p $PIN -m $METHOD --module $P11LIB \ + $PKCS11_TOOL --id $SIGN_KEY -s -p $PIN -m $METHOD --module "$P11LIB" \ --input-file data.hash --output-file data.sig assert $? "Failed to Sign data" - $PKCS11_TOOL --id $SIGN_KEY -s -p $PIN -m $METHOD --module $P11LIB \ + $PKCS11_TOOL --id $SIGN_KEY -s -p $PIN -m $METHOD --module "$P11LIB" \ --input-file data.hash --output-file data.sig.openssl \ --signature-format openssl assert $? "Failed to Sign data into OpenSSL format" @@ -169,7 +175,7 @@ for SIGN_KEY in "03" "04"; do assert $? "Failed to Verify signature using OpenSSL" # pkcs11-tool verification - $PKCS11_TOOL --id $SIGN_KEY --verify -m $METHOD --module $P11LIB \ + $PKCS11_TOOL --id $SIGN_KEY --verify -m $METHOD --module "$P11LIB" \ --input-file data.hash --signature-file data.sig assert $? "Failed to Verify signature using pkcs11-tool" rm data.sig{,.openssl} data.hash @@ -188,10 +194,10 @@ for MECHANISM in "SHA-1-HMAC" "SHA256-HMAC" "SHA384-HMAC" "SHA512-HMAC"; do echo "=======================================================" $PKCS11_TOOL --login --pin=$PIN --sign --mechanism=$MECHANISM \ - --input-file=data.msg --output-file=data.sig --module $P11LIB + --input-file=data.msg --output-file=data.sig --module "$P11LIB" assert $? "Failed to Sign data" $PKCS11_TOOL --login --pin=$PIN --verify --mechanism=$MECHANISM \ - --input-file=data.msg --signature-file=data.sig --module $P11LIB + --input-file=data.msg --signature-file=data.sig --module "$P11LIB" assert $? "Failed to Verify signature using pkcs11-tool" rm data.sig done; diff --git a/tests/test-pkcs11-tool-sym-crypt-test.sh b/tests/test-pkcs11-tool-sym-crypt-test.sh index b55fc0515c..0cd6bf0001 100755 --- a/tests/test-pkcs11-tool-sym-crypt-test.sh +++ b/tests/test-pkcs11-tool-sym-crypt-test.sh @@ -1,6 +1,14 @@ #!/bin/bash -source common.sh +if [ -z "$MESON_BUILD_ROOT" ]; then + SOURCE_PATH=${SOURCE_PATH:-..} + BUILD_PATH=${BUILD_PATH:-..} +else + SOURCE_PATH="$MESON_SOURCE_ROOT" + BUILD_PATH="$MESON_BUILD_ROOT" +fi + +source "$SOURCE_PATH/tests/common.sh" echo "=======================================================" echo "Setup SoftHSM" diff --git a/tests/test-pkcs11-tool-test-threads.sh b/tests/test-pkcs11-tool-test-threads.sh index bf2a060eeb..acc7b43533 100755 --- a/tests/test-pkcs11-tool-test-threads.sh +++ b/tests/test-pkcs11-tool-test-threads.sh @@ -1,10 +1,20 @@ #!/bin/bash -SOURCE_PATH=${SOURCE_PATH:-..} -source $SOURCE_PATH/tests/common.sh +if [ -z "$MESON_BUILD_ROOT" ]; then + SOURCE_PATH=${SOURCE_PATH:-..} + BUILD_PATH=${BUILD_PATH:-..} +else + SOURCE_PATH="$MESON_SOURCE_ROOT" + BUILD_PATH="$MESON_BUILD_ROOT" +fi -# Test our PKCS #11 module here -P11LIB="../src/pkcs11/.libs/opensc-pkcs11.so" +source "$SOURCE_PATH/tests/common.sh" + +if [ -z "$MESON_BUILD_ROOT" ]; then + P11LIB="../src/pkcs11/.libs/opensc-pkcs11.so" +else + P11LIB="$MESON_BUILD_ROOT/src/pkcs11/libopensc-pkcs11.so" +fi echo "=======================================================" echo "Test pkcs11 threads IN " diff --git a/tests/test-pkcs11-tool-test.sh b/tests/test-pkcs11-tool-test.sh index 1a96cbd754..a318132e6e 100755 --- a/tests/test-pkcs11-tool-test.sh +++ b/tests/test-pkcs11-tool-test.sh @@ -1,7 +1,14 @@ #!/bin/bash -SOURCE_PATH=${SOURCE_PATH:-..} -source $SOURCE_PATH/tests/common.sh +if [ -z "$MESON_BUILD_ROOT" ]; then + SOURCE_PATH=${SOURCE_PATH:-..} + BUILD_PATH=${BUILD_PATH:-..} +else + SOURCE_PATH="$MESON_SOURCE_ROOT" + BUILD_PATH="$MESON_BUILD_ROOT" +fi + +source "$SOURCE_PATH/tests/common.sh" echo "=======================================================" echo "Setup SoftHSM" diff --git a/tests/test-pkcs11-tool-unwrap-wrap-test.sh b/tests/test-pkcs11-tool-unwrap-wrap-test.sh index a785bb7aac..ac13d99fe0 100755 --- a/tests/test-pkcs11-tool-unwrap-wrap-test.sh +++ b/tests/test-pkcs11-tool-unwrap-wrap-test.sh @@ -1,5 +1,14 @@ #!/bin/bash -source common.sh + +if [ -z "$MESON_BUILD_ROOT" ]; then + SOURCE_PATH=${SOURCE_PATH:-..} + BUILD_PATH=${BUILD_PATH:-..} +else + SOURCE_PATH="$MESON_SOURCE_ROOT" + BUILD_PATH="$MESON_BUILD_ROOT" +fi + +source "$SOURCE_PATH/tests/common.sh" echo "=======================================================" echo "Setup SoftHSM" diff --git a/win32/OpenSC.iss.in b/win32/OpenSC.iss.in index faf607ff2b..8e84482e05 100644 --- a/win32/OpenSC.iss.in +++ b/win32/OpenSC.iss.in @@ -3,7 +3,7 @@ AppName=@OPENSC_VS_FF_PRODUCT_NAME@ AppVerName=@OPENSC_VS_FF_PRODUCT_NAME@ @PACKAGE_VERSION@ AppPublisher=@OPENSC_VS_FF_LEGAL_COMPANY_NAME@ AppPublisherURL=@OPENSC_VS_FF_COMPANY_URL@ -AppSupportURL=@PRODUCT_BUGREPORT@ +AppSupportURL=@PACKAGE_BUGREPORT@ AppUpdatesURL=@OPENSC_VS_FF_PRODUCT_UPDATES@ DefaultDirName={pf}\OpenSC Project\OpenSC OutputBaseFilename=OpenSC-@PACKAGE_VERSION@ diff --git a/win32/OpenSC.wxs.in b/win32/OpenSC.wxs.in index 9191da43af..5b3feac236 100644 --- a/win32/OpenSC.wxs.in +++ b/win32/OpenSC.wxs.in @@ -28,7 +28,7 @@ Version="@OPENSC_VERSION_MAJOR@.@OPENSC_VERSION_MINOR@.@OPENSC_VERSION_FIX@.@OPENSC_VERSION_REVISION@" Manufacturer="@OPENSC_VS_FF_COMPANY_NAME@"> - + diff --git a/win32/meson.build b/win32/meson.build new file mode 100644 index 0000000000..26eb094e42 --- /dev/null +++ b/win32/meson.build @@ -0,0 +1,32 @@ +configure_file( + configuration: conf_aux, + input: 'OpenSC.iss.in', + output: 'OpenSC.iss' +) + +if meson.get_compiler('cpp').get_id() == 'msvc' + depdutil = subproject('dutil').get_variable('depdutil') + depwcautil = subproject('wcautil').get_variable('depwcautil') + + shared_library('customactions', + modwindows.compile_resources( + configure_file( + configuration: conf_aux, + input: 'versioninfo-customactions.rc.in', + output: 'versioninfo-customactions.rc' + ) + ), + include_directories: core_inc, + sources: files('customactions.cpp'), + dependencies: [ + depdutil, + depwcautil + ] + ) + + configure_file( + configuration: conf, + input: 'OpenSC.wxs.in', + output: 'OpenSC.wxs' + ) +endif diff --git a/win32/winconfig.h.in b/win32/winconfig.h.in index de053c016d..f154b1dabf 100644 --- a/win32/winconfig.h.in +++ b/win32/winconfig.h.in @@ -4,7 +4,6 @@ #include #include #include -#include #include #ifdef _MSC_VER