Esempio n. 1
0
    def validate(self, data):
        public_key_provider = get_provider()
        public_key_pem = public_key_provider.get_public_key(self.keybase_username)
        signed_message = data['signed_message']

        with gpg_keyring(public_key_pem) as gpg:
            verification = gpg.verify(signed_message)
            validate_signature(verification)

            message = gpg.decrypt(signed_message).data

        try:
            peer_review_data = json.loads(message)
        except ValueError:
            raise serializers.ValidationError(self.error_messages['json_invalid'])

        validate_peer_review(peer_review_data)

        validated_data = {
            'data': json.dumps({
                'policy_application': peer_review_data,
                'signed_message': signed_message,
                'public_key': public_key_pem,
                'public_key_provider': public_key_provider.name,
                'public_key_identity': {
                    'username': self.keybase_username,
                }
            }, sort_keys=True),
            'result': peer_review_data['result'],
        }

        return validated_data