Compare commits

...

4 Commits

Author SHA1 Message Date
Harald Welte 9c73667324 initial support for sysmoISIM-SJA5
We inherit 99% of sysmoISIM-SJA2, but expand the algorithm definitions
2023-05-26 16:13:04 +02:00
Harald Welte caa06046be sja2: fix cosmetic copy+paste and copyright statement errors 2023-05-26 16:13:04 +02:00
Harald Welte 379a0fe771 sja2: Avoid mixed tab/space indentation
This file is tab-indented, but had very few lines that were space
indented.  This is bad python style, let's convert everything to tab
for consistency.
2023-05-26 16:11:17 +02:00
Harald Welte 82a785d27f sysmo_isim_sja2.py: Fix COMP128v3 support (copy+paste mistake) 2023-05-26 16:08:26 +02:00
3 changed files with 198 additions and 68 deletions

View File

@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-
"""
Commandline interface for sysmoUSIM-SJS1
Commandline interface for sysmoISIM-SJA2
(C) 2017 by Sysmocom s.f.m.c. GmbH
(C) 2019-2022 by sysmocom - s.f.m.c. GmbH
All Rights Reserved
Author: Philipp Maier
@ -37,7 +37,7 @@ class Application(Common):
# Automatically executed by superclass
def _banner(self):
print("sysmoISIM-SJA2 parameterization tool")
print("Copyright (c)2019 Sysmocom s.f.m.c. GmbH")
print("Copyright (c) 2019-2022 sysmocom - s.f.m.c. GmbH")
print("")

78
sysmo-isim-tool.sja5.py Executable file
View File

@ -0,0 +1,78 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Commandline interface for sysmoISIM-SJA5
(C) 2023 by sysmocom - s.f.m.c. GmbH
All Rights Reserved
Author: Philipp Maier
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import sys, getopt
from utils import *
from simcard import *
from sysmo_isim_sja2 import *
from common import *
class Application(Common):
getopt_dump = False
# Automatically executed by superclass
def _banner(self):
print("sysmoISIM-SJA5 parameterization tool")
print("Copyright (c) 2023 sysmocom - s.f.m.c. GmbH")
print("")
# Automatically executed by superclass
def _options(self, opts):
for opt, arg in opts:
if opt in ("-d", "--dump"):
self.getopt_dump = True
# Automatically executed by superclass when -h or --help is supplied as option
def _helptext(self):
print(" -d, --dump ..................... Dump propritary file contents")
print("")
print(" For Option -T, the following algorithms are valid:")
print('\n'.join([' %d %s' % entry for entry in sysmo_isimsja5_algorithms]))
print("")
# Automatically executed by superclass before _execute() is called
def _init(self):
self.sim = Sysmo_isim_sja5()
# Automatically executed by superclass
def _execute(self):
if self.getopt_dump:
self.sim.dump()
def main(argv):
Application(argv, "d", ["dump"])
if __name__ == "__main__":
main(sys.argv[1:])

View File

@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-
"""
Gadgets to modify SYSMO USIM SJA2 parameters
Gadgets to modify sysmoISIM-SJA2 parameters
(C) 2017 by Sysmocom s.f.m.c. GmbH
(C) 2017-2022 by sysmocom - s.f.m.c. GmbH
All Rights Reserved
Author: Philipp Maier
@ -70,16 +70,23 @@ SYSMO_ISIMSJA2_ALGO_COMP12V2 = 0x02
SYSMO_ISIMSJA2_ALGO_COMP12V3 = 0x03
SYSMO_ISIMSJA2_ALGO_MILENAGE = 0x04
SYSMO_ISIMSJA2_ALGO_SHA1AKA = 0x05
SYSMO_ISIMSJA5_ALGO_TUAK = 0x06
SYSMO_ISIMSJA5_ALGO_XOR_2G = 0x0E
SYSMO_ISIMSJA2_ALGO_XOR = 0x0F
sysmo_isimsja2_algorithms = (
sysmo_isimsja2_algorithms = [
(SYSMO_ISIMSJA2_ALGO_COMP12V1, 'COMP128v1'),
(SYSMO_ISIMSJA2_ALGO_COMP12V2, 'COMP128v2'),
(SYSMO_ISIMSJA2_ALGO_COMP12V3, 'XOR-2G'),
(SYSMO_ISIMSJA2_ALGO_COMP12V3, 'COMP128v3'),
(SYSMO_ISIMSJA2_ALGO_MILENAGE, 'MILENAGE'),
(SYSMO_ISIMSJA2_ALGO_SHA1AKA , 'SHA1-AKA'),
(SYSMO_ISIMSJA2_ALGO_XOR, 'XOR'),
)
]
sysmo_isimsja5_algorithms = sysmo_isimsja2_algorithms + [
(SYSMO_ISIMSJA5_ALGO_XOR_2G, 'XOR-2G'),
(SYSMO_ISIMSJA5_ALGO_TUAK, 'TUAK'),
]
class SYSMO_ISIMSJA2_FILE_EF_XSIM_AUTH_KEY:
"""
@ -111,7 +118,7 @@ class SYSMO_ISIMSJA2_FILE_EF_XSIM_AUTH_KEY:
pfx = " "
dump += pfx + "Algorithm: "
dump += id_to_str(sysmo_isimsja2_algorithms, self.algo)
dump += id_to_str(sysmo_isimsja5_algorithms, self.algo)
dump += "\n"
if self.use_opc == True:
@ -445,6 +452,7 @@ class SYSMO_ISIMSJA2_FILE_EF_USIM_SQN:
class Sysmo_isim_sja2(Sysmo_usim):
algorithms = sysmo_isimsja2_algorithms
def __init__(self):
card_detected = False
@ -532,9 +540,9 @@ class Sysmo_isim_sja2(Sysmo_usim):
self.sim.select(SYSMO_ISIMSJA2_EF_MILENAGE_CFG)
self.sim.update_binary(ef_milenage_cfg.encode())
if self.sim.has_isim:
self.sim.card.SELECT_ADF_ISIM()
self.sim.select(SYSMO_ISIMSJA2_EF_MILENAGE_CFG)
self.sim.update_binary(ef_milenage_cfg.encode())
self.sim.card.SELECT_ADF_ISIM()
self.sim.select(SYSMO_ISIMSJA2_EF_MILENAGE_CFG)
self.sim.update_binary(ef_milenage_cfg.encode())
print("")
@ -583,11 +591,11 @@ class Sysmo_isim_sja2(Sysmo_usim):
print(SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY_2G(res.apdu))
if self.sim.has_isim:
# ADF_ISIM/EF_ISIM_AUTH_KEY_2G:
self.__select_xsim_auth_key(isim = True, _2G = True)
res = self._read_binary(self.sim.filelen)
print(" * ADF_ISIM/EF_ISIM_AUTH_KEY_2G:")
print(SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY_2G(res.apdu))
# ADF_ISIM/EF_ISIM_AUTH_KEY_2G:
self.__select_xsim_auth_key(isim = True, _2G = True)
res = self._read_binary(self.sim.filelen)
print(" * ADF_ISIM/EF_ISIM_AUTH_KEY_2G:")
print(SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY_2G(res.apdu))
# ADF_USIM/EF_USIM_AUTH_KEY:
self.__select_xsim_auth_key(isim = False, _2G = False)
@ -596,11 +604,11 @@ class Sysmo_isim_sja2(Sysmo_usim):
print(SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu))
if self.sim.has_isim:
# ADF_ISIM/EF_ISIM_AUTH_KEY:
self.__select_xsim_auth_key(isim = True, _2G = False)
res = self._read_binary(self.sim.filelen)
print(" * ADF_ISIM/EF_ISIM_AUTH_KEY:")
print(SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu))
# ADF_ISIM/EF_ISIM_AUTH_KEY:
self.__select_xsim_auth_key(isim = True, _2G = False)
res = self._read_binary(self.sim.filelen)
print(" * ADF_ISIM/EF_ISIM_AUTH_KEY:")
print(SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu))
# ADF_USIM/EF_MILENAGE_CFG:
self.sim.select(GSM_SIM_MF)
@ -611,13 +619,13 @@ class Sysmo_isim_sja2(Sysmo_usim):
print(SYSMO_ISIMSJA2_FILE_EF_MILENAGE_CFG(res.apdu))
if self.sim.has_isim:
# ADF_ISIM/EF_MILENAGE_CFG:
self.sim.select(GSM_SIM_MF)
self.sim.card.SELECT_ADF_ISIM()
self.sim.select(SYSMO_ISIMSJA2_EF_MILENAGE_CFG)
res = self._read_binary(self.sim.filelen)
print(" * ADF_ISIM/EF_MILENAGE_CFG:")
print(SYSMO_ISIMSJA2_FILE_EF_MILENAGE_CFG(res.apdu))
# ADF_ISIM/EF_MILENAGE_CFG:
self.sim.select(GSM_SIM_MF)
self.sim.card.SELECT_ADF_ISIM()
self.sim.select(SYSMO_ISIMSJA2_EF_MILENAGE_CFG)
res = self._read_binary(self.sim.filelen)
print(" * ADF_ISIM/EF_MILENAGE_CFG:")
print(SYSMO_ISIMSJA2_FILE_EF_MILENAGE_CFG(res.apdu))
# ADF_USIM/EF_USIM_SQN:
self.sim.select(GSM_SIM_MF)
@ -628,13 +636,13 @@ class Sysmo_isim_sja2(Sysmo_usim):
print(SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu))
if self.sim.has_isim:
# ADF_USIM/EF_ISIM_SQN:
self.sim.select(GSM_SIM_MF)
self.sim.card.SELECT_ADF_ISIM()
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
res = self._read_binary(self.sim.filelen)
print(" * ADF_ISIM/EF_ISIM_SQN:")
print(SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu))
# ADF_USIM/EF_ISIM_SQN:
self.sim.select(GSM_SIM_MF)
self.sim.card.SELECT_ADF_ISIM()
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
res = self._read_binary(self.sim.filelen)
print(" * ADF_ISIM/EF_ISIM_SQN:")
print(SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu))
# Show current KI value
@ -676,11 +684,11 @@ class Sysmo_isim_sja2(Sysmo_usim):
self.sim.update_binary(ef.encode())
if self.sim.has_isim:
self.__select_xsim_auth_key(isim = True, _2G = False)
res = self._read_binary(self.sim.filelen)
ef = SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu)
ef.key = ki
self.sim.update_binary(ef.encode())
self.__select_xsim_auth_key(isim = True, _2G = False)
res = self._read_binary(self.sim.filelen)
ef = SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu)
ef.key = ki
self.sim.update_binary(ef.encode())
print("")
@ -703,8 +711,8 @@ class Sysmo_isim_sja2(Sysmo_usim):
algo_3g = ef.algo
print(" * Current algorithm setting:")
print(" 2G: %d=%s" % (algo_2g, id_to_str(sysmo_isimsja2_algorithms, algo_2g)))
print(" 3G: %d=%s" % (algo_3g, id_to_str(sysmo_isimsja2_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("")
@ -716,16 +724,16 @@ class Sysmo_isim_sja2(Sysmo_usim):
if algo_2g_str.isdigit():
algo_2g = int(algo_2g_str)
else:
algo_2g = str_to_id(sysmo_isimsja2_algorithms, algo_2g_str)
algo_2g = str_to_id(self.algorithms, algo_2g_str)
if algo_3g_str.isdigit():
algo_3g = int(algo_3g_str)
else:
algo_3g = str_to_id(sysmo_isimsja2_algorithms, algo_3g_str)
algo_3g = str_to_id(self.algorithms, algo_3g_str)
print(" * New algorithm setting:")
print(" 2G: %d=%s" % (algo_2g, id_to_str(sysmo_isimsja2_algorithms, algo_2g)))
print(" 3G: %d=%s" % (algo_3g, id_to_str(sysmo_isimsja2_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(" * Programming...")
@ -742,11 +750,11 @@ class Sysmo_isim_sja2(Sysmo_usim):
self.sim.update_binary(ef.encode())
if self.sim.has_isim:
self.__select_xsim_auth_key(isim = True, _2G = False)
res = self._read_binary(self.sim.filelen)
ef = SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu)
ef.algo = algo_3g
self.sim.update_binary(ef.encode())
self.__select_xsim_auth_key(isim = True, _2G = False)
res = self._read_binary(self.sim.filelen)
ef = SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu)
ef.algo = algo_3g
self.sim.update_binary(ef.encode())
print("")
@ -795,12 +803,12 @@ class Sysmo_isim_sja2(Sysmo_usim):
self.sim.update_binary(ef.encode())
if self.sim.has_isim:
self.__select_xsim_auth_key(isim = True, _2G = False)
res = self._read_binary(self.sim.filelen)
ef = SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu)
ef.opc = op
ef.use_opc = bool(select)
self.sim.update_binary(ef.encode())
self.__select_xsim_auth_key(isim = True, _2G = False)
res = self._read_binary(self.sim.filelen)
ef = SYSMO_ISIMSJA2_FILE_EF_USIM_AUTH_KEY(res.apdu)
ef.opc = op
ef.use_opc = bool(select)
self.sim.update_binary(ef.encode())
self.__select_xsim_auth_key(isim = False, _2G = False)
res = self._read_binary(self.sim.filelen)
@ -825,12 +833,12 @@ class Sysmo_isim_sja2(Sysmo_usim):
print(SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu))
if self.sim.has_isim:
print(" * Current SQN Configuration for ADF_ISIM:")
self.sim.select(GSM_SIM_MF)
self.sim.card.SELECT_ADF_ISIM()
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
res = self._read_binary(self.sim.filelen)
print(SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu))
print(" * Current SQN Configuration for ADF_ISIM:")
self.sim.select(GSM_SIM_MF)
self.sim.card.SELECT_ADF_ISIM()
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
res = self._read_binary(self.sim.filelen)
print(SYSMO_ISIMSJA2_FILE_EF_USIM_SQN(res.apdu))
print("")
@ -849,9 +857,53 @@ class Sysmo_isim_sja2(Sysmo_usim):
self.sim.update_binary(ef.encode())
if self.sim.has_isim:
self.sim.card.SELECT_ADF_ISIM()
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
ef = SYSMO_ISIMSJA2_FILE_EF_USIM_SQN()
self.sim.update_binary(ef.encode())
self.sim.card.SELECT_ADF_ISIM()
self.sim.select(SYSMO_ISIMSJA2_EF_USIM_SQN)
ef = SYSMO_ISIMSJA2_FILE_EF_USIM_SQN()
self.sim.update_binary(ef.encode())
print("")
class Sysmo_isim_sja5(Sysmo_isim_sja2):
algorithms = sysmo_isimsja5_algorithms
def __init__(self):
card_detected = False
# Try card model #1: sysmoISIM-SJA5 (9FV)
try:
atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 35 75 30 35 02 59 C4"
print("Trying to find card with ATR: " + atr)
Sysmo_usim.__init__(self, atr)
card_detected = True
except:
print(" * Card not detected!")
if card_detected == True:
return
# Try card model #2: sysmoISIM-SJA5 (SLM17)
try:
atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 35 75 30 35 02 65 F8"
print("Trying to find card with ATR: " + atr)
Sysmo_usim.__init__(self, atr)
card_detected = True
except:
print(" * Card not detected!")
if card_detected == True:
return
# Try card model #3: sysmoISIM-SJA5 (3FJ)
try:
atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 35 75 30 35 02 51 CC"
print("Trying to find card with ATR: " + atr)
Sysmo_usim.__init__(self, atr)
card_detected = True
except:
print(" * Card not detected!")
# Exit when we are not able to detect the card
if card_detected != True:
sys.exit(1)