Skip to content

Commit 9ce4b39

Browse files
committed
Fix entry tests to ensure ed25519 is now accepted
1 parent 3971e51 commit 9ce4b39

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

pkg/types/hashedrekord/v0.0.1/entry_test.go

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"github.com/sigstore/rekor/pkg/types"
4242
"github.com/sigstore/sigstore/pkg/cryptoutils"
4343
"github.com/sigstore/sigstore/pkg/signature"
44+
"github.com/sigstore/sigstore/pkg/signature/options"
4445
"go.uber.org/goleak"
4546
)
4647

@@ -113,17 +114,17 @@ func TestCrossFieldValidation(t *testing.T) {
113114
Type: "PUBLIC KEY",
114115
})
115116

116-
// testing lack of support for ed25519
117-
invalidEdPubKey, _, err := ed25519.GenerateKey(rand.Reader)
117+
// testing support ed25519
118+
edPubKey, edPrivKey, err := ed25519.GenerateKey(rand.Reader)
118119
if err != nil {
119120
t.Fatal(err)
120121
}
121-
invalidDer, err := x509.MarshalPKIXPublicKey(invalidEdPubKey)
122+
edDer, err := x509.MarshalPKIXPublicKey(edPubKey)
122123
if err != nil {
123124
t.Fatal(err)
124125
}
125-
invalidKeyBytes := pem.EncodeToMemory(&pem.Block{
126-
Bytes: invalidDer,
126+
edPubKeyBytes := pem.EncodeToMemory(&pem.Block{
127+
Bytes: edDer,
127128
Type: "PUBLIC KEY",
128129
})
129130

@@ -142,6 +143,9 @@ func TestCrossFieldValidation(t *testing.T) {
142143
sha512Signer, _ := signature.LoadSigner(key, crypto.SHA512)
143144
sha512SigBytes, _ := sha512Signer.SignMessage(bytes.NewReader(dataBytes))
144145

146+
edsha512Signer, _ := signature.LoadSignerWithOpts(edPrivKey, options.WithHash(crypto.SHA512), options.WithED25519ph())
147+
edsha512SigBytes, _ := edsha512Signer.SignMessage(bytes.NewReader(dataBytes))
148+
145149
incorrectLengthHash := sha256.Sum224(dataBytes)
146150
incorrectLengthSHA := hex.EncodeToString(incorrectLengthHash[:])
147151

@@ -197,16 +201,15 @@ func TestCrossFieldValidation(t *testing.T) {
197201
entry: V001Entry{
198202
HashedRekordObj: models.HashedrekordV001Schema{
199203
Signature: &models.HashedrekordV001SchemaSignature{
200-
Content: sha256SigBytes,
204+
Content: edsha512SigBytes,
201205
PublicKey: &models.HashedrekordV001SchemaSignaturePublicKey{
202-
Content: invalidKeyBytes,
206+
Content: edPubKeyBytes,
203207
},
204208
},
205209
},
206210
},
207-
expectedHashValue: "sha256:" + dataSHA256,
208-
expectUnmarshalSuccess: false,
209-
// successful even if unmarshalling fails, because the ed25519 key is valid
211+
expectedHashValue: "sha512:" + dataSHA512,
212+
expectUnmarshalSuccess: false,
210213
expectedVerifierSuccess: true,
211214
},
212215
{
@@ -242,6 +245,29 @@ func TestCrossFieldValidation(t *testing.T) {
242245
expectUnmarshalSuccess: false,
243246
expectedVerifierSuccess: true,
244247
},
248+
{
249+
caseDesc: "signature with ed25519 public key (with data)",
250+
entry: V001Entry{
251+
HashedRekordObj: models.HashedrekordV001Schema{
252+
Signature: &models.HashedrekordV001SchemaSignature{
253+
Content: edsha512SigBytes,
254+
PublicKey: &models.HashedrekordV001SchemaSignaturePublicKey{
255+
Content: edPubKeyBytes,
256+
},
257+
},
258+
Data: &models.HashedrekordV001SchemaData{
259+
Hash: &models.HashedrekordV001SchemaDataHash{
260+
Algorithm: swag.String(models.HashedrekordV001SchemaDataHashAlgorithmSha512),
261+
Value: swag.String(dataSHA512),
262+
},
263+
},
264+
},
265+
},
266+
expectedHashValue: "sha512:" + dataSHA512,
267+
expectUnmarshalSuccess: true,
268+
expectCanonicalizeSuccess: true,
269+
expectedVerifierSuccess: true,
270+
},
245271
{
246272
caseDesc: "signature with sha256 hash",
247273
entry: V001Entry{
@@ -457,8 +483,7 @@ func TestCrossFieldValidation(t *testing.T) {
457483
t.Errorf("%v: unexpected error, got %v", tc.caseDesc, err)
458484
} else {
459485
pub, _ := verifiers[0].CanonicalValue()
460-
// invalidKeyBytes is a valid ed25519 key
461-
if !reflect.DeepEqual(pub, keyBytes) && !reflect.DeepEqual(pub, invalidKeyBytes) {
486+
if !reflect.DeepEqual(pub, keyBytes) && !reflect.DeepEqual(pub, edPubKeyBytes) {
462487
t.Errorf("verifier and public keys do not match: %v, %v", string(pub), string(keyBytes))
463488
}
464489
}

0 commit comments

Comments
 (0)