aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpySim-prog.py18
-rw-r--r--pySim/cards.py3
2 files changed, 18 insertions, 3 deletions
diff --git a/pySim-prog.py b/pySim-prog.py
index 481d070..2ed3260 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -99,6 +99,10 @@ def parse_options():
parser.add_option("-k", "--ki", dest="ki",
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",
help="Secret used for ICCID/IMSI autogen",
@@ -305,6 +309,16 @@ def gen_parameters(opts):
else:
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 {
'name' : opts.name,
@@ -314,6 +328,7 @@ def gen_parameters(opts):
'imsi' : imsi,
'smsp' : smsp,
'ki' : ki,
+ 'opc' : opc,
}
@@ -326,6 +341,7 @@ def print_parameters(params):
> MCC/MNC : %(mcc)d/%(mnc)d
> IMSI : %(imsi)s
> Ki : %(ki)s
+ > OPC : %(opc)s
""" % params
@@ -333,7 +349,7 @@ def write_parameters(opts, params):
# CSV
if opts.write_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')
cw = csv.writer(f)
cw.writerow([params[x] for x in row])
diff --git a/pySim/cards.py b/pySim/cards.py
index fe8a6c9..88eceb0 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -337,9 +337,8 @@ class SysmoUSIMgr1(Card):
data, sw = self._scc._tp.send_apdu_checksw("0020000A083332323133323332")
# TODO: move into SimCardCommands
- # TODO: Add OPC support support to pySIM
par = ( p['ki'] + # 16b K
- 32*"F" + # 32b OPC
+ p['opc'] + # 32b OPC
self._e_iccid(p['iccid']) + # 10b ICCID
self._e_imsi(p['imsi']) # 9b IMSI_len + id_type(9) + IMSI
)