Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tpm2-pkcs11: 1.9.0 -> 1.9.1 + adopt #378737

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

numinit
Copy link
Contributor

@numinit numinit commented Feb 2, 2025

Enabled the unit tests, but not the integration or fuzz tests.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@numinit
Copy link
Contributor Author

numinit commented Feb 2, 2025

Asked why fuzztests are failing in tpm2-software/tpm2-pkcs11#884

@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1 10.rebuild-linux: 1-10 labels Feb 2, 2025
@numinit
Copy link
Contributor Author

numinit commented Feb 2, 2025

Integration tests require both Java and JUnit... got part of the way through trying them and stopped short 🙃

@numinit
Copy link
Contributor Author

numinit commented Feb 16, 2025

Thanks, good feedback!

@numinit numinit requested a review from illdefined February 16, 2025 05:04
@numinit numinit force-pushed the tpm2-pkcs11/1.9.1 branch 3 times, most recently from da7cb9a to a811f44 Compare February 16, 2025 08:03
Comment on lines +142 to +216
tests.tpm2-pkcs11-abrmd = tpm2-pkcs11.override {
abrmdSupport = true;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the fuzzing tests are stable enough, perhaps we could enable them as passthrough tests. It is however just an idea and I defer to your judgment.

Suggested change
tests.tpm2-pkcs11-abrmd = tpm2-pkcs11.override {
abrmdSupport = true;
};
tests = {
tpm2-pkcs11-abrmd = tpm2-pkcs11.override {
abrmdSupport = true;
};
tpm2-pkcs11-fuzzing = tpm2-pkcs11.override {
enableFuzzing = true;
};
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly they are not stable yet :(

# The preConfigure phase doesn't seem to be working here
# ./bootstrap MUST be executed as the first step, before all
# of the autoreconfHook stuff
postPatch = ''
echo ${version} > VERSION
echo "$version" > VERSION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this would work with __structuredAttrs enabled. If you happen to know that it does not, I’d suggest ${finalAttrs.version} instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works if I set __structuredAttrs = true; in the derivation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for testing.

@illdefined
Copy link
Contributor

The integration tests are a real mess. I managed to get half of them to work. I’ll provide a diff later.

@illdefined
Copy link
Contributor

I suggest to leave the Java integration tests for now:

diff --git a/Makefile-integration.am b/Makefile-integration.am
index e2255de..3cea1d8 100644
--- a/Makefile-integration.am
+++ b/Makefile-integration.am
@@ -7,7 +7,6 @@ integration_scripts = \
     test/integration/pkcs11-dbup.sh.nosetup \
     test/integration/tls-tests.sh \
     test/integration/openssl.sh \
-    test/integration/pkcs11-javarunner.sh.java \
     test/integration/nss-tests.sh \
     test/integration/ptool-link.sh.nosetup \
     test/integration/python-pkcs11.sh
@@ -110,13 +109,5 @@ test_integration_pkcs_lockout_int_CFLAGS  = $(AM_CFLAGS) $(TESTS_CFLAGS)
 test_integration_pkcs_lockout_int_LDADD   = $(TESTS_LDADD)  $(SQLITE3_LIBS)
 test_integration_pkcs_lockout_int_SOURCES = test/integration/pkcs-lockout.int.c test/integration/test.c
 
-#
-# Java Tests
-#
-AM_JAVA_LOG_FLAGS = --tabrmd-tcti=$(TABRMD_TCTI) --tsetup-script=$(top_srcdir)/test/integration/scripts/create_pkcs_store.sh
-JAVA_LOG_COMPILER=$(LOG_COMPILER)
-dist_noinst_JAVA = test/integration/PKCS11JavaTests.java
-CLEANFILES += test/integration/PKCS11JavaTests.class
-
 endif
 # END INTEGRATION
diff --git a/configure.ac b/configure.ac
index 1ec6eb4..7a0a8ee 100644
--- a/configure.ac
+++ b/configure.ac
@@ -258,13 +258,6 @@ AC_ARG_ENABLE(
     [build and execute integration tests])],,
   [enable_integration=no])
 
-# Test for Java compiler and interpreter without throwing fatal errors (since
-# these macros are defined using AC_DEFUN they cannot be called conditionally)
-m4_pushdef([AC_MSG_ERROR], [have_javac=no])
-AX_PROG_JAVAC()
-AX_PROG_JAVA()
-m4_popdef([AC_MSG_ERROR])
-
 AC_DEFUN([integration_test_checks], [
 
   AC_CHECK_PROG([tpm2_createprimary], [tpm2_createprimary], [yes], [no])
@@ -382,13 +375,6 @@ AC_DEFUN([integration_test_checks], [
         [AC_MSG_ERROR([Integration tests enabled but tss2_provision executable not found.])])
   ])
 
-  AS_IF([test "x$have_javac" = "xno"],
-    [AC_MSG_ERROR([Integration tests enabled but no Java compiler was found])])
-  AX_CHECK_CLASS([org.junit.Assert], ,
-    [AC_MSG_ERROR([Integration tests enabled but JUnit not found, try setting CLASSPATH])])
-  AX_CHECK_CLASS([org.hamcrest.SelfDescribing], ,
-    [AC_MSG_ERROR([Integration tests enabled but Hamcrest not found, try setting CLASSPATH])])
-
   AC_SUBST([ENABLE_INTEGRATION], [$enable_integration])
 ]) # end function integration_test_checks
  

And this works for me so far:

diff --git a/pkgs/by-name/tp/tpm2-pkcs11/package.nix b/pkgs/by-name/tp/tpm2-pkcs11/package.nix
index d4803bf7f967..a67de7952bb7 100644
--- a/pkgs/by-name/tp/tpm2-pkcs11/package.nix
+++ b/pkgs/by-name/tp/tpm2-pkcs11/package.nix
@@ -1,24 +1,35 @@
 {
   autoconf-archive,
   autoreconfHook,
+  buildEnv,
   clangStdenv,
   cmocka,
+  dbus,
+  expect,
   fetchFromGitHub,
-  glibc,
+  gnutls,
+  iproute2,
   lib,
   libyaml,
   makeWrapper,
   opensc,
+  openssh,
   openssl,
+  nss,
+  p11-kit,
   patchelf,
   pkg-config,
   python3,
   stdenv,
   sqlite,
+  swtpm,
   tpm2-abrmd,
+  tpm2-openssl,
   tpm2-pkcs11, # for passthru abrmd tests
   tpm2-tools,
   tpm2-tss,
+  which,
+  xxd,
   abrmdSupport ? false,
   fapiSupport ? true,
   enableFuzzing ? false,
@@ -38,25 +49,37 @@ chosenStdenv.mkDerivation (finalAttrs: {
     hash = "sha256-W74ckrpK7ypny1L3Gn7nNbOVh8zbHavIk/TX3b8XbI8=";
   };
 
-  # The preConfigure phase doesn't seem to be working here
-  # ./bootstrap MUST be executed as the first step, before all
-  # of the autoreconfHook stuff
+  # Disable Java‐based tests because of missing dependencies
+  patches = [ ./disable-java-integration.patch ];
+
   postPatch = ''
-    echo "$version" > VERSION
+    echo ${lib.escapeShellArg finalAttrs.version} >VERSION
 
     # Don't run git in the bootstrap
     substituteInPlace bootstrap --replace-warn "git" "# git"
 
-    # Don't run tests with dbus
-    substituteInPlace Makefile.am --replace-fail "dbus-run-session" "env"
+    # Provide configuration file for D-Bus
+    substituteInPlace Makefile.am --replace-fail \
+      "dbus-run-session" \
+      "dbus-run-session --config-file=${dbus}/share/dbus-1/session.conf"
+
+    # Disable failing tests
+    sed -E -i '/\<test\/integration\/(pkcs-crypt\.int|pkcs11-tool\.sh)\>/d' \
+      Makefile-integration.am
 
-    patchShebangs test
+    patchShebangs test tools
 
+    # The preConfigure phase doesn't seem to be working here
+    # ./bootstrap MUST be executed as the first step, before all
+    # of the autoreconfHook stuff
     ./bootstrap
   '';
 
   configureFlags =
-    lib.singleton (lib.enableFeature finalAttrs.doCheck "unit")
+    [
+      (lib.enableFeature finalAttrs.doCheck "unit")
+      (lib.enableFeature finalAttrs.doCheck "integration")
+    ]
     ++ lib.optionals enableFuzzing [
       "--enable-fuzzing"
       "--disable-hardening"
@@ -72,15 +95,20 @@ chosenStdenv.mkDerivation (finalAttrs: {
     patchelf
     pkg-config
     (python3.withPackages (
-      ps: with ps; [
+      ps:
+      with ps;
+      [
         packaging
         pyyaml
+        python-pkcs11
         cryptography
         pyasn1-modules
         tpm2-pytss
       ]
+      ++ cryptography.optional-dependencies.ssh
     ))
   ];
+
   buildInputs = [
     libyaml
     opensc
@@ -89,8 +117,28 @@ chosenStdenv.mkDerivation (finalAttrs: {
     tpm2-tools
     tpm2-tss
   ];
+
+  nativeCheckInputs = [
+    dbus
+    expect
+    gnutls
+    iproute2
+    nss.tools
+    opensc
+    openssh
+    openssl
+    p11-kit
+    sqlite
+    swtpm
+    tpm2-abrmd
+    tpm2-tools
+    which
+    xxd
+  ];
+
   checkInputs = [
     cmocka
+    tpm2-abrmd
   ];
 
   enableParallelBuilding = true;
@@ -106,27 +154,40 @@ chosenStdenv.mkDerivation (finalAttrs: {
   dontStrip = true;
   dontPatchELF = true;
 
-  # To be able to use the userspace resource manager, the RUNPATH must
-  # explicitly include the tpm2-abrmd shared libraries.
-  preFixup =
+  preConfigure = let
+    ldflags = [
+      "-Wl,--push-state,--no-as-needed"
+      "-ltss2-tcti-device"
+      "-ltss2-tcti-tabrmd"
+      "-Wl,--pop-state"
+    ];
+  in lib.optionalString abrmdSupport ''
+    configureFlagsArray+=(EXTRA_LDFLAGS=${lib.escapeShellArg ldflags})
+  '';
+
+  preCheck =
     let
-      rpath = lib.makeLibraryPath (
-        (lib.optional abrmdSupport tpm2-abrmd)
-        ++ [
-          glibc
-          libyaml
+      openssl-modules = buildEnv {
+        name = "openssl-modules";
+        pathsToLink = [ "/lib/ossl-modules" ];
+        paths = map lib.getLib [
           openssl
-          sqlite
-          tpm2-tss
-        ]
-      );
+          tpm2-openssl
+        ];
+      };
     in
     ''
-      patchelf \
-        --set-rpath ${rpath} \
-        ${lib.optionalString abrmdSupport "--add-needed ${lib.makeLibraryPath [ tpm2-abrmd ]}/libtss2-tcti-tabrmd.so"} \
-        --add-needed ${lib.makeLibraryPath [ tpm2-tss ]}/libtss2-tcti-device.so \
-        $out/lib/libtpm2_pkcs11.so.0.0.0
+      # Enable tests to load TCTI modules
+      export LD_LIBRARY_PATH+=":${
+        lib.makeLibraryPath [
+          swtpm
+          tpm2-abrmd
+          tpm2-tools
+        ]
+      }"
+
+      # Enable tests to load TPM2 OpenSSL module
+      export OPENSSL_MODULES="${openssl-modules}/lib/ossl-modules"
     '';
 
   postInstall = ''

@numinit
Copy link
Contributor Author

numinit commented Feb 16, 2025

Wow, well done. I'll integrate these.

@illdefined
Copy link
Contributor

illdefined commented Feb 16, 2025

Apart from the Java‐based tests, pkcs11-tool and pkcs-crypt are failing, but I can’t wrap my head around it.

I tried both swtpm and ibm-sw-tpm2 as emulators, but the tests fail with both of them.

pkcs-crypt:

WARNING:esys:src/tss2-esys/api/Esys_Unseal.c:295:Esys_Unseal_Finish() Received TPM Error 
ERROR:esys:src/tss2-esys/api/Esys_Unseal.c:98:Esys_Unseal() Esys Finish ErrorCode (0x0000098e) 
ERROR: Esys_Unseal: tpm:session(1):the authorization HMAC check failed and DA counter incremented
ERROR: Error unsealing wrapping key
[       OK ] test_aes_always_authenticate
[ RUN      ] test_aes_encrypt_decrypt_oneshot_5_2_returns
[       OK ] test_aes_encrypt_decrypt_oneshot_5_2_returns
[ RUN      ] test_aes_encrypt_decrypt_5_2_returns
[       OK ] test_aes_encrypt_decrypt_5_2_returns
[ RUN      ] test_aes_encrypt_decrypt_good
[       OK ] test_aes_encrypt_decrypt_good
[ RUN      ] test_aes_encrypt_decrypt_oneshot_good
[       OK ] test_aes_encrypt_decrypt_oneshot_good
[ RUN      ] test_rsa_oaep_encrypt_decrypt_oneshot_good
[       OK ] test_rsa_oaep_encrypt_decrypt_oneshot_good
[ RUN      ] test_cert_no_good
ERROR: Cannot use tobj id 17 in a crypto operation
ERROR: Cannot use tobj id 17 in a crypto operation
[       OK ] test_cert_no_good
[ RUN      ] test_rsa_x509_encrypt_decrypt_oneshot_good
[       OK ] test_rsa_x509_encrypt_decrypt_oneshot_good
[ RUN      ] test_rsa_pkcs_encrypt_decrypt_public_5_2_returns_good
[       OK ] test_rsa_pkcs_encrypt_decrypt_public_5_2_returns_good
[ RUN      ] test_aes_big_blockboundary_buffer_encrypt_decrypt_oneshot_5_2_returns
[       OK ] test_aes_big_blockboundary_buffer_encrypt_decrypt_oneshot_5_2_returns
[ RUN      ] test_aes_big_blockboundary_buffer_encrypt_decrypt_oneshot_5_2_returns
[       OK ] test_aes_big_blockboundary_buffer_encrypt_decrypt_oneshot_5_2_returns
[ RUN      ] test_aes_cbc_non_block_boundary_plaintext
[  ERROR   ] --- difference at offset 32 0x21 0xffffff87
difference at offset 33 0x22 0x17
difference at offset 34 0x23 0xffffff86
difference at offset 35 0x24 0x25
difference at offset 36 0x25 0x17
difference at offset 37 0x26 0xfffffff8
difference at offset 38 0x27 0x3c
difference at offset 39 0x28 0xffffff9d
difference at offset 40 0x29 0x3c
difference at offset 41 0x2a 0xffffffc0
difference at offset 42 0x2b 0xffffffe3
difference at offset 43 0x2c 0x0d
difference at offset 44 0x2d 0x32
difference at offset 45 0x2e 0x39
difference at offset 46 0x2f 0xffffffbc
difference at offset 47 0x30 0xffffffdb
...
16 bytes of 0x7fffffff9a60 and 0x7fffffff9af0 differ
[   LINE   ] --- test/integration/pkcs-crypt.int.c:1013: error: Failure!
[  FAILED  ] test_aes_cbc_non_block_boundary_plaintext
[ RUN      ] test_aes_0_bytes
[       OK ] test_aes_0_bytes
[ RUN      ] test_aes_cbc_non_block_boundary_plaintext_bad
[       OK ] test_aes_cbc_non_block_boundary_plaintext_bad
[ RUN      ] test_aes_cbc_pad_small_oneshot
[       OK ] test_aes_cbc_pad_small_oneshot
[ RUN      ] test_aes_cbc_pad_issue730
[       OK ] test_aes_cbc_pad_issue730
[ RUN      ] test_aes_cbc_pad_multiple_blocks
[  ERROR   ] --- difference at offset 32 0x21 0xffffff87
difference at offset 33 0x22 0x17
difference at offset 34 0x23 0xffffff86
difference at offset 35 0x24 0x25
difference at offset 36 0x25 0x17
difference at offset 37 0x26 0xfffffff8
difference at offset 38 0x27 0x3c
difference at offset 39 0x28 0xffffff9d
difference at offset 40 0x29 0x3c
difference at offset 41 0x2a 0xffffffc0
difference at offset 42 0x2b 0xffffffe3
difference at offset 43 0x2c 0x0d
difference at offset 44 0x2d 0x32
difference at offset 45 0x2e 0x39
difference at offset 46 0x2f 0xffffffbc
difference at offset 47 0x30 0xffffffdb
...
16 bytes of 0x7fffffff9a80 and 0x7fffffff9ab0 differ
[   LINE   ] --- test/integration/pkcs-crypt.int.c:1394: error: Failure!
[  FAILED  ] test_aes_cbc_pad_multiple_blocks
[ RUN      ] test_aes_cbc_pad_multiple_blocks_with_extra
[       OK ] test_aes_cbc_pad_multiple_blocks_with_extra
[ RUN      ] test_aes_ctr_multiple_blocks
[  ERROR   ] --- difference at offset 32 0x21 0x0b
difference at offset 33 0x22 0xffffff91
difference at offset 34 0x23 0x36
difference at offset 35 0x24 0x27
difference at offset 36 0x25 0x08
difference at offset 37 0x26 0x52
difference at offset 38 0x27 0xffffffa4
difference at offset 39 0x28 0x48
difference at offset 40 0x29 0x3c
difference at offset 41 0x2a 0x68
difference at offset 42 0x2b 0xffffffe7
difference at offset 43 0x2c 0xffffffae
difference at offset 44 0x2d 0x66
difference at offset 45 0x2e 0x45
difference at offset 46 0x2f 0xffffff89
difference at offset 47 0x30 0x2d
...
16 bytes of 0x7fffffff9a60 and 0x7fffffff9af0 differ
[   LINE   ] --- test/integration/pkcs-crypt.int.c:1703: error: Failure!
[  FAILED  ] test_aes_ctr_multiple_blocks
[ RUN      ] test_aes_ctr_one_block_oneshot
[       OK ] test_aes_ctr_one_block_oneshot
[ RUN      ] test_aes_ctr_bad_counter_size
ERROR: TPM Requires ulCounterBits to be 16, got 12
ERROR: TPM Requires ulCounterBits to be 16, got 12
[       OK ] test_aes_ctr_bad_counter_size
[==========] tests: 21 test(s) run.
[  PASSED  ] 18 test(s).
[  FAILED  ] tests: 3 test(s), listed below:
[  FAILED  ] test_aes_cbc_non_block_boundary_plaintext
[  FAILED  ] test_aes_cbc_pad_multiple_blocks
[  FAILED  ] test_aes_ctr_multiple_blocks

pkcs11-tool:

export TPM2_PKCS11_STORE=/tmp/tpm_simulator_YVqhWK
./test/integration/pkcs11-tool.sh
modpath=/build/source/src/.libs/libtpm2_pkcs11.so
Finding cert
Using slot 0 with a present token (0x1)
/P_RSA/HE/EK:/P_RSA/HE:/P_RSA/HS/SRK:/P_RSA/HS:/P_RSA/LOCKOUT:/P_RSA/HNExecution of ./test/integration/pkcs11-tool.sh failed: 1
FAIL test/integration/pkcs11-tool.sh (exit status: 1)

@illdefined
Copy link
Contributor

Some of the OpenSSL tests are skipped because they rely on OpenSSL 1, which I suspect (or hope) is soon going to be removed from nixpkgs. I tried to make them work, but I don’t believe that it is worth the effort.

@numinit
Copy link
Contributor Author

numinit commented Feb 17, 2025

I'm not familiar with pkcs-crypt but p11tool is quite old compared to other alternatives.

numinit added a commit to numinit/nixpkgs that referenced this pull request Feb 17, 2025
h/t @illdefined for the work on these; see:
NixOS#378737 (comment)

Only difference is a nixfmt pass.
numinit added a commit to numinit/nixpkgs that referenced this pull request Feb 17, 2025
h/t @illdefined for the work on these; see:
NixOS#378737 (comment)

Only difference is a nixfmt pass.
@numinit numinit requested a review from illdefined February 17, 2025 04:16
@numinit
Copy link
Contributor Author

numinit commented Feb 17, 2025

Ran into that weird GH actions bug where nothing runs and I had to repush.

Comment on lines 184 to 176
lib.makeLibraryPath [
swtpm
tpm2-abrmd
tpm2-tools
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lib.makeLibraryPath [
swtpm
tpm2-abrmd
tpm2-tools
]
lib.makeLibraryPath [
swtpm
tpm2-tools
] ++ lib.optionals (!abrmdSupport) [
# Only add this if userspace‐resource manager support has been disabled to check
# during testing whether it has been properly linked at compile time during.
tpm2-abrmd
]

Copy link
Contributor Author

@numinit numinit Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The passthru tests actually fail if I do that. I guess it's not getting linked properly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe my approach to inject the linker flags was incorrect. If in doubt, just revert to the previous variant using patchelf.

@illdefined
Copy link
Contributor

I suggested a small change to check during testing that the tabrmd TCTI module has been properly linked, by omitting it from LD_LIBRARY_PATH if abrmdSupport is disabled.

Otherwise this looks good to me.

- Switch to clang since fuzzing uses clang's libfuzzed
- Enable tests
- Support optional fuzzing (currently fails)
numinit added a commit to numinit/nixpkgs that referenced this pull request Feb 20, 2025
h/t @illdefined for the work on these; see:
NixOS#378737 (comment)

Only difference is a nixfmt pass.
@numinit numinit requested a review from illdefined February 20, 2025 05:22
@numinit
Copy link
Contributor Author

numinit commented Feb 22, 2025

With or without the patchelf and preConfigure, this is the first failure...

+ openssl genpkey -provider tpm2 -algorithm RSA -pkeyopt parent:0x81000000 -pkeyopt bits:2048 -out /build/tmp.hSckHjo1KO/tss2-rsa-2048.pem
ERROR:tcti:src/tss2-tcti/tctildr.c:477:tctildr_init_context_data() Failed to instantiate TCTI 
genpkey: unable to load provider tpm2
Hint: use -provider-path option or OPENSSL_MODULES environment variable.
40D771F7FF7F0000:error:40000006:lib(128)::reason(6)::-1:655381 tcti:Functionality not supported
40D771F7FF7F0000:error:078C0105:common libcrypto routines:provider_init:init fail:crypto/provider_core.c:969:name=tpm2
++ onerror
++ echo 'openssl genpkey -provider tpm2 -algorithm RSA -pkeyopt "parent:$handle" -pkeyopt bits:2048 -out "$tempdir/tss2-rsa-2048.pem" on line 101 failed: 1'
openssl genpkey -provider tpm2 -algorithm RSA -pkeyopt "parent:$handle" -pkeyopt bits:2048 -out "$tempdir/tss2-rsa-2048.pem" on line 101 failed: 1
++ exit 1
+ cleanup
+ rm -rf /build/tmp.hSckHjo1KO
/P_RSA/HS:/P_RSA/HS/SRK:/P_RSA/HN:/P_RSA/LOCKOUT:/P_RSA/HE:/P_RSA/HE/EKExecution of ./test/integration/ptool-link.sh.nosetup failed: 1
FAIL test/integration/ptool-link.sh.nosetup (exit status: 1)

Then here's one of the next:

++ tpm2_ptool export --id=14 --userpin=myuserpin --path=/tmp/tpm_simulator_HmbQ6u
ERROR:tcti:src/tss2-tcti/tctildr.c:477:tctildr_init_context_data() Failed to instantiate TCTI 
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/build/source/tools/tpm2_pkcs11/tpm2_ptool.py", line 30, in <module>
    main()
  File "/build/source/tools/tpm2_pkcs11/tpm2_ptool.py", line 26, in main
    commandlet.init('A tool for manipulating the tpm2-pkcs11 database')
  File "/build/source/tools/tpm2_pkcs11/command.py", line 117, in init
    commandlet.get()[d['which']](d)
  File "/build/source/tools/tpm2_pkcs11/commandlets_keys.py", line 837, in __call__
    Export.export(db, object_id, pin, is_so_pin, args['hierarchy_auth'], args['format'], output_prefix)
  File "/build/source/tools/tpm2_pkcs11/commandlets_keys.py", line 758, in export
    handler[cka_class](db, obj, pin, is_so_pin, hierarchyauth, format, output_prefix)
  File "/build/source/tools/tpm2_pkcs11/commandlets_keys.py", line 727, in _handle_tpm_key
    dump_tsspem(db, obj, pin, is_so_pin, output_prefix)               
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/source/tools/tpm2_pkcs11/utils.py", line 536, in dump_tsspem
    with ESAPI(os.getenv('TPM2TOOLS_TCTI', None)) as e:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/pgck9vwrs0xg3k7skm5qi2316jirq8k1-python3-3.12.8-env/lib/python3.12/site-packages/tpm2_pytss/ESAPI.py", line 123, in __init__
    tcti = TCTILdr.parse(tcti)
           ^^^^^^^^^^^^^^^^^^^
  File "/nix/store/pgck9vwrs0xg3k7skm5qi2316jirq8k1-python3-3.12.8-env/lib/python3.12/site-packages/tpm2_pytss/TCTILdr.py", line 54, in parse
    return cls(name, conf)
           ^^^^^^^^^^^^^^^
  File "/nix/store/pgck9vwrs0xg3k7skm5qi2316jirq8k1-python3-3.12.8-env/lib/python3.12/site-packages/tpm2_pytss/TCTILdr.py", line 29, in __init__
    _chkrc(lib.Tss2_TctiLdr_Initialize_Ex(name, conf, self._ctx_pp))
  File "/nix/store/pgck9vwrs0xg3k7skm5qi2316jirq8k1-python3-3.12.8-env/lib/python3.12/site-packages/tpm2_pytss/internal/utils.py", line 176, in _chkrc
    raise TSS2_Exception(rc)
tpm2_pytss.TSS2_Exception.TSS2_Exception: tcti:Functionality not supported
+ yaml_14=
Failed to run the setup script
/P_RSA/HN:/P_RSA/LOCKOUT:/P_RSA/HS:/P_RSA/HS/SRK:/P_RSA/HE:/P_RSA/HE/EKExecution of ./test/integration/pkcs-find-objects.int failed: 1
FAIL test/integration/pkcs-find-objects.int (exit status: 1)

h/t @illdefined for the work on these; see:
NixOS#378737 (comment)

Only difference is a nixfmt pass.
@numinit
Copy link
Contributor Author

numinit commented Feb 22, 2025

Fixed it, reverted to adding abrmd in the LD_LIBRARY_PATH and the patchelf and it's working again.

@illdefined
Copy link
Contributor

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 378737


x86_64-linux

✅ 3 packages built:
  • tpm2-pkcs11
  • tpm2-pkcs11.bin
  • tpm2-pkcs11.dev

aarch64-linux

✅ 3 packages built:
  • tpm2-pkcs11
  • tpm2-pkcs11.bin
  • tpm2-pkcs11.dev

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 10.rebuild-linux: 1 12.approvals: 1 This PR was reviewed and approved by one reputable person
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants