@@ -32,18 +32,19 @@ func genKey(c *C, r *repo.Repo, role string) []string {
3232// Deprecated ecdsa key support: Support verification against roots that were
3333// signed with hex-encoded ecdsa keys.
3434func (rs * RepoSuite ) TestDeprecatedHexEncodedKeysSucceed (c * C ) {
35+ type deprecatedP256Verifier struct {
36+ PublicKey data.HexBytes `json:"public"`
37+ }
3538 files := map [string ][]byte {"foo.txt" : []byte ("foo" )}
3639 local := repo .MemoryStore (make (map [string ]json.RawMessage ), files )
3740 r , err := repo .NewRepo (local )
3841 c .Assert (err , IsNil )
3942
4043 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"
4246 signer , err := keys .GenerateEcdsaKey ()
4347 c .Assert (err , IsNil )
44- type deprecatedP256Verifier struct {
45- PublicKey data.HexBytes `json:"public"`
46- }
4748 pub := signer .PublicKey
4849 keyValBytes , err := json .Marshal (& deprecatedP256Verifier {PublicKey : elliptic .Marshal (pub .Curve , pub .X , pub .Y )})
4950 c .Assert (err , IsNil )
@@ -55,6 +56,22 @@ func (rs *RepoSuite) TestDeprecatedHexEncodedKeysSucceed(c *C) {
5556 }
5657 err = r .AddVerificationKey ("root" , publicData )
5758 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+
5875 // Add other keys as normal
5976 genKey (c , r , "targets" )
6077 genKey (c , r , "snapshot" )
@@ -75,6 +92,14 @@ func (rs *RepoSuite) TestDeprecatedHexEncodedKeysSucceed(c *C) {
7592 Signature : rootSig }), IsNil )
7693 }
7794
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+
78103 // Committing should succeed because the deprecated key pkg is added.
79104 c .Assert (r .Snapshot (), IsNil )
80105 c .Assert (r .Timestamp (), IsNil )
0 commit comments