mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-16 18:38:32 +03:00
We're creating a 'pyosmocom' pypi module which contains a number of core Osmocom libraries / interfaces that are not specific to SIM card stuff contained here. The main modules moved in this initial step are pySim.tlv, pySim.utils and pySim.construct. utils is split, not all of the contents is unrelated to SIM Cards. The other two are moved completely. Change-Id: I4b63e45bcb0c9ba2424dacf85e0222aee735f411
94 lines
3.4 KiB
Python
94 lines
3.4 KiB
Python
"""GlobalPlatform Remote Application Management over HTTP Card Specification v2.3 - Amendment B.
|
|
Also known as SCP81 for SIM/USIM/UICC/eUICC/eSIM OTA.
|
|
"""
|
|
|
|
# (C) 2024 by Harald Welte <laforge@osmocom.org>
|
|
#
|
|
# 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/>.
|
|
|
|
from construct import Struct, Int8ub, Int16ub, Bytes, GreedyBytes, GreedyString, BytesInteger
|
|
from construct import this, len_, Rebuild, Const
|
|
from construct import Optional as COptional
|
|
from osmocom.tlv import BER_TLV_IE
|
|
|
|
from pySim import cat
|
|
|
|
|
|
# Table 3-3 + Section 3.8.1
|
|
class RasConnectionParams(BER_TLV_IE, tag=0x84, nested=cat.OpenChannel.nested_collection_cls.possible_nested):
|
|
pass
|
|
|
|
# Table 3-3 + Section 3.8.2
|
|
class SecurityParams(BER_TLV_IE, tag=0x85):
|
|
_test_de_encode = [
|
|
( '850804deadbeef020040', {'kid': 64,'kvn': 0, 'psk_id': b'\xde\xad\xbe\xef', 'sha_type': None} )
|
|
]
|
|
_construct = Struct('_psk_id_len'/Rebuild(Int8ub, len_(this.psk_id)), 'psk_id'/Bytes(this._psk_id_len),
|
|
'_kid_kvn_len'/Const(2, Int8ub), 'kvn'/Int8ub, 'kid'/Int8ub,
|
|
'sha_type'/COptional(Int8ub))
|
|
|
|
# Table 3-3 + ?
|
|
class ExtendedSecurityParams(BER_TLV_IE, tag=0xA5):
|
|
_construct = GreedyBytes
|
|
|
|
# Table 3-3 + Section 3.8.3
|
|
class SessionRetryPolicyParams(BER_TLV_IE, tag=0x86):
|
|
_construct = Struct('retry_counter'/Int16ub,
|
|
'retry_waiting_delay'/BytesInteger(5),
|
|
'retry_report_failure'/COptional(GreedyBytes))
|
|
|
|
# Table 3-3 + Section 3.8.4
|
|
class AdminHostParam(BER_TLV_IE, tag=0x8A):
|
|
_test_de_encode = [
|
|
( '8a0a61646d696e2e686f7374', 'admin.host' ),
|
|
]
|
|
_construct = GreedyString('utf-8')
|
|
|
|
# Table 3-3 + Section 3.8.5
|
|
class AgentIdParam(BER_TLV_IE, tag=0x8B):
|
|
_construct = GreedyString('utf-8')
|
|
|
|
# Table 3-3 + Section 3.8.6
|
|
class AdminUriParam(BER_TLV_IE, tag=0x8C):
|
|
_test_de_encode = [
|
|
( '8c1668747470733a2f2f61646d696e2e686f73742f757269', 'https://admin.host/uri' ),
|
|
]
|
|
_construct = GreedyString('utf-8')
|
|
|
|
# Table 3-3
|
|
class HttpPostParams(BER_TLV_IE, tag=0x89, nested=[AdminHostParam, AgentIdParam, AdminUriParam]):
|
|
pass
|
|
|
|
# Table 3-3
|
|
class AdmSessionParams(BER_TLV_IE, tag=0x83, nested=[RasConnectionParams, SecurityParams,
|
|
ExtendedSecurityParams, SessionRetryPolicyParams,
|
|
HttpPostParams]):
|
|
pass
|
|
|
|
# Table 3-3 + Section 3.11.4
|
|
class RasFqdn(BER_TLV_IE, tag=0xD6):
|
|
_construct = GreedyBytes # FIXME: DNS String
|
|
|
|
# Table 3-3 + Section 3.11.7
|
|
class DnsConnectionParams(BER_TLV_IE, tag=0xFA, nested=cat.OpenChannel.nested_collection_cls.possible_nested):
|
|
pass
|
|
|
|
# Table 3-3
|
|
class DnsResolutionParams(BER_TLV_IE, tag=0xB3, nested=[RasFqdn, DnsConnectionParams]):
|
|
pass
|
|
|
|
# Table 3-3
|
|
class AdmSessTriggerParams(BER_TLV_IE, tag=0x81, nested=[AdmSessionParams, DnsResolutionParams]):
|
|
pass
|