@@ -37,21 +37,37 @@ import (
37
37
)
38
38
39
39
func doTPMAttestation (clictx * cli.Context , ac * ca.ACMEClient , ch * acme.Challenge , identifier string , af * acmeFlow ) error {
40
+ attestationURI := clictx .String ("attestation-uri" )
40
41
tpmStorageDirectory := clictx .String ("tpm-storage-directory" )
41
- t , err := tpm .New (tpm .WithStore (tpmstorage .NewDirstore (tpmStorageDirectory )))
42
+ tpmAttestationCABaseURL := clictx .String ("attestation-ca-url" )
43
+ tpmAttestationCARootFile := clictx .String ("attestation-ca-root" )
44
+ tpmAttestationCAInsecure := clictx .Bool ("attestation-ca-insecure" )
45
+ insecure := clictx .Bool ("insecure" )
46
+
47
+ keyName , attURI , err := parseTPMAttestationURI (attestationURI )
42
48
if err != nil {
43
- return fmt .Errorf ("failed initializing TPM : %w" , err )
49
+ return fmt .Errorf ("failed parsing --attestation-uri : %w" , err )
44
50
}
45
51
46
- tpmAttestationCABaseURL := clictx .String ("attestation-ca-url" )
47
52
if tpmAttestationCABaseURL == "" {
48
- return errs .RequiredFlag (clictx , "attestation-ca-url" )
53
+ tpmAttestationCABaseURL = attURI .Get ("attestation-ca-url" )
54
+ if tpmAttestationCABaseURL == "" {
55
+ return errs .RequiredFlag (clictx , "attestation-ca-url" )
56
+ }
49
57
}
50
58
51
- tpmAttestationCARootFile := clictx .String ("attestation-ca-root" )
52
- tpmAttestationCAInsecure := clictx .Bool ("attestation-ca-insecure" )
59
+ tpmOpts := []tpm.NewTPMOption {
60
+ tpm .WithStore (tpmstorage .NewDirstore (tpmStorageDirectory )),
61
+ }
62
+ if device := attURI .Get ("device" ); device != "" {
63
+ tpmOpts = append (tpmOpts , tpm .WithDeviceName (device ))
64
+ }
65
+
66
+ t , err := tpm .New (tpmOpts ... )
67
+ if err != nil {
68
+ return fmt .Errorf ("failed initializing TPM: %w" , err )
69
+ }
53
70
54
- insecure := clictx .Bool ("insecure" )
55
71
kty , crv , size , err := utils .GetKeyDetailsFromCLI (clictx , insecure , "kty" , "curve" , "size" )
56
72
if err != nil {
57
73
return fmt .Errorf ("failed getting key details: %w" , err )
@@ -78,12 +94,6 @@ func doTPMAttestation(clictx *cli.Context, ac *ca.ACMEClient, ch *acme.Challenge
78
94
return fmt .Errorf ("unsupported key type: %q" , kty )
79
95
}
80
96
81
- attestationURI := clictx .String ("attestation-uri" )
82
- keyName , err := parseTPMAttestationURI (attestationURI )
83
- if err != nil {
84
- return fmt .Errorf ("failed parsing --attestation-uri: %w" , err )
85
- }
86
-
87
97
ctx := tpm .NewContext (context .Background (), t )
88
98
info , err := t .Info (ctx )
89
99
if err != nil {
@@ -185,23 +195,23 @@ func doTPMAttestation(clictx *cli.Context, ac *ca.ACMEClient, ch *acme.Challenge
185
195
}
186
196
187
197
// parseTPMAttestationURI parses attestation URIs for `tpmkms`.
188
- func parseTPMAttestationURI (attestationURI string ) (string , error ) {
198
+ func parseTPMAttestationURI (attestationURI string ) (string , * uri. URI , error ) {
189
199
if attestationURI == "" {
190
- return "" , errors .New ("attestation URI cannot be empty" )
200
+ return "" , nil , errors .New ("attestation URI cannot be empty" )
191
201
}
192
202
if ! strings .HasPrefix (attestationURI , "tpmkms:" ) {
193
- return "" , fmt .Errorf ("%q does not start with tpmkms" , attestationURI )
203
+ return "" , nil , fmt .Errorf ("%q does not start with tpmkms" , attestationURI )
194
204
}
195
205
u , err := uri .Parse (attestationURI )
196
206
if err != nil {
197
- return "" , fmt .Errorf ("failed parsing %q: %w" , attestationURI , err )
207
+ return "" , nil , fmt .Errorf ("failed parsing %q: %w" , attestationURI , err )
198
208
}
199
209
var name string
200
210
if name = u .Get ("name" ); name == "" {
201
- return "" , fmt .Errorf ("failed parsing %q: name is missing" , attestationURI )
211
+ return "" , nil , fmt .Errorf ("failed parsing %q: name is missing" , attestationURI )
202
212
}
203
213
// TODO(hs): more properties for objects created/attested in TPM
204
- return name , nil
214
+ return name , u , nil
205
215
}
206
216
207
217
// getAK returns an AK suitable for attesting the identifier that is requested. The
0 commit comments