git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #114080 from baloo/baloo/tpm2-pytss/init
commit3ede9d8c5c53e179166ab20660b281dd551b8048 authorSandro <sandro.jaeckel@gmail.com> dateThu 25 Feb 2021, 01:00 (6 years ago) parent31e113a7710eed
4 files changed+105−1
pkgs/development/libraries/tpm2-tss/default.nix+23−1 pkgs/development/libraries/tpm2-tss/no-dynamic-loader-path.patch+39 pkgs/development/python-modules/tpm2-pytss/default.nix+41 pkgs/top-level/python-packages.nix+2
pkgs/development/libraries/tpm2-tss/default.nix+23−1
@@ -27,7 +27,21 @@ stdenv.mkDerivation rec {
2727
2828 enableParallelBuilding = true;
2929
30− postPatch = "patchShebangs script";
30+ patches = [
31+ # Do not rely on dynamic loader path
32+ # TCTI loader relies on dlopen(), this patch prefixes all calls with the output directory
33+ ./no-dynamic-loader-path.patch
34+ ];
35+
36+ postPatch = ''
37+ patchShebangs script
38+ substituteInPlace src/tss2-tcti/tctildr-dl.c \
39+ --replace '@PREFIX@' $out/lib/
40+ substituteInPlace ./test/unit/tctildr-dl.c \
41+ --replace ', "libtss2' ", \"$out/lib/libtss2" \
42+ --replace ', "foo' ", \"$out/lib/foo" \
43+ --replace ', TEST_TCTI_NAME' ", \"$out/lib/\"TEST_TCTI_NAME"
44+ '';
3145
3246 configureFlags = [
3347 "--enable-unit"
@@ -35,6 +49,14 @@ stdenv.mkDerivation rec {
3549 ];
3650
3751 doCheck = true;
52+ preCheck = ''
53+ # Since we rewrote the load path in the dynamic loader for the TCTI
54+ # The various tcti implementation should be placed in their target directory
55+ # before we could run tests
56+ installPhase
57+ # install already done, dont need another one
58+ dontInstall=1
59+ '';
3860
3961 postInstall = ''
4062 # Do not install the upstream udev rules, they rely on specific
pkgs/development/libraries/tpm2-tss/no-dynamic-loader-path.patchnew file+39
@@ -0,0 +1,39 @@
1+diff --git a/src/tss2-tcti/tctildr-dl.c b/src/tss2-tcti/tctildr-dl.c
2+index b364695c..b13be3ef 100644
3+--- a/src/tss2-tcti/tctildr-dl.c
4++++ b/src/tss2-tcti/tctildr-dl.c
5+@@ -85,7 +85,15 @@ handle_from_name(const char *file,
6+ if (handle == NULL) {
7+ return TSS2_TCTI_RC_BAD_REFERENCE;
8+ }
9+- *handle = dlopen(file, RTLD_NOW);
10++ size = snprintf(file_xfrm,
11++ sizeof (file_xfrm),
12++ "@PREFIX@%s",
13++ file);
14++ if (size >= sizeof (file_xfrm)) {
15++ LOG_ERROR("TCTI name truncated in transform.");
16++ return TSS2_TCTI_RC_BAD_VALUE;
17++ }
18++ *handle = dlopen(file_xfrm, RTLD_NOW);
19+ if (*handle != NULL) {
20+ return TSS2_RC_SUCCESS;
21+ } else {
22+@@ -94,7 +102,7 @@ handle_from_name(const char *file,
23+ /* 'name' alone didn't work, try libtss2-tcti-<name>.so.0 */
24+ size = snprintf(file_xfrm,
25+ sizeof (file_xfrm),
26+- TCTI_NAME_TEMPLATE_0,
27++ "@PREFIX@" TCTI_NAME_TEMPLATE_0,
28+ file);
29+ if (size >= sizeof (file_xfrm)) {
30+ LOG_ERROR("TCTI name truncated in transform.");
31+@@ -109,7 +117,7 @@ handle_from_name(const char *file,
32+ /* libtss2-tcti-<name>.so.0 didn't work, try libtss2-tcti-<name>.so */
33+ size = snprintf(file_xfrm,
34+ sizeof (file_xfrm),
35+- TCTI_NAME_TEMPLATE,
36++ "@PREFIX@" TCTI_NAME_TEMPLATE,
37+ file);
38+ if (size >= sizeof (file_xfrm)) {
39+ LOG_ERROR("TCTI name truncated in transform.");
pkgs/development/python-modules/tpm2-pytss/default.nixnew file+41
@@ -0,0 +1,41 @@
1+{ lib, buildPythonPackage, fetchPypi, pythonOlder
2+, pkg-config, swig
3+, tpm2-tss
4+, cryptography, ibm-sw-tpm2
5+}:
6+
7+buildPythonPackage rec {
8+ pname = "tpm2-pytss";
9+
10+ # Last version on github is 0.2.4, but it looks
11+ # like a mistake (it's missing commits from 0.1.9)
12+ version = "0.1.9";
13+ disabled = pythonOlder "3.5";
14+
15+ src = fetchPypi {
16+ inherit pname version;
17+ sha256 = "sha256-v5Xth0A3tFnLFg54nvWYL2TD201e/GWv+2y5Qc60CmU=";
18+ };
19+ postPatch = ''
20+ substituteInPlace tpm2_pytss/config.py --replace \
21+ 'SYSCONFDIR = CONFIG.get("sysconfdir", "/etc")' \
22+ 'SYSCONFDIR = "${tpm2-tss}/etc"'
23+ '';
24+
25+ nativeBuildInputs = [ pkg-config swig ];
26+ # The TCTI is dynamically loaded from tpm2-tss, we have to provide the library to the end-user
27+ propagatedBuildInputs = [ tpm2-tss ];
28+
29+ checkInputs = [
30+ cryptography
31+ # provide tpm_server used as simulator for the tests
32+ ibm-sw-tpm2
33+ ];
34+
35+ meta = with lib; {
36+ homepage = "https://github.com/tpm2-software/tpm2-pytss";
37+ description = "TPM2 TSS Python bindings for Enhanced System API (ESYS)";
38+ license = licenses.bsd2;
39+ maintainers = with maintainers; [ baloo ];
40+ };
41+}
pkgs/top-level/python-packages.nix+2
@@ -7954,6 +7954,8 @@ in {
79547954
79557955 tox = callPackage ../development/python-modules/tox { };
79567956
7957+ tpm2-pytss = callPackage ../development/python-modules/tpm2-pytss { };
7958+
79577959 tqdm = callPackage ../development/python-modules/tqdm { };
79587960
79597961 traceback2 = callPackage ../development/python-modules/traceback2 { };