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-tss-engine #107298

Open
Binary-Eater opened this issue Dec 21, 2020 · 6 comments
Open

tpm2-tss-engine #107298

Binary-Eater opened this issue Dec 21, 2020 · 6 comments

Comments

@Binary-Eater
Copy link
Contributor

Binary-Eater commented Dec 21, 2020

OpenSSL cryptographic engine package for TPM 2.0

Uses the tpm2-tss package to provide an interface for OpenSSL to utilize TPM 2.0 for cryptographic purposes.

Metadata

@matthiasbeyer
Copy link
Contributor

If someone needs a starting point: https://git.beyermatthi.as/nixpkgs/log/?h=init-tpm2-tss-engine

I started it but I do not have enough time right now. It fails during compilation because it tries to create symbolic links in the openssl installation (probably submit this as bug report to upstream).

@stale

This comment was marked as off-topic.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 20, 2021
@terlar
Copy link
Contributor

terlar commented Oct 14, 2022

@matthiasbeyer @Binary-Eater

I got it to build like this:

{ stdenv, lib, fetchFromGitHub, autoreconfHook, autoconf-archive, pkg-config
, pandoc, doxygen
# Runtime
, openssl, tpm2-tss
# Check
, cmocka, expect, tpm2-tools, ibm-sw-tpm2, coreutils, iproute }:

let
  pname = "tpm2-tss-engine";
  version = "1.1.0";
in stdenv.mkDerivation {
  inherit pname version;

  src = fetchFromGitHub {
    owner = "tpm2-software";
    repo = pname;
    rev = "v${version}";
    sha256 = "1pwc38izkk50s73xzcca1l5h265lmh4hcgpfq8lmbv5grq2qdal8";
  };

  nativeBuildInputs =
    [ autoreconfHook autoconf-archive pkg-config doxygen pandoc ];
  buildInputs = [ openssl tpm2-tss ];
  checkInputs = [ cmocka expect tpm2-tools ibm-sw-tpm2 coreutils iproute ];

  postPatch = ''
    patchShebangs bootstrap
    patchShebangs test
  '';

  preAutoreconf = "./bootstrap";

  enableParallelBuilding = true;

  configureFlags = [
    "--with-enginesdir=${placeholder "out"}/lib/engines"
    "--enable-unit"
    # Integration tests disabled, as they rely on TPM2 support
    # "--enable-integration"
  ];

  doCheck = true;

  meta = {
    homepage = "https://github.com/tpm2-software/tpm2-tss-engine";
    description = "OpenSSL Engine for TPM2 devices";
    license = lib.licenses.bsd3;
    platforms = lib.platforms.linux;
    maintainers = [ lib.maintainers.terlar ];
  };
}

Unfortunately I didn't have a TPM2 device when I packaged it (January last year). So could perhaps have saved you some time. I remember it failed the integration tests, but I just re-ran them now on a device that has TPM2 and then the integration tests passed as well. After the build I can execute the binary. Not sure what more I need to verify.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 14, 2022
@Binary-Eater
Copy link
Contributor Author

Binary-Eater commented Nov 12, 2022

@terlar I finally got a chance to test your packaging.

You have a syntax error in your posting.

    maintainers = lib.maintainers.terlar ];

should be

    maintainers = [ lib.maintainers.terlar ];

I noticed this error when testing ./result/bin/tpm2tss-genkey.

./result/bin/tpm2tss-genkey key.priv
Could not load tpm2tss engine

This appears to be an issue with loading the shared object needed.

openat(AT_FDCWD, "/nix/store/dk9xkkxabg6mpcb3nahjg0pla75m69vq-openssl-1.1.1q/lib/engines-1.1/tpm2tss.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/nix/store/dk9xkkxabg6mpcb3nahjg0pla75m69vq-openssl-1.1.1q/lib/engines-1.1/libtpm2tss.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
write(2, "Could not load tpm2tss engine\n", 30Could not load tpm2tss engine

The required shared objects are under result/lib/engines and not result/lib/engines-1.1. Misread the path.

@Binary-Eater
Copy link
Contributor Author

This error makes sense to me. Uses openssl library functionality for invoking the engine. Openssl does not know where the tpm2-tss-engine is located.

https://github.com/tpm2-software/tpm2-tss-engine/blob/0745b9df717a6613f1415173861df46ec660b425/src/tpm2tss-genkey.c#L38-L40

Integration tests pass for me as well with my tpn2 device. I think this could be upstreamed and then the next step is adding an option for openssl 1.1.1 to have this engine installed with it.

Openssl 3 will require tpm2-openssl.

@stv0g
Copy link
Contributor

stv0g commented Apr 7, 2024

Just fyi, I've created a PR to add tpm2-openssl: #299626

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants