分类目录归档:sim

RSA

有OpenSSL生成RSA私钥 (其实应该叫 keypair,里面也有公钥的modulus)

openssl genrsa -out private.pem 512

由私钥 生成 公钥

openssl rsa -in private.pem  -pubout -out public.pem

默认格式是pem,所以不必要加 -outform PEM 选项>

从公钥中查看 modulus

openssl rsa -pubin -in public.pem -modulus -noout

列出modulus和Exponent

openssl rsa -pubin -in public.pem -text -noout

exponent一般为 65537 (0x10001)<

查看密钥对信息

openssl rsa -in private.pem -text -noout

privateExponent是由 prime1 prime2 exponent1 exponent2 生成,都应该保密

EF_SMS短消息文件

在UST(USIM Service Table)中 10号服务可用,那么EF_SMS文件应该存在。 文件标识 6F3C 结构: 线性定长 记录长度: 176字节 每条记录的第1个字节 状态 This data item commences with the TS-Service-Centre-Address as specified in TS 24.011 The bytes
immediately following the TS-Service-Centre-Address contain an appropriate short message TPDU as specified in
TS 23.040 [6], with identical coding and ordering of parameter

simtrace2使用记录

USB 转UART 连接 simtrace的debug接口(管脚1为 地, 4为发送, 5 为接收)

在PC上配置串口 (921600 8N1)
波特率 921600
8位数据位
无奇偶校验
停止位 1

重启板子(按 RESET 按钮, 或者 重新拔插 usb线缆)
在串口会看到输出


DFU模式(Device Firmware Upgrade)

firemware编译出 几种应用:
dfu: USB DFU 启动加载器,用来 升级其他应用的
ccid: USB CCID读卡器
cardem: 卡模拟,提供本地cos,以及远程sim卡功能
trace: 监听sim卡和设备间的通信
triple_play: 支持 ccid, cardem, trace三种功能,通过usb来配置。


应用可以放在设备的不同位置
flash
bootloader区域内(第1个16k区域保留为bootloader所用,dfu放这里)
ram (通过 jtag/swd 直接下载到ram)

iPhone debugserver lldb IDA调试

越狱后iPhone(iPad或iPod)

获取debugserver

  1. xcode新建一个singleview的简单项目,在iPhone设备上跑一遍。这样在设备的/Developer/usr/bin 下就会有debugserver
  2. 第二种方法,在 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/ 里找到对应版本的DeveloperDiskImage.dmg, 从里面提取

添加权限

分离fat binary
lipo -thin armv7s ~/debugserver -output ~/debugserver_7s
lipo -thin arm64 ~/debugserver -output ~/debugserver_64  (iPhone 6之后是 64位的)

强制添加权限
codesign -s - --entitlements entitlements.xml -f debugserver_7s

查看权限
codesign -d --entitlements :-  debugserver_7s
codesign -d --entitlements -   debugserver_7s


权限文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.backboardd.debugapplications</key>
    <true/>
    <key>com.apple.backboardd.launchapplications</key>
    <true/>
    <key>com.apple.springboard.debugapplications</key>
    <true/>
    <key>run-unsigned-code</key>
    <true/>
    <key>get-task-allow</key>
    <true/>
    <key>task_for_pid-allow</key>
    <true/>
</dict>
</plist>

0000000

开启端口转发
./tcprelay.py -i 192.168.0.119 -b 8192 -t 22:2222 8341:8341

ssh -v root@192.168.0.119 -p 2222
附加到被调试进程

debugserver *:8341 --attach Preferences

开启lldb

(lldb) platform select remote-ios
(lldb) process connect connect://192.168.0.119:1234
(lldb) po [[UIApp keyWindow] recursiveDescription]

iOs开发命令行程序

Virtualbox虚拟机导入 macOS Catalina Final Version by Geekrar的vmdk
app store下载安装XCode

xcrun --sdk iphoneos --find clang
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang



xcrun --sdk iphoneos --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk

编译命令

clang -arch armv7s -mios-version-min=7.0   imei.im -o imei \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk  \
-framework Foundation  -framework CoreTelephony

签名

codesign -s 'iPhone Develoer' ./path/to/binary

Android CarrierConfigManager和CarrierService

将运营商 ID 与 CarrierConfig 集成
从 Android 10 开始,运营商配置支持将运营商 ID 用作密钥,从 CarrierService 获取运营商专属配置。

将运营商 ID 与 CarrierConfig 集成具有以下优势:

将每个运营商的所有 MCC/MNC 对整合到一个位置,从而移除重复或不一致的数据。
为每个运营商创建规范标识符并消除歧义。

允许使用单个 ID 标识移动虚拟网络运营商 (MVNO),而不是将配置作为移动网络运营商 (MNO) 的一部分。

final CarrierConfigManager configManager = (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);

PersistableBundle b = configManager.getConfig();
b.putBoolean(KEY_PREFER_2G_BOOL, false);

b.putBoolean(KEY_DISPLAY_HD_AUDIO_PROPERTY_BOOL, true);

v4.putBoolean(“prefer_2g_bool”, false);
v4.putBoolean(“carrier_settings_enable_bool”, true);
v4.putBoolean(“carrier_allow_turnoff_ims_bool”, false);
v4.putBoolean(“carrier_wfc_ims_available_bool”, true);
v4.putBoolean(“display_hd_audio_property_bool”, true);
v4.putBoolean(“editable_enhanced_4g_lte_bool”, true);
v4.putBoolean(“carrier_volte_available_bool”, true);
v4.putBoolean(“carrier_volte_provisioning_required_bool”, false);
v4.putBoolean(“carrier_volte_provisioned_bool”, true);
v4.putBoolean(“carrier_vt_available_bool”, true);
v4.putBoolean(“carrier_volte_tty_supported_bool”, false);
v4.putBoolean(“hide_enhanced_4g_lte_bool”, false);
v4.putBoolean(“carrier_wfc_supports_wifi_only_bool”, true);
v4.putBoolean(“allow_adding_apns_bool”, true);
v4.putBoolean(“apn_expand_bool”, true);
v4.putBoolean(“carrier_ims_gba_required_bool”, false);
v4.putBoolean(“require_entitlement_checks_bool”, false);
v4.putBoolean(“hide_ims_apn_bool”, false);
v4.putInt(“volte_replacement_rat_int”, 0);
v4.putBoolean(“carrier_use_ims_first_for_emergency_bool”, true);
v4.putBoolean(“auto_retry_enabled_bool”, true);
v4.putBoolean(“world_phone_bool”, true);
v4.putBoolean(“carrier_ut_provisioning_required_bool”, false);
v4.putBoolean(“carrier_supports_ss_over_ut_bool”, false);
v4.putBoolean(“carrier_volte_default_enabled_bool”, true);
v4.putBoolean(“show_ims_registration_status_bool”, true);
v4.putBoolean(“support_manage_ims_conference_call_bool”, true);
v4.putBoolean(“support_ims_conference_call_bool”, true);
v4.putBoolean(“support_video_conference_call_bool”, true);
v4.putBoolean(“enhanced_4g_lte_on_by_default_bool”, true);
v4.putBoolean(“editable_wfc_mode_bool”, true);
v4.putBoolean(“emergency_sms_support_bool”, false);
v4.putBoolean(“notify_handover_video_from_wifi_to_lte_bool”, true);
v4.putBoolean(“notify_handover_video_from_lte_to_wifi_bool”, true);
v4.putBoolean(“support_downgrade_vt_to_audio_bool”, true);
v4.putInt(“carrier_default_wfc_ims_mode_int”, 1);
v4.putInt(“carrier_default_wfc_ims_roaming_mode_int”, 1);
v4.putBoolean(“carrier_default_wfc_ims_enabled_bool”, true);
v4.putBoolean(“carrier_default_wfc_ims_roaming_enabled_bool”, true);
v4.putBoolean(“carrier_promote_wfc_on_call_fail_bool”, true);
v4.putBoolean(“carrier_volte_override_wfc_provisioning_bool”, true);
v4.putBoolean(“allow_emergency_video_calls_bool”, false);
v4.putBoolean(“editable_wfc_roaming_mode_bool”, true);
v4.putBoolean(“carrier_config_applied_bool”, true);
v4.putStringArray(“carrier_wlan_disallowed_apn_types_string_array”, new String[]{“”});
v4.putStringArray(“carrier_wwan_disallowed_apn_types_string_array”, new String[]{“”});
v4.putBoolean(“hide_preset_apn_details_bool”, false);
v4.putStringArray(“read_only_apn_types_string_array”, new String[]{“”});
v4.putStringArray(“read_only_apn_fields_string_array”, new String[]{“”});
v4.putStringArray(“apn_settings_default_apn_types_string_array”, new String[]{“”});

Toolkit Applet

普通Java Card applet和Tookit applet的区别是,后者不直接处理APDU. 它只处理高层级的消息(事件)。

另外,后者一个方法(java method)的执行,能够跨越多个APDU(Fetch, Terminal Resposne等主动命令)。

并且,Tookiet applet 的触发,不会调用 select()方法,只会调用processTookit()

EVENT_EVENT_DOWNLOAD_CALL_DISCONNECTED
EVENT_EVENT_DOWNLOAD_LOCATION_STATUS
EVENT_EVENT_DOWNLOAD_DATA_AVAILABLE
EVENT_EVENT_DOWNLOAD_ACCESS_TECHNOLOGY_CHANGE
EVENT_UNRECOGNIZED_ENVELOPE

Java Card Tookit相关对象
1. ProactiveHandler
1) 在 Terminal Profile 命令被CAT运行环境处理之前, ProactiveHandler对象不可用。
2) 如果 ProactiveHandler对象 可用,它将一直保持可用,直到processToolkit()方法结束
3)ProactiveHandler不可用, 主动命令将被挂起
4) 调用 proHdlr.init()方法,将会清除 主动命令的内容,然后再初始化

  1. EnvelopeHandler
    1) 在 processToolkit()方法的调用 到结束的过程中,如果 EnvelopeHandler 可用,将在整个过程中保持可用。
    2) 它的TLV列表,是用 ENVELOPE 命令的APDU里的简单TLV数据对象填充的,并且保持原有的顺序。

TERMINAL PROFILE

uicc初始化过程中 , 终端回发送 profile download命令给uicc

如果支持 s 级,只要 通过 modem接口 访问 CAT功能的已连接实体  连接/端口/改变profile ,都会发送profile download指令。

过程定义在  ETSI TS 102.221 (Smart Cards; UICC-Terminal interface;Physical and logical characteristics) 规范中。

这个过程让UICC知道 终端有哪些能力,然后UICC决定使用那些终端可以支持的CAT指令。

如果终端不发送profile download指令,那么UICC应该认为终端不支持CAT.

80 10 00 00 23
10
FF FF FF FF -7F 9F- 00- DF FF 00 00 1F E2 08 11 06
C7 C0 00 00 00 00 40 00 51 00 00 00 00 18 00 00
03 00 00
91 0E

1个字节(下载能力)

Call Control by NAA

USSD string data object support in Call Contrl by USIM

Timer expiration

SMS-PP data download

Menu selection

Cell Broadcatst data download

SMS-PP data download

Profile download

第2个字节

Display text

UCS2 Display suported

UCS2 Enctry supported

Call Control by NAA

MO short message control support

Call Control by NAA

Call Control by NAA

Command result

第3个字节(Proactive UICC)

Refresh

Polling Off

Poll Interval

Play Tone

More Time

Get Input

Get InKey

Display Text

第4个字节(Proactive UICC)

Provide Local Information (NMR)  —此功能不支持

Provide Local Information(MCC, MNC, LAC, Cell Id, IMEI)

Set Up MENU

Set Up CALL

Send USSD

Send SS

Send Short Message with 3GPP SMS TPDU

Select Item

0111 1111

第5个字节(事件驱动信息)

Card reader status事件

Idle screen avaiable事件 (不支持)

User activity  (不支持)

Location status

Call disconnected

Call connected

MT Call

Proactive UICC: Set UP Event List

1001 1111

第6字节(事件驱动信息扩展)

Language Selection

Broswer Termination( “ac”被支持)

Data avaiable

Channel status

Access Technolopy Change

Disaplay parameters changes

Local Connection

Network Search Mode Change

全不支持

第7个字节(为 class a的Multi card proactive commands)

Power On Card

Power Off Card

Perform Card APDU

Get Reader Status(card reader status)

Get Reader Status(card reader identifier)

RFU=0

第8个字节 (Proactive UICC)

Call Control by NAA (Network Access Application)

Setup Call

Run AT Command(也就是b class被支持 )   (此功能不支持)

Setup Idel Mode text

Get InKey

Proactive UICC: Provider Local Infromation(date/time/timezone)

Proactive UICC: Timer Management(get current value)

Proactive UICC: Timer Management(start/stop)

1101 1111

第9字节

Proactive UICC:  Provide Local Information(Access Technology)

Proactive UICC:   Lanch Browser( class “ab” 支持)

Proactive UICC:   Language Notification

Proactive UICC:  Provide Local Information (Timing Advance)

Proactive UICC:  Provide Local Information (language)

Proactive UICC: Provide Local Information (NMR)

Send DTMF command

Display Text

第10字节 (软键盘支持)

RFU=0

RFU=0

RFU=0

RFU=0

RFU=0

RFU=0

Soft Key支持:Select Item

Soft Key支持: Setup Menu

第11字节(soft key info)

第12字节 (BIP proactive commands)

Proactive UICC: Declare Service  (不支持)

Proactive UICC: Get Service Information (不支持)

Proactive UICC: Service Search  (不支持)

Proactive UICC: Get Channel Status

Proactive UICC: Send Data

Proactive UICC: Receive Data

Proactive UICC: Close Channel

Proactive UICC: Open Channel

0001 1111

第13字节: (BIP支持的bearers)

b8-b6 = 终端支持的通道数

RS232

IrDA

Bluetooth

GPRS

CSD

1110 0010 也就是,支持的通道数为8, 仅支持GPRS

第14字节:(屏幕高度)

第15字节:(屏幕宽度)

第16字节: (屏幕效果)

第17字节: (BIP支持的传输接口/承载)

HSDPA

E-UTRAN

直接通信通道

UDP(UICC处于客户模式,本地连接)

TCP(UICC处于客户模式,本地连接)

TCP(UICC服务器模式)

UDP(UICC客户模式,远程连接)

TCP(UICC客户模式,远程连接)

第18字节:

Proactive UICC:  Provide Local Information(Search Mode Change)

第19字节: TIA/EIA-136-270 设施

第20字节:  3GPP2 C.S0035-B CCAT

CDMA CSIM应用

第21字节: 浏览器能力

b8-b5  RFU=0

CHTML

HTML

XHMTL

WML

第35字节:

b8-b5 RFU=0

Refresh with “Application Update” mode

Data conection Status Change Event support-PDN Connection

Data conection Status Change Event support-PDP Connection

Proactive UICC: GET INPUT (Variable Time out)


80 12 00 00 0E
12

D0 (Proactive UICC command tag)

0C   (command length)

81 (Command details tag) 03   01 (Command number) 05(SET UP EVENT LIST) 00 (Command Qualifier=RFU)

82 (Device identity tag)02 81 (UICC) 82(terminal)

99 (Event list tag) 01 03 (Location status)
90 00


80 14 00 00 0C
14
81 (Command details) 03 01 05(set up event) 00

02(Device identities)02 82(terminal) 81 (UICC)

83 (Result)01 00
90 00

表示  set up event list 命令,成功执行

参考:TS 102.223  第98页 Structure of TERMINAL RESPONSE


80 C2 00 00 17
C2
D6 (Event download)15

99 (Event list)01 03 (location status)

82 (Device identity)02 82 (terminal) 81 (uicc)

9B (Location status) 01 00 (Normal Service)

93 09

64 F0 00  70 CE (TAC)  F1 41 38 1F(Cell Id)
91 12

80 12 00 00 12
12
D0 (Proactive UICC command )10

81 (Command details)03 01 (Command number)   21 (Command Type=display text) 80 ( 1000 0000)

82 (Device identity)02 81 02

8D (Text string) 05    48 65 6C 6C 6F
90 00

bit 8 = 1 wait for user to clear message

bit 1 = 0 normal priority


80 C2 00 00 17
C2
D6 15

99 01 03

82 02 82 81

9B 01 00

93 09

64 F0 (MCC) 00 (MNC) 70 CE(LAC/TAC) F1 45 28 1F (Cell Id)
90 00


80 14 00 00 0C
14
81 ( (Command details) 03 01 21(display tex) 80

82 (Device identities)02 82 81

83 (result)01 00

90 00

报告显示文字任务,成功执行

stk事件

EVENT_PROFILE_DOWNLOAD 获取移动设备的能力
EVENT_STATUS_COMMAND 当移动设备份发送STATUS命令,得到触发
EVENT_UNRECOGNIZED_ENVELOPE 处理未定义的事件,将来升级用
EVENT_FORMATTED_SMS_PP_ENV 处理来自网络的SMS-PP消息
EVENT_FORMATEDD_SMS_PP_UPD
EVENT_UNFORMATTED_SMS_PP_ENV
EVENT_UNFORMATTED_SMS_PP_UPD
EVENT_UNFORMATTED_SMS_CB
EVENT_FORMATTED_SMS_CB
EVENT_FORMATTED_USSD
EVENT_UNFORMATTED_USSD
EVENT_TIMER_EXPIRATION
EVENT_CALL_CONTROL_BY_NAA
EVENT_MO_SHORT_MESSAGE_CONTROL_BY_NAA
EVENT_EVENT_DOWNLOAD_
_MT_CALL
_CALL_CONNNECTED
_CALL_DISCONNECTED
_LOCATION_STATUS
_USER_ACTIVITY
_IDEL_SCREEN_AVAILABLE
_CARD_READER_STATUS
_LANGUAGE_SELECTION
_BROWSER_TERMINATION
_DATA_AVAILABLE
_CHANNEL_STATUS
_ACCESS_TECHNOLOGY_CHANGE
_DISPLAY_PARAMETER_CHANGED
_LOCAL_CONNECTION
_NETWORK_SEARCH_MODE_CHANGE
_BROWSING_STATUS
_IWLAN_ACCESS_STATUS
EVENT_PROACTIVE_HANDLER_AVAILABLE
EVENT_EXTERNAL_FILE_UPDATE
EVENT_APPLICATION_DESELECT
EVENT_FIRST_COMMAND_AFTER_ATR

移动通信中的Java Card标准

ETSI TS 102 241 : Smart cards, UICC Application Programming Interface (UICC API) for Java Card

3GPP TS 31.130 : (U)SIM Application Programming Interface,((U)SIM API) for Java Card

102 241 定义的包
uicc.access
访问UICC文件系统
uicc.access.fileadministration
管理UICC文件系统
uicc.system
允许建立 实现TLV handler借口的对象
uicc.toolkit
注册CAT框架时间, 处理TLV信息
按照 TS 102.223规范,发送 主动命令

31.130 定义的包

uicc.usim.access
访问 USIM/SIM中定义的文件

uicc.usim.toolkit
注册USAT/STK中定义的事件
处理TLV信息
按照 3GPP TS 31.111 和 3GPP TS 51.014 规范,发送主动命令


Card Application Toolkit (CAT) 和 USIM Application Toolkit
(USAT)

Card Application Toolkit (CAT) 定义在 ETSI TS 102 223
USIM Application Toolkit (USAT)定义在 3GPP TS 31.111.