sysmo-isim-tool: allow selection of 4g5g auth algo individually

At the moment we set the algorithm type for 4g5g to the same algorithm
type we use for 3g. There is no way to select the algorithm type for
4g5g individually.

With the Advent of TUAK users might need to set the 4g5g algorithm to
TUAK and the Algorithm used for 3g to something else (e.g. Milenage). So
let's allow to select the algorithm for 4g5g individually, but only if
the user explicitly defines it.

Related: SYS#6473
This commit is contained in:
Philipp Maier 2023-06-23 11:11:26 +02:00
parent fb9d5f7591
commit b8c465a72d
6 changed files with 375 additions and 75 deletions

View File

@ -58,9 +58,15 @@ class Common():
show_iccid = False
show_aid = False
def __init__(self, argv, getopts, getopts_long):
# This flag specifies whether the commandline options should offer writing auth parameters (algorithm to use
# for authentication). The commandline options are not implemented separately for each card since the method
# calls are nearly the same for all card generations.
write_auth_4g5g = False
def __init__(self, argv, getopts, getopts_long, write_auth_4g5g = False):
self._banner()
self.write_auth_4g5g = write_auth_4g5g
# Analyze commandline options
try:
@ -98,7 +104,7 @@ class Common():
elif opt in ("-t", "--auth"):
self.show_auth = True
elif opt in ("-T", "--set-auth"):
self.write_auth = arg.split(':',1)
self.write_auth = arg.split(':', 2)
elif opt in ("-o", "--opc"):
self.show_opc = True
elif opt in ("-O", "--set-op"):
@ -143,8 +149,11 @@ class Common():
print(" -L, --set-milenage HEXSTRING ... Set milenage parameters")
print(" -k, --key ...................... Show auth key value")
print(" -K, --set-key .................. Set auth key value")
print(" -t, --auth ..................... Show Authentication algorithms")
print(" -T, --set-auth 2G:3G ........... Set 2G/3G Auth algo (e.g. COMP128v1:COMP128v1)")
print(" -t, --auth ..................... Show authentication algorithms")
if self.write_auth_4g5g:
print(" -T, --set-auth 2g:3g[:4g5g] .... Set 2G/3G auth algo (e.g. COMP128v1:COMP128v1)")
else:
print(" -T, --set-auth 2g:3g ........... Set 2G/3G auth algo (e.g. COMP128v1:COMP128v1)")
print(" -o, --opc ...................... Show OP/c configuration")
print(" -O, --set-op HEXSTRING ......... Set OP value")
print(" -C, --set-opc HEXSTRING ........ Set OPc value")
@ -192,7 +201,10 @@ class Common():
self.sim.show_auth_params()
if self.write_auth:
self.sim.write_auth_params(self.write_auth[0], self.write_auth[1])
if self.write_auth_4g5g and len(self.write_auth) > 2:
self.sim.write_auth_params(self.write_auth[0], self.write_auth[1], self.write_auth[2])
else:
self.sim.write_auth_params(self.write_auth[0], self.write_auth[1])
if self.show_opc:
self.sim.show_opc_params()

View File

@ -71,7 +71,7 @@ class Application(Common):
def main(argv):
Application(argv, "d", ["dump"])
Application(argv, "d", ["dump"], True)
if __name__ == "__main__":

View File

@ -71,7 +71,7 @@ class Application(Common):
def main(argv):
Application(argv, "d", ["dump"])
Application(argv, "d", ["dump"], True)
if __name__ == "__main__":

View File

@ -693,12 +693,21 @@ class Sysmo_isim_sja2(Sysmo_usim):
ef = SYSMO_ISIMSJAX_FILE_EF_USIM_AUTH_KEY(res.apdu)
algo_3g = ef.algo
if self.sim.has_isim:
self.__select_xsim_auth_key(isim = True, _2G = False)
res = self._read_binary(self.sim.filelen)
ef = SYSMO_ISIMSJAX_FILE_EF_USIM_AUTH_KEY(res.apdu)
algo_4g5g = ef.algo
else:
algo_4g5g = algo_3g
print(" * Current algorithm setting:")
print(" 2G: %d=%s" % (algo_2g, id_to_str(self.algorithms, algo_2g)))
print(" 3G: %d=%s" % (algo_3g, id_to_str(self.algorithms, algo_3g)))
print(" 2g: %d=%s" % (algo_2g, id_to_str(self.algorithms, algo_2g)))
print(" 3g: %d=%s" % (algo_3g, id_to_str(self.algorithms, algo_3g)))
print(" 4g5g: %d=%s" % (algo_3g, id_to_str(self.algorithms, algo_4g5g)))
print("")
def write_auth_params(self, algo_2g_str, algo_3g_str):
def write_auth_params(self, algo_2g_str, algo_3g_str, algo_4g5g_str = None):
"""
Write new authentication parameters
"""
@ -715,9 +724,18 @@ class Sysmo_isim_sja2(Sysmo_usim):
else:
algo_3g = str_to_id(self.algorithms, algo_3g_str)
if algo_4g5g_str:
if algo_4g5g_str.isdigit():
algo_4g5g = int(algo_4g5g_str)
else:
algo_4g5g = str_to_id(self.algorithms, algo_4g5g_str)
else:
algo_4g5g = algo_3g
print(" * New algorithm setting:")
print(" 2G: %d=%s" % (algo_2g, id_to_str(self.algorithms, algo_2g)))
print(" 3G: %d=%s" % (algo_3g, id_to_str(self.algorithms, algo_3g)))
print(" 2g: %d=%s" % (algo_2g, id_to_str(self.algorithms, algo_2g)))
print(" 3g: %d=%s" % (algo_3g, id_to_str(self.algorithms, algo_3g)))
print(" 4g5g: %d=%s" % (algo_4g5g, id_to_str(self.algorithms, algo_4g5g)))
print(" * Programming...")
@ -737,7 +755,7 @@ class Sysmo_isim_sja2(Sysmo_usim):
self.__select_xsim_auth_key(isim = True, _2G = False)
res = self._read_binary(self.sim.filelen)
ef = SYSMO_ISIMSJAX_FILE_EF_USIM_AUTH_KEY(res.apdu)
ef.algo = algo_3g
ef.algo = algo_4g5g
self.sim.update_binary(ef.encode())
print("")

View File

@ -16,8 +16,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 1=COMP128v1
3G: 1=COMP128v1
2g: 1=COMP128v1
3g: 1=COMP128v1
4g5g: 1=COMP128v1
* Programming...
Done!
@ -40,8 +41,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 1=COMP128v1
3G: 1=COMP128v1
2g: 1=COMP128v1
3g: 1=COMP128v1
4g5g: 1=COMP128v1
Done!
sysmoISIM-SJA2 parameterization tool
@ -62,8 +64,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 3=COMP128v3
3G: 1=COMP128v1
2g: 3=COMP128v3
3g: 1=COMP128v1
4g5g: 1=COMP128v1
* Programming...
Done!
@ -86,8 +89,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 3=COMP128v3
3G: 1=COMP128v1
2g: 3=COMP128v3
3g: 1=COMP128v1
4g5g: 1=COMP128v1
Done!
sysmoISIM-SJA2 parameterization tool
@ -108,8 +112,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 4=MILENAGE
3G: 1=COMP128v1
2g: 4=MILENAGE
3g: 1=COMP128v1
4g5g: 1=COMP128v1
* Programming...
Done!
@ -132,8 +137,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 4=MILENAGE
3G: 1=COMP128v1
2g: 4=MILENAGE
3g: 1=COMP128v1
4g5g: 1=COMP128v1
Done!
sysmoISIM-SJA2 parameterization tool
@ -154,8 +160,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 5=SHA1-AKA
3G: 1=COMP128v1
2g: 5=SHA1-AKA
3g: 1=COMP128v1
4g5g: 1=COMP128v1
* Programming...
Done!
@ -178,8 +185,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 5=SHA1-AKA
3G: 1=COMP128v1
2g: 5=SHA1-AKA
3g: 1=COMP128v1
4g5g: 1=COMP128v1
Done!
sysmoISIM-SJA2 parameterization tool
@ -200,8 +208,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 15=XOR
3G: 1=COMP128v1
2g: 15=XOR
3g: 1=COMP128v1
4g5g: 1=COMP128v1
* Programming...
Done!
@ -224,8 +233,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 15=XOR
3G: 1=COMP128v1
2g: 15=XOR
3g: 1=COMP128v1
4g5g: 1=COMP128v1
Done!
sysmoISIM-SJA2 parameterization tool
@ -246,8 +256,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 1=COMP128v1
3G: 4=MILENAGE
2g: 1=COMP128v1
3g: 4=MILENAGE
4g5g: 4=MILENAGE
* Programming...
Done!
@ -270,8 +281,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 1=COMP128v1
3G: 4=MILENAGE
2g: 1=COMP128v1
3g: 4=MILENAGE
4g5g: 4=MILENAGE
Done!
sysmoISIM-SJA2 parameterization tool
@ -292,8 +304,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 3=COMP128v3
3G: 15=XOR
2g: 3=COMP128v3
3g: 15=XOR
4g5g: 15=XOR
* Programming...
Done!
@ -316,8 +329,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 3=COMP128v3
3G: 15=XOR
2g: 3=COMP128v3
3g: 15=XOR
4g5g: 15=XOR
Done!
sysmoISIM-SJA2 parameterization tool
@ -338,8 +352,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 2=COMP128v2
3G: 2=COMP128v2
2g: 2=COMP128v2
3g: 2=COMP128v2
4g5g: 2=COMP128v2
* Programming...
Done!
@ -362,8 +377,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 2=COMP128v2
3G: 2=COMP128v2
2g: 2=COMP128v2
3g: 2=COMP128v2
4g5g: 2=COMP128v2
Done!
sysmoISIM-SJA2 parameterization tool
@ -384,8 +400,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 1=COMP128v1
3G: 3=COMP128v3
2g: 1=COMP128v1
3g: 3=COMP128v3
4g5g: 3=COMP128v3
* Programming...
Done!
@ -408,8 +425,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 1=COMP128v1
3G: 3=COMP128v3
2g: 1=COMP128v1
3g: 3=COMP128v3
4g5g: 3=COMP128v3
Done!
sysmoISIM-SJA2 parameterization tool
@ -430,8 +448,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 4=MILENAGE
3G: 4=MILENAGE
2g: 1=COMP128v1
3g: 2=COMP128v2
4g5g: 3=COMP128v3
* Programming...
Done!
@ -454,8 +473,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 4=MILENAGE
3G: 4=MILENAGE
2g: 1=COMP128v1
3g: 2=COMP128v2
4g5g: 2=COMP128v3
Done!
sysmoISIM-SJA2 parameterization tool
@ -476,8 +496,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 1=COMP128v1
3G: 4=MILENAGE
2g: 1=COMP128v1
3g: 4=MILENAGE
4g5g: 5=SHA1-AKA
* Programming...
Done!
@ -500,8 +521,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 1=COMP128v1
3G: 4=MILENAGE
2g: 1=COMP128v1
3g: 4=MILENAGE
4g5g: 4=SHA1-AKA
Done!
sysmoISIM-SJA2 parameterization tool
@ -522,8 +544,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 3=COMP128v3
3G: 4=MILENAGE
2g: 5=SHA1-AKA
3g: 4=MILENAGE
4g5g: 15=XOR
* Programming...
Done!
@ -546,8 +569,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 3=COMP128v3
3G: 4=MILENAGE
2g: 5=SHA1-AKA
3g: 4=MILENAGE
4g5g: 4=XOR
Done!
sysmoISIM-SJA2 parameterization tool
@ -568,8 +592,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 2=COMP128v2
3G: 4=MILENAGE
2g: 4=MILENAGE
3g: 4=MILENAGE
4g5g: 4=MILENAGE
* Programming...
Done!
@ -592,8 +617,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 2=COMP128v2
3G: 4=MILENAGE
2g: 4=MILENAGE
3g: 4=MILENAGE
4g5g: 4=MILENAGE
Done!
sysmoISIM-SJA2 parameterization tool
@ -614,8 +640,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 5=SHA1-AKA
3G: 15=XOR
2g: 1=COMP128v1
3g: 4=MILENAGE
4g5g: 4=MILENAGE
* Programming...
Done!
@ -638,8 +665,9 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 5=SHA1-AKA
3G: 15=XOR
2g: 1=COMP128v1
3g: 4=MILENAGE
4g5g: 4=MILENAGE
Done!
sysmoISIM-SJA2 parameterization tool
@ -660,8 +688,9 @@ Authenticating...
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2G: 1=COMP128v1
3G: 4=MILENAGE
2g: 3=COMP128v3
3g: 4=MILENAGE
4g5g: 4=MILENAGE
* Programming...
Done!
@ -684,7 +713,248 @@ Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2G: 1=COMP128v1
3G: 4=MILENAGE
2g: 3=COMP128v3
3g: 4=MILENAGE
4g5g: 4=MILENAGE
Done!
sysmoISIM-SJA2 parameterization tool
Copyright (c) 2019-2022 sysmocom - s.f.m.c. GmbH
Trying to find card with ATR: 3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9
Initializing smartcard terminal...
* Detected Card IMSI: 901700000046734
ISIM Application installed
USIM Application installed
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2g: 2=COMP128v2
3g: 4=MILENAGE
4g5g: 4=MILENAGE
* Programming...
Done!
sysmoISIM-SJA2 parameterization tool
Copyright (c) 2019-2022 sysmocom - s.f.m.c. GmbH
Trying to find card with ATR: 3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9
Initializing smartcard terminal...
* Detected Card IMSI: 901700000046734
ISIM Application installed
USIM Application installed
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2g: 2=COMP128v2
3g: 4=MILENAGE
4g5g: 4=MILENAGE
Done!
sysmoISIM-SJA2 parameterization tool
Copyright (c) 2019-2022 sysmocom - s.f.m.c. GmbH
Trying to find card with ATR: 3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9
Initializing smartcard terminal...
* Detected Card IMSI: 901700000046734
ISIM Application installed
USIM Application installed
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2g: 5=SHA1-AKA
3g: 15=XOR
4g5g: 15=XOR
* Programming...
Done!
sysmoISIM-SJA2 parameterization tool
Copyright (c) 2019-2022 sysmocom - s.f.m.c. GmbH
Trying to find card with ATR: 3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9
Initializing smartcard terminal...
* Detected Card IMSI: 901700000046734
ISIM Application installed
USIM Application installed
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2g: 5=SHA1-AKA
3g: 15=XOR
4g5g: 15=XOR
Done!
sysmoISIM-SJA2 parameterization tool
Copyright (c) 2019-2022 sysmocom - s.f.m.c. GmbH
Trying to find card with ATR: 3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9
Initializing smartcard terminal...
* Detected Card IMSI: 901700000046734
ISIM Application installed
USIM Application installed
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2g: 1=COMP128v1
3g: 4=MILENAGE
4g5g: 4=MILENAGE
* Programming...
Done!
sysmoISIM-SJA2 parameterization tool
Copyright (c) 2019-2022 sysmocom - s.f.m.c. GmbH
Trying to find card with ATR: 3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9
Initializing smartcard terminal...
* Detected Card IMSI: 901700000046734
ISIM Application installed
USIM Application installed
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2g: 1=COMP128v1
3g: 4=MILENAGE
4g5g: 4=MILENAGE
Done!
sysmoISIM-SJA2 parameterization tool
Copyright (c) 2019-2022 sysmocom - s.f.m.c. GmbH
Trying to find card with ATR: 3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9
Initializing smartcard terminal...
* Detected Card IMSI: 901700000046734
ISIM Application installed
USIM Application installed
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2g: 1=COMP128v1
3g: 4=MILENAGE
4g5g: 5=SHA1-AKA
* Programming...
Done!
sysmoISIM-SJA2 parameterization tool
Copyright (c) 2019-2022 sysmocom - s.f.m.c. GmbH
Trying to find card with ATR: 3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9
Initializing smartcard terminal...
* Detected Card IMSI: 901700000046734
ISIM Application installed
USIM Application installed
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2g: 1=COMP128v1
3g: 4=MILENAGE
4g5g: 4=SHA1-AKA
Done!
sysmoISIM-SJA2 parameterization tool
Copyright (c) 2019-2022 sysmocom - s.f.m.c. GmbH
Trying to find card with ATR: 3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9
Initializing smartcard terminal...
* Detected Card IMSI: 901700000046734
ISIM Application installed
USIM Application installed
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Programming Authentication parameters...
* Initalizing...
* New algorithm setting:
2g: 2=COMP128v2
3g: 1=COMP128v1
4g5g: 3=COMP128v3
* Programming...
Done!
sysmoISIM-SJA2 parameterization tool
Copyright (c) 2019-2022 sysmocom - s.f.m.c. GmbH
Trying to find card with ATR: 3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 4B A9
Initializing smartcard terminal...
* Detected Card IMSI: 901700000046734
ISIM Application installed
USIM Application installed
Authenticating...
* Remaining attempts: 3
* Authenticating...
* Authentication successful
* Remaining attempts: 3
Reading Authentication parameters...
* Initalizing...
* Reading...
* Current algorithm setting:
2g: 2=COMP128v2
3g: 1=COMP128v1
4g5g: 1=COMP128v3
Done!

View File

@ -1,8 +1,8 @@
#!/bin/sh
. ./test-data
ALGOS="1:1 3:1 4:1 5:1 15:1 1:4 3:15 2:2 1:3 "
ALGOS=$ALGOS"MILENAGE:MILENAGE COMP128v1:MILENAGE COMP128v3:MILENAGE COMP128v2:MILENAGE SHA1-AKA:XOR COMP128v1:MILENAGE"
ALGOS="1:1 3:1 4:1 5:1 15:1 1:4 3:15 2:2 1:3 1:2:3 1:4:5 5:4:15 "
ALGOS=$ALGOS"MILENAGE:MILENAGE COMP128v1:MILENAGE COMP128v3:MILENAGE COMP128v2:MILENAGE SHA1-AKA:XOR COMP128v1:MILENAGE COMP128v1:MILENAGE:SHA1-AKA COMP128v2:COMP128v1:COMP128v3"
for algo in $ALGOS; do
$TOOL -a $ADMPIN -T $algo
$TOOL -a $ADMPIN -t