-
Notifications
You must be signed in to change notification settings - Fork 17
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
[1/3] Keydata v3 platform API changes #265
Changes from 1 commit
0dc8c1b
f6cba7e
cfcca36
0712e4b
7fe9a98
98db494
fdfa79e
6452fb6
977d320
5af09ed
1a9de9b
08c2d56
c8cb933
3cf4c26
759419a
ce63a2f
25099ff
c7d0f3b
7f9a3b7
8c92177
18b89e5
23c36bc
ce88f13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ const ( | |
) | ||
|
||
var ( | ||
keyDataVersion int = 2 | ||
keyDataGeneration int = 2 | ||
snapModelHMACKDFLabel = []byte("SNAP-MODEL-HMAC") | ||
sha1Oid = asn1.ObjectIdentifier{1, 3, 14, 3, 2, 26} | ||
sha224Oid = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 4} | ||
|
@@ -415,7 +415,11 @@ type passphraseParams struct { | |
} | ||
|
||
type keyData struct { | ||
Version int `json:"version,omitempty"` | ||
// Generation is a number used to differentiate between different key formats. | ||
// i.e Gen1 keys are binary serialized and include a primary and an unlock key while | ||
// Gen2 keys are ASN1 serialized and include a primary key and a unique key which is | ||
// used to derive the unlock key. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The generations might also support different set of platform data fields? |
||
Generation int `json:"generation,omitempty"` | ||
|
||
PlatformName string `json:"platform_name"` // used to identify a PlatformKeyDataHandler | ||
|
||
|
@@ -644,15 +648,15 @@ func (d *KeyData) openWithPassphrase(passphrase string, kdf KDF) (payload []byte | |
|
||
func (d *KeyData) platformKeyData() *PlatformKeyData { | ||
return &PlatformKeyData{ | ||
Version: d.Version(), | ||
Generation: d.Generation(), | ||
EncodedHandle: d.data.PlatformHandle, | ||
KDFAlg: crypto.Hash(d.data.KDFAlg), | ||
AuthMode: d.AuthMode(), | ||
} | ||
} | ||
|
||
func (d *KeyData) recoverKeysCommon(data []byte) (DiskUnlockKey, PrimaryKey, error) { | ||
switch d.Version() { | ||
switch d.Generation() { | ||
case 1: | ||
unlockKey, primaryKey, err := unmarshalV1KeyPayload(data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why V1? as Version here is 0? also we have already key own versions, maybe we should use a different naming/termilogy than just version, internal for this level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is related to #265 (comment) as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I already changed it and replied to the comment above but summarizing it again to make sure I don't miss something. The following versions are possible:
When I first saw V1, I assumed there was another V0. Isn't that the case? If not, maybe we could simply call old keys legacy keys? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "generation"? So that we can refer to cross-platform keydata versions as generations and then each platform can refer to its internal version simply as "version". i.e TPM platform's key versions 0-2 use cross-platform keys of generation 1 (or 0, this is still a bit confusing) while TPM platform's version 3 keys use generation 2 cross-platform keys. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "generation" would work for me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, generation is ok with me as well. |
||
if err != nil { | ||
|
@@ -669,19 +673,19 @@ func (d *KeyData) recoverKeysCommon(data []byte) (DiskUnlockKey, PrimaryKey, err | |
} | ||
return pk.unlockKey(crypto.Hash(d.data.KDFAlg)), pk.Primary, nil | ||
default: | ||
return nil, nil, fmt.Errorf("invalid keydata version %d", d.Version()) | ||
return nil, nil, fmt.Errorf("invalid keydata generation %d", d.Generation()) | ||
} | ||
} | ||
|
||
// Version returns this key data's version. Since the version field didn't exist | ||
// for key data versions < 2, we fake the version returned to 1. | ||
func (d *KeyData) Version() int { | ||
switch d.data.Version { | ||
// Generation returns this keydata's generation. Since the generation field didn't exist | ||
// for older keydata with generation < 2, we fake the generation returned to 1. | ||
func (d *KeyData) Generation() int { | ||
switch d.data.Generation { | ||
case 0: | ||
// This field was missing in v1 | ||
// This field was missing in gen1 | ||
return 1 | ||
default: | ||
return d.data.Version | ||
return d.data.Generation | ||
} | ||
} | ||
|
||
|
@@ -931,7 +935,7 @@ func NewKeyData(params *KeyParams) (*KeyData, error) { | |
|
||
kd := &KeyData{ | ||
data: keyData{ | ||
Version: keyDataVersion, | ||
Generation: keyDataGeneration, | ||
PlatformName: params.PlatformName, | ||
PlatformHandle: json.RawMessage(encodedHandle), | ||
KDFAlg: hashAlg(params.KDFAlg), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a short doc comment describing this even it's private might not hurt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've actually got a follow-up PR that makes this public (so that the version can be bound into the AAD)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sorry about that, I thought I had that change in here already, I also make it public in the final PR because I needed it for a test for AAD 33445cf