Skip to content

Commit bc7f9d8

Browse files
committed
Gossip: Learn certificate at validation time
When an AliveMessage enters the routine that handles all messages, It is first validated and only then the certificate may be learned from the alive message, but then it is validated again when it is learned because the identity store validates the cert when it attempts to store it. This is redundant, we may simply learn the cert at validation time as part of storing the cert (gossip/identity/identityMapper:Put also validates a cert, and even checks if the calculated PKI-ID matches the claimed PKI-ID) Change-Id: I90900818aef3b51c413384df989f4e63073401f6 Signed-off-by: Yacov Manevich <[email protected]>
1 parent ed7ed80 commit bc7f9d8

File tree

1 file changed

+1
-19
lines changed

1 file changed

+1
-19
lines changed

gossip/gossip/gossip_impl.go

+1-19
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,6 @@ func (g *gossipServiceImpl) handleMessage(m proto.ReceivedMessage) {
285285
}
286286

287287
if msg.IsAliveMsg() {
288-
am := msg.GetAliveMsg()
289-
storedIdentity, _ := g.idMapper.Get(common.PKIidType(am.Membership.PkiId))
290-
// If peer's certificate is included inside AliveMessage, and we don't have a mapping between
291-
// its PKI-ID and certificate, create a mapping for it now.
292-
if identity := am.Identity; identity != nil && storedIdentity == nil {
293-
err := g.idMapper.Put(common.PKIidType(am.Membership.PkiId), api.PeerIdentityType(identity))
294-
if err != nil {
295-
g.logger.Warning("Failed adding identity of", am, "into identity store:", err)
296-
return
297-
}
298-
g.logger.Info("Learned identity of", am.Membership.PkiId)
299-
}
300-
301288
added := g.aliveMsgStore.Add(msg)
302289
if !added {
303290
return
@@ -771,13 +758,8 @@ func (sa *discoverySecurityAdapter) ValidateAliveMsg(m *proto.SignedGossipMessag
771758
// If identity is included inside AliveMessage
772759
if am.Identity != nil {
773760
identity = api.PeerIdentityType(am.Identity)
774-
calculatedPKIID := sa.mcs.GetPKIidOfCert(identity)
775761
claimedPKIID := am.Membership.PkiId
776-
if !bytes.Equal(calculatedPKIID, claimedPKIID) {
777-
sa.logger.Warning("Calculated pkiID doesn't match identity:", calculatedPKIID, claimedPKIID)
778-
return false
779-
}
780-
err := sa.mcs.ValidateIdentity(api.PeerIdentityType(identity))
762+
err := sa.idMapper.Put(claimedPKIID, identity)
781763
if err != nil {
782764
sa.logger.Warning("Failed validating identity of", am, "reason:", err)
783765
return false

0 commit comments

Comments
 (0)