Skip to content
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

Convert ED25519phSignerVerifier to the Pure version #1616

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/signature/ed25519ph.go
Expand Up @@ -46,6 +46,16 @@ func LoadED25519phSigner(priv ed25519.PrivateKey) (*ED25519phSigner, error) {
}, nil
}

// ToED25519SignerVerifier creates a ED25519SignerVerifier from a ED25519phSignerVerifier
//
// Clients that use ED25519phSignerVerifier should use this method to get a
// SignerVerifier that uses the same ED25519 private key, but with the Pure
// Ed25519 algorithm. This might be necessary to interact with Fulcio, which
// only supports the Pure Ed25519 algorithm.
func (e ED25519phSignerVerifier) ToED25519SignerVerifier() (*ED25519SignerVerifier, error) {
return LoadED25519SignerVerifier(e.priv)
}

// SignMessage signs the provided message. If the message is provided,
// this method will compute the digest according to the hash function specified
// when the ED25519phSigner was created.
Expand Down
27 changes: 27 additions & 0 deletions pkg/signature/signerverifier_test.go
Expand Up @@ -17,6 +17,7 @@ package signature
import (
"bytes"
"crypto"
"crypto/ed25519"
"crypto/rsa"
"encoding/base64"
"testing"
Expand Down Expand Up @@ -53,3 +54,29 @@ func TestLoadRSAPSSSignerVerifier(t *testing.T) {
t.Fatalf("unexpected error verifying expected signature: %v", err)
}
}

func TestConvertED25519ph(t *testing.T) {
privateKey, err := cryptoutils.UnmarshalPEMToPrivateKey([]byte(ed25519Priv), cryptoutils.SkipPassword)
if err != nil {
t.Fatalf("unexpected error unmarshalling public key: %v", err)
}
edPriv, ok := privateKey.(ed25519.PrivateKey)
if !ok {
t.Fatalf("expected ed25519.PrivateKey")
}

sv, err := LoadED25519phSignerVerifier(edPriv)
if err != nil {
t.Fatalf("unexpected error creating signer/verifier: %v", err)
}

newSV, err := sv.ToED25519SignerVerifier()
if err != nil {
t.Fatalf("unexpected error converting to ed25519: %v", err)
}

message := []byte("sign me")
sig, _ := base64.StdEncoding.DecodeString("cnafwd8DKq2nQ564eN66ckYV8anVFGFi5vaYiQg2aal7ej/J0/OE0PPdKHLHe9wdzWRMFy5MpurRD/2cGXGLBQ==")
testingSigner(t, newSV, "ed25519", crypto.SHA256, message)
testingVerifier(t, newSV, "ed25519", crypto.SHA256, sig, message)
}