-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multikey peer authentication sender integration #4394
Merged
sstanculeanu
merged 13 commits into
feat/multisigner
from
integrate_peerauthentication_sender
Aug 31, 2022
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2d84dca
integrated multikey peer authentication
sstanculeanu 0802272
fixed tests
sstanculeanu 1e51c1a
Merge branch 'feat/multisigner' into integrate_peerauthentication_sender
sstanculeanu 56e4148
fixed build
sstanculeanu 1541f0b
Merge branch 'feat/multisigner' into integrate_peerauthentication_sender
sstanculeanu 8c36f42
fixes after review
sstanculeanu 8b91a00
fix after review
sstanculeanu 7823d6d
renamed xxxWithSk to xxxWithPrivateKey
sstanculeanu 704702e
renamed xxxWithPrivateKey/xxxWithSk to xxxUsingPrivateKey
sstanculeanu 60fd880
added multikeyHeartbeatSender + extracted common functionality
sstanculeanu 037596c
fix after rebase
sstanculeanu ef6f76a
Revert "fix after rebase"
sstanculeanu 495176b
Revert "added multikeyHeartbeatSender + extracted common functionality"
sstanculeanu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,10 @@ import ( | |
// P2PMessenger defines a subset of the p2p.Messenger interface | ||
type P2PMessenger interface { | ||
Broadcast(topic string, buff []byte) | ||
BroadcastWithSk(topic string, buff []byte, pid core.PeerID, skBytes []byte) | ||
ID() core.PeerID | ||
Sign(payload []byte) ([]byte, error) | ||
SignWithPrivateKey(skBytes []byte, payload []byte) ([]byte, error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also follow the naming convention above (either abbreviation of secret key, or private key) |
||
IsInterfaceNil() bool | ||
} | ||
|
||
|
@@ -120,3 +122,22 @@ type NodesCoordinator interface { | |
GetValidatorWithPublicKey(publicKey []byte) (validator nodesCoordinator.Validator, shardId uint32, err error) | ||
IsInterfaceNil() bool | ||
} | ||
|
||
// KeysHolder defines the operations of an entity that holds virtual identities for a node | ||
type KeysHolder interface { | ||
AddVirtualPeer(privateKeyBytes []byte) error | ||
GetPrivateKey(pkBytes []byte) (crypto.PrivateKey, error) | ||
GetP2PIdentity(pkBytes []byte) ([]byte, core.PeerID, error) | ||
GetMachineID(pkBytes []byte) (string, error) | ||
IncrementRoundsWithoutReceivedMessages(pkBytes []byte) error | ||
ResetRoundsWithoutReceivedMessages(pkBytes []byte) error | ||
GetManagedKeysByCurrentNode() map[string]crypto.PrivateKey | ||
IsKeyManagedByCurrentNode(pkBytes []byte) bool | ||
IsKeyRegistered(pkBytes []byte) bool | ||
IsPidManagedByCurrentNode(pid core.PeerID) bool | ||
IsKeyValidator(pkBytes []byte) bool | ||
SetValidatorState(pkBytes []byte, state bool) | ||
GetNextPeerAuthenticationTime(pkBytes []byte) (time.Time, error) | ||
SetNextPeerAuthenticationTime(pkBytes []byte, nextTime time.Time) | ||
IsInterfaceNil() bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package sender | ||
|
||
import ( | ||
"bytes" | ||
"time" | ||
|
||
"github.com/ElrondNetwork/elrond-go-core/data/batch" | ||
crypto "github.com/ElrondNetwork/elrond-go-crypto" | ||
"github.com/ElrondNetwork/elrond-go/heartbeat" | ||
) | ||
|
||
type commonPeerAuthenticationSender struct { | ||
baseSender | ||
nodesCoordinator heartbeat.NodesCoordinator | ||
peerSignatureHandler crypto.PeerSignatureHandler | ||
hardforkTrigger heartbeat.HardforkTrigger | ||
hardforkTriggerPubKey []byte | ||
} | ||
|
||
func (cpas *commonPeerAuthenticationSender) generateMessageBytes( | ||
pkBytes []byte, | ||
privateKey crypto.PrivateKey, | ||
p2pSkBytes []byte, | ||
pidBytes []byte, | ||
) ([]byte, bool, error) { | ||
msg := &heartbeat.PeerAuthentication{ | ||
Pid: pidBytes, | ||
Pubkey: pkBytes, | ||
} | ||
|
||
hardforkPayload, isTriggered := cpas.getHardforkPayload() | ||
payload := &heartbeat.Payload{ | ||
Timestamp: time.Now().Unix(), | ||
HardforkMessage: string(hardforkPayload), | ||
} | ||
payloadBytes, err := cpas.marshaller.Marshal(payload) | ||
if err != nil { | ||
return nil, isTriggered, err | ||
} | ||
msg.Payload = payloadBytes | ||
|
||
if p2pSkBytes != nil { | ||
msg.PayloadSignature, err = cpas.messenger.SignWithPrivateKey(p2pSkBytes, payloadBytes) | ||
if err != nil { | ||
return nil, isTriggered, err | ||
} | ||
} else { | ||
msg.PayloadSignature, err = cpas.messenger.Sign(payloadBytes) | ||
if err != nil { | ||
return nil, isTriggered, err | ||
} | ||
} | ||
|
||
msg.Signature, err = cpas.peerSignatureHandler.GetPeerSignature(privateKey, msg.Pid) | ||
if err != nil { | ||
return nil, isTriggered, err | ||
} | ||
|
||
msgBytes, err := cpas.marshaller.Marshal(msg) | ||
if err != nil { | ||
return nil, isTriggered, err | ||
} | ||
|
||
b := &batch.Batch{ | ||
Data: make([][]byte, 1), | ||
} | ||
b.Data[0] = msgBytes | ||
data, err := cpas.marshaller.Marshal(b) | ||
if err != nil { | ||
return nil, isTriggered, err | ||
} | ||
|
||
return data, isTriggered, nil | ||
} | ||
|
||
func (cpas *commonPeerAuthenticationSender) isValidator(pkBytes []byte) bool { | ||
_, _, err := cpas.nodesCoordinator.GetValidatorWithPublicKey(pkBytes) | ||
return err == nil | ||
} | ||
|
||
func (cpas *commonPeerAuthenticationSender) isHardforkSource(pkBytes []byte) bool { | ||
return bytes.Equal(pkBytes, cpas.hardforkTriggerPubKey) | ||
} | ||
|
||
func (cpas *commonPeerAuthenticationSender) getHardforkPayload() ([]byte, bool) { | ||
payload := make([]byte, 0) | ||
_, isTriggered := cpas.hardforkTrigger.RecordedTriggerMessage() | ||
if isTriggered { | ||
payload = cpas.hardforkTrigger.CreateData() | ||
} | ||
|
||
return payload, isTriggered | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we raname this into
BroadcastUsingSk
(orBroadcastSigningWithSk
)? I know that the naming convention follows libp2p'sPublishWithSk
but I find it very misleading, I really thought we were sending the sk over the wire. (SendableData
having an SK member doesn't help either :)) @iulianpascalau thoughts?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, let's rename to
BroadcastWithPrivateKey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushed