add picopass emulation

This commit is contained in:
Tiernan Messmer
2022-12-22 09:37:37 +10:00
parent 4900e8b7a2
commit 78119a519a
21 changed files with 1054 additions and 9 deletions

View File

@@ -7,6 +7,7 @@
#include <mbedtls/des.h>
#include "rfal_picopass.h"
#include "loclass_writer.h"
#include <optimized_ikeys.h>
#include <optimized_cipher.h>
#include "helpers/iclass_elite_dict.h"
@@ -24,6 +25,49 @@
#define PICOPASS_AIA_BLOCK_INDEX 5
#define PICOPASS_PACS_CFG_BLOCK_INDEX 6
// Personalization Mode
#define PICOPASS_FUSE_PERS 0x80
// Crypt1 // 1+1 (crypt1+crypt0) means secured and keys changable
#define PICOPASS_FUSE_CRYPT1 0x10
// Crypt0 // 1+0 means secure and keys locked, 0+1 means not secured, 0+0 means disable auth entirely
#define PICOPASS_FUSE_CRTPT0 0x08
#define PICOPASS_FUSE_CRYPT10 (PICOPASS_FUSE_CRYPT1 | PICOPASS_FUSE_CRTPT0)
// Read Access, 1 meanns anonymous read enabled, 0 means must auth to read applicaion
#define PICOPASS_FUSE_RA 0x01
// PicoPass command bytes:
// Low nibble used for command
// High nibble used for options and checksum (MSB)
// The only option we care about in 15693 mode is the key
// which is only used by READCHECK, so for simplicity we
// don't bother breaking down the command and flags into parts
// READ: ADDRESS(1) CRC16(2) -> DATA(8) CRC16(2)
// IDENTIFY: No args -> ASNB(8) CRC16(2)
#define PICOPASS_CMD_READ_OR_IDENTIFY 0x0C
// ADDRESS(1) CRC16(2) -> DATA(32) CRC16(2)
#define PICOPASS_CMD_READ4 0x06
// ADDRESS(1) DATA(8) SIGN(4)|CRC16(2) -> DATA(8) CRC16(2)
#define PICOPASS_CMD_UPDATE 0x87
// ADDRESS(1) -> DATA(8)
#define PICOPASS_CMD_READCHECK_KD 0x88
// ADDRESS(1) -> DATA(8)
#define PICOPASS_CMD_READCHECK_KC 0x18
// CHALLENGE(4) READERSIGNATURE(4) -> CHIPRESPONSE(4)
#define PICOPASS_CMD_CHECK 0x05
// No args -> SOF
#define PICOPASS_CMD_ACTALL 0x0A
// No args -> SOF
#define PICOPASS_CMD_ACT 0x8E
// ASNB(8)|SERIALNB(8) -> SERIALNB(8) CRC16(2)
#define PICOPASS_CMD_SELECT 0x81
// No args -> SERIALNB(8) CRC16(2)
#define PICOPASS_CMD_DETECT 0x0F
// No args -> SOF
#define PICOPASS_CMD_HALT 0x00
// PAGE(1) CRC16(2) -> BLOCK1(8) CRC16(2)
#define PICOPASS_CMD_PAGESEL 0x84
#define PICOPASS_APP_FOLDER ANY_PATH("picopass")
#define PICOPASS_APP_EXTENSION ".picopass"
#define PICOPASS_APP_SHADOW_EXTENSION ".pas"
@@ -49,6 +93,13 @@ typedef enum {
PicopassDeviceSaveFormatLF,
} PicopassDeviceSaveFormat;
typedef enum {
PicopassEmulatorStateHalt,
PicopassEmulatorStateIdle,
PicopassEmulatorStateActive,
PicopassEmulatorStateSelected,
} PicopassEmulatorState;
typedef struct {
bool valid;
uint8_t bitLength;
@@ -80,6 +131,15 @@ typedef struct {
IclassEliteDictAttackData iclass_elite_dict_attack_data;
} PicopassDeviceData;
typedef struct {
PicopassEmulatorState state;
LoclassState_t cipher_state;
uint8_t key_block_num; // in loclass mode used to store csn#
bool loclass_mode;
bool loclass_got_std_key;
LoclassWriter* loclass_writer;
} PicopassEmulatorCtx;
typedef struct {
Storage* storage;
DialogsApp* dialogs;