def test1(self): data = [('EB33F77EE73D4053', 'TIDE ITCH SLOW REIN RULE MOT'), ('CCAC2AED591056BE4F90FD441C534766', 'RASH BUSH MILK LOOK BAD BRIM AVID GAFF BAIT ROT POD LOVE'), ('EFF81F9BFBC65350920CDD7416DE8009', 'TROD MUTE TAIL WARM CHAR KONG HAAG CITY BORE O TEAL AWL')] for key_hex, words in data: key_bin = binascii.a2b_hex(key_hex) w2 = key_to_english(key_bin) self.assertEqual(w2, words) k2 = english_to_key(words) self.assertEqual(k2, key_bin)
def fingerprint(request, api, account_info, config, username): brand_identifier = api.info()['brand_identifier'] layers = serial.loads(server.get_escrow_layers(brand_identifier)) # Generate fingerprint h = sha256() for key_id, key in layers: s = '{0}{1}'.format(key_id, key.publickey().exportKey('DER')) h.update(s) fingerprint = enumerate(key_to_english(h.digest()).split(' ')) fingerprint = ' '.join([word for x, word in fingerprint if x % 2 == 0]) return render_to_response( 'fingerprint.html', dict( user=request.user, username=username, account_info=account_info, fingerprint=fingerprint, ), RequestContext(request))
def fingerprint(request, api, account_info, config, username): brand_identifier = api.info()['brand_identifier'] layers = serial.loads(server.get_escrow_layers(brand_identifier)) # Generate fingerprint h = sha256() for key_id, key in layers: s = '{0}{1}'.format(key_id, key.publickey().exportKey('DER')) h.update(s) fingerprint = enumerate(key_to_english(h.digest()).split(' ')) fingerprint = ' '.join([word for x, word in fingerprint \ if x % 2 == 0]) return render_to_response('fingerprint.html', dict( user=request.user, username=username, account_info=account_info, fingerprint=fingerprint, ), RequestContext(request))
def try_reconnecting(self): self.connect_to_server() # Send my public key. public_key_header = f"{len(str(self.public_key)):<{self.HEADER_LENGTH}}".encode( 'utf-8') self.server_socket.send(public_key_header + self.public_key.save_pkcs1(format='DER')) # Receive the server's public key. self.server_key = self.loop(key=True) aes_key_to_go = key_to_english(self.aes_key) username_password = self.encrypt_json_object( dictionary={ "login_register": "login", "username": self.login_username, "password": self.login_password, "aes_key": aes_key_to_go }) # We need to encode username to bytes, then count number of bytes and prepare header of fixed size, that we encode to bytes as well username_password_header = f"{len(username_password):<{self.HEADER_LENGTH}}".encode( 'utf-8') time.sleep(0.5) self.server_socket.send(username_password_header + username_password) # We don't need any information back. answer = self.decrypt_json_object(encrytped_json_object=self.loop()) self.server_aes_key = english_to_key(answer['aes_key']) color_code = "#00ff35" self.output.emit(self.textBrowser, '', '', '', True, self.server_socket, self.server_key, self.server_aes_key) downtime = self.downtime() print('Connection to the server has been restored, after {0}'.format( downtime)) self.textBrowser.append( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Ubuntu\'; font-size:11pt; font-weight:400; font-style:normal;\">\n" f"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; color:{color_code}; \">CLIENT: <font style=\" color:{color_code}; \">Connection to the server has been restored, after </font><font style=\" color:#FFFFFF; \">{downtime}</font></p>\n" )