@@ -32,18 +32,19 @@ func genKey(c *C, r *repo.Repo, role string) []string {
32
32
// Deprecated ecdsa key support: Support verification against roots that were
33
33
// signed with hex-encoded ecdsa keys.
34
34
func (rs * RepoSuite ) TestDeprecatedHexEncodedKeysSucceed (c * C ) {
35
+ type deprecatedP256Verifier struct {
36
+ PublicKey data.HexBytes `json:"public"`
37
+ }
35
38
files := map [string ][]byte {"foo.txt" : []byte ("foo" )}
36
39
local := repo .MemoryStore (make (map [string ]json.RawMessage ), files )
37
40
r , err := repo .NewRepo (local )
38
41
c .Assert (err , IsNil )
39
42
40
43
r .Init (false )
41
- // Add a root key with hex-encoded ecdsa format
44
+
45
+ // Add a root key with hex-encoded ecdsa format - compliant "ecdsa"
42
46
signer , err := keys .GenerateEcdsaKey ()
43
47
c .Assert (err , IsNil )
44
- type deprecatedP256Verifier struct {
45
- PublicKey data.HexBytes `json:"public"`
46
- }
47
48
pub := signer .PublicKey
48
49
keyValBytes , err := json .Marshal (& deprecatedP256Verifier {PublicKey : elliptic .Marshal (pub .Curve , pub .X , pub .Y )})
49
50
c .Assert (err , IsNil )
@@ -55,6 +56,22 @@ func (rs *RepoSuite) TestDeprecatedHexEncodedKeysSucceed(c *C) {
55
56
}
56
57
err = r .AddVerificationKey ("root" , publicData )
57
58
c .Assert (err , IsNil )
59
+
60
+ // Add a root key with hex-encoded ecdsa format - deprecated "ecdsa-sha2-nistp256"
61
+ signerDeprecated , err := keys .GenerateEcdsaKey ()
62
+ c .Assert (err , IsNil )
63
+ pubDeprecated := signerDeprecated .PublicKey
64
+ keyValBytesDeprecated , err := json .Marshal (& deprecatedP256Verifier {PublicKey : elliptic .Marshal (pubDeprecated .Curve , pubDeprecated .X , pubDeprecated .Y )})
65
+ c .Assert (err , IsNil )
66
+ publicDataDeprecated := & data.PublicKey {
67
+ Type : data .KeyTypeECDSA_SHA2_P256_OLD_FMT ,
68
+ Scheme : data .KeySchemeECDSA_SHA2_P256 ,
69
+ Algorithms : data .HashAlgorithms ,
70
+ Value : keyValBytesDeprecated ,
71
+ }
72
+ err = r .AddVerificationKey ("root" , publicDataDeprecated )
73
+ c .Assert (err , IsNil )
74
+
58
75
// Add other keys as normal
59
76
genKey (c , r , "targets" )
60
77
genKey (c , r , "snapshot" )
@@ -75,6 +92,14 @@ func (rs *RepoSuite) TestDeprecatedHexEncodedKeysSucceed(c *C) {
75
92
Signature : rootSig }), IsNil )
76
93
}
77
94
95
+ rootSigDeprecated , err := signerDeprecated .PrivateKey .Sign (rand .Reader , hash [:], crypto .SHA256 )
96
+ c .Assert (err , IsNil )
97
+ for _ , id := range publicDataDeprecated .IDs () {
98
+ c .Assert (r .AddOrUpdateSignature ("root.json" , data.Signature {
99
+ KeyID : id ,
100
+ Signature : rootSigDeprecated }), IsNil )
101
+ }
102
+
78
103
// Committing should succeed because the deprecated key pkg is added.
79
104
c .Assert (r .Snapshot (), IsNil )
80
105
c .Assert (r .Timestamp (), IsNil )
0 commit comments