CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
openpgp.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

Go to the source code of this file.

Macros

#define ALGO_RSA   0x01
#define ALGO_ECDH   0x12
#define ALGO_ECDSA   0x13
#define ALGO_EDDSA   0x16
#define KEY_SIG   0xB6
#define KEY_DEC   0xB8
#define KEY_AUT   0xA4
#define OPENPGP_PW1_MIN_LEN   6
#define OPENPGP_PW3_MIN_LEN   8
#define OPENPGP_PIN_MAX_LEN   32
#define DO_AID   0x004F
#define DO_HIST_BYTES   0x5F52
#define DO_CARDHOLDER   0x0065
#define DO_APP_RELATED   0x006E
#define DO_DISCRET_DO   0x0073
#define DO_EXT_CAP   0x00C0
#define DO_ALGO_SIG   0x00C1
#define DO_ALGO_DEC   0x00C2
#define DO_ALGO_AUT   0x00C3
#define DO_PW_STATUS   0x00C4
#define DO_RC   0x00D3
#define DO_FP_SIG   0x00C7
#define DO_FP_DEC   0x00C8
#define DO_FP_AUT   0x00C9
#define DO_CA_FP_1   0x00CA
#define DO_CA_FP_2   0x00CB
#define DO_CA_FP_3   0x00CC
#define DO_GEN_TIME_ALL   0x00CD
#define DO_GEN_TIME_SIG   0x00CE
#define DO_GEN_TIME_DEC   0x00CF
#define DO_GEN_TIME_AUT   0x00D0
#define DO_SIG_COUNT   0x0093
#define DO_URL   0x5F50
#define DO_LOGIN   0x005E
#define DO_NAME   0x005B
#define DO_LANG_PREF   0x5F2D
#define DO_SEX   0x5F35
#define DO_UIF_SIG   0x00D6
#define DO_UIF_DEC   0x00D7
#define DO_UIF_AUT   0x00D8
#define DO_KEY_INFO   0x00DE
#define DO_SEC_TPL   0x007A
#define DO_KDF   0x00F9
#define DO_AES_KEY   0x00D5
#define DO_CARDHOLDER_CERT   0x7F21
#define SW_OK   0x9000
#define SW_FILE_TERMINATED   0x6285
#define SW_WRONG_LENGTH   0x6700
#define SW_SECURITY_NOT_SATISFIED   0x6982
#define SW_AUTH_METHOD_BLOCKED   0x6983
#define SW_CONDITIONS_NOT_SATISFIED   0x6985
#define SW_WRONG_DATA   0x6A80
#define SW_FILE_NOT_FOUND   0x6A82
#define SW_INCORRECT_P1P2   0x6A86
#define SW_REFERENCED_DATA_NOT_FOUND   0x6A88
#define SW_WRONG_P1P2   0x6B00
#define SW_INS_NOT_SUPPORTED   0x6D00
#define SW_CLA_NOT_SUPPORTED   0x6E00
#define SW_UNKNOWN   0x6F00

Functions

bool openpgp_init (void)
int openpgp_process_apdu (const uint8_t *cmd, size_t cmd_len, uint8_t *resp, size_t resp_max)
bool openpgp_is_selected (void)
uint32_t openpgp_get_sig_count (void)
bool openpgp_set_key_fingerprint (uint8_t key_type, const uint8_t *fingerprint, uint32_t gen_time)
void openpgp_factory_reset (void)
bool openpgp_get_fingerprint (uint8_t key_type, uint8_t *fp_out)
 Reads the stored OpenPGP v4 fingerprint for a key role.
bool openpgp_has_any_key (void)
 Reports whether any of the SIG / DEC / AUT roles has a non-zero fingerprint configured. Acts as the canonical "card has keys" check.
size_t openpgp_get_cardholder_name (char *out, size_t out_size)
 Copies the cardholder name (OpenPGP DO 0x5B) into the caller buffer. Format is gpg's "Surname<<Firstname" or empty when unset.
uint32_t openpgp_get_gen_time (uint8_t key_type)
 Returns the stored Unix timestamp of key generation, or 0 when unset.
bool openpgp_set_cardholder_name (const char *name)
 Sets the cardholder name (OpenPGP DO 0x5B) and persists state.

Variables

const uint8_t * OPENPGP_AID
const uint8_t OPENPGP_AID_LEN

Macro Definition Documentation

◆ ALGO_ECDH

#define ALGO_ECDH   0x12

Definition at line 30 of file openpgp.h.

◆ ALGO_ECDSA

#define ALGO_ECDSA   0x13

Definition at line 31 of file openpgp.h.

◆ ALGO_EDDSA

#define ALGO_EDDSA   0x16

Definition at line 32 of file openpgp.h.

◆ ALGO_RSA

#define ALGO_RSA   0x01

Definition at line 29 of file openpgp.h.

◆ DO_AES_KEY

#define DO_AES_KEY   0x00D5

Definition at line 86 of file openpgp.h.

Referenced by cmd_put_data().

◆ DO_AID

#define DO_AID   0x004F

Definition at line 45 of file openpgp.h.

Referenced by build_do_app_related(), and cmd_get_data().

◆ DO_ALGO_AUT

#define DO_ALGO_AUT   0x00C3

Definition at line 53 of file openpgp.h.

Referenced by build_do_app_related(), cmd_get_data(), cmd_put_data(), and put_data_algo_attr().

◆ DO_ALGO_DEC

#define DO_ALGO_DEC   0x00C2

Definition at line 52 of file openpgp.h.

Referenced by build_do_app_related(), cmd_get_data(), cmd_put_data(), and put_data_algo_attr().

◆ DO_ALGO_SIG

#define DO_ALGO_SIG   0x00C1

Definition at line 51 of file openpgp.h.

Referenced by build_do_app_related(), cmd_get_data(), cmd_put_data(), and put_data_algo_attr().

◆ DO_APP_RELATED

#define DO_APP_RELATED   0x006E

Definition at line 48 of file openpgp.h.

Referenced by cmd_get_data().

◆ DO_CA_FP_1

#define DO_CA_FP_1   0x00CA

Definition at line 59 of file openpgp.h.

Referenced by cmd_get_data(), and find_put_data_desc().

◆ DO_CA_FP_2

#define DO_CA_FP_2   0x00CB

Definition at line 60 of file openpgp.h.

Referenced by cmd_get_data(), and find_put_data_desc().

◆ DO_CA_FP_3

#define DO_CA_FP_3   0x00CC

Definition at line 61 of file openpgp.h.

Referenced by cmd_get_data(), and find_put_data_desc().

◆ DO_CARDHOLDER

#define DO_CARDHOLDER   0x0065

Definition at line 47 of file openpgp.h.

Referenced by build_do_cardholder(), and cmd_get_data().

◆ DO_CARDHOLDER_CERT

#define DO_CARDHOLDER_CERT   0x7F21

Definition at line 87 of file openpgp.h.

Referenced by cmd_get_data().

◆ DO_DISCRET_DO

#define DO_DISCRET_DO   0x0073

Definition at line 49 of file openpgp.h.

◆ DO_EXT_CAP

#define DO_EXT_CAP   0x00C0

Definition at line 50 of file openpgp.h.

Referenced by build_do_app_related(), and cmd_get_data().

◆ DO_FP_AUT

#define DO_FP_AUT   0x00C9

Definition at line 58 of file openpgp.h.

Referenced by cmd_get_data(), and find_put_data_desc().

◆ DO_FP_DEC

#define DO_FP_DEC   0x00C8

Definition at line 57 of file openpgp.h.

Referenced by cmd_get_data(), and find_put_data_desc().

◆ DO_FP_SIG

#define DO_FP_SIG   0x00C7

Definition at line 56 of file openpgp.h.

Referenced by cmd_get_data(), and find_put_data_desc().

◆ DO_GEN_TIME_ALL

#define DO_GEN_TIME_ALL   0x00CD

Definition at line 70 of file openpgp.h.

◆ DO_GEN_TIME_AUT

#define DO_GEN_TIME_AUT   0x00D0

Definition at line 73 of file openpgp.h.

Referenced by cmd_get_data(), and find_put_data_desc().

◆ DO_GEN_TIME_DEC

#define DO_GEN_TIME_DEC   0x00CF

Definition at line 72 of file openpgp.h.

Referenced by cmd_get_data(), and find_put_data_desc().

◆ DO_GEN_TIME_SIG

#define DO_GEN_TIME_SIG   0x00CE

Definition at line 71 of file openpgp.h.

Referenced by cmd_get_data(), and find_put_data_desc().

◆ DO_HIST_BYTES

#define DO_HIST_BYTES   0x5F52

Definition at line 46 of file openpgp.h.

Referenced by build_do_app_related(), and cmd_get_data().

◆ DO_KDF

#define DO_KDF   0x00F9

Definition at line 85 of file openpgp.h.

Referenced by cmd_get_data().

◆ DO_KEY_INFO

#define DO_KEY_INFO   0x00DE

Definition at line 83 of file openpgp.h.

Referenced by cmd_get_data().

◆ DO_LANG_PREF

#define DO_LANG_PREF   0x5F2D

Definition at line 78 of file openpgp.h.

Referenced by build_do_cardholder(), cmd_get_data(), and find_put_data_desc().

◆ DO_LOGIN

#define DO_LOGIN   0x005E

Definition at line 76 of file openpgp.h.

Referenced by cmd_get_data(), and find_put_data_desc().

◆ DO_NAME

#define DO_NAME   0x005B

Definition at line 77 of file openpgp.h.

Referenced by build_do_cardholder(), cmd_get_data(), and find_put_data_desc().

◆ DO_PW_STATUS

#define DO_PW_STATUS   0x00C4

Definition at line 54 of file openpgp.h.

Referenced by build_do_app_related(), and cmd_get_data().

◆ DO_RC

#define DO_RC   0x00D3

Definition at line 55 of file openpgp.h.

Referenced by cmd_put_data().

◆ DO_SEC_TPL

#define DO_SEC_TPL   0x007A

Definition at line 84 of file openpgp.h.

Referenced by cmd_get_data().

◆ DO_SEX

#define DO_SEX   0x5F35

Definition at line 79 of file openpgp.h.

Referenced by build_do_cardholder(), cmd_get_data(), and cmd_put_data().

◆ DO_SIG_COUNT

#define DO_SIG_COUNT   0x0093

Definition at line 74 of file openpgp.h.

Referenced by cmd_get_data().

◆ DO_UIF_AUT

#define DO_UIF_AUT   0x00D8

Definition at line 82 of file openpgp.h.

Referenced by cmd_get_data().

◆ DO_UIF_DEC

#define DO_UIF_DEC   0x00D7

Definition at line 81 of file openpgp.h.

Referenced by cmd_get_data().

◆ DO_UIF_SIG

#define DO_UIF_SIG   0x00D6

Definition at line 80 of file openpgp.h.

Referenced by cmd_get_data().

◆ DO_URL

#define DO_URL   0x5F50

Definition at line 75 of file openpgp.h.

Referenced by cmd_get_data(), and find_put_data_desc().

◆ KEY_AUT

◆ KEY_DEC

◆ KEY_SIG

◆ OPENPGP_PIN_MAX_LEN

◆ OPENPGP_PW1_MIN_LEN

#define OPENPGP_PW1_MIN_LEN   6

Definition at line 40 of file openpgp.h.

Referenced by cmd_change_reference_data(), and cmd_reset_retry_counter().

◆ OPENPGP_PW3_MIN_LEN

#define OPENPGP_PW3_MIN_LEN   8

Definition at line 41 of file openpgp.h.

Referenced by cmd_change_reference_data().

◆ SW_AUTH_METHOD_BLOCKED

#define SW_AUTH_METHOD_BLOCKED   0x6983

Definition at line 94 of file openpgp.h.

Referenced by cmd_change_reference_data(), cmd_reset_retry_counter(), and cmd_verify().

◆ SW_CLA_NOT_SUPPORTED

#define SW_CLA_NOT_SUPPORTED   0x6E00

Definition at line 102 of file openpgp.h.

Referenced by openpgp_process_apdu().

◆ SW_CONDITIONS_NOT_SATISFIED

◆ SW_FILE_NOT_FOUND

#define SW_FILE_NOT_FOUND   0x6A82

Definition at line 97 of file openpgp.h.

Referenced by cmd_put_data(), cmd_select(), and put_data_algo_attr().

◆ SW_FILE_TERMINATED

#define SW_FILE_TERMINATED   0x6285

Definition at line 91 of file openpgp.h.

Referenced by openpgp_process_apdu().

◆ SW_INCORRECT_P1P2

◆ SW_INS_NOT_SUPPORTED

#define SW_INS_NOT_SUPPORTED   0x6D00

Definition at line 101 of file openpgp.h.

Referenced by openpgp_process_apdu().

◆ SW_OK

◆ SW_REFERENCED_DATA_NOT_FOUND

#define SW_REFERENCED_DATA_NOT_FOUND   0x6A88

Definition at line 99 of file openpgp.h.

Referenced by cmd_generate_keypair(), and cmd_get_data().

◆ SW_SECURITY_NOT_SATISFIED

◆ SW_UNKNOWN

◆ SW_WRONG_DATA

◆ SW_WRONG_LENGTH

◆ SW_WRONG_P1P2

#define SW_WRONG_P1P2   0x6B00

Definition at line 100 of file openpgp.h.

Function Documentation

◆ openpgp_factory_reset()

◆ openpgp_get_cardholder_name()

size_t openpgp_get_cardholder_name ( char * out,
size_t out_size )

Copies the cardholder name (OpenPGP DO 0x5B) into the caller buffer. Format is gpg's "Surname<<Firstname" or empty when unset.

Returns
number of bytes copied (excluding null terminator).

Definition at line 913 of file openpgp.cpp.

References cardholder_name.

Referenced by gpg_get_status().

◆ openpgp_get_fingerprint()

bool openpgp_get_fingerprint ( uint8_t key_type,
uint8_t * fp_out )

Reads the stored OpenPGP v4 fingerprint for a key role.

Parameters
key_typeOne of KEY_SIG, KEY_DEC, KEY_AUT.
fp_out20-byte output buffer.
Returns
true on success.

Definition at line 890 of file openpgp.cpp.

References fingerprint_aut, fingerprint_dec, fingerprint_sig, KEY_AUT, KEY_DEC, KEY_SIG, and OPENPGP_FINGERPRINT_SIZE.

Referenced by gpg_get_status().

◆ openpgp_get_gen_time()

uint32_t openpgp_get_gen_time ( uint8_t key_type)

Returns the stored Unix timestamp of key generation, or 0 when unset.

Parameters
key_typeOne of KEY_SIG, KEY_DEC, KEY_AUT.

Definition at line 922 of file openpgp.cpp.

References gen_time_aut, gen_time_dec, gen_time_sig, KEY_AUT, KEY_DEC, and KEY_SIG.

Referenced by gpg_get_status().

◆ openpgp_get_sig_count()

uint32_t openpgp_get_sig_count ( void )

Definition at line 886 of file openpgp.cpp.

References sig_count.

Referenced by gpg_get_status().

◆ openpgp_has_any_key()

bool openpgp_has_any_key ( void )

Reports whether any of the SIG / DEC / AUT roles has a non-zero fingerprint configured. Acts as the canonical "card has keys" check.

Definition at line 907 of file openpgp.cpp.

References fingerprint_aut, fingerprint_dec, fingerprint_sig, and fp_is_set().

Referenced by gpg_export_pubkey_pem(), gpg_generate_key(), gpg_get_status(), gpg_is_initialized(), and cdc::mod_gpg::rebuildMenu().

◆ openpgp_init()

bool openpgp_init ( void )

◆ openpgp_is_selected()

bool openpgp_is_selected ( void )

Definition at line 882 of file openpgp.cpp.

References app_selected.

◆ openpgp_process_apdu()

◆ openpgp_set_cardholder_name()

bool openpgp_set_cardholder_name ( const char * name)

Sets the cardholder name (OpenPGP DO 0x5B) and persists state.

Parameters
nameUTF-8 string; truncated to fit the storage buffer.

Definition at line 936 of file openpgp.cpp.

References cardholder_name, name, and save_state_to_nvs().

Referenced by gpg_generate_key().

◆ openpgp_set_key_fingerprint()

bool openpgp_set_key_fingerprint ( uint8_t key_type,
const uint8_t * fingerprint,
uint32_t gen_time )

Variable Documentation

◆ OPENPGP_AID

const uint8_t* OPENPGP_AID
extern

Definition at line 156 of file openpgp.cpp.

Referenced by build_do_app_related(), cmd_get_data(), and cmd_select().

◆ OPENPGP_AID_LEN

const uint8_t OPENPGP_AID_LEN
extern

Definition at line 157 of file openpgp.cpp.

Referenced by build_do_app_related(), and cmd_get_data().