Skip to content

Commit 0e66d19

Browse files
author
Rob Percival
committed
Make trees.Signer() verify key algorithm regardless of signer type
By checking the public key provided by the signer, rather than the type of the signer itself, this check can be performed even for unknown signer types.
1 parent 63f5618 commit 0e66d19

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

trees/trees.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package trees
1818

1919
import (
2020
"crypto"
21-
"crypto/ecdsa"
22-
"crypto/rsa"
2321
"fmt"
2422

2523
"github.com/golang/protobuf/ptypes"
@@ -129,19 +127,9 @@ func Signer(ctx context.Context, sf keys.SignerFactory, tree *trillian.Tree) (*t
129127
return nil, err
130128
}
131129

132-
var ok bool
133-
switch signer.(type) {
134-
case *ecdsa.PrivateKey:
135-
ok = tree.SignatureAlgorithm == sigpb.DigitallySigned_ECDSA
136-
case *rsa.PrivateKey:
137-
ok = tree.SignatureAlgorithm == sigpb.DigitallySigned_RSA
138-
default:
139-
// TODO(codingllama): Make SignatureAlgorithm / key matching part of the SignerFactory contract?
140-
// We don't know about custom signers, so let it pass
141-
ok = true
142-
}
143-
if !ok {
144-
return nil, fmt.Errorf("%s signature not supported by key of type %T", tree.SignatureAlgorithm, signer)
130+
if tcrypto.SignatureAlgorithm(signer.Public()) != tree.SignatureAlgorithm {
131+
return nil, fmt.Errorf("%s signature not supported by signer of type %T", tree.SignatureAlgorithm, signer)
145132
}
133+
146134
return &tcrypto.Signer{Hash: hash, Signer: signer}, nil
147135
}

0 commit comments

Comments
 (0)