// Attempt to load private key. bool AdbEndpoint::load_key() { BIO* bp_public; BIO* bp_private; wxFileName key_file_name(globalSettings()->settings_folder()); key_file_name.SetName("adb_public.pem"); bp_public = BIO_new_file(key_file_name.GetFullPath(), "r"); if (!bp_public) { wxLogError("Unable to open public key file %s", key_file_name.GetFullPath()); return false; } key_file_name.SetName("adb_private.pem"); bp_private = BIO_new_file(key_file_name.GetFullPath(), "r"); if (!bp_private) { wxLogError("Unable to open private key file %s", key_file_name.GetFullPath()); BIO_free_all(bp_public); return false; } _key = RSA_new(); PEM_read_bio_RSAPublicKey(bp_public, &_key, NULL, NULL); //PEM_read_bio_RSAPrivateKey(bp_private, &_key, NULL, NULL); BIO_free_all(bp_private); BIO_free_all(bp_public); return true; }
void s_ResetLibInstallKey(const string& dir, const string& lib) { string key_file_name(lib); NStr::ToLower(key_file_name); key_file_name += ".installed"; string key_file_path = CDirEntry::ConcatPath(dir, key_file_name); if ( CDirEntry(key_file_path).Exists() ) { CDirEntry(key_file_path).Remove(); } }
bool AdbEndpoint::generate_key() { bool success = false; BIGNUM* bne = NULL; //BIO* bp_public = NULL; //BIO* bp_private = NULL; int bits = 2048; unsigned long e = RSA_F4; // Generate RSA key bne = BN_new(); if (1 == BN_set_word(bne, e)) { _key = RSA_new(); if (1 == RSA_generate_key_ex(_key, bits, bne, NULL)) { success = true; int ret; BIO* bp; wxLogDebug("generated RSA key"); // save it. wxFileName key_file_name(globalSettings()->settings_folder()); key_file_name.SetName("adb_public.pem"); bp = BIO_new_file(key_file_name.GetFullPath(), "w+"); ret = PEM_write_bio_RSAPublicKey(bp, _key); BIO_free_all(bp); key_file_name.SetName("adb_private.pem"); bp = BIO_new_file(key_file_name.GetFullPath(), "w+"); ret = PEM_write_bio_RSAPrivateKey(bp, _key, NULL, NULL, 0, NULL, NULL); BIO_free_all(bp); } BN_free(bne); } return success; }