def test_5(self): """test_5 Make sure all one time passwords are random i.e. they should collide""" # random number generator rng = mpin.create_csprng(self.seed) s = set() match = 0 for i in range(1, 10000): OTP = mpin.generate_otp(rng) if OTP in s: # print i match = 1 s.add(OTP) self.assertEqual(match, 1)
def test_7(self): """test_6 Make sure all random values are random i.e. they should collide""" # random number generator rng = mpin.create_csprng(self.seed) # Generate 4 byte random number s = set() match = 0 for i in range(1, 208900): random = mpin.generate_random(rng, 4) # print i, " ", random.encode("hex") if random in s: match = 1 break s.add(random) self.assertEqual(match, 1)
def test_4(self): """test_4 Make sure all client secret are unique""" # random number generator rng = mpin.create_csprng(self.seed) # Generate master secret share rtn, ms1 = mpin.random_generate(rng) self.assertEqual(rtn, 0) s = set() match = 0 for i in range(1, 1000): rand_val = os.urandom(32) hash_mpin_id = mpin.hash_id(HASH_TYPE_MPIN, rand_val) # Generate client secret shares rtn, cs1 = mpin.get_client_secret(ms1, hash_mpin_id) self.assertEqual(rtn, 0) cs1Hex = cs1.encode("hex") if cs1Hex in s: match = 1 self.assertEqual(match, 0) s.add(cs1Hex)
TIME_PERMITS = True MPIN_FULL = True PIN_ERROR = True USE_ANONYMOUS = False if TIME_PERMITS: date = mpin.today() else: date = 0 # Seed seedHex = "b75e7857fa17498c333d3c8d42e10f8c3cb8a66f7a84d85f86cd5acb537fa211" seed = seedHex.decode("hex") # random number generator rng = mpin.create_csprng(seed) # Identity mpin_id = "*****@*****.**" # Hash mpin_id hash_mpin_id = mpin.hash_id(HASH_TYPE_MPIN, mpin_id) if DEBUG: print "mpin_id: %s" % mpin_id.encode("hex") print "hash_mpin_id: %s" % hash_mpin_id.encode("hex") if USE_ANONYMOUS: pID = hash_mpin_id else: pID = mpin_id
def test_1(self): """test_1 Good PIN and good token""" PIN1 = 1234 PIN2 = 1234 # random number generator rng = mpin.create_csprng(self.seed) # Generate Client master secret share for MIRACL and Customer rtn, ms1 = mpin.random_generate(rng) self.assertEqual(rtn, 0) rtn, ms2 = mpin.random_generate(rng) self.assertEqual(rtn, 0) # Generate server secret shares rtn, ss1 = mpin.get_server_secret(ms1) self.assertEqual(rtn, 0) rtn, ss2 = mpin.get_server_secret(ms2) self.assertEqual(rtn, 0) # Combine server secret shares rtn, server_secret = mpin.recombine_G2(ss1, ss2) self.assertEqual(rtn, 0) # Generate client secret shares rtn, cs1 = mpin.get_client_secret(ms1, self.hash_mpin_id) self.assertEqual(rtn, 0) rtn, cs2 = mpin.get_client_secret(ms2, self.hash_mpin_id) self.assertEqual(rtn, 0) # Combine client secret shares rtn, client_secret = mpin.recombine_G1(cs1, cs2) self.assertEqual(rtn, 0) # Generate Time Permit shares rtn, tp1 = mpin.get_client_permit(HASH_TYPE_MPIN, self.date, ms1, self.hash_mpin_id) self.assertEqual(rtn, 0) rtn, tp2 = mpin.get_client_permit(HASH_TYPE_MPIN, self.date, ms2, self.hash_mpin_id) self.assertEqual(rtn, 0) # Combine Time Permit shares rtn, time_permit = mpin.recombine_G1(tp1, tp2) self.assertEqual(rtn, 0) # Client extracts PIN from secret to create Token rtn, token = mpin.extract_pin(HASH_TYPE_MPIN, self.mpin_id, PIN1, client_secret) self.assertEqual(rtn, 0) # Client first pass rtn, x, u, ut, sec = mpin.client_1(HASH_TYPE_MPIN, self.date, self.mpin_id, rng, None, PIN2, token, time_permit) self.assertEqual(rtn, 0) # Server calculates H(ID) and H(T|H(ID)) HID, HTID = mpin.server_1(HASH_TYPE_MPIN, self.date, self.hash_mpin_id) # Server generates Random number Y and sends it to Client rtn, y = mpin.random_generate(rng) self.assertEqual(rtn, 0) # Client second pass rtn, v = mpin.client_2(x, y, sec) self.assertEqual(rtn, 0) # Server second pass rtn, E, F = mpin.server_2(self.date, HID, HTID, y, server_secret, u, ut, v) self.assertEqual(rtn, 0)