aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/settings/GlobalSettingStation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/settings/GlobalSettingStation.cpp')
-rw-r--r--src/ui/settings/GlobalSettingStation.cpp51
1 files changed, 43 insertions, 8 deletions
diff --git a/src/ui/settings/GlobalSettingStation.cpp b/src/ui/settings/GlobalSettingStation.cpp
index 43534926..4e9bac73 100644
--- a/src/ui/settings/GlobalSettingStation.cpp
+++ b/src/ui/settings/GlobalSettingStation.cpp
@@ -24,6 +24,10 @@
#include "GlobalSettingStation.h"
+#include <openssl/bio.h>
+#include <openssl/pem.h>
+
+#include <vmime/security/cert/openssl/X509Certificate_OpenSSL.hpp>
#include <vmime/vmime.hpp>
std::unique_ptr<GpgFrontend::UI::GlobalSettingStation>
@@ -50,10 +54,7 @@ void GpgFrontend::UI::GlobalSettingStation::Sync() noexcept {
}
}
-GpgFrontend::UI::GlobalSettingStation::GlobalSettingStation() noexcept
- : default_certs_verifier_(
- vmime::make_shared<
- vmime::security::cert::defaultCertificateVerifier>()) {
+GpgFrontend::UI::GlobalSettingStation::GlobalSettingStation() noexcept {
using namespace boost::filesystem;
using namespace libconfig;
@@ -98,8 +99,42 @@ GpgFrontend::UI::GlobalSettingStation::GlobalSettingStation() noexcept
}
}
-void GpgFrontend::UI::GlobalSettingStation::SetRootCerts(
- const std::vector<
- vmime::shared_ptr<vmime::security::cert::X509Certificate>>& certs) {
- default_certs_verifier_->setX509RootCAs(certs);
+void GpgFrontend::UI::GlobalSettingStation::AddRootCert(
+ const boost::filesystem::path& path) {
+ auto out_buffer = GpgFrontend::read_all_data_in_file(path.string());
+
+ auto mem_bio = std::shared_ptr<BIO>(
+ BIO_new_mem_buf(out_buffer.data(), static_cast<int>(out_buffer.size())),
+ [](BIO* _p) { BIO_free(_p); });
+
+ auto x509 = std::shared_ptr<X509>(
+ PEM_read_bio_X509(mem_bio.get(), nullptr, nullptr, nullptr),
+ [](X509* _p) { X509_free(_p); });
+
+ if (!x509) return;
+
+ root_certs_.push_back(x509);
}
+
+vmime::shared_ptr<vmime::security::cert::defaultCertificateVerifier>
+GpgFrontend::UI::GlobalSettingStation::GetCertVerifier() const {
+ auto p_cv =
+ vmime::make_shared<vmime::security::cert::defaultCertificateVerifier>();
+
+ std::vector<vmime::shared_ptr<vmime::security::cert::X509Certificate>>
+ _root_certs;
+ for (const auto& cert : root_certs_) {
+ _root_certs.push_back(
+ std::make_shared<vmime::security::cert::X509Certificate_OpenSSL>(
+ cert.get()));
+ }
+ return p_cv;
+}
+
+const std::vector<std::shared_ptr<X509>>&
+GpgFrontend::UI::GlobalSettingStation::GetRootCerts() {
+ return root_certs_;
+}
+
+GpgFrontend::UI::GlobalSettingStation::~GlobalSettingStation() noexcept =
+ default;