[Bug 1983160] Re: Starting a salted session fails when using an RSA key in FIPS mode
Robie Basak
1983160 at bugs.launchpad.net
Wed Aug 24 20:19:54 UTC 2022
We assume that it’s the client on which FIPS needs to be enabled to
reproduce this issue, and not necessarily the server. If this is right,
please could you state that explicitly to confirm - both in the Impact
and mention a step to enable FIPS in the Test Plan?
Please fix the references to /usr/local in the Test Plan as we assume
they don’t apply here.
Is the code path that is being changed possible to exercise for users
not using FIPS? If so, is there any risk to this class of users, and
would it be useful to verify this for QA during SRU verification? Or
would this be pointless?
Accepting since the above won’t change that decision, but the discussion
in the above paragraph may need to change the Test Plan to include the
non-FIPS users.
** Changed in: tpm2-tss (Ubuntu Focal)
Status: Triaged => Fix Committed
** Tags added: verification-needed verification-needed-focal
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to tpm2-tss in Ubuntu.
https://bugs.launchpad.net/bugs/1983160
Title:
Starting a salted session fails when using an RSA key in FIPS mode
Status in tpm2-tss package in Ubuntu:
Fix Released
Status in tpm2-tss source package in Focal:
Fix Committed
Status in tpm2-tss source package in Jammy:
Fix Released
Bug description:
When configuring SSH to use a TPM protected key for authentication
using tpm2-pkcs11 following the steps documented in
https://github.com/tpm2-software/tpm2-pkcs11/blob/master/docs/SSH.md,
it fails when trying to login on a system that is running in FIPS
mode, with the following error message:
WARNING:esys:src/tss2-esys/api/Esys_StartAuthSession.c:383:Esys_StartAuthSession_Finish() Received TPM Error
ERROR:esys:src/tss2-esys/api/Esys_StartAuthSession.c:136:Esys_StartAuthSession() Esys Finish ErrorCode (0x000002c4)
ERROR: Esys_StartAuthSession: tpm:parameter(2):value is out of range or is not correct for the context
ERROR: Could not start Auth Session with the TPM.
ERROR: Error unsealing wrapping key
C_Login failed: 5
login failed
pkcs11_get_key failed
sign_and_send_pubkey: signing failed for RSA "": error in libcrypto
Parameter 2 in this case is the encrypted salt supplied to the
TPM2_StartAuthSession command. tpm2-pkcs11 is creating a session that
is salted with a value which is encrypted with the public part of a
TPM protected RSA key before being sent to the TPM.
This encryption happens in iesys_cryptossl_pk_encrypt which has a bug
in the version in focal that was fixed accidentally in
https://github.com/tpm2-software/tpm2-tss/commit/362fda1daa398da2944e76013c215500761d46a5.
In focal, iesys_cryptossl_pk_encrypt generates a RSA key using openssl
and then overwrites the public modulus with the one associated with
the TPM key. This fails when running a FIPS certified version of
openssl in FIPS mode because openssl performs a test on the generated
key, which results in the Montgomery value associated with the
generated public modulus being cached. The cached value isn't updated
when the public modulus is changed, and the incorrect value is used in
the subsequent encryption operation.
[Impact]
It's not possible to use tpm2-pkcs11 on a system that is running in FIPS mode with the version of tpm2-tss in focal.
This is fixed by partially backporting
https://github.com/tpm2-software/tpm2-tss/commit/362fda1daa398da2944e76013c215500761d46a5
so that iesys_cryptossl_pk_encrypt does not perform an unnecessary key
generation.
[Test plan]
[racb: pending amendment - see comment 3 below]
Follow the instructions detailed in
https://github.com/tpm2-software/tpm2-pkcs11/blob/master/docs/SSH.md
and verify that it is possible to login to localhost with the TPM
protected key. Or is the tiny reproducer meanwhile:
```
# Add the key
```
sudo usermod -a -G tss $USER
tpm2_ptool init
tpm2_ptool addtoken --pid=1 --label=ssh --userpin=MySecretPassword --sopin=MyRecoveryPassword
tpm2_ptool addkey --label=ssh --userpin=MySecretPassword --algorithm=rsa2048
```
# List the public SSH keys
```
ssh-keygen -D /usr/local/lib/libtpm2_pkcs11.so 2>/dev/null
```
Those warnings/errors are displayed, but can be ignored from what I
can understand (see
https://github.com/tpm2-software/tpm2-pkcs11/issues/655):
```
WARNING:fapi:src/tss2-fapi/api/Fapi_List.c:226:Fapi_List_Finish() Profile of path not provisioned: /HS/SRK
ERROR:fapi:src/tss2-fapi/api/Fapi_List.c:81:Fapi_List() ErrorCode (0x00060034) Entities_List
ERROR: Listing FAPI token objects failed.
```
# Add the SSH key authorized_keys
Add this key to root's authorized keys:
```
ssh-keygen -D /usr/local/lib/libtpm2_pkcs11.so 2>/dev/null | sudo tee -a /root/.ssh/authorized_keys
```
# SSH as root
Pin is `MySecretPassword`:
```
ssh -I /usr/local/lib/libtpm2_pkcs11.so root at localhost
```
Observe the error.
```
[Regression potential]
This is minimal - iesys_cryptossl_pk_encrypt is implemented this way already in releases after focal. It's also only used by StartAuthSession when called with a TPM key, which isn't that usual.
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/tpm2-tss/+bug/1983160/+subscriptions
More information about the foundations-bugs
mailing list