Revision 615aaaba lib/serializer.py

b/lib/serializer.py
31 31

  
32 32
import simplejson
33 33
import re
34
import hmac
35 34

  
36 35
from ganeti import errors
37

  
38
try:
39
  from hashlib import sha1
40
except ImportError:
41
  import sha as sha1
36
from ganeti import utils
42 37

  
43 38

  
44 39
_JSON_INDENT = 2
......
123 118
    message = salt + key_selector + txt
124 119
  else:
125 120
    message = salt + txt
126
  signed_dict["hmac"] = hmac.new(key, message,
127
                                 sha1).hexdigest()
121
  signed_dict["hmac"] = utils.Sha1Hmac(key, message)
128 122

  
129 123
  return DumpJson(signed_dict, indent=False)
130 124

  
......
162 156
    key_selector = ""
163 157
    hmac_key = key
164 158

  
165
  if hmac.new(hmac_key, salt + key_selector + msg,
166
              sha1).hexdigest() != hmac_sign:
159
  if not utils.VerifySha1Hmac(hmac_key, salt + key_selector + msg, hmac_sign):
167 160
    raise errors.SignatureError('Invalid Signature')
168 161

  
169 162
  return LoadJson(msg), salt

Also available in: Unified diff