Commit Graph

1187 Commits

Author SHA1 Message Date
Stefan Berger
81d8f5335f WIP: tpm2: Add a FIPS 140-2 profile
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 02:00:00 -04:00
Stefan Berger
0b31322157 wip: tpm2: Require I/O Parameter Encryption (FIPS) [drop ?]
Follow TPM 2 FIPS-140-2 document 5.2.1.9 enforcing I/O parameter
encryption.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 02:00:00 -04:00
Stefan Berger
fee4f5f0dc WIP: tpm2: Enforce EncryptedDuplication in TPM2_Duplicate (FIPS TPM 2)
Follow TPM 2 FIPS-140-2 document 5.2.1.8.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 01:59:59 -04:00
Stefan Berger
442aa6ae3d tpm2: Add a profile FIPS-host for a FIPS-enabled host
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 01:56:39 -04:00
Stefan Berger
fc19480f63 tpm2: Display RuntimeAttributes as part of TPMLIB_GetInfo
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 01:56:39 -04:00
Stefan Berger
0f490d58c7 tpm2: Implement RuntimeAttributesGet to print out attributes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 01:56:39 -04:00
Stefan Berger
2a5ece304e man: Extend man page for TPMLIB_SetProfile() with 'Attributes'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 01:56:39 -04:00
Stefan Berger
62117fa122 tpm2: Forbid RSA < 2048 key generation using new flag (FIPS on host)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 01:56:39 -04:00
Stefan Berger
085e5cb625 tpm2: Forbid RSA < 2048 signature generation using new flag (FIPS on host)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 01:56:39 -04:00
Stefan Berger
030ee7d89a tpm2: Forbid SHA1 signature generation using new flag (FIPS on host)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 01:56:39 -04:00
Stefan Berger
34e7633e78 tpm2: Prohibit raw RSA encryption and decryption (FIPS on host)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 01:56:39 -04:00
Stefan Berger
a72c87df7e tpm2: Implement function to check a profile's attribute 2024-07-18 01:56:39 -04:00
Stefan Berger
652ae3c483 tpm2: Implement function checking attributeFlags 2024-07-18 01:56:38 -04:00
Stefan Berger
3ce574f747 tpm2: Implement support for RuntimeAttributes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-18 01:56:37 -04:00
Stefan Berger
e9d3e6b688 tpm2: Start code block after case statement for variable declaration
Older versions of gcc don't accept variable declations after a case
statement without starting a code block with '{'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-17 23:38:45 -04:00
Stefan Berger
92ab421194 tpm2: Check for out-of-range command code before accessing array
Check for an out-of-range command code before using it to access
an index in an array in a debug statement.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-16 13:12:10 -04:00
Stefan Berger
e3520059cf tpm2: Print error message when invalid hash algorithm id appears (Coverity)
In case a hash algorithm id has a value >= 64 print out and error. This
should never occur since any hash algorithm id should have been set through
unmarshalling or by TPM 2-internal code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-16 13:12:10 -04:00
Stefan Berger
ee141c60e0 tpm2: Enable Camellia-192 and AES-192 and bump up stateFormatLevel
Enable Camellia-192 and AES-192 and bump up the stateFormatLevel to '4'.
This now prevents using this state with previous stateFormatLevels (< 4)
because there Camellia-192 or AES-192 was not enabled and the user would
otherwise not be able to decrypt data with either one if it was usable.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 14:09:09 -04:00
Stefan Berger
341a278896 tpm2: Enable ECC_Decrypt & ECC_Encrypt in 'default' profile
Enable new commands ECC_Decrypt and ECC_Encrypt in the TPmProfile.h
and also in the 'default' profile. Since the additional commands extend
the ppList and auditCommands array, bump up the version of the stateLevel
to '2' and use the new marshalling functions by using the PERSISTENT_DATA
blob_version '5'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 14:09:09 -04:00
Stefan Berger
2803917a09 tpm2: Switch to uncompressed lists and adapt un/marshal functions
Switch the implementation to uncompressed lists (from now on it must
remain uncompressed lists forever) and adapt functions who marshal
and unmarshal arrays that are affected by this switch:

- PERSISTENT_DATA.ppList
- PERSISTENT_DATA.auditCommands

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 14:09:09 -04:00
Stefan Berger
811616f87d tpm2: Implement function to convert from and to compressed lists' bit arrays
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 14:09:09 -04:00
Stefan Berger
a848c37b7b tpm2: Implement RuntimeProfileGetSeedCompatLevel()
The maximum SEED_COMPAT_LEVEL that libtpms may use depends on the earliest
version of libtpms that a profile can run on. Therefore, implement
RuntimeProfileGetSeedCompatLevel() to determine the SEED_COMPAT_LEVEL that
a profile can use, which depends on the profile's stateCompatLevel (which
in turn depends on the version of libtpms)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
3e49f54640 tpm2: Write (part) of PERSISTENT_DATA using RuntimeProfile
Resolves: https://github.com/stefanberger/libtpms/issues/284
Resolves: https://github.com/stefanberger/swtpm/issues/710
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
bda457104e tests: Add test case for TPMLIB_SetProfile()
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
7e07d15b16 man: Add man page for TPMLIB_SetProfile()
Add a man page describing the details of TPNLIB_SetProfile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
11655415a7 tpm2: Add new API call TPMLIB_SetProfile to enable user to set a profile
Add a new API call TPMLIB_SetProfile that enables a user to set a profile.
The user gets control over the name of the profile to apply and may supply
the algoritms to enable. The user does not get control over the individual
commands to enable.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
e02af1e06b tpm2: Use ANY_OBJECT_Marshal for OBJECTs is StateFormatLevel >=2
For profiles that work for libtpms v0.10 or later, so for
StatFormatLevel >=2, use ANY_MARSHAL_Object to write OBJECTS into
the NVRAM. This way OBJECTS are written in a more compact format.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
f8d9e6b853 tpm2: Check for unsupported algs in IncrementalSelfTest
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
4f3def8794 tpm2: Allow to runtime-disable ECC curves by their key sizes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
6a39d24669 tpm2: Allow to runtime-disable SHA3 (not currenty supported)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
cbf4757385 tpm2: Allow to runtime-disable SM2
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
689376598e tpm2: Allow to runtime-disable ECDAA
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
b6df124f7b tpm2: Allow to runtime-disable ECSCHNORR
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
8afb546148 tpm2: Allow to runtime-disable CMAC
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
57385aa204 tpm2: Allow to runtime-disable AES by key sizes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
7d11c20963 tpm2: Allow to runtime-disable cipher modes CTR,OFB,CBC, and ECB
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
1e3e82c074 tpm2: Allow to runtime-disable SHA-1 & SHA-512 hashing algorithm
Runtime-disabling any hash algorithm also means that the corresponding
hash bank must be disabled as well. In case the SHA-1 bank is disabled,
the output of TPM2_GetCapability must therefore filter-out the SHA-1 bank
that is still compiled-in but otherwise cannot be used.

$ tssgetcapability -cap 5
3 PCR selections
    hash TPM_ALG_SHA256
    TPMS_PCR_SELECTION length 3
    ff ff ff
    hash TPM_ALG_SHA384
    TPMS_PCR_SELECTION length 3
    ff ff ff
    hash TPM_ALG_SHA512
    TPMS_PCR_SELECTION length 3
    ff ff ff

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
c6e4785063 tpm2: Allow to runtime-disable ECMQV
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
289611fada tpm2: Allow to runtime-disable RSA by key sizes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
83a18c67e7 tpm2: Allow to runtime-disable RSAES encryption scheme
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
50fc1a383c tpm2: Allow to runtime-disable RSASSA signing scheme
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
26ad3f2167 tpm2: Allow to runtime-disable RSAPSS signing scheme
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
01d5759990 tpm2: Allow to runtime-disable SM4 symmetric encryption algorithm
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
5a02cd2ea3 tpm2: Allow to runtime-disable TDES symmetric encryption algorithm
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
ad7c4a9b8f tpm2: Allow to runtime-disable Camellia symmetric encryption algorithm
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
7ffdb8a6b3 tpm2: Return number of enabled commands in TPM_CAP_TPM_PROPERTIES
Rather than returning the hardcoded number of commands for the
TPM_CAP_TPM_PROPERTIES capability return the number of commands
that are currently enabled due to the active profile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
3b5afd325c tpm2: Extend TPM2_GetInfo with info about available profiles
Also extend the man page to describe the new output.

swtpm_ioctl --info 0x40 --tcp :2322 | jq
{
  "AvailableProfiles": [
    {
      "Name": "default-v1",
      "StateFormatLevel": 4,
      "Commands": "0x11f-0x122,0x124-0x12e,0x130-0x140,0x142-0x159,0x15b-0x15e,0x160-0x165,0x167-0x174,0x176-0x178,0x17a-0x193,0x197,0x199-0x19a",
      "Algorithms": "rsa,rsa-min-size=1024,tdes,tdes-min-size=128,sha1,hmac,aes,aes-min-size=128,mgf1,keyedhash,xor,sha256,sha384,sha512,null,rsassa,rsaes,rsapss,oaep,ecdsa,ecdh,ecdaa,sm2,ecschnorr,ecmqv,kdf1-sp800-56a,kdf2,kdf1-sp800-108,ecc,ecc-min-size=192,ecc-nist,ecc-bn,symcipher,camellia,camellia-min-size=128,cmac,ctr,ofb,cbc,cfb,ecb",
      "Description": "This profile enables all currenly supported commands and algorithms. It is applied when the user chooses no profile."
    },
    {
      "Name": "null",
      "StateFormatLevel": 1,
      "Commands": "0x11f-0x122,0x124-0x12e,0x130-0x140,0x142-0x159,0x15b-0x15e,0x160-0x165,0x167-0x174,0x176-0x178,0x17a-0x193,0x197",
      "Algorithms": "rsa,rsa-min-size=1024,tdes,tdes-min-size=128,sha1,hmac,aes,aes-min-size=128,mgf1,keyedhash,xor,sha256,sha384,sha512,null,rsassa,rsaes,rsapss,oaep,ecdsa,ecdh,ecdaa,sm2,ecschnorr,ecmqv,kdf1-sp800-56a,kdf2,kdf1-sp800-108,ecc,ecc-min-size=192,ecc-nist,ecc-bn,symcipher,camellia,camellia-min-size=128,cmac,ctr,ofb,cbc,cfb,ecb",
      "Description": "The profile enables the commands and algorithms that were enabled in libtpms v0.9. This profile is automatically used when the state does not have a profile, for example when it was created by libtpms v0.9 or before."
    },
    ...
}

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
9ce8f1038c tpm2: Extend TPM2_GetInfo with info about the runtime profile
Also extend the man page to describe the new output.

swtpm_ioctl --info 0x20 --tcp :2322  | jq
{
  "ActiveProfile": {
    "Name": "null",
    "StateFormatLevel": 1,
    "Commands": "0x11f-0x122,0x124-0x12e,0x130-0x140,0x142-0x159,0x15b-0x15e,0x160-0x165,0x167-0x174,0x176-0x178,0x17a-0x193,0x197",
    "Algorithms": "rsa,rsa-min-size=1024,tdes,tdes-min-size=128,sha1,hmac,aes,aes-min-size=128,mgf1,keyedhash,xor,sha256,sha384,sha512,null,rsassa,rsaes,rsapss,oaep,ecdsa,ecdh,ecdaa,sm2,ecschnorr,ecmqv,kdf1-sp800-56a,kdf2,kdf1-sp800-108,ecc,ecc-min-size=192,ecc-nist,ecc-bn,symcipher,camellia,camellia-min-size=128,cmac,ctr,ofb,cbc,cfb,ecb",
    "Description": "The profile enables the commands and algorithms that were enabled in libtpms v0.9. This profile is automatically used when the state does not have a profile, for example when it was created by libtpms v0.9 or before."
  }
}

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
03b022a717 tpm2: Extend TPM2_GetInfo with info about runtime-enabled commands
Also extend the man page to describe the new output.

swtpm_ioctl --info 0x10 --tcp :2322 | jq
{
  "RuntimeCommands": {
    "Implemented": "0x11f-0x122,0x124-0x12e,0x130-0x140,0x142-0x159,0x15b-0x15e,0x160-0x165,0x167-0x174,0x176-0x178,0x17a-0x193,0x197,0x199-0x19a",
    "CanBeDisabled": "0x11f,0x121-0x122,0x124-0x128,0x12a-0x12e,0x130,0x132-0x13b,0x13d-0x140,0x142,0x146-0x147,0x149-0x14d,0x14f-0x152,0x154-0x155,0x159,0x15b,0x15d-0x15e,0x160-0x164,0x167-0x168,0x16a-0x172,0x174,0x177-0x178,0x17b,0x17f-0x181,0x183-0x184,0x187-0x193,0x197,0x199-0x19a",
    "Enabled": "0x11f-0x122,0x124-0x12e,0x130-0x140,0x142-0x159,0x15b-0x15e,0x160-0x165,0x167-0x174,0x176-0x178,0x17a-0x193,0x197,0x199-0x19a",
    "Disabled": ""
  }
}

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00
Stefan Berger
3cb8d4d22a tpm2: Extend TPM2_GetInfo with info about runtime-enabled algorithms
Extend TPM2_GetInfo() to return information about runtime-enabled
algorithms like this:

$ swtpm_ioctl --info 8 --tcp :2322  | jq
{
  "RuntimeAlgorithms": {
    "Implemented": "rsa,rsa-min-size=1024,tdes,tdes-min-size=128,sha1,hmac,aes,aes-min-size=128,mgf1,keyedhash,xor,sha256,sha384,sha512,null,rsassa,rsaes,rsapss,oaep,ecdsa,ecdh,ecdaa,sm2,ecschnorr,ecmqv,kdf1-sp800-56a,kdf2,kdf1-sp800-108,ecc,ecc-min-size=192,ecc-nist,ecc-bn,ecc-nist-p192,ecc-nist-p224,ecc-nist-p256,ecc-nist-p384,ecc-nist-p521,ecc-bn-p256,ecc-bn-p638,ecc-sm2-p256,symcipher,camellia,camellia-min-size=128,cmac,ctr,ofb,cbc,cfb,ecb",
    "CanBeDisabled": "tdes,sha1,sha512,rsassa,rsaes,rsapss,ecmqv,ecc-nist,ecc-bn,ecc-nist-p192,ecc-nist-p224,ecc-nist-p521,ecc-bn-p256,ecc-bn-p638,ecc-sm2-p256,camellia,cmac,ctr,ofb,cbc,ecb",
    "Enabled": "rsa,rsa-min-size=1024,hmac,aes,aes-min-size=128,mgf1,keyedhash,xor,sha256,sha384,null,oaep,ecdsa,ecdh,ecdaa,sm2,ecschnorr,kdf1-sp800-56a,kdf2,kdf1-sp800-108,ecc,ecc-min-size=192,ecc-bn,ecc-nist-p192,ecc-nist-p224,ecc-nist-p256,ecc-nist-p384,ecc-nist-p521,ecc-bn-p256,ecc-bn-p638,ecc-sm2-p256,symcipher,camellia,camellia-min-size=128,cmac,ctr,ofb,cbc,cfb,ecb",
    "Disabled": "tdes,sha1,sha512,rsassa,rsaes,rsapss,ecmqv,ecc-nist"
  }
}

Also describe the JSON object in the TPMLIB_GetInfo man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-15 11:51:38 -04:00