diff --git a/Makefile.am b/Makefile.am index ea17862d1..ca77f2f04 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,7 @@ NULL = AM_CPPFLAGS = \ -I$(top_srcdir) \ -I$(top_srcdir)/common \ + -I$(top_builddir)/common \ -DBINDIR=\"$(bindir)\" \ -DBUILDDIR=\"$(abs_builddir)\" \ -DDATA_DIR=\"$(datadir)\" \ diff --git a/common/Makefile.am b/common/Makefile.am index 571ecf894..4eac28163 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -141,4 +141,51 @@ common_frob_getprogname_SOURCES = common/frob-getprogname.c common_frob_getprogname_LDADD = $(common_LIBS) endif +if WITH_ASN1 +SUFFIXES += .asn .asn.h +.asn.asn.h: + $(AM_V_GEN)$(ASN1PARSER) -o $@ $< + +asn_h = \ + common/basic.asn.h \ + common/openssl.asn.h \ + common/pkix.asn.h \ + $(NULL) + +BUILT_SOURCES += $(asn_h) + +EXTRA_DIST += \ + common/basic.asn \ + common/openssl.asn \ + common/pkix.asn \ + $(NULL) + +noinst_LTLIBRARIES += libp11-asn1.la + +libp11_asn1_la_SOURCES = \ + common/asn1.c common/asn1.h \ + common/oid.c common/oid.h \ + $(asn_h) \ + $(NULL) + +asn1_LIBS = \ + libp11-asn1.la \ + $(LIBTASN1_LIBS) \ + $(common_LIBS) \ + $(NULL) + +test_asn1_SOURCES = common/test-asn1.c +test_asn1_LDADD = $(asn1_LIBS) +test_asn1_CFLAGS = $(LIBTASN1_CFLAGS) + +test_oid_SOURCES = common/test-oid.c +test_oid_LDADD = $(asn1_LIBS) +test_oid_CFLAGS = $(LIBTASN1_CFLAGS) + +c_tests += \ + test-asn1 \ + test-oid \ + $(NULL) +endif + EXTRA_DIST += common/meson.build diff --git a/trust/asn1.c b/common/asn1.c similarity index 100% rename from trust/asn1.c rename to common/asn1.c diff --git a/trust/asn1.h b/common/asn1.h similarity index 100% rename from trust/asn1.h rename to common/asn1.h diff --git a/trust/basic.asn b/common/basic.asn similarity index 100% rename from trust/basic.asn rename to common/basic.asn diff --git a/common/meson.build b/common/meson.build index a66a97198..621af8f2c 100644 --- a/common/meson.build +++ b/common/meson.build @@ -65,6 +65,54 @@ libp11_tool = static_library('p11-tool', libp11_tool_sources, libp11_tool_dep = declare_dependency(link_with: libp11_tool, dependencies: [libp11_common_dep]) +libp11_asn1_deps = [] + +if with_asn1 + libp11_asn1_sources = [ + 'asn1.c', + 'oid.c', + ] + + basic_asn_h = custom_target( + 'basic.asn.h', + output: 'basic.asn.h', + input: 'basic.asn', + command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@'], + ) + + pkix_asn_h = custom_target( + 'pkix.asn.h', + output: 'pkix.asn.h', + input: 'pkix.asn', + command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@'], + ) + + openssl_asn_h = custom_target( + 'openssl.asn.h', + output: 'openssl.asn.h', + input: 'openssl.asn', + command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@'], + ) + + asn_h_dep = declare_dependency( + sources: [basic_asn_h, pkix_asn_h, openssl_asn_h], + ) + + libp11_asn1 = static_library( + 'p11-asn1', libp11_asn1_sources, + gnu_symbol_visibility: 'hidden', + include_directories: configinc, + ) + + libp11_asn1_dep = declare_dependency( + include_directories: [configinc, commoninc], + link_with: libp11_asn1, + dependencies: [asn_h_dep] + libtasn1_deps, + ) + + libp11_asn1_deps += libp11_asn1_dep +endif + # Tests ---------------------------------------------------------------- if get_option('test') @@ -111,6 +159,22 @@ if get_option('test') test(name, t) endforeach + if with_asn1 + asn1_tests = [ + 'test-asn1', + 'test-oid', + ] + + foreach name : asn1_tests + t = executable(name, '@0@.c'.format(name), + c_args: tests_c_args, + include_directories: configinc, + dependencies: libp11_asn1_deps + dlopen_deps, + link_with: [libp11_test, libp11_common]) + test(name, t) + endforeach + endif + common_progs = [ 'frob-getauxval', 'frob-getenv' diff --git a/trust/oid.c b/common/oid.c similarity index 100% rename from trust/oid.c rename to common/oid.c diff --git a/trust/oid.h b/common/oid.h similarity index 100% rename from trust/oid.h rename to common/oid.h diff --git a/trust/openssl.asn b/common/openssl.asn similarity index 100% rename from trust/openssl.asn rename to common/openssl.asn diff --git a/trust/pkix.asn b/common/pkix.asn similarity index 100% rename from trust/pkix.asn rename to common/pkix.asn diff --git a/trust/test-asn1.c b/common/test-asn1.c similarity index 99% rename from trust/test-asn1.c rename to common/test-asn1.c index 5c5ee2671..2938ea50d 100644 --- a/trust/test-asn1.c +++ b/common/test-asn1.c @@ -38,7 +38,6 @@ #include "asn1.h" #include "debug.h" #include "oid.h" -#include "x509.h" #include #include diff --git a/trust/test-oid.c b/common/test-oid.c similarity index 100% rename from trust/test-oid.c rename to common/test-oid.c diff --git a/meson.build b/meson.build index cc606386b..71b682199 100644 --- a/meson.build +++ b/meson.build @@ -398,6 +398,7 @@ endif # -------------------------------------------------------------------- # Trust Module +with_asn1 = false with_trust_module = false libtasn1_deps = [] libtasn1 = dependency('libtasn1', version: '>= 2.3', @@ -407,6 +408,7 @@ if libtasn1.found() if asn1Parser.found() conf.set('WITH_ASN1', 1) libtasn1_deps += libtasn1 + with_asn1 = true with_trust_module = true endif endif diff --git a/trust/Makefile.am b/trust/Makefile.am index c8e4ab161..e7685a1f9 100644 --- a/trust/Makefile.am +++ b/trust/Makefile.am @@ -8,11 +8,8 @@ check_LTLIBRARIES += \ $(NULL) libtrust_data_la_SOURCES = \ - trust/asn1.c trust/asn1.h \ - trust/oid.c trust/oid.h \ trust/utf8.c trust/utf8.h \ trust/x509.c trust/x509.h \ - $(asn_h) \ $(NULL) libtrust_data_la_CFLAGS = \ @@ -52,6 +49,7 @@ p11_kit_trust_la_LIBADD = \ libtrust-data.la \ libp11-library.la \ libp11-common.la \ + libp11-asn1.la \ $(LIBTASN1_LIBS) \ $(HASH_LIBS) \ $(NULL) @@ -85,6 +83,7 @@ trust_trust_LDADD = \ libp11-kit.la \ libp11-common.la \ libp11-tool.la \ + libp11-asn1.la \ $(LTLIBINTL) \ $(LIBTASN1_LIBS) \ $(HASH_LIBS) \ @@ -113,7 +112,6 @@ trust_trust_SOURCES = \ trust/save.c trust/save.h \ trust/check-format.c trust/check-format.h \ trust/trust.c \ - $(asn_h) \ $(NULL) externaldir = $(privatedir) @@ -129,22 +127,6 @@ EXTRA_DIST += \ trust/p11-kit-trust.module \ trust/meson.build -SUFFIXES += .asn .asn.h -.asn.asn.h: - $(AM_V_GEN)$(ASN1PARSER) -o $@ $< - -asn_h = \ - trust/basic.asn.h \ - trust/openssl.asn.h \ - trust/pkix.asn.h - -BUILT_SOURCES += $(asn_h) - -EXTRA_DIST += \ - trust/basic.asn \ - trust/openssl.asn \ - trust/pkix.asn - # Tests ---------------------------------------------------------------- trust_CFLAGS = \ @@ -159,6 +141,7 @@ trust_LIBS = \ libp11-library.la \ libp11-test.la \ libp11-common.la \ + libp11-asn1.la \ $(LIBTASN1_LIBS) \ $(HASH_LIBS) \ $(NULL) @@ -173,7 +156,6 @@ libtrust_test_la_SOURCES = \ c_tests += \ test-digest \ - test-asn1 \ test-base64 \ test-pem \ test-oid \ @@ -194,10 +176,6 @@ c_tests += \ test-jks \ $(NULL) -test_asn1_SOURCES = trust/test-asn1.c -test_asn1_LDADD = $(trust_LIBS) -test_asn1_CFLAGS = $(trust_CFLAGS) - test_base64_SOURCES = trust/test-base64.c test_base64_LDADD = $(trust_LIBS) test_base64_CFLAGS = $(trust_CFLAGS) @@ -230,10 +208,6 @@ test_module_SOURCES = trust/test-module.c test_module_LDADD = $(trust_LIBS) test_module_CFLAGS = $(trust_CFLAGS) -test_oid_SOURCES = trust/test-oid.c -test_oid_LDADD = $(trust_LIBS) -test_oid_CFLAGS = $(trust_CFLAGS) - test_openssl_SOURCES = trust/test-openssl.c test_openssl_LDADD = $(trust_LIBS) test_openssl_CFLAGS = $(trust_CFLAGS) diff --git a/trust/meson.build b/trust/meson.build index b6a87d74f..9f9e11f35 100644 --- a/trust/meson.build +++ b/trust/meson.build @@ -1,33 +1,12 @@ libtrust_data_sources = [ - 'asn1.c', - 'oid.c', 'utf8.c', 'x509.c' ] -basic_asn_h = custom_target('basic.asn.h', - output: 'basic.asn.h', - input: 'basic.asn', - command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@']) - -pkix_asn_h = custom_target('pkix.asn.h', - output: 'pkix.asn.h', - input: 'pkix.asn', - command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@']) - -openssl_asn_h = custom_target('openssl.asn.h', - output: 'openssl.asn.h', - input: 'openssl.asn', - command: [asn1Parser, '-o', '@OUTPUT@', '@INPUT@']) - -asn_h_dep = declare_dependency( - sources: [basic_asn_h, pkix_asn_h, openssl_asn_h] -) - libtrust_data = static_library('libtrust-data', libtrust_data_sources, include_directories: [configinc, commoninc], - dependencies: [asn_h_dep] + libtasn1_deps) + dependencies: libp11_asn1_deps) libtrust_sources = [ 'builder.c', @@ -54,7 +33,7 @@ shared_module('p11-kit-trust', 'module-init.c', name_prefix: '', c_args: p11_kit_trust_c_args, - dependencies: [asn_h_dep, libp11_library_dep] + dlopen_deps + libtasn1_deps, + dependencies: [libp11_library_dep] + libp11_asn1_deps + dlopen_deps, link_args: p11_module_ldflags, link_depends: [p11_module_symbol_map], link_with: libtrust_data, @@ -119,10 +98,8 @@ if get_option('test') trust_tests = [ 'test-digest', - 'test-asn1', 'test-base64', 'test-pem', - 'test-oid', 'test-utf8', 'test-x509', 'test-persist',