Skip to content

Commit 1488556

Browse files
committed
tpm2-pkcs11: enable integration tests
h/t @illdefined for the work on these; see: #378737 (comment) Only difference is a nixfmt pass.
1 parent de85fc8 commit 1488556

File tree

2 files changed

+150
-18
lines changed

2 files changed

+150
-18
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
diff --git a/Makefile-integration.am b/Makefile-integration.am
2+
index e2255de..3cea1d8 100644
3+
--- a/Makefile-integration.am
4+
+++ b/Makefile-integration.am
5+
@@ -7,7 +7,6 @@ integration_scripts = \
6+
test/integration/pkcs11-dbup.sh.nosetup \
7+
test/integration/tls-tests.sh \
8+
test/integration/openssl.sh \
9+
- test/integration/pkcs11-javarunner.sh.java \
10+
test/integration/nss-tests.sh \
11+
test/integration/ptool-link.sh.nosetup \
12+
test/integration/python-pkcs11.sh
13+
@@ -110,13 +109,5 @@ test_integration_pkcs_lockout_int_CFLAGS = $(AM_CFLAGS) $(TESTS_CFLAGS)
14+
test_integration_pkcs_lockout_int_LDADD = $(TESTS_LDADD) $(SQLITE3_LIBS)
15+
test_integration_pkcs_lockout_int_SOURCES = test/integration/pkcs-lockout.int.c test/integration/test.c
16+
17+
-#
18+
-# Java Tests
19+
-#
20+
-AM_JAVA_LOG_FLAGS = --tabrmd-tcti=$(TABRMD_TCTI) --tsetup-script=$(top_srcdir)/test/integration/scripts/create_pkcs_store.sh
21+
-JAVA_LOG_COMPILER=$(LOG_COMPILER)
22+
-dist_noinst_JAVA = test/integration/PKCS11JavaTests.java
23+
-CLEANFILES += test/integration/PKCS11JavaTests.class
24+
-
25+
endif
26+
# END INTEGRATION
27+
diff --git a/configure.ac b/configure.ac
28+
index 1ec6eb4..7a0a8ee 100644
29+
--- a/configure.ac
30+
+++ b/configure.ac
31+
@@ -258,13 +258,6 @@ AC_ARG_ENABLE(
32+
[build and execute integration tests])],,
33+
[enable_integration=no])
34+
35+
-# Test for Java compiler and interpreter without throwing fatal errors (since
36+
-# these macros are defined using AC_DEFUN they cannot be called conditionally)
37+
-m4_pushdef([AC_MSG_ERROR], [have_javac=no])
38+
-AX_PROG_JAVAC()
39+
-AX_PROG_JAVA()
40+
-m4_popdef([AC_MSG_ERROR])
41+
-
42+
AC_DEFUN([integration_test_checks], [
43+
44+
AC_CHECK_PROG([tpm2_createprimary], [tpm2_createprimary], [yes], [no])
45+
@@ -382,13 +375,6 @@ AC_DEFUN([integration_test_checks], [
46+
[AC_MSG_ERROR([Integration tests enabled but tss2_provision executable not found.])])
47+
])
48+
49+
- AS_IF([test "x$have_javac" = "xno"],
50+
- [AC_MSG_ERROR([Integration tests enabled but no Java compiler was found])])
51+
- AX_CHECK_CLASS([org.junit.Assert], ,
52+
- [AC_MSG_ERROR([Integration tests enabled but JUnit not found, try setting CLASSPATH])])
53+
- AX_CHECK_CLASS([org.hamcrest.SelfDescribing], ,
54+
- [AC_MSG_ERROR([Integration tests enabled but Hamcrest not found, try setting CLASSPATH])])
55+
-
56+
AC_SUBST([ENABLE_INTEGRATION], [$enable_integration])
57+
]) # end function integration_test_checks
58+

pkgs/by-name/tp/tpm2-pkcs11/package.nix

Lines changed: 92 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
11
{
22
autoconf-archive,
33
autoreconfHook,
4+
buildEnv,
45
clangStdenv,
56
cmocka,
7+
dbus,
8+
expect,
69
fetchFromGitHub,
710
glibc,
11+
gnutls,
12+
iproute2,
813
lib,
914
libyaml,
1015
makeWrapper,
1116
opensc,
17+
openssh,
1218
openssl,
19+
nss,
20+
p11-kit,
1321
patchelf,
1422
pkg-config,
1523
python3,
1624
stdenv,
1725
sqlite,
26+
swtpm,
1827
tpm2-abrmd,
28+
tpm2-openssl,
1929
tpm2-pkcs11, # for passthru abrmd tests
2030
tpm2-tools,
2131
tpm2-tss,
32+
which,
33+
xxd,
2234
abrmdSupport ? false,
2335
fapiSupport ? true,
2436
enableFuzzing ? false,
@@ -38,25 +50,37 @@ chosenStdenv.mkDerivation (finalAttrs: {
3850
hash = "sha256-W74ckrpK7ypny1L3Gn7nNbOVh8zbHavIk/TX3b8XbI8=";
3951
};
4052

41-
# The preConfigure phase doesn't seem to be working here
42-
# ./bootstrap MUST be executed as the first step, before all
43-
# of the autoreconfHook stuff
53+
# Disable Java‐based tests because of missing dependencies
54+
patches = [ ./disable-java-integration.patch ];
55+
4456
postPatch = ''
45-
echo "$version" > VERSION
57+
echo ${lib.escapeShellArg finalAttrs.version} >VERSION
4658
4759
# Don't run git in the bootstrap
4860
substituteInPlace bootstrap --replace-warn "git" "# git"
4961
50-
# Don't run tests with dbus
51-
substituteInPlace Makefile.am --replace-fail "dbus-run-session" "env"
62+
# Provide configuration file for D-Bus
63+
substituteInPlace Makefile.am --replace-fail \
64+
"dbus-run-session" \
65+
"dbus-run-session --config-file=${dbus}/share/dbus-1/session.conf"
66+
67+
# Disable failing tests
68+
sed -E -i '/\<test\/integration\/(pkcs-crypt\.int|pkcs11-tool\.sh)\>/d' \
69+
Makefile-integration.am
5270
53-
patchShebangs test
71+
patchShebangs test tools
5472
73+
# The preConfigure phase doesn't seem to be working here
74+
# ./bootstrap MUST be executed as the first step, before all
75+
# of the autoreconfHook stuff
5576
./bootstrap
5677
'';
5778

5879
configureFlags =
59-
lib.singleton (lib.enableFeature finalAttrs.doCheck "unit")
80+
[
81+
(lib.enableFeature finalAttrs.doCheck "unit")
82+
(lib.enableFeature finalAttrs.doCheck "integration")
83+
]
6084
++ lib.optionals enableFuzzing [
6185
"--enable-fuzzing"
6286
"--disable-hardening"
@@ -72,15 +96,20 @@ chosenStdenv.mkDerivation (finalAttrs: {
7296
patchelf
7397
pkg-config
7498
(python3.withPackages (
75-
ps: with ps; [
99+
ps:
100+
with ps;
101+
[
76102
packaging
77103
pyyaml
104+
python-pkcs11
78105
cryptography
79106
pyasn1-modules
80107
tpm2-pytss
81108
]
109+
++ cryptography.optional-dependencies.ssh
82110
))
83111
];
112+
84113
buildInputs = [
85114
libyaml
86115
opensc
@@ -89,8 +118,28 @@ chosenStdenv.mkDerivation (finalAttrs: {
89118
tpm2-tools
90119
tpm2-tss
91120
];
121+
122+
nativeCheckInputs = [
123+
dbus
124+
expect
125+
gnutls
126+
iproute2
127+
nss.tools
128+
opensc
129+
openssh
130+
openssl
131+
p11-kit
132+
sqlite
133+
swtpm
134+
tpm2-abrmd
135+
tpm2-tools
136+
which
137+
xxd
138+
];
139+
92140
checkInputs = [
93141
cmocka
142+
tpm2-abrmd
94143
];
95144

96145
enableParallelBuilding = true;
@@ -106,19 +155,51 @@ chosenStdenv.mkDerivation (finalAttrs: {
106155
dontStrip = true;
107156
dontPatchELF = true;
108157

158+
preCheck =
159+
let
160+
openssl-modules = buildEnv {
161+
name = "openssl-modules";
162+
pathsToLink = [ "/lib/ossl-modules" ];
163+
paths = map lib.getLib [
164+
openssl
165+
tpm2-openssl
166+
];
167+
};
168+
in
169+
''
170+
# Enable tests to load TCTI modules
171+
export LD_LIBRARY_PATH+=":${
172+
lib.makeLibraryPath [
173+
swtpm
174+
tpm2-tools
175+
tpm2-abrmd
176+
]
177+
}"
178+
179+
# Enable tests to load TPM2 OpenSSL module
180+
export OPENSSL_MODULES="${openssl-modules}/lib/ossl-modules"
181+
'';
182+
183+
postInstall = ''
184+
mkdir -p $bin/bin/ $bin/share/tpm2_pkcs11/
185+
mv ./tools/* $bin/share/tpm2_pkcs11/
186+
makeWrapper $bin/share/tpm2_pkcs11/tpm2_ptool.py $bin/bin/tpm2_ptool \
187+
--prefix PATH : ${lib.makeBinPath [ tpm2-tools ]}
188+
'';
189+
109190
# To be able to use the userspace resource manager, the RUNPATH must
110191
# explicitly include the tpm2-abrmd shared libraries.
111192
preFixup =
112193
let
113194
rpath = lib.makeLibraryPath (
114-
(lib.optional abrmdSupport tpm2-abrmd)
115-
++ [
195+
[
116196
glibc
117197
libyaml
118198
openssl
119199
sqlite
120200
tpm2-tss
121201
]
202+
++ (lib.optional abrmdSupport tpm2-abrmd)
122203
);
123204
in
124205
''
@@ -129,13 +210,6 @@ chosenStdenv.mkDerivation (finalAttrs: {
129210
$out/lib/libtpm2_pkcs11.so.0.0.0
130211
'';
131212

132-
postInstall = ''
133-
mkdir -p $bin/bin/ $bin/share/tpm2_pkcs11/
134-
mv ./tools/* $bin/share/tpm2_pkcs11/
135-
makeWrapper $bin/share/tpm2_pkcs11/tpm2_ptool.py $bin/bin/tpm2_ptool \
136-
--prefix PATH : ${lib.makeBinPath [ tpm2-tools ]}
137-
'';
138-
139213
passthru = {
140214
tests.tpm2-pkcs11-abrmd = tpm2-pkcs11.override {
141215
abrmdSupport = true;

0 commit comments

Comments
 (0)