aboutsummaryrefslogtreecommitdiff
path: root/src/ssltrust.cpp
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-06-21 21:29:30 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-06-21 21:29:30 +0200
commit6ef3d6a41f07a2f43a9b69f4e75adbffe634ea09 (patch)
tree791ad53823e47ecff837ec6004aa80c8fb1e1445 /src/ssltrust.cpp
parent6225064a008eccb9099ed2db49dad04c5f6d0550 (diff)
Adds option for manually trusting a TLS server.
Diffstat (limited to 'src/ssltrust.cpp')
-rw-r--r--src/ssltrust.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/ssltrust.cpp b/src/ssltrust.cpp
index f35988e..7ccdf9c 100644
--- a/src/ssltrust.cpp
+++ b/src/ssltrust.cpp
@@ -47,6 +47,27 @@ void SslTrust::save(QSettings &settings) const
settings.endArray();
}
+bool SslTrust::addTrust(const QUrl &url, const QSslCertificate &certificate)
+{
+ if(certificate.isNull())
+ return false;
+ if(auto host_or_none = trusted_hosts.get(url.host()); host_or_none)
+ {
+ return false;
+ }
+ else
+ {
+ TrustedHost host;
+ host.host_name = url.host();
+ host.trusted_at = QDateTime::currentDateTime();
+ host.public_key = certificate.publicKey();
+
+ bool ok = trusted_hosts.insert(host);
+ assert(ok);
+ return true;
+ }
+}
+
bool SslTrust::isTrusted(QUrl const & url, const QSslCertificate &certificate)
{
return (getTrust(url, certificate) == Trusted);
@@ -54,6 +75,9 @@ bool SslTrust::isTrusted(QUrl const & url, const QSslCertificate &certificate)
SslTrust::TrustStatus SslTrust::getTrust(const QUrl &url, const QSslCertificate &certificate)
{
+ if(certificate.isNull())
+ return Untrusted;
+
if(trust_level == TrustEverything)
return Trusted;