Skip to content

Commit ca0c316

Browse files
authored
fix: fail to load deprecated ecdsa verifier (#541)
* fix: fail to load deprecated ecdsa verifier Signed-off-by: Radoslav Dimitrov <dimitrovr@vmware.com> * test: update deprecated tests and fix assigned verifier Signed-off-by: Radoslav Dimitrov <dimitrovr@vmware.com> * chore: temporarily silence govulncheck alerts Signed-off-by: Radoslav Dimitrov <dimitrovr@vmware.com> --------- Signed-off-by: Radoslav Dimitrov <dimitrovr@vmware.com>
1 parent ad706ed commit ca0c316

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ jobs:
7171
uses: golang/govulncheck-action@v1
7272
with:
7373
go-version-input: ${{ matrix.go-version }}
74-
go-package: ./...
74+
go-package: -json ./...

pkg/deprecated/deprecated_repo_test.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
3434
func (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)

pkg/deprecated/set_ecdsa/set_ecdsa.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ func init() {
1919
if !ok {
2020
panic(errors.New("expected to override previously loaded PEM-only ECDSA verifier"))
2121
}
22-
keys.VerifierMap.Store(data.KeyTypeECDSA_SHA2_P256, keys.NewDeprecatedEcdsaVerifier)
22+
// store a mapping for both data.KeyTypeECDSA_SHA2_P256_OLD_FMT and data.KeyTypeECDSA_SHA2_P256
23+
// in case a client is verifying using both the old non-compliant format and a newly generated root
24+
keys.VerifierMap.Store(data.KeyTypeECDSA_SHA2_P256, keys.NewDeprecatedEcdsaVerifier) // compliant format
25+
keys.VerifierMap.Store(data.KeyTypeECDSA_SHA2_P256_OLD_FMT, keys.NewDeprecatedEcdsaVerifier) // deprecated format
2326
}

0 commit comments

Comments
 (0)