Пример #1
0
def get_params(uname, A, s):
  try:
    if uname and A:
      b = util.get_random_number()
      p = client_store[uname]
      x = util.H(s, uname, p)
      N, g = util.get_ng()
      v = pow(g, x, N)  
      k = util.get_K()
      B = (k*v + pow(g, b, N)) % N
      return B, v, b
    else:
      print(' Please enter valid username and password ')
  except Exception as e:
    print(' Invalid username password entered... ')
Пример #2
0
def compute_shared_key(A, msg, username, password, a):
  try:
    if(msg.has_key('SIGNED_SALT') and msg.has_key('SIGNED_B') and msg.has_key('SALT') and msg.has_key('B')):
      signed_salt = msg['SIGNED_SALT']
      signed_B = msg['SIGNED_B']
      salt = msg['SALT']
      B = msg['B']

      util.verify_signature(SERVER_KEY, signed_salt, str(salt).encode())
      util.verify_signature(SERVER_KEY, signed_B, str(B).encode())
    else:
      raise Exception('Did not found the expected keys for Salt and B')
  except Exception as e:
    print "An error occured while verifying the digital signature"
    raise 

  u = util.H(A, B)
  x = util.H(salt, username, password)
  k = util.get_K()
  key = util.get_client_shared_key(B, k, x, a, u)
  return key