Fix PEM reading issues and assert to catch generating corrupt keypairs

This commit is contained in:
Cameron Gutman 2018-04-30 21:33:36 -07:00
parent 9bd804c4c3
commit d4689b466a
2 changed files with 6 additions and 2 deletions

View file

@ -110,6 +110,10 @@ IdentityManager::IdentityManager(QDir directory)
BIO_free(biokey);
BIO_free(biocert);
// Ensure we can actually consume the keys we just wrote
assert(!QSslCertificate(m_CachedPemCert).isNull());
assert(!QSslKey(m_CachedPrivateKey, QSsl::Rsa).isNull());
qDebug() << "Wrote new identity credentials to disk";
}

View file

@ -29,9 +29,9 @@ NvPairingManager::NvPairingManager(QString address, IdentityManager im) :
bio = BIO_new_mem_buf(pk.data(), -1);
THROW_BAD_ALLOC_IF_NULL(bio);
PEM_read_bio_PrivateKey(bio, &m_PrivateKey, nullptr, nullptr);
m_PrivateKey = PEM_read_bio_PrivateKey(bio, nullptr, nullptr, nullptr);
BIO_free_all(bio);
if (m_Cert == nullptr)
if (m_PrivateKey == nullptr)
{
throw new std::runtime_error("Unable to load private key");
}