def genAckPayload(streamNumber=1, stealthLevel=0):
    """Generate and return payload obj."""
    if (stealthLevel == 2):  # Generate privacy-enhanced payload
        # Generate a dummy privkey and derive the pubkey
        dummyPubKeyHex = highlevelcrypto.privToPub(
            hexlify(helper_random.randomBytes(32)))
        # Generate a dummy message of random length
        # (the smallest possible standard-formatted message is 234 bytes)
        dummyMessage = helper_random.randomBytes(
            helper_random.randomrandrange(234, 801))
        # Encrypt the message using standard BM encryption (ECIES)
        ackdata = highlevelcrypto.encrypt(dummyMessage, dummyPubKeyHex)
        acktype = 2  # message
        version = 1

    elif (stealthLevel == 1):  # Basic privacy payload (random getpubkey)
        ackdata = helper_random.randomBytes(32)
        acktype = 0  # getpubkey
        version = 4

    else:  # Minimum viable payload (non stealth)
        ackdata = helper_random.randomBytes(32)
        acktype = 2  # message
        version = 1

    ackobject = pack(
        '>I',
        acktype) + encodeVarint(version) + encodeVarint(streamNumber) + ackdata

    return ackobject
예제 #2
0
def genAckPayload(streamNumber=1, stealthLevel=0):
    if (stealthLevel==2):      # Generate privacy-enhanced payload
        # Generate a dummy privkey and derive the pubkey
        dummyPubKeyHex = highlevelcrypto.privToPub(hexlify(helper_random.randomBytes(32)))
        # Generate a dummy message of random length
        # (the smallest possible standard-formatted message is 234 bytes)
        dummyMessage = helper_random.randomBytes(random.randint(234, 800))
        # Encrypt the message using standard BM encryption (ECIES)
        ackdata = highlevelcrypto.encrypt(dummyMessage, dummyPubKeyHex)
        acktype = 2  # message
        version = 1

    elif (stealthLevel==1):    # Basic privacy payload (random getpubkey)
        ackdata = helper_random.randomBytes(32)
        acktype = 0  # getpubkey
        version = 4

    else:            # Minimum viable payload (non stealth)
        ackdata = helper_random.randomBytes(32)
        acktype = 2  # message
        version = 1

    ackobject = pack('>I', acktype) + encodeVarint(version) + encodeVarint(streamNumber) + ackdata

    return ackobject
예제 #3
0
 def state_proxy_handshake_done(self):
     Socks4aConnection.state_proxy_handshake_done(self)
     self.nodeid = randomBytes(8)
     self.append_write_buf(protocol.assembleVersionMessage(self.destination.host, self.destination.port, \
             network.connectionpool.BMConnectionPool().streams, False, nodeid=self.nodeid))
     self.set_state("bm_header", expectBytes=protocol.Header.size)
     return True
예제 #4
0
 def state_proxy_handshake_done(self):
     Socks4aConnection.state_proxy_handshake_done(self)
     self.nodeid = randomBytes(8)
     self.append_write_buf(protocol.assembleVersionMessage(self.destination.host, self.destination.port, \
             network.connectionpool.BMConnectionPool().streams, False, nodeid=self.nodeid))
     self.set_state("bm_header", expectBytes=protocol.Header.size)
     return True
예제 #5
0
def genAckPayload(streamNumber=1, stealthLevel=0):
    """
    Generate and return payload obj.

    This function generates payload objects for message acknowledgements
    Several stealth levels are available depending on the privacy needs;
    a higher level means better stealth, but also higher cost (size+POW)

       - level 0: a random 32-byte sequence with a message header appended
       - level 1: a getpubkey request for a (random) dummy key hash
       - level 2: a standard message, encrypted to a random pubkey
    """
    if stealthLevel == 2:  # Generate privacy-enhanced payload
        # Generate a dummy privkey and derive the pubkey
        dummyPubKeyHex = highlevelcrypto.privToPub(
            hexlify(helper_random.randomBytes(32)))
        # Generate a dummy message of random length
        # (the smallest possible standard-formatted message is 234 bytes)
        dummyMessage = helper_random.randomBytes(
            helper_random.randomrandrange(234, 801))
        # Encrypt the message using standard BM encryption (ECIES)
        ackdata = highlevelcrypto.encrypt(dummyMessage, dummyPubKeyHex)
        acktype = 2  # message
        version = 1

    elif stealthLevel == 1:  # Basic privacy payload (random getpubkey)
        ackdata = helper_random.randomBytes(32)
        acktype = 0  # getpubkey
        version = 4

    else:  # Minimum viable payload (non stealth)
        ackdata = helper_random.randomBytes(32)
        acktype = 2  # message
        version = 1

    ackobject = pack(
        '>I',
        acktype) + encodeVarint(version) + encodeVarint(streamNumber) + ackdata

    return ackobject
예제 #6
0
 def handle_connect(self):
     try:
         AdvancedDispatcher.handle_connect(self)
     except socket.error as e:
         if e.errno in asyncore._DISCONNECTED:
             logger.debug("%s:%i: Connection failed: %s" % (self.destination.host, self.destination.port, str(e)))
             return
     self.nodeid = randomBytes(8)
     self.append_write_buf(protocol.assembleVersionMessage(self.destination.host, self.destination.port, \
             network.connectionpool.BMConnectionPool().streams, False, nodeid=self.nodeid))
     #print "%s:%i: Sending version"  % (self.destination.host, self.destination.port)
     self.connectedAt = time.time()
     receiveDataQueue.put(self.destination)
예제 #7
0
 def state_proxy_handshake_done(self):
     """State when SOCKS4a connection succeeds, we need to send a Bitmessage handshake to peer."""
     Socks4aConnection.state_proxy_handshake_done(self)
     self.nodeid = randomBytes(8)
     self.append_write_buf(
         protocol.assembleVersionMessage(
             self.destination.host,
             self.destination.port,
             network.connectionpool.BMConnectionPool().streams,
             False,
             nodeid=self.nodeid))
     self.set_state("bm_header", expectBytes=protocol.Header.size)
     return True
예제 #8
0
 def handle_connect(self):
     try:
         AdvancedDispatcher.handle_connect(self)
     except socket.error as e:
         if e.errno in asyncore._DISCONNECTED:
             logger.debug("%s:%i: Connection failed: %s" % (self.destination.host, self.destination.port, str(e)))
             return
     self.nodeid = randomBytes(8)
     self.append_write_buf(protocol.assembleVersionMessage(self.destination.host, self.destination.port, \
             network.connectionpool.BMConnectionPool().streams, False, nodeid=self.nodeid))
     #print "%s:%i: Sending version"  % (self.destination.host, self.destination.port)
     self.connectedAt = time.time()
     receiveDataQueue.put(self.destination)
예제 #9
0
 def __init__(self, address=None, sock=None):
     BMProto.__init__(self, address=address, sock=sock)
     self.verackReceived = False
     self.verackSent = False
     self.streams = [0]
     self.fullyEstablished = False
     self.connectedAt = 0
     self.skipUntil = 0
     if address is None and sock is not None:
         self.destination = Peer(*sock.getpeername())
         self.isOutbound = False
         TLSDispatcher.__init__(self, sock, server_side=True)
         self.connectedAt = time.time()
         logger.debug(
             'Received connection from %s:%i',
             self.destination.host, self.destination.port)
         self.nodeid = randomBytes(8)
     elif address is not None and sock is not None:
         TLSDispatcher.__init__(self, sock, server_side=False)
         self.isOutbound = True
         logger.debug(
             'Outbound proxy connection to %s:%i',
             self.destination.host, self.destination.port)
     else:
         self.destination = address
         self.isOutbound = True
         self.create_socket(
             socket.AF_INET6 if ":" in address.host else socket.AF_INET,
             socket.SOCK_STREAM)
         self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         TLSDispatcher.__init__(self, sock, server_side=False)
         self.connect(self.destination)
         logger.debug(
             'Connecting to %s:%i',
             self.destination.host, self.destination.port)
     try:
         self.local = (
             protocol.checkIPAddress(
                 protocol.encodeHost(self.destination.host), True)
             and not protocol.checkSocksIP(self.destination.host)
         )
     except socket.error:
         # it's probably a hostname
         pass
     self.network_group = protocol.network_group(self.destination.host)
     ObjectTracker.__init__(self)  # pylint: disable=non-parent-init-called
     self.bm_proto_reset()
     self.set_state("bm_header", expectBytes=protocol.Header.size)
예제 #10
0
 def __init__(self, address=None, sock=None):
     BMProto.__init__(self, address=address, sock=sock)
     self.verackReceived = False
     self.verackSent = False
     self.streams = [0]
     self.fullyEstablished = False
     self.connectedAt = 0
     self.skipUntil = 0
     if address is None and sock is not None:
         self.destination = state.Peer(sock.getpeername()[0],
                                       sock.getpeername()[1])
         self.isOutbound = False
         TLSDispatcher.__init__(self, sock, server_side=True)
         self.connectedAt = time.time()
         logger.debug("Received connection from %s:%i",
                      self.destination.host, self.destination.port)
         self.nodeid = randomBytes(8)
     elif address is not None and sock is not None:
         TLSDispatcher.__init__(self, sock, server_side=False)
         self.isOutbound = True
         logger.debug("Outbound proxy connection to %s:%i",
                      self.destination.host, self.destination.port)
     else:
         self.destination = address
         self.isOutbound = True
         if ":" in address.host:
             self.create_socket(socket.AF_INET6, socket.SOCK_STREAM)
         else:
             self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
         self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         TLSDispatcher.__init__(self, sock, server_side=False)
         self.connect(self.destination)
         logger.debug("Connecting to %s:%i", self.destination.host,
                      self.destination.port)
     encodedAddr = protocol.encodeHost(self.destination.host)
     if protocol.checkIPAddress(
             encodedAddr,
             True) and not protocol.checkSocksIP(self.destination.host):
         self.local = True
     else:
         self.local = False
     #shared.connectedHostsList[self.destination] = 0
     ObjectTracker.__init__(self)
     UISignalQueue.put(('updateNetworkStatusTab', 'no data'))
     self.bm_proto_reset()
     self.set_state("bm_header", expectBytes=protocol.Header.size)
예제 #11
0
 def handle_connect(self):
     """Callback for TCP connection being established."""
     try:
         AdvancedDispatcher.handle_connect(self)
     except socket.error as e:
         # pylint: disable=protected-access
         if e.errno in asyncore._DISCONNECTED:
             logger.debug(
                 '%s:%i: Connection failed: %s',
                 self.destination.host, self.destination.port, e)
             return
     self.nodeid = randomBytes(8)
     self.append_write_buf(
         protocol.assembleVersionMessage(
             self.destination.host, self.destination.port,
             connectionpool.BMConnectionPool().streams,
             False, nodeid=self.nodeid))
     self.connectedAt = time.time()
     receiveDataQueue.put(self.destination)
예제 #12
0
 def __init__(self, address=None, sock=None):
     BMProto.__init__(self, address=address, sock=sock)
     self.verackReceived = False
     self.verackSent = False
     self.streams = [0]
     self.fullyEstablished = False
     self.connectedAt = 0
     self.skipUntil = 0
     if address is None and sock is not None:
         self.destination = state.Peer(sock.getpeername()[0], sock.getpeername()[1])
         self.isOutbound = False
         TLSDispatcher.__init__(self, sock, server_side=True)
         self.connectedAt = time.time()
         logger.debug("Received connection from %s:%i", self.destination.host, self.destination.port)
         self.nodeid = randomBytes(8)
     elif address is not None and sock is not None:
         TLSDispatcher.__init__(self, sock, server_side=False)
         self.isOutbound = True
         logger.debug("Outbound proxy connection to %s:%i", self.destination.host, self.destination.port)
     else:
         self.destination = address
         self.isOutbound = True
         if ":" in address.host:
             self.create_socket(socket.AF_INET6, socket.SOCK_STREAM)
         else:
             self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
         self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         TLSDispatcher.__init__(self, sock, server_side=False)
         self.connect(self.destination)
         logger.debug("Connecting to %s:%i", self.destination.host, self.destination.port)
     encodedAddr = protocol.encodeHost(self.destination.host)
     if protocol.checkIPAddress(encodedAddr, True) and not protocol.checkSocksIP(self.destination.host):
         self.local = True
     else:
         self.local = False
     #shared.connectedHostsList[self.destination] = 0
     ObjectTracker.__init__(self)
     self.bm_proto_reset()
     self.set_state("bm_header", expectBytes=protocol.Header.size)