Skip to content

Commit

Permalink
Only allow change-pin for NK3
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Nov 22, 2024
1 parent a395b75 commit 9dbf100
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/operations_ccid.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ int set_pin_ccid(struct Device *dev, const char *admin_PIN) {
}

int nk3_change_pin(struct Device *dev, const char *old_pin, const char*new_pin) {
libusb_device *usb_dev;
struct libusb_device_descriptor usb_desc;
usb_dev = libusb_get_device(dev->mp_devhandle_ccid);

int r = libusb_get_device_descriptor(usb_dev, &usb_desc);

if (r < 0) {
return r;
}


if (usb_desc.idVendor != NITROKEY_USB_VID || usb_desc.idProduct != NITROKEY_3_USB_PID) {
return RET_NOT_FOUND;
}

TLV tlvs[] = {
{
.tag = Tag_Password,
Expand All @@ -83,7 +98,7 @@ int nk3_change_pin(struct Device *dev, const char *old_pin, const char*new_pin)
tlvs, ARR_LEN(tlvs), Ins_ChangePIN);
// send
IccResult iccResult;
int r = ccid_process_single(dev->mp_devhandle_ccid, dev->ccid_buffer_in, sizeof dev->ccid_buffer_in,
r = ccid_process_single(dev->mp_devhandle_ccid, dev->ccid_buffer_in, sizeof dev->ccid_buffer_in,
dev->ccid_buffer_out, icc_actual_length, &iccResult);
if (r != 0) {
return r;
Expand Down
3 changes: 2 additions & 1 deletion src/return_codes.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const char *res_to_error_string(int res) {
if (res == RET_NO_PIN_ATTEMPTS) return "Device does not show PIN attempts counter";
if (res == RET_SLOT_NOT_CONFIGURED) return "HOTP slot is not configured";
if (res == RET_SECURITY_STATUS_NOT_SATISFIED) return "Touch was not recognized, or there was other problem with the authentication";
if (res == RET_NOT_FOUND) return "Device not found";
return "Unknown error";
}

Expand All @@ -55,4 +56,4 @@ int res_to_exit_code(int res) {
if (res == RET_BADLY_FORMATTED_HOTP_CODE) return EXIT_BAD_FORMAT;
if (res == RET_CONNECTION_LOST) return EXIT_CONNECTION_LOST;
return EXIT_OTHER_ERROR;
}
}

0 comments on commit 9dbf100

Please sign in to comment.