int check_firmware_version(YK_KEY *yk, bool verbose, bool quiet) { YK_STATUS *st = ykds_alloc(); if (!yk_get_status(yk, st)) { free(st); return 0; } if (verbose) { printf("Firmware version %d.%d.%d\n", ykds_version_major(st), ykds_version_minor(st), ykds_version_build(st)); fflush(stdout); } if (ykds_version_major(st) < 2 || (ykds_version_major(st) == 2 && ykds_version_minor(st) < 2)) { if (! quiet) fprintf(stderr, "Challenge-response not supported before YubiKey 2.2.\n"); free(st); return 0; } free(st); return 1; }
YK_STATUS * _test_init_st(int major, int minor, int build) { YK_STATUS *st = ykds_alloc(); struct status_st *t; t = (struct status_st *) st; /* connected key details */ t->versionMajor = major; t->versionMinor = minor; t->versionBuild = build; return st; }
int main(int argc, char **argv) { YK_KEY *yk = 0; bool error = true; int exit_code = 0; /* Options */ bool serial_dec = false; bool serial_modhex = false; bool serial_hex = false; bool version = false; bool touch_level = false; bool pgm_seq = false; bool slot1 = false; bool slot2 = false; bool vid = false; bool pid = false; bool quiet = false; yk_errno = 0; if (! parse_args(argc, argv, &serial_dec, &serial_modhex, &serial_hex, &version, &touch_level, &pgm_seq, &quiet, &slot1, &slot2, &vid, &pid, &exit_code)) exit(exit_code); if (!yk_init()) { exit_code = 1; goto err; } if (!(yk = yk_open_first_key())) { exit_code = 1; goto err; } if(serial_dec || serial_modhex || serial_hex) { unsigned int serial; int ret = yk_get_serial(yk, 1, 0, &serial); if(!ret) { exit_code = 1; goto err; } if(serial_dec) { if(!quiet) printf("serial: "); printf("%d\n", serial); } if(serial_modhex || serial_hex) { char buf[64]; char hex_serial[64]; char modhex_serial[64]; char *ptr = buf; int chars = snprintf(buf + 1, 63, "%x", serial); if(chars % 2 == 1) { buf[0] = '0'; } else { ptr += 1; } if(serial_hex) { if(!quiet) printf("serial_hex: "); printf("%s\n", ptr); } if(serial_modhex) { yubikey_hex_decode(hex_serial, ptr, strlen(ptr)); yubikey_modhex_encode(modhex_serial, hex_serial, strlen(hex_serial)); if(!quiet) printf("serial_modhex: "); printf("%s\n", modhex_serial); } } } if(version || touch_level || pgm_seq || slot1 || slot2) { YK_STATUS *st = ykds_alloc(); if(!yk_get_status(yk, st)) { ykds_free(st); exit_code = 1; goto err; } if(version) { if(!quiet) printf("version: "); printf("%d.%d.%d\n", ykds_version_major(st), ykds_version_minor(st), ykds_version_build(st)); } if(touch_level) { if(!quiet) printf("touch_level: "); printf("%d\n", ykds_touch_level(st)); } if(pgm_seq) { if(!quiet) printf("programming_sequence: "); printf("%d\n", ykds_pgm_seq(st)); } if(slot1) { if(!quiet) printf("slot1_status: "); printf("%d\n", (ykds_touch_level(st) & CONFIG1_VALID) == CONFIG1_VALID); } if(slot2) { if(!quiet) printf("slot2_status: "); printf("%d\n", (ykds_touch_level(st) & CONFIG2_VALID) == CONFIG2_VALID); } ykds_free(st); } if(vid || pid) { int vendor_id, product_id; if(!yk_get_key_vid_pid(yk, &vendor_id, &product_id)) { exit_code = 1; goto err; } if(vid) { if(!quiet) printf("vendor_id: "); printf("%x\n", vendor_id); } if(pid) { if(!quiet) printf("product_id: "); printf("%x\n", product_id); } } exit_code = 0; error = false; err: if (error || exit_code != 0) { report_yk_error(); } if (yk && !yk_close_key(yk)) { report_yk_error(); exit_code = 2; } if (!yk_release()) { report_yk_error(); exit_code = 2; } exit(exit_code); }
int main(int argc, char** argv) { char showmessage = 1; if((argc == 2) && (strcmp(argv[1], "-y") == 0)) showmessage = 0; if(showmessage == 1) { puts("--------------------------------------------"); puts("Hi! You're going to crack the access code of"); puts("a Yubikey. As soon as the appropriate code "); puts("is found, the AES key will be set to zeros."); puts("Brute forcing the code can take a very long "); puts("time, and with long I mean like more than a "); puts("year."); puts("(By the way you can bypass this message by "); puts("passing the -y option to the program.) "); puts("--------------------------------------------"); puts("Type \"start\" to continue."); char acknowledge[256]; fgets(acknowledge, 256, stdin); if(strcmp(acknowledge, "start\n") != 0) { puts("Quitting."); return EXIT_SUCCESS; } } yk = 0; unsigned char access_code[6]; const char* aeshash="00000000000000000000000000000000"; YKP_CONFIG *cfg = ykp_create_config(); YK_STATUS *st = ykds_alloc(); if(!yk_init()) { fputs("Failed to init Yubikey.\n", stderr); return EXIT_FAILURE; } if(!(yk = yk_open_first_key())) { fputs("No Yubikey found.\n", stderr); return EXIT_FAILURE; } if(!yk_get_status(yk,st)) { fputs("Failed to get status of the Yubikey.\n", stderr); return EXIT_FAILURE; } printf("Found Yubikey. Version: %d.%d.%d Touch level: %d\n", ykds_version_major(st), ykds_version_minor(st), ykds_version_build(st), ykds_touch_level(st)); if(!ykp_configure_for(cfg, 1, st)) { printf("Can't set configuration to 1.\n"); return EXIT_FAILURE; } if(ykp_AES_key_from_hex(cfg, aeshash)) { fputs("Bad AES key. WTF did you do to my source?", stderr); return EXIT_FAILURE; } coreconfig = ykp_core_config(cfg); coreconfignum = ykp_config_num(cfg); bruteforce(access_code, 5); if(st) free(st); if(!yk_close_key(yk)) { fputs("Can't close Yubikey! What the hell are you doing over there?", stderr); return EXIT_FAILURE; } if(!yk_release()) { fputs("Can't release Yubikey.", stderr); return EXIT_FAILURE; } if(cfg) ykp_free_config(cfg); return EXIT_SUCCESS; }
int main(int argc, char **argv) { YK_KEY *yk = 0; bool error = true; int exit_code = 0; /* Options */ bool serial_dec = false; bool serial_modhex = false; bool serial_hex = false; bool version = false; bool touch_level = false; bool pgm_seq = false; bool quiet = false; yk_errno = 0; if (! parse_args(argc, argv, &serial_dec, &serial_modhex, &serial_hex, &version, &touch_level, &pgm_seq, &quiet, &exit_code)) exit(exit_code); if (!yk_init()) { exit_code = 1; goto err; } if (!(yk = yk_open_first_key())) { exit_code = 1; goto err; } if(serial_dec || serial_modhex || serial_hex) { unsigned int serial; int ret = yk_get_serial(yk, 1, 0, &serial); if(!ret) { exit_code = 1; goto err; } if(serial_dec) { if(!quiet) printf("serial: "); printf("%d\n", serial); } if(serial_hex) { if(!quiet) printf("serial_hex: "); printf("%x\n", serial); } if(serial_modhex) { char buf[64]; char hex_serial[64]; char modhex_serial[64]; snprintf(buf, 64, "%x", serial); yubikey_hex_decode(hex_serial, buf, strlen(buf)); yubikey_modhex_encode(modhex_serial, hex_serial, strlen(hex_serial)); if(!quiet) printf("serial_modhex: "); printf("%s\n", modhex_serial); } } if(version || touch_level || pgm_seq) { YK_STATUS *st = ykds_alloc(); if(!yk_get_status(yk, st)) { ykds_free(st); exit_code = 1; goto err; } if(version) { if(!quiet) printf("version: "); printf("%d.%d.%d\n", ykds_version_major(st), ykds_version_minor(st), ykds_version_build(st)); } if(touch_level) { if(!quiet) printf("touch_level: "); printf("%d\n", ykds_touch_level(st)); } if(pgm_seq) { if(!quiet) printf("programming_sequence: "); printf("%d\n", ykds_pgm_seq(st)); } ykds_free(st); } exit_code = 0; error = false; err: if (error || exit_code != 0) { report_yk_error(); } if (yk && !yk_close_key(yk)) { report_yk_error(); exit_code = 2; } if (!yk_release()) { report_yk_error(); exit_code = 2; } exit(exit_code); }