mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-28 08:18:36 +03:00
usim/opc: Add support to write completely random OPC
Allow to set the OPC, write it out to the state, generate it randomly.
This commit is contained in:
committed by
Holger Hans Peter Freyther
parent
4d91bf449f
commit
93b38cd0f5
@@ -99,6 +99,10 @@ def parse_options():
|
|||||||
parser.add_option("-k", "--ki", dest="ki",
|
parser.add_option("-k", "--ki", dest="ki",
|
||||||
help="Ki (default is to randomize)",
|
help="Ki (default is to randomize)",
|
||||||
)
|
)
|
||||||
|
parser.add_option("-o", "--opc", dest="opc",
|
||||||
|
help="OPC (default is to randomize)",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
parser.add_option("-z", "--secret", dest="secret", metavar="STR",
|
parser.add_option("-z", "--secret", dest="secret", metavar="STR",
|
||||||
help="Secret used for ICCID/IMSI autogen",
|
help="Secret used for ICCID/IMSI autogen",
|
||||||
@@ -305,6 +309,16 @@ def gen_parameters(opts):
|
|||||||
else:
|
else:
|
||||||
ki = ''.join(['%02x' % random.randrange(0,256) for i in range(16)])
|
ki = ''.join(['%02x' % random.randrange(0,256) for i in range(16)])
|
||||||
|
|
||||||
|
# Ki (random)
|
||||||
|
if opts.opc is not None:
|
||||||
|
opc = opts.opc
|
||||||
|
if not re.match('^[0-9a-fA-F]{32}$', opc):
|
||||||
|
raise ValueError('OPC needs to be 128 bits, in hex format')
|
||||||
|
|
||||||
|
else:
|
||||||
|
opc = ''.join(['%02x' % random.randrange(0,256) for i in range(16)])
|
||||||
|
|
||||||
|
|
||||||
# Return that
|
# Return that
|
||||||
return {
|
return {
|
||||||
'name' : opts.name,
|
'name' : opts.name,
|
||||||
@@ -314,6 +328,7 @@ def gen_parameters(opts):
|
|||||||
'imsi' : imsi,
|
'imsi' : imsi,
|
||||||
'smsp' : smsp,
|
'smsp' : smsp,
|
||||||
'ki' : ki,
|
'ki' : ki,
|
||||||
|
'opc' : opc,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -326,6 +341,7 @@ def print_parameters(params):
|
|||||||
> MCC/MNC : %(mcc)d/%(mnc)d
|
> MCC/MNC : %(mcc)d/%(mnc)d
|
||||||
> IMSI : %(imsi)s
|
> IMSI : %(imsi)s
|
||||||
> Ki : %(ki)s
|
> Ki : %(ki)s
|
||||||
|
> OPC : %(opc)s
|
||||||
""" % params
|
""" % params
|
||||||
|
|
||||||
|
|
||||||
@@ -333,7 +349,7 @@ def write_parameters(opts, params):
|
|||||||
# CSV
|
# CSV
|
||||||
if opts.write_csv:
|
if opts.write_csv:
|
||||||
import csv
|
import csv
|
||||||
row = ['name', 'iccid', 'mcc', 'mnc', 'imsi', 'smsp', 'ki']
|
row = ['name', 'iccid', 'mcc', 'mnc', 'imsi', 'smsp', 'ki', 'opc']
|
||||||
f = open(opts.write_csv, 'a')
|
f = open(opts.write_csv, 'a')
|
||||||
cw = csv.writer(f)
|
cw = csv.writer(f)
|
||||||
cw.writerow([params[x] for x in row])
|
cw.writerow([params[x] for x in row])
|
||||||
|
|||||||
@@ -337,9 +337,8 @@ class SysmoUSIMgr1(Card):
|
|||||||
data, sw = self._scc._tp.send_apdu_checksw("0020000A083332323133323332")
|
data, sw = self._scc._tp.send_apdu_checksw("0020000A083332323133323332")
|
||||||
|
|
||||||
# TODO: move into SimCardCommands
|
# TODO: move into SimCardCommands
|
||||||
# TODO: Add OPC support support to pySIM
|
|
||||||
par = ( p['ki'] + # 16b K
|
par = ( p['ki'] + # 16b K
|
||||||
32*"F" + # 32b OPC
|
p['opc'] + # 32b OPC
|
||||||
self._e_iccid(p['iccid']) + # 10b ICCID
|
self._e_iccid(p['iccid']) + # 10b ICCID
|
||||||
self._e_imsi(p['imsi']) # 9b IMSI_len + id_type(9) + IMSI
|
self._e_imsi(p['imsi']) # 9b IMSI_len + id_type(9) + IMSI
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user