mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 13:55:17 +00:00
Enforce validators can only use the correct pubkey type (#2739)
* Enforce validators can only use the correct pubkey type * adapt to variable renames * Address comments from #2636 * separate updating and validation logic * update spec * Add test case for TestStringSliceEqual, clarify slice copying code * Address @ebuchman's comments * Split up testing validator update execution, and its validation
This commit is contained in:
@@ -187,20 +187,19 @@ var PB2TM = pb2tm{}
|
||||
type pb2tm struct{}
|
||||
|
||||
func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) {
|
||||
// TODO: define these in crypto and use them
|
||||
sizeEd := 32
|
||||
sizeSecp := 33
|
||||
switch pubKey.Type {
|
||||
case ABCIPubKeyTypeEd25519:
|
||||
if len(pubKey.Data) != sizeEd {
|
||||
return nil, fmt.Errorf("Invalid size for PubKeyEd25519. Got %d, expected %d", len(pubKey.Data), sizeEd)
|
||||
if len(pubKey.Data) != ed25519.PubKeyEd25519Size {
|
||||
return nil, fmt.Errorf("Invalid size for PubKeyEd25519. Got %d, expected %d",
|
||||
len(pubKey.Data), ed25519.PubKeyEd25519Size)
|
||||
}
|
||||
var pk ed25519.PubKeyEd25519
|
||||
copy(pk[:], pubKey.Data)
|
||||
return pk, nil
|
||||
case ABCIPubKeyTypeSecp256k1:
|
||||
if len(pubKey.Data) != sizeSecp {
|
||||
return nil, fmt.Errorf("Invalid size for PubKeyEd25519. Got %d, expected %d", len(pubKey.Data), sizeSecp)
|
||||
if len(pubKey.Data) != secp256k1.PubKeySecp256k1Size {
|
||||
return nil, fmt.Errorf("Invalid size for PubKeySecp256k1. Got %d, expected %d",
|
||||
len(pubKey.Data), secp256k1.PubKeySecp256k1Size)
|
||||
}
|
||||
var pk secp256k1.PubKeySecp256k1
|
||||
copy(pk[:], pubKey.Data)
|
||||
|
||||
Reference in New Issue
Block a user