Esempio n. 1
0
def handshake(conn):
  ekeypair=createEphemeralKeypair()

  epub=yield conn.read(KEY_SIZE)
  esession=makeEphemeralSession(ekeypair, epub).bytes
  print('esssion: '+encode(esession))
  coder=lite_socket(esession.bytes)
  yield conn.write(ekeypair.public.bytes)

  yield Return(coder)
Esempio n. 2
0
def handshake(conn):
    ekeypair = createEphemeralKeypair()

    epub = yield conn.read(KEY_SIZE)
    esession = makeEphemeralSession(ekeypair, epub).bytes
    print('esssion: ' + encode(esession))
    coder = lite_socket(esession.bytes)
    yield conn.write(ekeypair.public.bytes)

    yield Return(coder)
Esempio n. 3
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 Dust 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 = lite_socket(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))
Esempio n. 4
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 Dust 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 = lite_socket(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))