CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
ccid.cpp File Reference
#include "mod_gpg/openpgp/ccid.h"
#include "mod_gpg/openpgp/openpgp.h"
#include "mod_gpg/openpgp/apdu.h"
#include "cdc_log.h"
#include <string.h>
#include <stdio.h>

Go to the source code of this file.

Functions

void ccid_driver_link_anchor (void)
 Initializes CCID transport and backing OpenPGP applet.
bool ccid_init (void)
const uint8_t * ccid_get_atr (size_t *len)
 Returns pointer and length of ATR bytes.
bool ccid_card_present (void)
 Returns whether virtual CCID card is available.
static void ccid_build_header (uint8_t *resp, uint8_t msg_type, uint32_t data_len, uint8_t slot, uint8_t seq, uint8_t status, uint8_t error)
 Builds a CCID response header in transport byte format.
int ccid_process_message (const uint8_t *msg, size_t msg_len, uint8_t *resp, size_t resp_max)
 Processes one incoming CCID message and writes corresponding response.

Variables

static const char * TAG = "CCID"
 USB CCID (Chip Card Interface Device) transport for OpenPGP applet.
const uint8_t CCID_DESCRIPTOR []
 CCID functional descriptor (54 bytes) per OpenPGP 3.4.1 profile.
const size_t CCID_DESCRIPTOR_LEN = sizeof(CCID_DESCRIPTOR)
static const uint8_t ATR []
 ATR (Answer To Reset) for CDC Badge OpenPGP card.
static bool initialized = false
static uint8_t current_slot = 0
static uint8_t current_seq = 0

Function Documentation

◆ ccid_build_header()

void ccid_build_header ( uint8_t * resp,
uint8_t msg_type,
uint32_t data_len,
uint8_t slot,
uint8_t seq,
uint8_t status,
uint8_t error )
static

Builds a CCID response header in transport byte format.

Parameters
respOutput response buffer.
msg_typeCCID response message type.
data_lenPayload length in bytes.
slotSlot index.
seqSequence number.
statusCCID status flags.
errorCCID error code.

Definition at line 126 of file ccid.cpp.

Referenced by ccid_process_message().

◆ ccid_card_present()

bool ccid_card_present ( void )

Returns whether virtual CCID card is available.

Returns
true if CCID/OpenPGP stack is initialized.

Definition at line 112 of file ccid.cpp.

References initialized.

◆ ccid_driver_link_anchor()

void ccid_driver_link_anchor ( void )

Initializes CCID transport and backing OpenPGP applet.

Returns
true if initialization succeeded.

Definition at line 226 of file ccid_driver.cpp.

Referenced by ccid_init().

◆ ccid_get_atr()

const uint8_t * ccid_get_atr ( size_t * len)

Returns pointer and length of ATR bytes.

Parameters
lenOptional output receiving ATR length.
Returns
Pointer to static ATR buffer.

Definition at line 101 of file ccid.cpp.

References ATR.

Referenced by ccid_process_message().

◆ ccid_init()

bool ccid_init ( void )

Definition at line 83 of file ccid.cpp.

References ccid_driver_link_anchor(), initialized, LOG_E, LOG_I, openpgp_init(), and TAG.

Referenced by cdc::mod_gpg::GpgModule::start().

◆ ccid_process_message()

int ccid_process_message ( const uint8_t * msg,
size_t msg_len,
uint8_t * resp,
size_t resp_max )

Processes one incoming CCID message and writes corresponding response.

Parameters
Message transfer (badge-to-badge)Incoming CCID message bytes.
msg_lenIncoming message length.
respOutput response buffer.
resp_maxOutput buffer capacity.
Returns
Response length in bytes, or negative value on fatal parameter errors.

Definition at line 148 of file ccid.cpp.

References ccid_build_header(), CCID_CMD_STATUS_FAILED, CCID_ERROR_CMD_NOT_SUPPORTED, CCID_ERROR_HW_ERROR, CCID_ERROR_XFR_OVERRUN, ccid_get_atr(), CCID_HEADER_SIZE, ccid_header_t, CCID_ICC_PRESENT_ACTIVE, CCID_ICC_PRESENT_INACTIVE, CCID_PC_TO_RDR_GET_PARAMETERS, CCID_PC_TO_RDR_GET_SLOT_STATUS, CCID_PC_TO_RDR_ICC_POWER_OFF, CCID_PC_TO_RDR_ICC_POWER_ON, CCID_PC_TO_RDR_RESET_PARAMETERS, CCID_PC_TO_RDR_XFR_BLOCK, CCID_RDR_TO_PC_DATA_BLOCK, CCID_RDR_TO_PC_PARAMETERS, CCID_RDR_TO_PC_SLOT_STATUS, current_seq, current_slot, LOG_E, LOG_I, LOG_W, openpgp_process_apdu(), and TAG.

Referenced by ccid_driver_xfer_cb().

Variable Documentation

◆ ATR

const uint8_t ATR[]
static
Initial value:
= {
0x3B,
0xDA,
0x18,
0xFF,
0x81,
0xB1,
0xFE,
0x75,
0x1F,
0x03,
0x00, 0x31, 0xF5, 0x73, 0xC0, 0x01, 0x60, 0x00, 0x90, 0x00,
0x1C
}

ATR (Answer To Reset) for CDC Badge OpenPGP card.

T=1 protocol layout, OpenPGP 3.x compatible.

Definition at line 57 of file ccid.cpp.

Referenced by ccid_get_atr().

◆ CCID_DESCRIPTOR

const uint8_t CCID_DESCRIPTOR[]
Initial value:
= {
0x36,
0x21,
0x10, 0x01,
0x00,
0x07,
0x02, 0x00, 0x00, 0x00,
0xA0, 0x0F, 0x00, 0x00,
0xA0, 0x0F, 0x00, 0x00,
0x00,
0xB0, 0x04, 0x00, 0x00,
0xB0, 0x04, 0x00, 0x00,
0x00,
0xFE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x42, 0x08, 0x04, 0x00,
0x00, 0x08, 0x00, 0x00,
0xFF,
0xFF,
0x00, 0x00,
0x00,
0x01
}

CCID functional descriptor (54 bytes) per OpenPGP 3.4.1 profile.

Definition at line 20 of file ccid.cpp.

◆ CCID_DESCRIPTOR_LEN

const size_t CCID_DESCRIPTOR_LEN = sizeof(CCID_DESCRIPTOR)

Definition at line 50 of file ccid.cpp.

◆ current_seq

uint8_t current_seq = 0
static

Definition at line 75 of file ccid.cpp.

Referenced by ccid_process_message().

◆ current_slot

uint8_t current_slot = 0
static

Definition at line 74 of file ccid.cpp.

Referenced by ccid_process_message().

◆ initialized

bool initialized = false
static

Definition at line 73 of file ccid.cpp.

◆ TAG

const char* TAG = "CCID"
static

USB CCID (Chip Card Interface Device) transport for OpenPGP applet.

Based on pico-openpgp (https://github.com/polhenarejos/pico-openpgp). Original project copyright: Pol Henarejos, AGPLv3.

Definition at line 15 of file ccid.cpp.