/* * Make sure the authentication key is present. */ int isns_dsa_init_key(const char *filename) { char pubkey_path[1024]; EVP_PKEY *pkey; isns_mkdir_recursive(isns_dirname(filename)); snprintf(pubkey_path, sizeof(pubkey_path), "%s.pub", filename); if (access(filename, R_OK) == 0 && access(pubkey_path, R_OK) == 0) return 1; if (!(pkey = isns_dsa_generate_key())) { isns_error("Failed to generate AuthKey\n"); return 0; } if (!isns_dsa_store_private(filename, pkey)) { isns_error("Unable to write private key to %s\n", filename); return 0; } isns_notice("Stored private key in %s\n", filename); if (!isns_dsa_store_public(pubkey_path, pkey)) { isns_error("Unable to write public key to %s\n", pubkey_path); return 0; } isns_notice("Stored private key in %s\n", pubkey_path); return 1; }
isns_attr_t * generate_key_callback(void) { EVP_PKEY *pkey; if (opt_keyfile == NULL) isns_fatal("Key generation requires --keyfile option\n"); if (!(pkey = isns_dsa_generate_key())) isns_fatal("Key generation failed\n"); if (!isns_dsa_store_private(opt_keyfile, pkey)) isns_fatal("Unable to write private key to %s\n", opt_keyfile); printf("Stored DSA private key in %s\n", opt_keyfile); return __key_to_attr(pkey); }