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.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/ui/settings/GlobalSettingStation.cpp b/src/ui/settings/GlobalSettingStation.cpp
index e88de93b..4e9bac73 100644
--- a/src/ui/settings/GlobalSettingStation.cpp
+++ b/src/ui/settings/GlobalSettingStation.cpp
@@ -24,6 +24,12 @@
#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>
GpgFrontend::UI::GlobalSettingStation::_instance = nullptr;
@@ -92,3 +98,43 @@ GpgFrontend::UI::GlobalSettingStation::GlobalSettingStation() noexcept {
}
}
}
+
+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;