From ee5f8b6c21a9fd038105c4b2440eec78cdbfcde4 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 1 Sep 2022 21:42:57 +0300 Subject: [PATCH] consensus: update dbft, drop marshaling from private key dbft doesn not need this and we must not leak the key in any way. --- go.mod | 4 ++-- go.sum | 7 ++++--- pkg/consensus/crypto.go | 11 ----------- pkg/consensus/crypto_test.go | 9 +-------- 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index da7d338e8..f686cf5be 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/holiman/uint256 v1.2.0 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/mr-tron/base58 v1.2.0 - github.com/nspcc-dev/dbft v0.0.0-20220629112714-fd49ca59d354 + github.com/nspcc-dev/dbft v0.0.0-20220902113116-58a5e763e647 github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220809123759-3094d3e0c14b github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659 @@ -42,7 +42,7 @@ require ( github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/nspcc-dev/hrw v1.0.9 // indirect github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 // indirect - github.com/nspcc-dev/neofs-crypto v0.3.0 // indirect + github.com/nspcc-dev/neofs-crypto v0.4.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.37.0 // indirect diff --git a/go.sum b/go.sum index b75b397ff..7dd037d23 100644 --- a/go.sum +++ b/go.sum @@ -251,8 +251,8 @@ github.com/nspcc-dev/dbft v0.0.0-20191209120240-0d6b7568d9ae/go.mod h1:3FjXOoHmA github.com/nspcc-dev/dbft v0.0.0-20200117124306-478e5cfbf03a/go.mod h1:/YFK+XOxxg0Bfm6P92lY5eDSLYfp06XOdL8KAVgXjVk= github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ= github.com/nspcc-dev/dbft v0.0.0-20210721160347-1b03241391ac/go.mod h1:U8MSnEShH+o5hexfWJdze6uMFJteP0ko7J2frO7Yu1Y= -github.com/nspcc-dev/dbft v0.0.0-20220629112714-fd49ca59d354 h1:/NYQJ9dmeOajNuS0b8x8SMt0b4mEYwUWOpMXuLQ1qwM= -github.com/nspcc-dev/dbft v0.0.0-20220629112714-fd49ca59d354/go.mod h1:U8MSnEShH+o5hexfWJdze6uMFJteP0ko7J2frO7Yu1Y= +github.com/nspcc-dev/dbft v0.0.0-20220902113116-58a5e763e647 h1:handGBjqVzRx7HD6152zsP8ZRxw083zCMbN0IlUaPQk= +github.com/nspcc-dev/dbft v0.0.0-20220902113116-58a5e763e647/go.mod h1:g9xisXmX9NP9MjioaTe862n9SlZTrP+6PVUWLBYOr98= github.com/nspcc-dev/go-ordered-json v0.0.0-20210915112629-e1b6cce73d02/go.mod h1:79bEUDEviBHJMFV6Iq6in57FEOCMcRhfQnfaf0ETA5U= github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 h1:n4ZaFCKt1pQJd7PXoMJabZWK9ejjbLOVrkl/lOUmshg= github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22/go.mod h1:79bEUDEviBHJMFV6Iq6in57FEOCMcRhfQnfaf0ETA5U= @@ -267,8 +267,9 @@ github.com/nspcc-dev/neofs-api-go/v2 v2.11.1 h1:SVqc523pZsSaS9vnPS1mm3VV6b6xY0gv github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= -github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM= github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= +github.com/nspcc-dev/neofs-crypto v0.4.0 h1:5LlrUAM5O0k1+sH/sktBtrgfWtq1pgpDs09fZo+KYi4= +github.com/nspcc-dev/neofs-crypto v0.4.0/go.mod h1:6XJ8kbXgOfevbI2WMruOtI+qUJXNwSGM/E9eClXxPHs= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659 h1:rpMCoRa7expLc9gMiOP724gz6YSykZzmMALR/CmiwnU= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40= diff --git a/pkg/consensus/crypto.go b/pkg/consensus/crypto.go index 0c6cc69b8..702930f10 100644 --- a/pkg/consensus/crypto.go +++ b/pkg/consensus/crypto.go @@ -13,17 +13,6 @@ type privateKey struct { *keys.PrivateKey } -// MarshalBinary implements the encoding.BinaryMarshaler interface. -func (p privateKey) MarshalBinary() (data []byte, err error) { - return p.PrivateKey.Bytes(), nil -} - -// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. -func (p *privateKey) UnmarshalBinary(data []byte) (err error) { - p.PrivateKey, err = keys.NewPrivateKeyFromBytes(data) - return -} - // Sign implements the dbft's crypto.PrivateKey interface. func (p *privateKey) Sign(data []byte) ([]byte, error) { return p.PrivateKey.Sign(data), nil diff --git a/pkg/consensus/crypto_test.go b/pkg/consensus/crypto_test.go index 2f6bd10ac..f21fe5df9 100644 --- a/pkg/consensus/crypto_test.go +++ b/pkg/consensus/crypto_test.go @@ -12,19 +12,12 @@ func TestCrypt(t *testing.T) { require.NoError(t, err) priv := privateKey{key} - data, err := priv.MarshalBinary() - require.NoError(t, err) key1, err := keys.NewPrivateKey() require.NoError(t, err) - priv1 := privateKey{key1} - require.NotEqual(t, priv, priv1) - require.NoError(t, priv1.UnmarshalBinary(data)) - require.Equal(t, priv, priv1) - pub := publicKey{key.PublicKey()} - data, err = pub.MarshalBinary() + data, err := pub.MarshalBinary() require.NoError(t, err) pub1 := publicKey{key1.PublicKey()}