georgemarshall / django-cryptography

Easily encrypt data in Django
https://django-cryptography.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
370 stars 69 forks source link

django.core.signing.BadSignature: Signature is not valid #26

Open reyesvicente opened 4 years ago

reyesvicente commented 4 years ago

I got this when I logged in on the admin and checked the newsletter signups, it returned

BadSignature at /admin/sendemail/newsletteruser/ Signature is not valid

This is the whole traceback on the CLI

Internal Server Error: /admin/sendemail/newsletteruser/
Traceback (most recent call last):
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django_cryptography/core/signing.py", line 223, in unsign
version, timestamp, value, sig = struct.unpack(fmt, signed_value)
struct.error: bad char in struct format

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/contrib/admin/options.py", line 606, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/contrib/admin/sites.py", line 223, in inner
return view(request, *args, **kwargs)
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/utils/decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1790, in changelist_view
'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/db/models/query.py", line 256, in __len__
self._fetch_all()
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/db/models/query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/db/models/query.py", line 72, in __iter__
for row in compiler.results_iter(results):
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1044, in apply_converters
value = converter(value, expression, connection)
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django_cryptography/fields.py", line 180, in from_db_value
return self._load(force_bytes(value))
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django_cryptography/fields.py", line 121, in _load
return pickle.loads(self._fernet.decrypt(value, self.ttl))
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django_cryptography/utils/crypto.py", line 143, in decrypt
data = self._signer.unsign(data, ttl)
  File "/Users/user/Dev/AML/env/lib/python3.7/site-packages/django_cryptography/core/signing.py", line 225, in unsign
raise BadSignature('Signature is not valid')
django.core.signing.BadSignature: Signature is not valid
"GET /admin/sendemail/newsletteruser/ HTTP/1.1" 500 144750

What does this mean? What do I need to show?

Thanasis1101 commented 4 years ago

Does this take place on a column that already has values? Because I had the same issue for an already existing column. If this is also the case for you, you can try the solutions from this issue. The problem was solved for me when I applied this migration, after changing the parameters to match the data of my model and column name etc.

reyesvicente commented 4 years ago

Does this take place on a column that already has values? Because I had the same issue for an already existing column. If this is also the case for you, you can try the solutions from this issue. The problem was solved for me when I applied this migration, after changing the parameters to match the data of my model and column name etc.

Yes, it takes place on columns that has value. It makes sense now. I'll try the solution then update this thread afterwards. Thanks.