raspberry-piraspbiantpm

How to install/start using swtpm on Linux


I am trying to start using TPM on Linux, on my Raspberry Pi to be accurate, and the easiest would be to use swtpm to get used to commands and system, before using a TPM chip. I've tried the way presented on https://github.com/stefanberger/swtpm/wiki#compile-on-ubuntu-2104, but I got the error "Unable to locate libtpms-dev".

Then I looked for a way to install libtpms, and found this one solution. But after getting those both, I still couldn't run this command :

sudo swtpm socket --tpmstate dir=/home/ludovic.peyter/swtpm  --tpm2 --server type=tcp,port=2321 --ctrl type=tcp,port=2322 --flags not-need-init,startup-clear

All I get is the following error :

swtpm: SWTPM_NVRAM_Lock_Dir: Could not open lockfile: No such file or directory

and

swtpm: Error: Could not initialize libtpms.

And here am I stuck, finding nothing to help me with this problem, or even an other way to avoid it.

Thanks for reading.


Solution

  • I have a complete solution, built with many different solutions and my own tests.

    sudo apt -y install dpkg-dev debhelper libssl-dev libtool net-tools libfuse-dev libglib2.0-dev libgmp-dev expect libtasn1-dev socat python3-twisted gnutls-dev gnutls-bin  libjson-glib-dev gawk git python3-setuptools softhsm2 libseccomp-dev automake autoconf libtool gcc build-essential libssl-dev dh-exec pkg-config dh-autoreconf libtool-bin tpm2-tools libtss0 libtss2-dev 
    

    Then make a new directory for more comfort, and step into it.

    Clone git repository for libtpms :

    git clone https://github.com/stefanberger/libtpms.git
    

    Move to the generated libtpms directory and run these commands :

    ./autogen.sh -–with-openssl
    make dist
    dpkg-buildpackage -us -uc -j4
    

    Then, as asked at the end of the last running command, run :

    libtool --finish /usr/lib/aarch64-linux-gnu/
    

    The directory could be different, so pay attention to the warning at the end of dpkg command.

    And to finish the installation of libtpms :

    sudo apt install ../libtpms*.deb
    

    Now get back to the previous directory and clone swtpm git repository :

    git clone https://github.com/stefanberger/swtpm.git
    

    Now run this command :

    dpkg-buildpackage -us -uc -j4
    

    And the command asked by the previous running command :

    libtool --finish /usr/lib/aarch64-linux-gnu/swtpm
    

    The directory could be different, so pay attention to the warning at the end of dpkg command.

    Now finish the installation with this :

    sudo apt install ../swtpm*.deb
    

    Everithing you need is installed. Now you need to modify the file ~/.profile or ~/.bash_profile to add this line :

    export TPM2TOOLS_TCTI="swtpm:port=2321"
    

    And now, everytime you need your swtpm, open two terminals, and in one of them run :

    swtpm socket --tpmstate dir=<swtpm_path> --tpm2 --server type=tcp,port=2321 --ctrl type=tcp,port=2322 --flags not-need-init,startup-clear
    

    In the other terminal, as long as the above command runs, you can run all your TPM commands.