def Payload_Challenge_Response(ID, RAND, ETYPE): # Let's build EAP-Payload Challenge-Response AVP # Create EAP-Payload (empty) EAP = eap.EAPItem() # Set command code EAP.cmd = eap.EAP_CODE_RESPONSE # Set id EAP.id = ID # Set type EAP.type = ETYPE # Set sub-type EAP.stype = eap.dictEAPSUBname2type("SIM-Challenge") # RAND is copied from Challenge # These values can be calculated or entered manually # Copied from SIP-Auth-Data-Item->Authentication-Information-SIM(301) a1 = "8b7e0f1147f9af050809bbaf50881dbb08014ca81b36d9fa" # Copied from SIP-Auth-Data-Item->Authorization-Information-SIM(302) b1 = "334131fc" RAND, KC = prepareKeysFromTriplets(a1, a1, a1) SRES = b1 + b1 + b1 # Step 2 KENCR, KAUT, MSK, EMSK, MK = eap.sim_calc_keys(IDENTITY, KC, NONCE_MT, VERSION_LIST, "1") # Add AT_MAC as last eap.addMAC(EAP, KAUT, SRES) # Do not add any AVPs after adding MAC Payload = eap.encode_EAP(EAP) # Payload now contains EAP-Payload AVP return Payload
def Payload_Challenge_Response(ID,RAND,ETYPE): # Let's build EAP-Payload Challenge-Response AVP # Create EAP-Payload (empty) EAP=eap.EAPItem() # Set command code EAP.cmd=eap.EAP_CODE_RESPONSE # Set id EAP.id=ID # Set type EAP.type=ETYPE # Set sub-type EAP.stype=eap.dictEAPSUBname2type("SIM-Challenge") # RAND is copied from Challenge # These values can be calculated or entered manually # Copied from SIP-Auth-Data-Item->Authentication-Information-SIM(301) a1="8b7e0f1147f9af050809bbaf50881dbb08014ca81b36d9fa" # Copied from SIP-Auth-Data-Item->Authorization-Information-SIM(302) b1="334131fc" RAND,KC=prepareKeysFromTriplets(a1,a1,a1) SRES=b1+b1+b1 # Step 2 KENCR,KAUT,MSK,EMSK,MK=eap.sim_calc_keys(IDENTITY,KC,NONCE_MT,VERSION_LIST, "1") # Add AT_MAC as last eap.addMAC(EAP,KAUT, SRES) # Do not add any AVPs after adding MAC Payload=eap.encode_EAP(EAP) # Payload now contains EAP-Payload AVP return Payload
"hex") a3 = "323534333064306365383134306564656238386464653763303135326432343235386261656331386330386331633030".decode( "hex") # Copied from SIP-Auth-Data-Item->Authorization-Information-SIM(302) b1 = "6639333733396536" b2 = "3937356635386534" b3 = "3737343362623433" SRES = b1 + b2 + b3 RAND, KC = prepareKeysFromTriplets(a1, a2, a3) print RAND, SRES, KC print "RAND=", RAND.encode("hex") print "KC=", KC.encode("hex") print "=" * 30 # Step 2 KENCR, KAUT, MSK, EMSK, MK = eap.sim_calc_keys(Identity, KC.encode("hex"), NONCE_MT, VERSION_LIST, SELECTED_VER) # KAUT is used to sign AT_MAC # Step 3 (optional) DATA = eap.decrypt_data(IV, KENCR, ENCR_DATA) print DATA print "-" * 30 avps = eap.splitEAPAVPs(DATA) for avp in avps: (Name, Value) = avp print Name, "=", Value REAUTH = findAVP("AT_NEXT_REAUTH_ID", avps) if REAUTH <> ERROR: print REAUTH.decode("hex") print "=" * 30
# Copied from SIP-Auth-Data-Item->Authentication-Information-SIM(301) a1="343766636361653132353364383564326662383664393337636266653631313532373163633231646232643365303030".decode("hex") a2="663065366339636161643166353733613832616137356665363066343666353965346331396335393936316161633030".decode("hex") a3="323534333064306365383134306564656238386464653763303135326432343235386261656331386330386331633030".decode("hex") # Copied from SIP-Auth-Data-Item->Authorization-Information-SIM(302) b1="6639333733396536" b2="3937356635386534" b3="3737343362623433" SRES=b1+b2+b3 RAND,KC=prepareKeysFromTriplets(a1,a2,a3) print RAND,SRES,KC print "RAND=",RAND.encode("hex") print "KC=",KC.encode("hex") print "="*30 # Step 2 KENCR,KAUT,MSK,EMSK,MK=eap.sim_calc_keys(Identity,KC.encode("hex"),NONCE_MT,VERSION_LIST,SELECTED_VER) # KAUT is used to sign AT_MAC # Step 3 (optional) DATA=eap.decrypt_data(IV,KENCR,ENCR_DATA) print DATA print "-"*30 avps=eap.splitEAPAVPs(DATA) for avp in avps: (Name,Value)=avp print Name,"=",Value REAUTH=findAVP("AT_NEXT_REAUTH_ID",avps) if REAUTH<>ERROR: print REAUTH.decode("hex") print "="*30 ######################################################