Permalink
Browse files

guard against bad algorithms

  • Loading branch information...
1 parent a87e67e commit ae85d657527ce9d6303c36c5c6de26137af0fe35 @atl committed Feb 29, 2012
Showing with 4 additions and 2 deletions.
  1. +2 −2 .gitignore
  2. +2 −0 http_signature/sign.py
View
4 .gitignore
@@ -17,6 +17,6 @@ devdatabase.db
bundle_version.gen
celeryd.log
celeryd.pid
-joy-rsa
-joy-rsa.pub
+joy_rsa
+joy_rsa.pub
View
2 http_signature/sign.py
@@ -4,12 +4,14 @@
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
+ALGORITHMS = frozenset(['rsa-sha1', 'rsa-sha256', 'rsa-sha512', 'hmac-sha1', 'hmac-sha256', 'hmac-sha512'])
HASHES = {'sha256': SHA256,
'sha1': SHA,
'sha512': SHA512}
class Signer(object):
def __init__(self, secret='', algorithm='rsa-sha256'):
+ assert algorithm in ALGORITHMS, "Unknown algorithm"
self.sign_algorithm, self.hash_algorithm = algorithm.split('-')
if self.sign_algorithm == 'rsa':
with open(secret) as fh:

0 comments on commit ae85d65

Please sign in to comment.