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

Refactor ACME TPM attestation to use the TPMKMS #973

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions command/ca/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ multiple SANs. The '--san' flag and the '--token' flag are mutually exclusive.`,
Usage: "The directory where TPM keys and certificates will be stored",
Value: filepath.Join(step.Path(), "tpm"),
},
cli.StringFlag{
Name: "tpm-device",
Usage: "The TPM device (name) to use",
},
flags.TemplateSet,
flags.TemplateSetFile,
flags.CaConfig,
Expand Down
26 changes: 21 additions & 5 deletions utils/cautils/acmeutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"go.step.sm/cli-utils/ui"
"go.step.sm/crypto/jose"
"go.step.sm/crypto/keyutil"
"go.step.sm/crypto/kms/apiv1"
"go.step.sm/crypto/kms/uri"
"go.step.sm/crypto/pemutil"
"go.step.sm/crypto/tpm"
tpmstorage "go.step.sm/crypto/tpm/storage"
Expand Down Expand Up @@ -401,8 +403,19 @@
// doDeviceAttestation performs `device-attest-01` challenge validation.
func doDeviceAttestation(clictx *cli.Context, ac *ca.ACMEClient, ch *acme.Challenge, identifier string, af *acmeFlow) error {
// TODO(hs): make TPM flow work with CreateAttestor()/Attest() too
// TODO: prepare the full attestation-uri: fill in missing data, fill in values from flags,
// get defaults (AK name, based on TPM presence); fail early if no TPM available.

Check warning on line 407 in utils/cautils/acmeutils.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/acmeutils.go#L406-L407

Added lines #L406 - L407 were not covered by tests
attestationURI := clictx.String("attestation-uri")
if strings.HasPrefix(attestationURI, "tpmkms:") {
u, err := uri.ParseWithScheme(string(apiv1.TPMKMS), attestationURI)
if err != nil {
return fmt.Errorf("failed to parse %q: %w", attestationURI, err)
}
if device := clictx.String("tpm-device"); device != "" {
u.Values.Set("device", device)
clictx.Set("attestation-uri", u.String())
}

Check warning on line 417 in utils/cautils/acmeutils.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/acmeutils.go#L410-L417

Added lines #L410 - L417 were not covered by tests

return doTPMAttestation(clictx, ac, ch, identifier, af)
}

Expand Down Expand Up @@ -832,17 +845,20 @@
if af.tpmSigner != nil {
attestationURI := af.ctx.String("attestation-uri")
tpmStorageDirectory := af.ctx.String("tpm-storage-directory")
tpmDevice := af.ctx.String("tpm-device")

tpmOpts := []tpm.NewTPMOption{
tpm.WithStore(tpmstorage.NewDirstore(tpmStorageDirectory)),
}

Check warning on line 852 in utils/cautils/acmeutils.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/acmeutils.go#L848-L852

Added lines #L848 - L852 were not covered by tests

keyName, attURI, err := parseTPMAttestationURI(attestationURI)
if err != nil {
return nil, fmt.Errorf("failed parsing --attestation-uri: %w", err)
}

tpmOpts := []tpm.NewTPMOption{
tpm.WithStore(tpmstorage.NewDirstore(tpmStorageDirectory)),
}
if device := attURI.Get("device"); device != "" {
tpmOpts = append(tpmOpts, tpm.WithDeviceName(device))
if tpmDevice == "" {
tpmDevice := attURI.Get("device")
tpmOpts = append(tpmOpts, tpm.WithDeviceName(tpmDevice))

Check warning on line 861 in utils/cautils/acmeutils.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/acmeutils.go#L859-L861

Added lines #L859 - L861 were not covered by tests
}

t, err := tpm.New(tpmOpts...)
Expand Down
13 changes: 8 additions & 5 deletions utils/cautils/tpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@
func doTPMAttestation(clictx *cli.Context, ac *ca.ACMEClient, ch *acme.Challenge, identifier string, af *acmeFlow) error {
attestationURI := clictx.String("attestation-uri")
tpmStorageDirectory := clictx.String("tpm-storage-directory")
tpmDevice := clictx.String("tpm-device")

Check warning on line 42 in utils/cautils/tpm.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/tpm.go#L42

Added line #L42 was not covered by tests
tpmAttestationCABaseURL := clictx.String("attestation-ca-url")
tpmAttestationCARootFile := clictx.String("attestation-ca-root")
tpmAttestationCAInsecure := clictx.Bool("attestation-ca-insecure")
insecure := clictx.Bool("insecure")

tpmOpts := []tpm.NewTPMOption{
tpm.WithStore(tpmstorage.NewDirstore(tpmStorageDirectory)),
}

Check warning on line 51 in utils/cautils/tpm.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/tpm.go#L48-L51

Added lines #L48 - L51 were not covered by tests
keyName, attURI, err := parseTPMAttestationURI(attestationURI)
if err != nil {
return fmt.Errorf("failed parsing --attestation-uri: %w", err)
Expand All @@ -56,11 +61,9 @@
}
}

tpmOpts := []tpm.NewTPMOption{
tpm.WithStore(tpmstorage.NewDirstore(tpmStorageDirectory)),
}
if device := attURI.Get("device"); device != "" {
tpmOpts = append(tpmOpts, tpm.WithDeviceName(device))
if tpmDevice == "" {
tpmDevice := attURI.Get("device")
tpmOpts = append(tpmOpts, tpm.WithDeviceName(tpmDevice))

Check warning on line 66 in utils/cautils/tpm.go

View check run for this annotation

Codecov / codecov/patch

utils/cautils/tpm.go#L64-L66

Added lines #L64 - L66 were not covered by tests
}

t, err := tpm.New(tpmOpts...)
Expand Down