def test_location_announcement(self): self.pager.startProtocol() self.pager.location_announcement() self.assertEqual(len(self.transport.written), 2) packet_serialized, addr = self.transport.written[0] packet = deserialize(packet_serialized) self.assertEqual(packet[0], constants.Header.LOCATIONANNOUNCEMENT)
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)
def lineReceived(self, line): print "Received %s from Network Operator" % line packet = deserialize(line) if packet[0] == constants.Header.LOCATIONUPDATE: plaintext = asym_decrypt(packet[1], constants.L.private_key) self.factory.server.store(plaintext[0], plaintext[1], plaintext[2]) # pseudo, loc, seed else: print "Unknown operator %d" % packet[0]
def lineReceived(self, line): """ will only receive lines, when connected to P or N for outgoing call """ data = deserialize(line) if data[0] == constants.Header.ANSWERCALL: cid = data[1] self.p_deferred.callback(cid) elif data[0] == constants.Header.RAWNOW: self.n_deferred.callback("_") elif data[0] == constants.Header.ERROR: self.n_deferred.errback("Couldn't verify coin.")
def lineReceived(self, line): print "received " + line packet = deserialize(line) if packet[0] == constants.Header.ANSWERCALL: cid = packet[1] self.factory.P.spawn_proxy(cid) elif packet[0] == constants.Header.PSEUDONYMUPDATE: plaintext = asym_decrypt(packet[1], constants.P.private_key) self.factory.P.pseudonym_update(plaintext[0], plaintext[1], plaintext[2]) # pseudonym, identifier, secret else: print "Type %d unknown" % packet[0]
def lineReceived(self, line): data = deserialize(line) if data[0] == constants.Header.SIGN: # sign my blinds blinds = data[1:] print("Signing %d blinds" % len(blinds)) answer = [constants.Header.SIGN] for blind in blinds: blindsig = self.key.sign(b64decode(blind), "bla")[0] answer.append(blindsig) self.sendLine(serialize(answer))
def lineReceived(self, line): print "Received %s from Pseudonym Provider" % line packet = deserialize(line) if packet[0] == constants.Header.REGISTER: if packet[1] == "P": # register pseudonym provider self.factory.pseudonym_provider = self print "Registered Pseudonym Provider" elif packet[0] == constants.Header.INITCALL: self.handle_call(packet[1], packet[2]) else: print "Wrong request_type %d" % packet[0]
def lineReceived(self, line): data = deserialize(line) if data[0] == constants.Header.SIGN: print "Receiving blind signatures" answers = data[1:] for i in range(len(answers)): blindsig = long(answers[i]) blinding_factor, msg = self.blinding_factors[i] sig = self.bank_key.unblind(blindsig, blinding_factor) if self.bank_key.verify(msg, (sig,)): self.user.coins.append((msg, (sig,))) else: print "Couldn't verify signature for %s" % msg print "You now have %d coins." % len(self.user.coins)
def lineReceived(self, line): print "received " + str(line) data = deserialize(line) op = data[0] if op == constants.Header.INITCALL: # if len(data) == 3: # callee = data[1] # caller = data[2] # el if len(data) == 2: callee, caller, pseudonym, msg = asym_decrypt(data[1], constants.P.private_key) else: print "Wrong amount of arguments" print data self.factory.P.init_call(callee, caller, pseudonym, self) elif op == constants.Header.MSG: callee, caller, msg = asym_decrypt(data[1], constants.P.private_key) self.factory.P.send_msg(callee, caller, msg) else: print "Type %d unknown" % op
def lineReceived(self, line): # addr = self.transport.getPeer() # print "received: " + line + " from %s:%d" % (addr.host, addr.port) inputs = deserialize(line) if inputs[0] == constants.Header.REGISTER: self.register(inputs[1], self) return elif inputs[0] == constants.Header.PAGING: self.build_paging(inputs) return if self.factory.fully_connected: if inputs[0] == constants.Header.STORE_CID: self.factory.store_cid(inputs[1]) return elif inputs[0] == constants.Header.LOCATIONUPDATE: # XXX check location validity? # forward to L self.factory.location_provider.sendLine(line) return elif inputs[0] == constants.Header.ANSWERCALL: cid = inputs[1] self.factory.connect_call(cid, self) return elif inputs[0] == constants.Header.INITCALL: cid = inputs[1] coin = (inputs[2], (long(inputs[3]),)) self.forward(cid, coin) return elif inputs[0] == constants.Header.PSEUDONYMUPDATE: # forward to P self.factory.pseudonym_provider.sendLine(line) return else: print "Received unrecognized header %d" % inputs[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))
for b in chunk: yield b else: break s = socket(AF_INET, SOCK_STREAM) #s.bind(('192.168.50.4', 0)) pseudonym_provider = (constants.P.ip, constants.P.port) s.connect(pseudonym_provider) data = [constants.Header.INITCALL, constants.user1_id, 1111111111111111] # callee , caller s.send(serialize(data) + "\r\n") print "sending %s" % serialize(data) answer = s.recv(1024) packet = deserialize(answer) print packet if packet[0] == constants.Header.ANSWERCALL: cid = packet[1] # connect to network operator with CID and send raw data network = socket(AF_INET, SOCK_STREAM) network.connect((constants.N.ip, constants.N.port)) announcement = [constants.Header.INITCALL, cid] network.send(serialize(announcement) + "\r\n") answer = network.recv(1024) packet = deserialize(answer) if packet[0] == constants.Header.RAWNOW: print "Sending" for b in bytes_from_file('hints.txt'):