1 #ifndef SSLTRUST_HPP 2 #define SSLTRUST_HPP 3 4 #include <QSslCertificate> 5 #include <QSslKey> 6 #include <QSettings> 7 #include <QSslError> 8 9 #include "trustedhostcollection.hpp" 10 11 struct SslTrust 12 { 13 enum TrustLevel { 14 TrustOnFirstUse = 0, // default 15 TrustEverything = 1, // not recommended 16 TrustNoOne = 2, // approve every fingerprint by hand 17 }; 18 19 enum TrustStatus { 20 Untrusted = 0, 21 Trusted = 1, 22 Mistrusted = 2, 23 }; 24 25 SslTrust() = default; 26 SslTrust(SslTrust const &) = default; 27 SslTrust(SslTrust &&) = default; 28 29 SslTrust & operator=(SslTrust const &) = default; 30 SslTrust & operator=(SslTrust &&) = default; 31 32 TrustLevel trust_level = TrustOnFirstUse; 33 34 TrustedHostCollection trusted_hosts; 35 36 bool enable_ca = false; 37 38 void load(QSettings & settings); 39 void save(QSettings & settings) const; 40 41 //! Adds the certificate to the trust store. Returns `true` on success. 42 bool addTrust(QUrl const & url, QSslCertificate const & certificate); 43 44 bool isTrusted(QUrl const & url, QSslCertificate const & certificate); 45 46 TrustStatus getTrust(QUrl const & url, QSslCertificate const & certificate); 47 48 static bool isTrustRelated(QSslError::SslError err); 49 }; 50 51 #endif // SSLTRUST_HPP 52