def hello(request): client_hello = request.decrypted_json try: client_key = PublicKey.objects.get( fingerprint=client_hello["client_key_fingerprint"]) except PublicKey.DoesNotExist: return HttpResponseForbidden("Unknown client: %s" % client_hello["client_key_fingerprint"]) response = { "client_guid": client_hello["client_guid"], "server_guid": random_guid(), "expires": None, "server_key_fingerprint": SERVER_KEY_FINGERPRINT } started_session = PQAuthSession(server_guid=response["server_guid"], client_guid=response["client_guid"], user=client_key.user) started_session.save() encrypted_response = rsa_encrypt(json.dumps(response), client_key.public_key) return HttpResponse(encrypted_response, mimetype="application/pqauth-encrypted")
def hello(request): client_hello = request.decrypted_json try: client_key = PublicKey.objects.get(fingerprint=client_hello["client_key_fingerprint"]) except PublicKey.DoesNotExist: return HttpResponseForbidden("Unknown client: %s" % client_hello["client_key_fingerprint"]) response = { "client_guid": client_hello["client_guid"], "server_guid": random_guid(), "expires": None, "server_key_fingerprint": SERVER_KEY_FINGERPRINT, } started_session = PQAuthSession( server_guid=response["server_guid"], client_guid=response["client_guid"], user=client_key.user ) started_session.save() encrypted_response = rsa_encrypt(json.dumps(response), client_key.public_key) return HttpResponse(encrypted_response, mimetype="application/pqauth-encrypted")
def encrypt_for_server(self, message): as_json = json.dumps(message) return crypto.rsa_encrypt(as_json, self.server_key)
def encrypt(message, public_key): as_json = json.dumps(message) return rsa_encrypt(as_json, public_key)