Skip to content

Commit

Permalink
Crypto refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
heynemann committed Aug 3, 2011
1 parent 292db74 commit 37be956
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
35 changes: 16 additions & 19 deletions thumbor/handlers/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,23 @@ def get(self,
security_key=None,
**kw):

if not security_key and conf.STORES_CRYPTO_KEY_FOR_EACH_IMAGE:
security_key = self.storage.get_crypto(image)

cr = Crypto(security_key or conf.SECURITY_KEY)
opt = cr.decrypt(crypto)
cr = Crypto(conf.SECURITY_KEY)
try:
opt = cr.decrypt(crypto)
except ValueError:
opt = None

image_hash = opt and opt.get('image_hash')
image_hash = image_hash[1:] if image_hash and image_hash.startswith('/') else image_hash
path_hash = hashlib.md5(image).hexdigest()

if not image_hash or image_hash != path_hash:
self._error(404, 'Request denied because the specified image hash "%s" does not match the given image path hash "%s"' %(
unicode(image_hash, errors='replace'),
path_hash
))
return
if not opt and not security_key and conf.STORES_CRYPTO_KEY_FOR_EACH_IMAGE:
security_key = self.storage.get_crypto(image)
cr = Crypto(security_key)
opt = cr.decrypt(crypto)

if not self.validate(image):
self._error(404)
return
if opt:
image_hash = opt and opt.get('image_hash')
image_hash = image_hash[1:] if image_hash and image_hash.startswith('/') else image_hash
path_hash = hashlib.md5(image).hexdigest()

return self.execute_image_operations(opt, image)
if image_hash and image_hash == path_hash and self.validate(image):
return self.execute_image_operations(opt, image)

self._error(404, 'Request denied because the specified image hash is not valid')
4 changes: 2 additions & 2 deletions thumbor/thumbor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ REDIS_STORAGE_SERVER_PORT = 6379
REDIS_STORAGE_SERVER_DB = 0

# imaging engine to use to process images
#ENGINE = 'thumbor.engines.graphicsmagick'
ENGINE = 'thumbor.engines.pil'
ENGINE = 'thumbor.engines.graphicsmagick'
#ENGINE = 'thumbor.engines.pil'
#ENGINE = 'thumbor.engines.imagemagick'
#ENGINE = 'thumbor.engines.opencv'

Expand Down

0 comments on commit 37be956

Please sign in to comment.