Exemple #1
0
    def get_coins(self, amount=5):
        packet = [constants.Header.SIGN]
        blinding_factors = list()

        for _ in range(int(amount)):
            msg = pick_random()
            blinding_factor = pick_random()
            key = RSA.importKey(constants.B.public_key)
            blind = b64encode(key.blind(msg, blinding_factor))
            packet.append(blind)
            blinding_factors.append((blinding_factor, msg))

        d = ClientCreator(reactor, BankClient).connectTCP(constants.B.external_ip, constants.B.port)
        d.addCallback(self._send_blinds, blinding_factors, packet)
        d.addErrback(self._error, "Bank")
Exemple #2
0
 def test_pick_random(self):
     for _ in range(10000):
         identifier = helpers.pick_random()
         self.assertEqual(len(identifier), 16, "Must be 16byte block")
         self.assertNotIn(" ", identifier)
         self.assertNotIn("\t", identifier)
         self.assertNotIn(constants.variable_delimiter, identifier)
Exemple #3
0
 def test_asym_encryption(self):
     identifier = helpers.pick_random()
     ciphertext = helpers.asym_encrypt(identifier, constants.P.public_key)
     s = helpers.serialize([0, ciphertext])
     [op, d] = helpers.deserialize(s)
     plaintext = helpers.asym_decrypt(d, constants.P.private_key)
     self.assertEqual(identifier, plaintext)
Exemple #4
0
    def update_providers(self, location="", retry=False):
        """ Update location of user and tell providers """
        if retry:
            sleep(2)

        if location != "":
            self.location = location
            self.io.sendLine("Your location: %s" % self.location)

        # create new pseudonym for location
        self.pseudonym = pick_random()
        self.seed = pick_random()
        self.paging_names = create_paging_names(self.seed, amount=100)
        d = ClientCreator(reactor, UserClientProtocol, self).connectTCP(constants.N.external_ip, constants.N.port)
        d.addCallback(self._update_location)
        if retry:
            d.addErrback(self._error, "network operator")
        else:
            d.addErrback(self.retry)
Exemple #5
0
 def init_call(self, callee, caller, pseudonym, connection):
     # check validity of caller
     if self.pseudonyms[caller] == pseudonym:
         cid = pick_random()
         try:
             assert len(callee) == constants.word_len
             assert len(caller) == constants.word_len
             pseudonym = self.pseudonyms[callee]
         except KeyError:
             print "Call for unknown user"
         except AssertionError:
             print "IDs have wrong length."
         else:
             self.calls[cid] = [callee, caller, connection]
             blob = encrypt([cid, caller], self.secrets[callee])
             self.L.init_call(pseudonym, blob)
             self.N.init_call(cid)
Exemple #6
0
 def test_serialization(self):
     packet = [constants.Header.INITCALL, helpers.pick_random(), helpers.pick_random()]
     line = helpers.serialize(packet)
     self.assertEqual(type(line), str)
     self.assertEqual(packet, helpers.deserialize(line))
Exemple #7
0
 def test_encryption(self):
     test_string = helpers.pick_random()
     ciphertext = helpers.encrypt(test_string, constants.user1_secret)
     plaintext = helpers.decrypt(ciphertext, constants.user1_secret)
     self.assertEqual(test_string, plaintext)
Exemple #8
0
 def create_dummy():
     ''' Create a dummy that looks like an actual paging message '''
     cid = pick_random()
     callee = pick_random()
     caller = pick_random()
     return [callee, b64encode(cid+caller)]  # + simulates encryption
 def test_store_cid(self):
     cid = pick_random()
     self.factory.store_cid(cid)
     self.assertEqual(self.factory.cids, [cid])
     self.factory.connect_call(cid, self.protocol)
     self.assertEqual(self.factory.cids, [])
        for follower in self.followers:
            for followees in users[follower].followees:
                self.connections.append(followees)
        self.count_connections()


if __name__ == '__main__':

    streamer_list = ['a', 'b', 'c']
    user_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o']
    
    users = {}

    # Generate streamer followers/followees
    for user in user_list:
        new_user = User(user, pick_random(user, user_list), pick_random(user, user_list))
        users[user] = new_user

    # Determine follower weight
    for user in users:
        users[user].follow_weight = (len(user_list) - len(users[user].followers)) / len(user_list)
        users[user].describe()

    # Calculate connections
    for user in streamer_list:
        users[user].find_connections(users)
        users[user].score_connections(users)

    print('----------------------')
    user = users['b']
    print(user.connections)