From 863c405802ecb5c8cdc394c94b76b2a673864cb1 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 26 May 2020 13:23:45 +0300 Subject: [PATCH] Rename pubkey to loginPubkey because we'll soon have another pubkey. This breaks sharing because we no longer have a normal pubkey. This will be fixed in the next commit. --- .../migrations/0005_auto_20200526_1021.py | 18 ++++++++++++++++++ django_etesync/models.py | 2 +- django_etesync/serializers.py | 6 ++---- django_etesync/views.py | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 django_etesync/migrations/0005_auto_20200526_1021.py diff --git a/django_etesync/migrations/0005_auto_20200526_1021.py b/django_etesync/migrations/0005_auto_20200526_1021.py new file mode 100644 index 0000000..470556b --- /dev/null +++ b/django_etesync/migrations/0005_auto_20200526_1021.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.3 on 2020-05-26 10:21 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('django_etesync', '0004_collectioninvitation_version'), + ] + + operations = [ + migrations.RenameField( + model_name='userinfo', + old_name='pubkey', + new_name='loginPubkey', + ), + ] diff --git a/django_etesync/models.py b/django_etesync/models.py index cbfa269..62c3868 100644 --- a/django_etesync/models.py +++ b/django_etesync/models.py @@ -174,7 +174,7 @@ class CollectionInvitation(models.Model): class UserInfo(models.Model): owner = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, primary_key=True) version = models.PositiveSmallIntegerField(default=1) - pubkey = models.BinaryField(editable=True, blank=False, null=False) + loginPubkey = models.BinaryField(editable=True, blank=False, null=False) salt = models.BinaryField(editable=True, blank=False, null=False) def __str__(self): diff --git a/django_etesync/serializers.py b/django_etesync/serializers.py index 650b981..5772000 100644 --- a/django_etesync/serializers.py +++ b/django_etesync/serializers.py @@ -348,13 +348,11 @@ class UserInfoPubkeySerializer(serializers.ModelSerializer): class AuthenticationSignupSerializer(serializers.Serializer): user = UserQuerySerializer(many=False) salt = BinaryBase64Field() - pubkey = BinaryBase64Field() + loginPubkey = BinaryBase64Field() def create(self, validated_data): """Function that's called when this serializer creates an item""" user_data = validated_data.pop('user') - salt = validated_data.pop('salt') - pubkey = validated_data.pop('pubkey') with transaction.atomic(): instance, _ = User.objects.get_or_create(**user_data) @@ -364,7 +362,7 @@ class AuthenticationSignupSerializer(serializers.Serializer): instance.set_unusable_password() # FIXME: send email verification - models.UserInfo.objects.create(salt=salt, pubkey=pubkey, owner=instance) + models.UserInfo.objects.create(**validated_data, owner=instance) return instance diff --git a/django_etesync/views.py b/django_etesync/views.py index bde22e4..916c2a2 100644 --- a/django_etesync/views.py +++ b/django_etesync/views.py @@ -603,7 +603,7 @@ class AuthenticationViewSet(viewsets.ViewSet): content = {'code': 'wrong_host', 'detail': detail} return Response(content, status=status.HTTP_400_BAD_REQUEST) - verify_key = nacl.signing.VerifyKey(user.userinfo.pubkey, encoder=nacl.encoding.RawEncoder) + verify_key = nacl.signing.VerifyKey(user.userinfo.loginPubkey, encoder=nacl.encoding.RawEncoder) verify_key.verify(response_raw, signature) data = self.login_response_data(user)