• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

canokeys / canokey-core / 26453907226

26 May 2026 10:07AM UTC coverage: 89.919% (-0.4%) from 90.351%
26453907226

Pull #152

github

dangfan
Update canokey-crypto for CIU ML-KEM APIs
Pull Request #152: Move CIU-backed persistent configuration hooks into core

157 of 227 new or added lines in 18 files covered. (69.16%)

2 existing lines in 1 file now uncovered.

10472 of 11646 relevant lines covered (89.92%)

277415.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.67
/include/admin.h
1
/* SPDX-License-Identifier: Apache-2.0 */
2
#ifndef CANOKEY_CORE_ADMIN_ADMIN_H_
3
#define CANOKEY_CORE_ADMIN_ADMIN_H_
4

5
#include <apdu.h>
6
#include <stdbool.h>
7
#include <stdint.h>
8

9
#define ADMIN_INS_WRITE_FIDO_PRIVATE_KEY 0x01
10
#define ADMIN_INS_WRITE_FIDO_CERT 0x02
11
#define ADMIN_INS_RESET_OPENPGP 0x03
12
#define ADMIN_INS_RESET_PIV 0x04
13
#define ADMIN_INS_RESET_OATH 0x05
14
#define ADMIN_INS_RESET_NDEF 0x07
15
#define ADMIN_INS_TOGGLE_NDEF_READ_ONLY 0x08
16
#define ADMIN_INS_RESET_CTAP 0x09
17
#define ADMIN_INS_READ_CTAP_SM2_CONFIG 0x11
18
#define ADMIN_INS_WRITE_CTAP_SM2_CONFIG 0x12
19
#define ADMIN_INS_RESET_PASS 0x13
20
#define ADMIN_INS_NFC_ENABLE 0x14
21
#define ADMIN_INS_VERIFY 0x20
22
#define ADMIN_INS_CHANGE_PIN 0x21
23
#define ADMIN_INS_WRITE_SN 0x30
24
#define ADMIN_INS_READ_VERSION 0x31
25
#define ADMIN_INS_READ_SN 0x32
26
#define ADMIN_INS_CONFIG 0x40
27
#define ADMIN_INS_FLASH_USAGE 0x41
28
#define ADMIN_INS_READ_CONFIG 0x42
29
#define ADMIN_INS_READ_PASS_CONFIG 0x43
30
#define ADMIN_INS_WRITE_PASS_CONFIG 0x44
31

32
/**
33
 * @brief KBD keymap admin APDUs.
34
 *
35
 * The keymap is a fixed 128-entry ASCII table. Entry N maps ASCII code N to
36
 * two bytes: {HID modifier, HID usage}. A stored table is authoritative for
37
 * KBDHID output; usage 0 means "skip this character" instead of falling back
38
 * to the built-in QWERTY map.
39
 *
40
 * ADMIN_INS_WRITE_KBD_KEYMAP:
41
 *   P1 = 0x00
42
 *   P2 = host-defined layout id
43
 *   Lc = ADMIN_KBD_KEYMAP_LENGTH
44
 *   Data = 128 consecutive {modifier, usage} entries
45
 *
46
 * ADMIN_INS_READ_KBD_KEYMAP:
47
 *   P1 = 0x00
48
 *   P2 = ADMIN_P2_KBD_READ_LAYOUT_ID: Le >= 1, returns one layout-id byte
49
 *   P2 = ADMIN_P2_KBD_READ_KEYMAP: Le >= ADMIN_KBD_KEYMAP_LENGTH, returns the
50
 *        128-entry {modifier, usage} table without the layout id
51
 *
52
 * ADMIN_INS_CLEAR_KBD_KEYMAP:
53
 *   P1 = 0x00, P2 = 0x00, Lc = 0
54
 */
55
#define ADMIN_INS_WRITE_KBD_KEYMAP 0x45
56
#define ADMIN_INS_READ_KBD_KEYMAP 0x46
57
#define ADMIN_INS_CLEAR_KBD_KEYMAP 0x47
58
#define ADMIN_INS_FACTORY_RESET 0x50
59
#define ADMIN_INS_SELECT 0xA4
60
#define ADMIN_INS_VENDOR_SPECIFIC 0xFF
61

62
#define ADMIN_KBD_ASCII_COUNT 128
63
#define ADMIN_KBD_KEYMAP_ENTRY_SIZE 2
64
#define ADMIN_KBD_KEYMAP_LENGTH (ADMIN_KBD_ASCII_COUNT * ADMIN_KBD_KEYMAP_ENTRY_SIZE)
65
#define ADMIN_P2_KBD_READ_LAYOUT_ID 0x00
66
#define ADMIN_P2_KBD_READ_KEYMAP 0x01
67

68
#define ADMIN_P1_CFG_LED_ON 0x01
69
#define ADMIN_P1_CFG_NDEF 0x04
70
#define ADMIN_P1_CFG_WEBUSB_LANDING 0x05
71

72
typedef struct {
73
  uint32_t led_normally_on : 1;
74
  uint32_t ndef_en : 1;
75
  uint32_t webusb_landing_en : 1;
76
} __packed admin_device_config_t;
77

78
void admin_poweroff(void);
697✔
79
int admin_install(uint8_t reset);
336✔
80
int admin_process_apdu(const CAPDU *capdu, RAPDU *rapdu);
315✔
81
int admin_vendor_specific(const CAPDU *capdu, RAPDU *rapdu);
1✔
82
int admin_vendor_version(const CAPDU *capdu, RAPDU *rapdu);
×
83
int admin_vendor_hw_variant(const CAPDU *capdu, RAPDU *rapdu);
×
84
int admin_vendor_hw_sn(const CAPDU *capdu, RAPDU *rapdu);
×
85
int admin_vendor_nfc_enable(const CAPDU *capdu, RAPDU *rapdu, bool pin_validated);
×
86

87
/*
88
 * Platform persistence hooks.
89
 *
90
 * Core owns the config semantics, while the platform owns the physical storage layout.
91
 */
NEW
92
int admin_platform_device_config_read(admin_device_config_t *cfg);
×
NEW
93
int admin_platform_device_config_write(const admin_device_config_t *cfg);
×
NEW
94
int admin_platform_serial_read(uint8_t *buf);
×
NEW
95
int admin_platform_serial_write_once(const uint8_t *buf);
×
96
/*
97
 * KBD keymap admin commands use a 128-entry ASCII table. Each entry is
98
 * {modifier, HID usage}; a valid platform table is authoritative, and usage 0
99
 * means the character is intentionally skipped.
100
 */
NEW
101
int admin_platform_kbd_keymap_write(uint8_t layout_id, const uint8_t *keymap, uint16_t len);
×
NEW
102
int admin_platform_kbd_keymap_read(uint8_t *layout_id, uint8_t *keymap, uint16_t len);
×
NEW
103
int admin_platform_kbd_keymap_clear(void);
×
104

105
#endif // CANOKEY_CORE_ADMIN_ADMIN_H_
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc