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

Add TPM Key Support #74

Merged
merged 31 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6e5e91b
Add stub of TPMv2 support
dwmw2 Jun 12, 2023
3610922
Flesh out unimplemented TPMv2Signer a little more
dwmw2 Jun 14, 2023
a17714e
Basic shell of TPM, working at least for EC
dwmw2 Jun 14, 2023
eda60b6
Add RSA support
dwmw2 Jun 15, 2023
72ead0c
Add TPM support to docs
dwmw2 Jun 15, 2023
77a97d5
Add tests for TPM
dwmw2 Jul 3, 2023
5d35347
Allow $TPM_DEVICE to set TPM device path
dwmw2 Jul 4, 2023
908569c
Add swtpm testing
dwmw2 Jul 4, 2023
2944557
Test cert + key both in one PEM file
dwmw2 Jul 4, 2023
42afaef
Merge in dwmw2:tpm
13ajay Jun 12, 2024
e785ffd
Merge branch 'dwmw2-tpm' into pkcs11
13ajay Jun 12, 2024
7767d1d
Support password-protected TPM signing keys
13ajay Jun 26, 2024
aca9860
Add testing for RSA TPM keys that have the Sign capability
13ajay Jun 26, 2024
5cec079
Code formatting and clean up
13ajay Jun 26, 2024
38e0412
Add further documentation around TPM keys
13ajay Jun 26, 2024
cceb33d
Add TPM capability check before signing
13ajay Jun 27, 2024
085de24
Add parent key password support
13ajay Jun 28, 2024
2b1ea32
Add tests to verify parent key password support
13ajay Aug 11, 2024
8a09473
Fix builds on Windows
13ajay Sep 6, 2024
dfbcf65
Introduce flags to convey intent when not using TPM key passwords
13ajay Sep 19, 2024
70904cc
Add some more tests for TPMv2Signer
13ajay Sep 19, 2024
7bdd7a9
Accept TPM key handles
13ajay Oct 17, 2024
0694dfc
Switch Makefile to using Intel tools to generate TPM fixtures
13ajay Oct 18, 2024
54968db
Determine authorization requirement based on CLI flags or key file
13ajay Oct 19, 2024
d6c3740
Improve TPM key guidance
13ajay Oct 19, 2024
a17522f
Fix 'scripts' section of README
13ajay Oct 23, 2024
574140c
Modify TPM key file password indication behavior
13ajay Oct 24, 2024
8ac0e84
Miscellaneous changes
13ajay Nov 6, 2024
19bb307
Error out when TPM key files are used on Windows
13ajay Nov 6, 2024
15598e3
Merge branch 'main' into tpm
13ajay Nov 6, 2024
d937441
Update THIRD-PARTY-LICENSES.txt
13ajay Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add further documentation around TPM keys
* Note that the guidance as written now hasn't been fully tested
  • Loading branch information
13ajay committed Jun 26, 2024
commit 38e0412a3a49d9c1c5a597a7fd1eafce28058c57
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ PKCS12CERTS := $(patsubst %-cert.pem, %.p12, $(RSACERTS) $(ECCERTS))
#
# For the actual test, we need it to run in UNIX socket mode, since
# *that* is all that go-tpm can cope with. So we start it in that mode
# in the 'test:' recipe, and stop it again afterwards.
#
# in the 'test:' (or 'test-tpm-signer:') recipe(s), and stop it again
# afterwards.
SWTPM_STATEDIR := $(curdir)/tst/swtpm
SWTPM_CTRLSOCK := $(curdir)/tst/swtpm-ctrl
SWTPM_SERVSOCK := $(curdir)/tst/swtpm-serv
Expand Down
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,52 @@ they're likely to be added:
* TPM Policy / AuthPolicy
* Sealed keys

##### Testing
Currently, unit tests for testing TPM support are written in such a way that TPM keys that are used
for testing are either bound to a hardware TPM, or are bound to a software TPM. For software TPM
testing, `swtpm` is used. You can find the repository [here](/~https://github.com/stefanberger/swtpm).
Also, to create the keys and certificates that are required for unit testing, you will need to install
the [IBM TSS](/~https://github.com/kgoldman/ibmtss), in addition to the
[IBM OpenSSL TPM engine](https://git.kernel.org/pub/scm/linux/kernel/git/jejb/openssl_tpm2_engine.git/).
The OpenSSL TPM engine comes with utility programs that can be used to create TPM keys that are in
the appropriate format to be used by the credential helper application.

Once you've installed all the dependencies, you can run just the unit tests related to TPM support
through `make test-tpm-signer`. Note that `swtpm` will have to be run in UNIX socket mode (it can't
be run in TCP socket mode) for the tests since that is all `go-tpm` can cope with. But key and
certificate fixtures will be created when `swtpm` is running in TCP socket mode (as a part of the
appropriate `Makefile` targets). Afterwards, right before the unit tests are run, `swtpm` we switch
`swtpm` over to run in UNIX socket mode.

##### Guidance
Once you have initialized the TPM appropriately, you can create a primary key in the owner hierarchy.
Using one of the utility programs that comes with the IBM TSS (you can find more
information about it in the previous section), create this primary key:

```
tsscreateprimary -hi o -ho 80000000 -hp 81000001 -ecc nistp256 -pwdk ${TPM_PRIMARY_KEY_PASSWORD}
```

This will create a primary key in the TPM owner hierarchy, with a key password of
`${TPM_PRIMARY_KEY_PASSWORD}`. If the owner hierarchy in your TPM has a password, you can specify it
through the `-pwdk` option.

Next, you can make that primary key persistent (it was created as transient above):
```
tssevictcontrol -hi o -ho 80000000 -hp 81000001 -pwda ${TPM_PRIMARY_KEY_PASSWORD}
```

Next, you can create a child key, which has the previously created primary as its parent:
```
create_tpm2_key -e prime256v1 -p 81000001 client-tpm-key.pem --auth --password ${TPM_CLIENT_KEY_PASSWORD}
```

Note that the above uses a utility program provided by the IBM OpenSSL engine.

Lastly, you can create a certificate using the client key that was just created. Make sure to provide
the client key password and the engine identifier when using the OpenSSL CLI, in addition to the
necessary information about the issuing CA.

#### Other Notes

##### YubiKey Attestation Certificates
Expand Down
15 changes: 11 additions & 4 deletions aws_signing_helper/tpm_signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ func createRsaTpmPemKeyWithSignCapability(suffix string, emptyAuth bool) error {
return nil
}

// The RSA key with the Sign capability will have already been created
// as a part of the owner hierarchy (as a part of the Makefile testing
// target). This method will marshal the resulting data into the PEM
// TPM key format.
// An RSA key with the Sign capability will have already been created by a Makefile
// target. Another target will be responsible for calling this testing function, which will
// then create a TPM key file that adheres to Bottomley's ASN.1 specification, so that it
// can be used for testing RSA signing.
func TestCreateRsaTpmPemKeyWithSignCapability(t *testing.T) {
err := createRsaTpmPemKeyWithSignCapability("", true)
if err != nil {
Expand All @@ -107,6 +107,8 @@ func TestCreateRsaTpmPemKeyWithSignCapability(t *testing.T) {
}
}

// This function is similar to the above, but creates a TPM key file for a key that
// is protected by a password.
func TestCreateRsaTpmPemKeyWithPasswordWithSignCapability(t *testing.T) {
err := createRsaTpmPemKeyWithSignCapability("-with-pw", false)
if err != nil {
Expand Down Expand Up @@ -139,6 +141,11 @@ func TestTPMSignerFails(t *testing.T) {
PrivateKeyId: keyWithPw,
TpmKeyPassword: "incorrect-password",
})

testTable = append(testTable, CredentialsOpts{
CertificateId: cert,
PrivateKeyId: keyWithPw,
})
}
}

Expand Down
Loading