blob: cd5992bf473de75fa0e1d2e3b56154c32cce6c0c [file] [log] [blame]
Harald Weltee6124b02024-01-25 09:08:26 +01001#!/usr/bin/env python3
2
3# Command line tool to compute or verify EID (eUICC ID) values
4#
5# (C) 2024 by Harald Welte <laforge@osmocom.org>
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20import sys
21import argparse
22
23from pySim.euicc import compute_eid_checksum, verify_eid_checksum
24
25
26option_parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
27 description="""pySim EID Tool
28This utility program can be used to compute or verify the checksum of an EID
29(eUICC Identifier). See GSMA SGP.29 for the algorithm details.
30
31Example (verification):
32 $ eidtool.py --verify 89882119900000000000000000001654
33 EID checksum verified successfully
34
35Example (generation, passing first 30 digits):
36 $ eidtool.py --compute 898821199000000000000000000016
37 89882119900000000000000000001654
38
39Example (generation, passing all 32 digits):
40 $ eidtool.py --compute 89882119900000000000000000001600
41 89882119900000000000000000001654
42
43Example (generation, specifying base 30 digits and number to add):
44 $ eidtool.py --compute 898821199000000000000000000000 --add 16
45 89882119900000000000000000001654
46""")
47group = option_parser.add_mutually_exclusive_group(required=True)
48group.add_argument('--verify', help='Verify given EID csum')
49group.add_argument('--compute', help='Generate EID csum')
50option_parser.add_argument('--add', type=int, help='Add value to EID base before computing')
51
52
53if __name__ == '__main__':
54 opts = option_parser.parse_args()
55
56 if opts.verify:
57 res = verify_eid_checksum(opts.verify)
58 if res:
59 print("EID checksum verified successfully")
60 sys.exit(0)
61 else:
62 print("EID checksum invalid")
63 sys.exit(1)
64 elif opts.compute:
65 eid = opts.compute
66 if opts.add:
67 if len(eid) != 30:
68 print("EID base must be 30 digits when using --add")
69 sys.exit(2)
70 eid = str(int(eid) + int(opts.add))
71 res = compute_eid_checksum(eid)
72 print(res)
73