|
|
@ -17,7 +17,9 @@ import ( |
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
"github.com/tendermint/tendermint/crypto" |
|
|
|
"github.com/tendermint/tendermint/crypto/ed25519" |
|
|
|
"github.com/tendermint/tendermint/crypto/secp256k1" |
|
|
|
cmn "github.com/tendermint/tendermint/libs/common" |
|
|
|
) |
|
|
|
|
|
|
@ -363,6 +365,51 @@ func TestDeriveSecretsAndChallengeGolden(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
type privKeyWithNilPubKey struct { |
|
|
|
orig crypto.PrivKey |
|
|
|
} |
|
|
|
|
|
|
|
func (pk privKeyWithNilPubKey) Bytes() []byte { return pk.orig.Bytes() } |
|
|
|
func (pk privKeyWithNilPubKey) Sign(msg []byte) ([]byte, error) { return pk.orig.Sign(msg) } |
|
|
|
func (pk privKeyWithNilPubKey) PubKey() crypto.PubKey { return nil } |
|
|
|
func (pk privKeyWithNilPubKey) Equals(pk2 crypto.PrivKey) bool { return pk.orig.Equals(pk2) } |
|
|
|
|
|
|
|
func TestNilPubkey(t *testing.T) { |
|
|
|
var fooConn, barConn = makeKVStoreConnPair() |
|
|
|
var fooPrvKey = ed25519.GenPrivKey() |
|
|
|
var barPrvKey = privKeyWithNilPubKey{ed25519.GenPrivKey()} |
|
|
|
|
|
|
|
go func() { |
|
|
|
_, err := MakeSecretConnection(barConn, barPrvKey) |
|
|
|
assert.NoError(t, err) |
|
|
|
}() |
|
|
|
|
|
|
|
assert.NotPanics(t, func() { |
|
|
|
_, err := MakeSecretConnection(fooConn, fooPrvKey) |
|
|
|
if assert.Error(t, err) { |
|
|
|
assert.Equal(t, "expected ed25519 pubkey, got <nil>", err.Error()) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
func TestNonEd25519Pubkey(t *testing.T) { |
|
|
|
var fooConn, barConn = makeKVStoreConnPair() |
|
|
|
var fooPrvKey = ed25519.GenPrivKey() |
|
|
|
var barPrvKey = secp256k1.GenPrivKey() |
|
|
|
|
|
|
|
go func() { |
|
|
|
_, err := MakeSecretConnection(barConn, barPrvKey) |
|
|
|
assert.NoError(t, err) |
|
|
|
}() |
|
|
|
|
|
|
|
assert.NotPanics(t, func() { |
|
|
|
_, err := MakeSecretConnection(fooConn, fooPrvKey) |
|
|
|
if assert.Error(t, err) { |
|
|
|
assert.Equal(t, "expected ed25519 pubkey, got secp256k1.PubKeySecp256k1", err.Error()) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
// Creates the data for a test vector file.
|
|
|
|
// The file format is:
|
|
|
|
// Hex(diffie_hellman_secret), loc_is_least, Hex(recvSecret), Hex(sendSecret), Hex(challenge)
|
|
|
|