Ejemplo n.º 1
0
    def encryptAndHMAC( self, crypter, HMACKey ):

        encrypted = crypter.encrypt(serialize.htons(self.totalLen) + \
                serialize.htons(self.payloadLen) + self.payload + \
                (self.totalLen - self.payloadLen) * '\0')

        hmac = mycrypto.MyHMAC_SHA256_128(HMACKey, encrypted)

        return hmac + encrypted
Ejemplo n.º 2
0
    def encryptAndHMAC(self, crypter, HMACKey):

        encrypted = crypter.encrypt(serialize.htons(self.totalLen) + \
                serialize.htons(self.payloadLen) + self.payload + \
                (self.totalLen - self.payloadLen) * '\0')

        hmac = mycrypto.MyHMAC_SHA256_128(HMACKey, encrypted)

        return hmac + encrypted
Ejemplo n.º 3
0
 def __str__(self):
     """Return string representation of the message."""
     totalLenStr = pack.htons(self.totalLen)
     payloadLenStr = pack.htons(self.payloadLen)
     flagsStr = chr(self.flags)
     headerStr = totalLenStr + payloadLenStr + flagsStr
     if isControl(self):
         opCodeStr = chr(self.opcode)
         argsLenStr = pack.htons(self.argsLen)
         headerStr += opCodeStr + argsLenStr
     paddingStr = self.generatePadding()
     payloadStr = self.args + self.payload + paddingStr
     return headerStr + payloadStr
Ejemplo n.º 4
0
 def __str__(self):
     """Return string representation of the message."""
     totalLenStr = pack.htons(self.totalLen)
     payloadLenStr = pack.htons(self.payloadLen)
     flagsStr = chr(self.flags)
     headerStr = totalLenStr + payloadLenStr + flagsStr
     if isControl(self):
         opCodeStr = chr(self.opcode)
         argsLenStr = pack.htons(self.argsLen)
         headerStr += opCodeStr + argsLenStr
     paddingStr = self.generatePadding()
     payloadStr = self.args + self.payload + paddingStr
     return headerStr + payloadStr
Ejemplo n.º 5
0
    def encryptAndHMAC( self, crypter, hmacKey ):
        """
        Encrypt and authenticate this protocol message.

        This protocol message is encrypted using `crypter' and authenticated
        using `hmacKey'.  Finally, the encrypted message prepended by a
        HMAC-SHA256-128 is returned and ready to be sent over the wire.
        """

        encrypted = crypter.encrypt(pack.htons(self.totalLen) +
                                    pack.htons(self.payloadLen) +
                                    chr(self.flags) + self.payload +
                                    (self.totalLen - self.payloadLen) * '\0')

        hmac = mycrypto.HMAC_SHA256_128(hmacKey, encrypted)

        return hmac + encrypted
Ejemplo n.º 6
0
    def encryptAndHMAC(self, crypter, hmacKey):
        """
        Encrypt and authenticate this protocol message.

        This protocol message is encrypted using `crypter' and authenticated
        using `hmacKey'.  Finally, the encrypted message prepended by a
        HMAC-SHA256-128 is returned and ready to be sent over the wire.
        """

        encrypted = crypter.encrypt(
            pack.htons(self.totalLen) + pack.htons(self.payloadLen) +
            chr(self.flags) + self.payload +
            (self.totalLen - self.payloadLen) * '\0')

        hmac = mycrypto.HMAC_SHA256_128(hmacKey, encrypted)

        return hmac + encrypted
Ejemplo n.º 7
0
    def _write_ext_orport_command(self, command, body):
        """
        Serialize 'command' and 'body' to an Extended ORPort command
        and send it to the Extended ORPort.

        Throws CouldNotWriteExtCommand
        """
        payload = ''

        if len(body) > 65535: # XXX split instead of quitting?
            log.warning("Obfsproxy was asked to send Extended ORPort command with more than "
                        "65535 bytes of body. This is not supported by the Extended ORPort "
                        "protocol. Please file a bug.")
            raise CouldNotWriteExtCommand("Too large body.")
        if command > 65535:
            raise CouldNotWriteExtCommand("Not supported command type.")

        payload += srlz.htons(command)
        payload += srlz.htons(len(body))
        payload += body # body might be absent (empty string)
        self.write(payload)