Harald Welte | 21caf32 | 2022-07-16 14:06:46 +0200 | [diff] [blame^] | 1 | # coding=utf-8 |
| 2 | """APDU definition/decoder of GlobalPLatform Card Spec (currently 2.1.1) |
| 3 | |
| 4 | (C) 2022 by Harald Welte <laforge@osmocom.org> |
| 5 | |
| 6 | This program is free software: you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation, either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | """ |
| 19 | |
| 20 | from pySim.apdu import ApduCommand, ApduCommandSet |
| 21 | |
| 22 | class GpDelete(ApduCommand, n='DELETE', ins=0xE4, cla=['8X', 'CX', 'EX']): |
| 23 | _apdu_case = 4 |
| 24 | |
| 25 | class GpStoreData(ApduCommand, n='STORE DATA', ins=0xE2, cla=['8X', 'CX', 'EX']): |
| 26 | @classmethod |
| 27 | def _get_apdu_case(cls, hdr:bytes) -> int: |
| 28 | p1 = hdr[2] |
| 29 | if p1 & 0x01: |
| 30 | return 4 |
| 31 | else: |
| 32 | return 3 |
| 33 | |
| 34 | class GpGetDataCA(ApduCommand, n='GET DATA', ins=0xCA, cla=['8X', 'CX', 'EX']): |
| 35 | _apdu_case = 4 |
| 36 | |
| 37 | class GpGetDataCB(ApduCommand, n='GET DATA', ins=0xCB, cla=['8X', 'CX', 'EX']): |
| 38 | _apdu_case = 4 |
| 39 | |
| 40 | class GpGetStatus(ApduCommand, n='GET STATUS', ins=0xF2, cla=['8X', 'CX', 'EX']): |
| 41 | _apdu_case = 4 |
| 42 | |
| 43 | class GpInstall(ApduCommand, n='INSTALL', ins=0xE6, cla=['8X', 'CX', 'EX']): |
| 44 | _apdu_case = 4 |
| 45 | |
| 46 | class GpLoad(ApduCommand, n='LOAD', ins=0xE8, cla=['8X', 'CX', 'EX']): |
| 47 | _apdu_case = 4 |
| 48 | |
| 49 | class GpPutKey(ApduCommand, n='PUT KEY', ins=0xD8, cla=['8X', 'CX', 'EX']): |
| 50 | _apdu_case = 4 |
| 51 | |
| 52 | class GpSetStatus(ApduCommand, n='SET STATUS', ins=0xF0, cla=['8X', 'CX', 'EX']): |
| 53 | _apdu_case = 3 |
| 54 | |
| 55 | ApduCommands = ApduCommandSet('GlobalPlatform v2.3.1', cmds=[GpDelete, GpStoreData, |
| 56 | GpGetDataCA, GpGetDataCB, GpGetStatus, GpInstall, |
| 57 | GpLoad, GpPutKey, GpSetStatus]) |