From fb20b7bc58b17ed4fff09e23e1ef357a56ba3bbf Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 18 Nov 2025 01:17:57 +0100 Subject: [PATCH] contrib: Add a small command line script to generate StoreMetadataRequest It's occasionally useful to be able to manually generate a SGP.22 StoreMetadataRequest (tag BF25), so let's add a small utility program doing exactly that. Change-Id: I56ebd040f09dcd167b0b22148c2f1af56240b3b5 --- contrib/esim_gen_metadata.py | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 contrib/esim_gen_metadata.py diff --git a/contrib/esim_gen_metadata.py b/contrib/esim_gen_metadata.py new file mode 100755 index 00000000..1f092745 --- /dev/null +++ b/contrib/esim_gen_metadata.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +# (C) 2025 by Harald Welte +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import argparse +from osmocom.utils import h2b, swap_nibbles +from pySim.esim.es8p import ProfileMetadata + +parser = argparse.ArgumentParser(description="""Utility program to generate profile metadata in the +StoreMetadataRequest format based on input values from the command line.""") +parser.add_argument('--iccid', required=True, help="ICCID of eSIM profile"); +parser.add_argument('--spn', required=True, help="Service Provider Name"); +parser.add_argument('--profile-name', required=True, help="eSIM Profile Name"); +parser.add_argument('--profile-class', choices=['test', 'operational', 'provisioning'], + default='operational', help="Profile Class"); +parser.add_argument('--outfile', required=True, help="Output File Name"); + +if __name__ == '__main__': + opts = parser.parse_args() + + iccid_bin = h2b(swap_nibbles(opts.iccid)) + pmd = ProfileMetadata(iccid_bin, spn=opts.spn, profile_name=opts.profile_name, + profile_class=opts.profile_class) + + with open(opts.outfile, 'wb') as f: + f.write(pmd.gen_store_metadata_request()) + print("Written StoreMetadataRequest to '%s'" % opts.outfile)