diff options
author | René Korthaus <[email protected]> | 2017-09-08 13:26:38 +0200 |
---|---|---|
committer | René Korthaus <[email protected]> | 2017-09-08 13:26:38 +0200 |
commit | 808952a620af1ed9068bb17b68ed5e58e4eec69d (patch) | |
tree | 62ca7779c1e871011f57da3dca0e50b52f2c438c /src/lib | |
parent | 51f8edb0cb83c75bdf3818d7e88cac87502b4d31 (diff) |
Fix loading of plaintext PKCS#8 private keys
We fixed this in the C++ API in GH #381, but apparently not
in ffi. Also adds the missing tests.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/ffi/ffi_pkey.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/lib/ffi/ffi_pkey.cpp b/src/lib/ffi/ffi_pkey.cpp index 1577118b1..d4c629149 100644 --- a/src/lib/ffi/ffi_pkey.cpp +++ b/src/lib/ffi/ffi_pkey.cpp @@ -56,16 +56,21 @@ int botan_privkey_load(botan_privkey_t* key, botan_rng_t rng_obj, { *key = nullptr; - if(password == nullptr) - password = ""; - return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() { Botan::DataSource_Memory src(bits, len); Botan::RandomNumberGenerator& rng = safe_get(rng_obj); - std::unique_ptr<Botan::PKCS8_PrivateKey> pkcs8( - Botan::PKCS8::load_key(src, rng, static_cast<std::string>(password))); + std::unique_ptr<Botan::PKCS8_PrivateKey> pkcs8; + + if(password == nullptr) + { + pkcs8.reset(Botan::PKCS8::load_key(src, rng)); + } + else + { + pkcs8.reset(Botan::PKCS8::load_key(src, rng, static_cast<std::string>(password))); + } if(pkcs8) { |