QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
NTRIPTlsPolicy_p.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QCryptographicHash>
4#include <QtCore/QList>
5#include <QtCore/QString>
6#include <QtNetwork/QSslCertificate>
7#include <QtNetwork/QSslError>
8
9namespace NTRIPTlsPolicy {
11[[nodiscard]] inline QString certificatePin(const QString& endpoint, const QSslCertificate& certificate)
12{
13 return endpoint + QLatin1Char('|') + QString::fromLatin1(certificate.digest(QCryptographicHash::Sha256).toHex());
14}
15
17[[nodiscard]] inline bool isSelfSignedOnly(const QList<QSslError>& errors)
18{
19 if (errors.isEmpty()) {
20 return false;
21 }
22 for (const QSslError& error : errors) {
23 switch (error.error()) {
24 case QSslError::SelfSignedCertificate:
25 case QSslError::SelfSignedCertificateInChain:
26 break;
27 case QSslError::UnableToGetLocalIssuerCertificate:
28 case QSslError::UnableToVerifyFirstCertificate:
29 case QSslError::CertificateUntrusted:
30 if (error.certificate().isNull() || !error.certificate().isSelfSigned()) {
31 return false;
32 }
33 break;
34 default:
35 return false;
36 }
37 }
38 return true;
39}
40} // namespace NTRIPTlsPolicy
Error error
QString certificatePin(const QString &endpoint, const QSslCertificate &certificate)
Binds the certificate's SHA-256 digest to one caster endpoint ("host:port").
bool isSelfSignedOnly(const QList< QSslError > &errors)
Callers must also require opt-in and ignore only the supplied error objects.