示例#1
0
 def make_2g_vector(self, IMSI, RAND=None):
     """
     return a 2G authentication vector "triplet":
     RAND [16 bytes], RES [4 bytes], Kc [8 bytes]
     or None if the IMSI is not defined in the db or ALG is invalid
     
     RAND can be passed as argument
     """
     # lookup db for authentication Key and algorithm id for IMSI
     try:
         K_ALG_SQN_OP = self.db[IMSI]
     except KeyError:
         self._log('WNG', '[make_2g_vector] IMSI %s not present in AuC.db' % IMSI)
         return None
     if len(K_ALG_SQN_OP) == 4:
         K, ALG, SQN, OP = K_ALG_SQN_OP
     else:
         K, ALG, SQN = K_ALG_SQN_OP
         OP = None
     #
     if not RAND:
         RAND = genrand(16)
     #
     if ALG == 0:
         # Milenage, adapted to 2G
         if OP is not None:
             XRES, CK, IK, AK = self.Milenage.f2345(RAND, K, OP)
         else:
             XRES, CK, IK, AK = self.Milenage.f2345(RAND, K)
         RES, Kc = conv_102_C2(XRES), conv_102_C3(CK, IK)
     elif ALG == 4:
         # TUAK, adapted to 2G
         if OP is not None:
             # which is actually TOP, for TUAK
             XRES, CK, IK, AK = self.TUAK.f2345(RAND, K, OP)
         else:
             XRES, CK, IK, AK = self.TUAK.f2345(RAND, K)
         RES, Kc = conv_102_C2(XRES), conv_102_C3(CK, IK)
     else:
         # COMP128
         if ALG == 1:
             RES, Kc = comp128v1(K, RAND)
         elif ALG == 2:
             RES, Kc = comp128v2(K, RAND)
         elif ALG == 3:
             RES, Kc = comp128v3(K, RAND)
         else:
             # invalid ALG
             return None
     #
     # return auth vector
     self._log('DBG', '[make_2g_vector] IMSI %s: RAND %s, RES %s, Kc %s'\
               % (IMSI, hexlify(RAND).decode('ascii'), hexlify(RES).decode('ascii'), 
                  hexlify(Kc).decode('ascii')))
     return RAND, RES, Kc
示例#2
0
 def make_2g_vector(self, IMSI, RAND=None):
     """
     return a 2G authentication vector "triplet":
     RAND [16 bytes], RES [4 bytes], Kc [8 bytes]
     or None if the IMSI is not defined in the db or ALG2 is invalid
     
     RAND can be passed as argument
     """
     # lookup db for authentication Key and algorithm id for IMSI
     try:
         K, ALG2, SQN, OP = self.db[IMSI]
     except KeyError:
         self._log('WNG',
                   '[make_2g_vector] IMSI %s not present in AuC.db' % IMSI)
         return None
     #
     if not RAND:
         RAND = genrand(16)
     #
     if ALG2 == 0:
         if OP is not None:
             XRES, CK, IK, AK = self.Milenage.f2345(RAND, K, OP)
         else:
             XRES, CK, IK, AK = self.Milenage.f2345(RAND, K)
         RES, Ck = conv_C2(XRES), conv_C3(CK, IK)
     else:
         if ALG2 == 1:
             RES, Ck = comp128v1(K, RAND)
         elif ALG2 == 2:
             RES, Ck = comp128v2(K, RAND)
         elif ALG2 == 3:
             RES, Ck = comp128v3(K, RAND)
         else:
             return None
     #
     # return auth vector
     self._log('DBG', '[make_2g_vector] IMSI %s: RAND %s, RES %s, Kc %s'\
               % (IMSI, hexlify(RAND).decode('ascii'), hexlify(RES).decode('ascii'),
                  hexlify(Kc).decode('ascii')))
     return RAND, RES, Kc