mirror of https://github.com/vacp2p/dasy.git
enhancement/signature-verification (#6)
This commit is contained in:
parent
17145c3dd5
commit
93625382b6
|
@ -3,8 +3,6 @@ package client
|
|||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"log"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
|
@ -99,6 +97,15 @@ func (c *Client) onReceive(message mvdsproto.Message) {
|
|||
return
|
||||
}
|
||||
|
||||
pubkey, err := crypto.SigToPub(msg.ID(), msg.Signature)
|
||||
if err != nil {
|
||||
log.Printf("error while recovering pubkey: %s", err.Error())
|
||||
// @todo
|
||||
return
|
||||
}
|
||||
|
||||
// @todo probably store the sender somewhere?
|
||||
|
||||
// @todo pump messages to subscriber channels
|
||||
|
||||
if len(msg.PreviousMessage) == 0 {
|
||||
|
@ -124,12 +131,7 @@ func (c *Client) handlePreviousMessage(group state.GroupID, previousMessage stat
|
|||
|
||||
// sign signs generates a signature of the message and adds it to the message.
|
||||
func (c *Client) sign(m *protobuf.Message) error {
|
||||
b := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(b, uint32(m.MessageType))
|
||||
b = append(b, m.Body...)
|
||||
b = append(b, m.PreviousMessage...)
|
||||
|
||||
hash := sha256.Sum256(b)
|
||||
hash := m.ID()
|
||||
|
||||
sig, err := crypto.Sign(hash[:], c.identity)
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package protobuf
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
func (m *Message) ID() []byte {
|
||||
b := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(b, uint32(m.MessageType))
|
||||
b = append(b, m.Body...)
|
||||
b = append(b, m.PreviousMessage...)
|
||||
|
||||
hash := sha256.Sum256(b)
|
||||
return hash[:]
|
||||
}
|
Loading…
Reference in New Issue