int client_register(int user_level, const char* password, int type, int mode) { con.user_level = user_level; strcpy(con.password, password); rcp_packet reg_req; init_rcp_header(®_req, 0, RCP_COMMAND_CONF_RCP_CLIENT_REGISTRATION, RCP_COMMAND_MODE_WRITE, RCP_DATA_TYPE_P_OCTET); char pphrase[MAX_PASSPHRASE_LEN]; int plen; int res = generate_passphrase(mode, con.user_level, con.password, pphrase, &plen); if (res == -1) goto error; tlog_hex(TLOG_DEBUG, "passphrase", pphrase, plen); unsigned short tmp16; reg_req.payload[0] = type; reg_req.payload[1] = 0; tmp16 = htons(0); memcpy(reg_req.payload+2, &tmp16, 2); reg_req.payload[4] = mode; reg_req.payload[5] = plen; tmp16 = htons(1); memcpy(reg_req.payload+6, &tmp16, 2); tmp16 = htons(0xffff); memcpy(reg_req.payload+8, &tmp16, 2); memcpy(reg_req.payload+10, pphrase, plen); //cl_reg.payload[plen+10] = 0; reg_req.payload_length = plen + 10; //tlog_hex("client register payload", cl_reg.payload, cl_reg.payload_length); rcp_packet* reg_resp = rcp_command(®_req); if (reg_resp == NULL) goto error; tlog_hex(TLOG_DEBUG, "client register response", reg_resp->payload, reg_resp->payload_length); if (reg_resp->payload[0] == 0) goto error; con.user_level = reg_resp->payload[1]; con.client_id = ntohs(*(unsigned short*)(reg_resp->payload+2)); return 0; error: TL_ERROR("client_register()"); return -1; }
int main(int argc, char* argv[]) { uint8* pass = NULL; uint8* key = NULL; if (argc < 3) { fprintf(stderr, "usage: genpass <platform> <ramdisk.dmg> <filesystem.dmg>\n"); return -1; } char* platform = argv[1]; char* ramdisk = argv[2]; char* filesystem = argv[3]; pass = generate_passphrase(platform, ramdisk); if (pass == NULL) { fprintf(stderr, "unable to generate asr passphrase\n"); return -1; } //printf("asr passphrase: "); //print_hex(pass, 0x20); key = decrypt_key(filesystem, pass); if (key == NULL) { fprintf(stderr, "unable to decrypt vfdecrypt key\n"); return -1; } printf("vfdecrypt key: "); print_hex(key, 0x24); if (pass) free(pass); if (key) free(key); return 0; }
int main(int argc, char **argv) { int opt; int ret; const char *mac_address = NULL; const char *npw = NULL; const char *dpw = NULL; const char *iface = NULL; struct context ctx; unsigned int hash_only = 0; unsigned int reset_device = 0; unsigned int push_button = 0; uint8_t mac[ETH_ALEN] = { 0 }; memset(&ctx, 0, sizeof(ctx)); while ((opt = getopt(argc, argv, "n:d:p:a:i:ukrh")) > 0) { switch (opt) { case 'n': case 'p': npw = optarg; break; case 'd': dpw = optarg; break; case 'a': mac_address = optarg; break; case 'i': iface = optarg; break; case 'k': hash_only = 1; break; case 'r': reset_device = 1; break; case 'u': push_button = 1; break; case 'h': default: usage(); return 1; } } if (argc < 2) { usage(); return 1; } argc -= optind; argv += optind; if (hash_only) return generate_passphrase(&ctx, npw, dpw); iface = argv[0]; if (!iface) { fprintf(stderr, "missing interface argument\n"); return 1; } fprintf(stdout, "Interface: %s\n", iface); if (mac_address) { ret = sscanf(mac_address, "%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8"", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); if (ret != ETH_ALEN) { fprintf(stdout, "invalid MAC address\n"); return ret; } fprintf(stdout, "MAC: %s\n", mac_address); } else { memcpy(mac, bcast_hpav_mac, sizeof(bcast_hpav_mac)); fprintf(stdout, "MAC: using broadcast HPAV\n"); } ret = init_socket(&ctx, iface); if (ret) { fprintf(stdout, "failed to initialize raw socket\n"); return ret; } if (reset_device) { ret = send_reset(&ctx, mac); if (ret) fprintf(stdout, "failed to send reset\n"); return ret; } if (push_button) { ret = pushbutton_request(&ctx, mac); fprintf(stdout, "sending PushButton request on the local link\n"); if (ret) fprintf(stdout, "failed to send push_button\n"); return ret; } if (!npw) { fprintf(stderr, "missing NPW argument\n"); return 1; } fprintf(stdout, "NPW: %s\n", npw); ret = send_key(&ctx, npw, dpw, mac); if (ret) { fprintf(stdout, "failed to send key\n"); return ret; } if (signal(SIGALRM, sighandler) == SIG_ERR) { fprintf(stdout, "failed to setup signal handler\n"); return ret; } /* catch answer or timeout */ alarm(3); ret = read_key_confirm(&ctx, mac); return ret; }