Skip to content

Commit fbfc4a7

Browse files
committed
Add TPM 2 application key support for Windows
There's currently no support for creating application keys on Windows systems. This patch transitions the Windows key type to specifically refer to attestation keys, and reuses the existing wrapped key support for application keys. This allows the creation of keys in the platform store, while still allowing said keys to be manipulated with existing TPM functionality rather than duplicating it.
1 parent 3ef3949 commit fbfc4a7

File tree

3 files changed

+251
-53
lines changed

3 files changed

+251
-53
lines changed

attest/key_windows.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ import (
2424
"github.com/google/go-tpm/tpm2"
2525
)
2626

27-
// windowsKey12 represents a Windows-managed key on a TPM1.2 TPM.
28-
type windowsKey12 struct {
27+
// windowsAK12 represents a Windows-managed key on a TPM1.2 TPM.
28+
type windowsAK12 struct {
2929
hnd uintptr
3030
pcpKeyName string
3131
public []byte
3232
}
3333

34-
func newWindowsKey12(hnd uintptr, pcpKeyName string, public []byte) ak {
35-
return &windowsKey12{
34+
func newWindowsAK12(hnd uintptr, pcpKeyName string, public []byte) ak {
35+
return &windowsAK12{
3636
hnd: hnd,
3737
pcpKeyName: pcpKeyName,
3838
public: public,
3939
}
4040
}
4141

42-
func (k *windowsKey12) marshal() ([]byte, error) {
42+
func (k *windowsAK12) marshal() ([]byte, error) {
4343
out := serializedKey{
4444
Encoding: keyEncodingOSManaged,
4545
TPMVersion: TPMVersion12,
@@ -49,7 +49,7 @@ func (k *windowsKey12) marshal() ([]byte, error) {
4949
return out.Serialize()
5050
}
5151

52-
func (k *windowsKey12) activateCredential(t tpmBase, in EncryptedCredential) ([]byte, error) {
52+
func (k *windowsAK12) activateCredential(t tpmBase, in EncryptedCredential) ([]byte, error) {
5353
tpm, ok := t.(*windowsTPM)
5454
if !ok {
5555
return nil, fmt.Errorf("expected *windowsTPM, got %T", t)
@@ -61,7 +61,7 @@ func (k *windowsKey12) activateCredential(t tpmBase, in EncryptedCredential) ([]
6161
return decryptCredential(secretKey, in.Secret)
6262
}
6363

64-
func (k *windowsKey12) quote(tb tpmBase, nonce []byte, alg HashAlg) (*Quote, error) {
64+
func (k *windowsAK12) quote(tb tpmBase, nonce []byte, alg HashAlg) (*Quote, error) {
6565
if alg != HashSHA1 {
6666
return nil, fmt.Errorf("only SHA1 algorithms supported on TPM 1.2, not %v", alg)
6767
}
@@ -103,21 +103,21 @@ func (k *windowsKey12) quote(tb tpmBase, nonce []byte, alg HashAlg) (*Quote, err
103103
}, nil
104104
}
105105

106-
func (k *windowsKey12) close(tpm tpmBase) error {
106+
func (k *windowsAK12) close(tpm tpmBase) error {
107107
return closeNCryptObject(k.hnd)
108108
}
109109

110-
func (k *windowsKey12) attestationParameters() AttestationParameters {
110+
func (k *windowsAK12) attestationParameters() AttestationParameters {
111111
return AttestationParameters{
112112
Public: k.public,
113113
}
114114
}
115-
func (k *windowsKey12) certify(tb tpmBase, handle interface{}) (*CertificationParameters, error) {
115+
func (k *windowsAK12) certify(tb tpmBase, handle interface{}) (*CertificationParameters, error) {
116116
return nil, fmt.Errorf("not implemented")
117117
}
118118

119-
// windowsKey20 represents a key bound to a TPM 2.0.
120-
type windowsKey20 struct {
119+
// windowsAK20 represents a key bound to a TPM 2.0.
120+
type windowsAK20 struct {
121121
hnd uintptr
122122

123123
pcpKeyName string
@@ -127,8 +127,8 @@ type windowsKey20 struct {
127127
createSignature []byte
128128
}
129129

130-
func newWindowsKey20(hnd uintptr, pcpKeyName string, public, createData, createAttest, createSig []byte) ak {
131-
return &windowsKey20{
130+
func newWindowsAK20(hnd uintptr, pcpKeyName string, public, createData, createAttest, createSig []byte) ak {
131+
return &windowsAK20{
132132
hnd: hnd,
133133
pcpKeyName: pcpKeyName,
134134
public: public,
@@ -138,7 +138,7 @@ func newWindowsKey20(hnd uintptr, pcpKeyName string, public, createData, createA
138138
}
139139
}
140140

141-
func (k *windowsKey20) marshal() ([]byte, error) {
141+
func (k *windowsAK20) marshal() ([]byte, error) {
142142
out := serializedKey{
143143
Encoding: keyEncodingOSManaged,
144144
TPMVersion: TPMVersion20,
@@ -152,15 +152,15 @@ func (k *windowsKey20) marshal() ([]byte, error) {
152152
return out.Serialize()
153153
}
154154

155-
func (k *windowsKey20) activateCredential(t tpmBase, in EncryptedCredential) ([]byte, error) {
155+
func (k *windowsAK20) activateCredential(t tpmBase, in EncryptedCredential) ([]byte, error) {
156156
tpm, ok := t.(*windowsTPM)
157157
if !ok {
158158
return nil, fmt.Errorf("expected *windowsTPM, got %T", t)
159159
}
160160
return tpm.pcp.ActivateCredential(k.hnd, append(in.Credential, in.Secret...))
161161
}
162162

163-
func (k *windowsKey20) quote(tb tpmBase, nonce []byte, alg HashAlg) (*Quote, error) {
163+
func (k *windowsAK20) quote(tb tpmBase, nonce []byte, alg HashAlg) (*Quote, error) {
164164
t, ok := tb.(*windowsTPM)
165165
if !ok {
166166
return nil, fmt.Errorf("expected *windowsTPM, got %T", tb)
@@ -177,11 +177,11 @@ func (k *windowsKey20) quote(tb tpmBase, nonce []byte, alg HashAlg) (*Quote, err
177177
return quote20(tpm, tpmKeyHnd, alg.goTPMAlg(), nonce)
178178
}
179179

180-
func (k *windowsKey20) close(tpm tpmBase) error {
180+
func (k *windowsAK20) close(tpm tpmBase) error {
181181
return closeNCryptObject(k.hnd)
182182
}
183183

184-
func (k *windowsKey20) attestationParameters() AttestationParameters {
184+
func (k *windowsAK20) attestationParameters() AttestationParameters {
185185
return AttestationParameters{
186186
Public: k.public,
187187
CreateData: k.createData,
@@ -190,7 +190,7 @@ func (k *windowsKey20) attestationParameters() AttestationParameters {
190190
}
191191
}
192192

193-
func (k *windowsKey20) certify(tb tpmBase, handle interface{}) (*CertificationParameters, error) {
193+
func (k *windowsAK20) certify(tb tpmBase, handle interface{}) (*CertificationParameters, error) {
194194
t, ok := tb.(*windowsTPM)
195195
if !ok {
196196
return nil, fmt.Errorf("expected *windowsTPM, got %T", tb)

0 commit comments

Comments
 (0)