|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+import hashlib
|
|
|
2
|
+import logging
|
|
1
|
3
|
from collections import OrderedDict
|
|
2
|
4
|
from decimal import Decimal as D
|
|
3
|
5
|
|
|
4
|
6
|
from django.conf import settings
|
|
|
7
|
+from django.core.exceptions import ImproperlyConfigured
|
|
5
|
8
|
from django.core.signing import BadSignature, Signer
|
|
6
|
9
|
from django.db import models
|
|
7
|
10
|
from django.db.models import Sum
|
|
|
@@ -22,6 +25,9 @@ from oscar.models.fields import AutoSlugField
|
|
22
|
25
|
from . import exceptions
|
|
23
|
26
|
|
|
24
|
27
|
|
|
|
28
|
+logger = logging.getLogger('oscar.order')
|
|
|
29
|
+
|
|
|
30
|
+
|
|
25
|
31
|
@python_2_unicode_compatible
|
|
26
|
32
|
class AbstractOrder(models.Model):
|
|
27
|
33
|
"""
|
|
|
@@ -303,11 +309,38 @@ class AbstractOrder(models.Model):
|
|
303
|
309
|
signer = Signer(salt='oscar.apps.order.Order')
|
|
304
|
310
|
return signer.sign(self.number)
|
|
305
|
311
|
|
|
|
312
|
+ def check_deprecated_verification_hash(self, hash_to_check):
|
|
|
313
|
+ """
|
|
|
314
|
+ Backward compatible check for md5 hashes that were generated in
|
|
|
315
|
+ Oscar 1.5 and lower.
|
|
|
316
|
+
|
|
|
317
|
+ This must explicitly be enabled by setting OSCAR_DEPRECATED_ORDER_VERIFY_KEY,
|
|
|
318
|
+ which must not be equal to SECRET_KEY - i.e., the project must
|
|
|
319
|
+ have changed its SECRET_KEY since this change was applied.
|
|
|
320
|
+
|
|
|
321
|
+ TODO: deprecate this method in Oscar 2.0, and remove it in Oscar 2.1.
|
|
|
322
|
+ """
|
|
|
323
|
+ old_verification_key = getattr(settings, 'OSCAR_DEPRECATED_ORDER_VERIFY_KEY', None)
|
|
|
324
|
+ if old_verification_key is None:
|
|
|
325
|
+ return False
|
|
|
326
|
+
|
|
|
327
|
+ if old_verification_key == settings.SECRET_KEY:
|
|
|
328
|
+ raise ImproperlyConfigured(
|
|
|
329
|
+ 'OSCAR_DEPRECATED_ORDER_VERIFY_KEY cannot be equal to SECRET_KEY')
|
|
|
330
|
+
|
|
|
331
|
+ logger.warning('Using insecure md5 hashing for order URL hash verification.')
|
|
|
332
|
+ string_to_hash = '%s%s' % (self.number, old_verification_key)
|
|
|
333
|
+ order_hash = hashlib.md5(string_to_hash.encode('utf8')).hexdigest()
|
|
|
334
|
+ return constant_time_compare(order_hash, hash_to_check)
|
|
|
335
|
+
|
|
306
|
336
|
def check_verification_hash(self, hash_to_check):
|
|
307
|
337
|
"""
|
|
308
|
338
|
Checks the received verification hash against this order number.
|
|
309
|
339
|
Returns False if the verification failed, True otherwise.
|
|
310
|
340
|
"""
|
|
|
341
|
+ if self.check_deprecated_verification_hash(hash_to_check):
|
|
|
342
|
+ return True
|
|
|
343
|
+
|
|
311
|
344
|
signer = Signer(salt='oscar.apps.order.Order')
|
|
312
|
345
|
try:
|
|
313
|
346
|
signed_number = signer.unsign(hash_to_check)
|