From d4689b466ac2b3c1545c3b94edaf4854b3077a90 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 30 Apr 2018 21:33:36 -0700 Subject: [PATCH] Fix PEM reading issues and assert to catch generating corrupt keypairs --- identitymanager.cpp | 4 ++++ nvpairingmanager.cpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/identitymanager.cpp b/identitymanager.cpp index bd8220dd..303ac29e 100644 --- a/identitymanager.cpp +++ b/identitymanager.cpp @@ -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"; } diff --git a/nvpairingmanager.cpp b/nvpairingmanager.cpp index 5947df47..91a12baf 100644 --- a/nvpairingmanager.cpp +++ b/nvpairingmanager.cpp @@ -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"); }