Exemple #1
0
    def receivedUpstream(self, data):
        """
        This is the callback method which is called by the framework when bytes have been received on the upstream socket.
        In the obfs3 protocol, the upstream handshake is read, and then the protocol is switched to STREAM mode, at which point all bytes received from upstream are encrypted and sent downstream.
        """

        if self.state == HANDSHAKE:
            self.epub = self.read(self.upstreamConnection, self.epub,
                                  HANDSHAKE_SIZE)
            if self.checkTransition(self.epub, HANDSHAKE_SIZE, STREAM):
                esession = makeEphemeralSession(self.ekeypair, self.epub)
                self.coder = AESCoder(esession)

                data = self.downstreamConnection.read_some()
                if data:
                    self.upstreamConnection.write(self.coder.encode(data))

                data = self.upstreamConnection.read_some()
                if data:
                    self.downstreamConnection.write(self.coder.decode(data))
        else:
            data = self.upstreamConnection.read_some()
            if data:
                self.downstreamConnection.write(self.coder.decode(data))
Exemple #2
0
def e(k, s):
    """ E(k,s) is the AES-CTR-128 encryption of s using K as key. """

    cipher = AESCoder(k)
    return cipher.encode(s)
Exemple #3
0
def d(k, s):
    """ D(k, s) is the AES-CTR-128 decryption of s using K as key. """

    cipher = AESCoder(k)
    return cipher.decode(s)
Exemple #4
0
    def initCipher(self, iv, key):
        """ initCipher initializes the AES cipher using the given key and IV. """

        coder = AESCoder(key)
        coder.encode(iv)
        return coder