From a6a2e5538de2fac16650b5ba82f1fca812e152db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Wed, 11 Dec 2024 10:19:18 +0100 Subject: [PATCH] Run make format --- src/main.c | 7 ++--- src/operations_ccid.c | 68 +++++++++++++++++++++---------------------- src/operations_ccid.h | 4 +-- src/settings.h | 2 +- src/structs.h | 14 ++++----- 5 files changed, 46 insertions(+), 49 deletions(-) diff --git a/src/main.c b/src/main.c index 84c0afe..008200b 100644 --- a/src/main.c +++ b/src/main.c @@ -24,7 +24,6 @@ #include "operations_ccid.h" #include "return_codes.h" #include "utils.h" -#include "operations_ccid.h" #include "version.h" #include #include @@ -100,7 +99,7 @@ int parse_cmd_and_run(int argc, char *const *argv) { break; case 'i': {// id | info struct FullResponseStatus status; - memset(&status, 0, sizeof (struct FullResponseStatus)); + memset(&status, 0, sizeof(struct FullResponseStatus)); res = device_get_status(&dev, &status); check_ret((res != RET_NO_ERROR) && (res != RET_NO_PIN_ATTEMPTS), res); @@ -113,7 +112,7 @@ int parse_cmd_and_run(int argc, char *const *argv) { printf("\tCard serial: "); print_card_serial(&status.response_status); if (status.device_type == Nk3) { - printf("\tFirmware Nitrokey 3: v%d.%d.%d\n", + printf("\tFirmware Nitrokey 3: v%d.%d.%d\n", (status.nk3_extra_info.firmware_version >> 22) & 0b1111111111, (status.nk3_extra_info.firmware_version >> 6) & 0xFFFF, status.nk3_extra_info.firmware_version & 0b111111); @@ -167,7 +166,7 @@ int parse_cmd_and_run(int argc, char *const *argv) { case 'r': if (strncmp(argv[1], "reset", 15) == 0) { if (argc != 2 && argc != 3) break; - res = nk3_reset(&dev, argc == 3 ? argv[2]: NULL); + res = nk3_reset(&dev, argc == 3 ? argv[2] : NULL); } else if (strncmp(argv[1], "regenerate", 15) == 0) { if (argc != 3) break; res = regenerate_AES_key(&dev, argv[2]); diff --git a/src/operations_ccid.c b/src/operations_ccid.c index 5a8a138..c06efdb 100644 --- a/src/operations_ccid.c +++ b/src/operations_ccid.c @@ -32,8 +32,7 @@ #include - -int nk3_reset(struct Device *dev, const char * new_pin) { +int nk3_reset(struct Device *dev, const char *new_pin) { libusb_device *usb_dev; struct libusb_device_descriptor usb_desc; @@ -42,7 +41,7 @@ int nk3_reset(struct Device *dev, const char * new_pin) { printf("No Nitrokey 3 found. No operation performed\n"); return RET_NO_ERROR; } - + usb_dev = libusb_get_device(dev->mp_devhandle_ccid); int r = libusb_get_device_descriptor(usb_dev, &usb_desc); @@ -64,12 +63,12 @@ int nk3_reset(struct Device *dev, const char * new_pin) { // encode ccid wrapper icc_actual_length = icc_compose(dev->ccid_buffer_out, sizeof dev->ccid_buffer_out, - 0x6F, icc_actual_length, - 0, 0, 0, buf); + 0x6F, icc_actual_length, + 0, 0, 0, buf); // send IccResult iccResult; 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); + dev->ccid_buffer_out, icc_actual_length, &iccResult); if (r != 0) { return r; } @@ -116,13 +115,13 @@ int set_pin_ccid(struct Device *dev, const char *admin_PIN) { return 0; } -int nk3_change_pin(struct Device *dev, const char *old_pin, const char*new_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; if (!dev->mp_devhandle_ccid) { printf("No Nitrokey 3 found. No operation performed\n"); - return RET_NO_ERROR; + return RET_NO_ERROR; } usb_dev = libusb_get_device(dev->mp_devhandle_ccid); @@ -136,22 +135,22 @@ int nk3_change_pin(struct Device *dev, const char *old_pin, const char*new_pin) if (usb_desc.idVendor != NITROKEY_USB_VID || usb_desc.idProduct != NITROKEY_3_USB_PID) { printf("No Nitrokey 3 found. No operation performed\n"); - return RET_NO_ERROR; + return RET_NO_ERROR; } TLV tlvs[] = { - { - .tag = Tag_Password, - .length = strnlen(old_pin, MAX_PIN_SIZE_CCID), - .type = 'S', - .v_str = old_pin, - }, - { - .tag = Tag_NewPassword, - .length = strnlen(new_pin, MAX_PIN_SIZE_CCID), - .type = 'S', - .v_str = new_pin, - }, + { + .tag = Tag_Password, + .length = strnlen(old_pin, MAX_PIN_SIZE_CCID), + .type = 'S', + .v_str = old_pin, + }, + { + .tag = Tag_NewPassword, + .length = strnlen(new_pin, MAX_PIN_SIZE_CCID), + .type = 'S', + .v_str = new_pin, + }, }; // encode uint32_t icc_actual_length = icc_pack_tlvs_for_sending(dev->ccid_buffer_out, sizeof dev->ccid_buffer_out, @@ -159,7 +158,7 @@ int nk3_change_pin(struct Device *dev, const char *old_pin, const char*new_pin) // send IccResult iccResult; 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); + dev->ccid_buffer_out, icc_actual_length, &iccResult); if (r != 0) { return r; } @@ -223,15 +222,14 @@ int authenticate_or_set_ccid(struct Device *dev, const char *admin_PIN) { } -int delete_secret_on_device_ccid(struct Device *dev) { +int delete_secret_on_device_ccid(struct Device *dev) { TLV tlvs[] = { - { - .tag = Tag_CredentialId, - .length = SLOT_NAME_LEN, - .type = 'S', - .v_str = SLOT_NAME, - } - }; + { + .tag = Tag_CredentialId, + .length = SLOT_NAME_LEN, + .type = 'S', + .v_str = SLOT_NAME, + }}; clean_buffers(dev); // encode @@ -275,11 +273,11 @@ int set_secret_on_device_ccid(struct Device *dev, const char *admin_PIN, const c } #ifdef CCID_SECRETS_AUTHENTICATE_OR_CREATE_PIN - if (strnlen(admin_PIN, 30) > 0) { - if (authenticate_or_set_ccid(dev, admin_PIN) != RET_NO_ERROR) { - return RET_SECURITY_STATUS_NOT_SATISFIED; - } + if (strnlen(admin_PIN, 30) > 0) { + if (authenticate_or_set_ccid(dev, admin_PIN) != RET_NO_ERROR) { + return RET_SECURITY_STATUS_NOT_SATISFIED; } + } #endif TLV tlvs[] = { { @@ -317,7 +315,7 @@ int set_secret_on_device_ccid(struct Device *dev, const char *admin_PIN, const c // send IccResult iccResult; 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); + dev->ccid_buffer_out, icc_actual_length, &iccResult); if (r != 0) { diff --git a/src/operations_ccid.h b/src/operations_ccid.h index 4d55ad8..d8da6a6 100644 --- a/src/operations_ccid.h +++ b/src/operations_ccid.h @@ -11,11 +11,11 @@ int authenticate_or_set_ccid(struct Device *dev, const char *admin_PIN); int set_secret_on_device_ccid(struct Device *dev, const char *admin_PIN, const char *OTP_secret_base32, const uint64_t hotp_counter); int verify_code_ccid(struct Device *dev, const uint32_t code_to_verify); int status_ccid(libusb_device_handle *handle, struct FullResponseStatus *full_response); -int nk3_change_pin(struct Device *dev, const char *old_pin, const char*new_pin); +int nk3_change_pin(struct Device *dev, const char *old_pin, const char *new_pin); // new_pin can be `null` // // If it is, no new pin will be set -int nk3_reset(struct Device *dev, const char * new_pin); +int nk3_reset(struct Device *dev, const char *new_pin); #endif//NITROKEY_HOTP_VERIFICATION_OPERATIONS_CCID_H diff --git a/src/settings.h b/src/settings.h index a170943..28d7285 100644 --- a/src/settings.h +++ b/src/settings.h @@ -44,7 +44,7 @@ // #define FEATURE_CCID_ASK_FOR_PIN_ON_ERROR // Use the provided PIN for authentication over CCID -// #define CCID_AUTHENTICATE +// #define CCID_AUTHENTICATE // Attempt to authenticate before setting the PIN, if no pin is present, create the PIN #define CCID_SECRETS_AUTHENTICATE_OR_CREATE_PIN diff --git a/src/structs.h b/src/structs.h index 9e87134..61f3cc5 100644 --- a/src/structs.h +++ b/src/structs.h @@ -117,11 +117,11 @@ struct ResponseStatus { }; enum DeviceType { - Unknown = 0, - Nk3, - NkPro2, - NkStorage, - LibremKey, + Unknown = 0, + Nk3, + NkPro2, + NkStorage, + LibremKey, }; struct FullResponseStatus { @@ -129,8 +129,8 @@ struct FullResponseStatus { struct ResponseStatus response_status; struct { // Only valid if device_type is NK3 - uint8_t pgp_admin_pin_retries; - uint8_t pgp_user_pin_retries; + uint8_t pgp_admin_pin_retries; + uint8_t pgp_user_pin_retries; uint32_t firmware_version; } nk3_extra_info; };