-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
[FAB-17675] Prevent gossip probe from registering as a connection #925
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,10 @@ const ( | |
DefSendBuffSize = 20 | ||
) | ||
|
||
var ( | ||
errProbe = errors.New("probe") | ||
) | ||
|
||
// SecurityAdvisor defines an external auxiliary object | ||
// that provides security and identity related capabilities | ||
type SecurityAdvisor interface { | ||
|
@@ -163,7 +167,7 @@ func (c *commImpl) createConnection(endpoint string, expectedPKIID common.PKIidT | |
|
||
ctx, cancel = context.WithCancel(context.Background()) | ||
if stream, err = cl.GossipStream(ctx); err == nil { | ||
connInfo, err = c.authenticateRemotePeer(stream, true) | ||
connInfo, err = c.authenticateRemotePeer(stream, true, false) | ||
if err == nil { | ||
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. Unrelated to this CR. Can be 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. This is by design. 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. I see. Got it. |
||
pkiID = connInfo.ID | ||
// PKIID is nil when we don't know the remote PKI id's | ||
|
@@ -305,7 +309,7 @@ func (c *commImpl) Handshake(remotePeer *RemotePeer) (api.PeerIdentityType, erro | |
if err != nil { | ||
return nil, err | ||
} | ||
connInfo, err := c.authenticateRemotePeer(stream, true) | ||
connInfo, err := c.authenticateRemotePeer(stream, true, true) | ||
if err != nil { | ||
c.logger.Warningf("Authentication failed: %v", err) | ||
return nil, err | ||
|
@@ -404,7 +408,7 @@ func extractRemoteAddress(stream stream) string { | |
return remoteAddress | ||
} | ||
|
||
func (c *commImpl) authenticateRemotePeer(stream stream, initiator bool) (*protoext.ConnectionInfo, error) { | ||
func (c *commImpl) authenticateRemotePeer(stream stream, initiator, isProbe bool) (*protoext.ConnectionInfo, error) { | ||
ctx := stream.Context() | ||
remoteAddress := extractRemoteAddress(stream) | ||
remoteCertHash := extractCertificateHashFromContext(ctx) | ||
|
@@ -431,7 +435,7 @@ func (c *commImpl) authenticateRemotePeer(stream stream, initiator bool) (*proto | |
return nil, fmt.Errorf("No TLS certificate") | ||
} | ||
|
||
cMsg, err = c.createConnectionMsg(c.PKIID, selfCertHash, c.peerIdentity, signer) | ||
cMsg, err = c.createConnectionMsg(c.PKIID, selfCertHash, c.peerIdentity, signer, isProbe) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -492,6 +496,10 @@ func (c *commImpl) authenticateRemotePeer(stream stream, initiator bool) (*proto | |
|
||
c.logger.Debug("Authenticated", remoteAddress) | ||
|
||
if receivedMsg.Probe { | ||
return connInfo, errProbe | ||
} | ||
|
||
return connInfo, nil | ||
} | ||
|
||
|
@@ -556,7 +564,13 @@ func (c *commImpl) GossipStream(stream proto.Gossip_GossipStreamServer) error { | |
if c.isStopping() { | ||
return fmt.Errorf("Shutting down") | ||
} | ||
connInfo, err := c.authenticateRemotePeer(stream, false) | ||
connInfo, err := c.authenticateRemotePeer(stream, false, false) | ||
|
||
if err == errProbe { | ||
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. It can be confusing to the code reader. Some questions might arise like why we are ignoring an error. If we are trying to not store info in the conn store for probs, can't the return value be an 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. No, 3 return values is ugly, and this is an un-exported function. Look at:
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. Thanks for the clarification. Agree that 3 return value is ugly. |
||
c.logger.Infof("Peer %s (%s) probed us", connInfo.ID, connInfo.Endpoint) | ||
return nil | ||
} | ||
|
||
if err != nil { | ||
c.logger.Errorf("Authentication failed: %v", err) | ||
return err | ||
|
@@ -618,7 +632,7 @@ func readWithTimeout(stream stream, timeout time.Duration, address string) (*pro | |
} | ||
} | ||
|
||
func (c *commImpl) createConnectionMsg(pkiID common.PKIidType, certHash []byte, cert api.PeerIdentityType, signer protoext.Signer) (*protoext.SignedGossipMessage, error) { | ||
func (c *commImpl) createConnectionMsg(pkiID common.PKIidType, certHash []byte, cert api.PeerIdentityType, signer protoext.Signer, isProbe bool) (*protoext.SignedGossipMessage, error) { | ||
m := &proto.GossipMessage{ | ||
Tag: proto.GossipMessage_EMPTY, | ||
Nonce: 0, | ||
|
@@ -627,6 +641,7 @@ func (c *commImpl) createConnectionMsg(pkiID common.PKIidType, certHash []byte, | |
TlsCertHash: certHash, | ||
Identity: cert, | ||
PkiId: pkiID, | ||
Probe: isProbe, | ||
}, | ||
}, | ||
} | ||
|
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't we have a more descriptive error message for better readability?
Correct me if I have misunderstood: this error would be returned when the peer tries to authenticate a stream which is not a probe (by passing an appropriate flag) but it ends up being a probe. As a result, we don't store info in the connection store. If my understanding is correct, I am not sure whether it should be an error. Maybe a bool can be used instead as I mentioned in the other comment.
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.
You misunderstood. This error just means that the remote peer probed us, so there is no point in doing anything with the returned first value.
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.
Okay. That's what I meant may be my wordings didn't convey that. That's why I suggested
isProbe bool
later in the comment.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.
I see a function that returns an object and an error in the following way:
If the error is nil, use the first return value.
Else, use the other return value.
This perfectly fits my needs here.