Beispiel #1
0
    def VerifyHandshake(self, data):
        authVersion = P2P.Version.V1
        ret = None
        version1 = False
        version2 = False

        if len(data) == 48:
            authVersion = P2P.Version.V1
            version1 = True
        elif len(data) == 16:
            authVersion = P2P.Version.V2
            version2 = True
        else:
            return None

        if authVersion != self.Version:
            return None

        incomingHandshake = P2PMessage.P2PDCHandshakeMessage(self.Version)
        incomingHandshake.ParseBytes(data)

        incomingGuid = incomingHandshake.Guid
        if version1 and ((incomingHandshake.VHeader.Flags & P2P.Flags.DCHS) !=
                         P2P.Flags.DCHS):
            return None

        compareGuid = incomingGuid
        if self.needHash:
            compareGuid = MSNU.HashNonce(compareGuid)

        if self.Nonce == compareGuid or not self.StrictNonce:
            if self.Nonce != compareGuid:
                log.warning("nonces don't match! continuing anyway.")

            ret = P2PMessage.P2PDCHandshakeMessage(self.Version)
            ret.ParseBytes(data)
            ret.Guid = compareGuid
            ret.Header.Identifier = 0
            return ret

        return None
Beispiel #2
0
    def OnConnected(self):
        if (not self.IsListener) and self.DCState == DCState.Closed:
            log.info(
                "Connected! Changing state to Foo, sending Foo, changing state to Handshake, sending handshake, changing state to HandshakeReply"
            )
            self.DCState = DCState.Foo
            self.SendSocketData(self.dcSocket, '\x04\0\0\0foo\0')

            self.DCState = DCState.Handshake
            hm = P2PMessage.P2PDCHandshakeMessage(self.Version)
            hm.Guid = self.Reply
            log.info("Sending handshake reply message: %r", hm)

            if self.Version == P2P.Version.V1:
                hm.Header.Identifier = self.startupSession.NextLocalIdentifier(
                    0)

            self.SendSocketData(self.dcSocket, hm.GetBytes())
            self.DCState = DCState.HandshakeReply