21#include <QDialogButtonBox>
37 const QList<QSslError> &sslErrors,
39 const QString &digest,
40 const QString &hostport )
42 , mSslConfiguration( reply->sslConfiguration() )
43 , mSslErrors( sslErrors )
45 , mHostPort( hostport )
47 if ( mDigest.isEmpty() )
51 if ( mHostPort.isEmpty() )
53 mHostPort = QStringLiteral(
"%1:%2" )
54 .arg( reply->url().host() )
55 .arg( reply->url().port() != -1 ? reply->url().port() : 443 )
60 connect( buttonBox, &QDialogButtonBox::clicked,
this, &QgsAuthSslErrorsDialog::buttonBox_clicked );
61 connect( btnChainInfo, &QToolButton::clicked,
this, &QgsAuthSslErrorsDialog::btnChainInfo_clicked );
62 connect( btnChainCAs, &QToolButton::clicked,
this, &QgsAuthSslErrorsDialog::btnChainCAs_clicked );
64 QStyle *style = QApplication::style();
65 lblWarningIcon->setPixmap( style->standardIcon( QStyle::SP_MessageBoxWarning ).pixmap( 48, 48 ) );
66 lblWarningIcon->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
68 lblErrorsText->setStyleSheet( QStringLiteral(
"QLabel{ font-weight: bold; }" ) );
69 leUrl->setText( reply->request().url().toString() );
71 ignoreButton()->setDefault(
false );
72 abortButton()->setDefault(
true );
76 saveButton()->setEnabled(
false );
78 saveButton()->setText( QStringLiteral(
"%1 && %2" ).arg( saveButton()->text(),
79 ignoreButton()->text() ) );
81 grpbxSslConfig->setChecked(
false );
82 grpbxSslConfig->setCollapsed(
true );
83 connect( grpbxSslConfig, &QGroupBox::toggled,
84 this, &QgsAuthSslErrorsDialog::loadUnloadCertificate );
87 this, &QgsAuthSslErrorsDialog::widgetReadyToSaveChanged );
88 wdgtSslConfig->setConfigCheckable(
false );
89 wdgtSslConfig->certificateGroupBox()->setFlat(
true );
93 btnChainInfo->setVisible(
false );
94 btnChainCAs->setVisible(
false );
95 grpbxSslConfig->setVisible(
false );
96 saveButton()->setVisible(
false );
102void QgsAuthSslErrorsDialog::loadUnloadCertificate(
bool load )
104 grpbxSslErrors->setCollapsed( load );
107 QgsDebugMsgLevel( QStringLiteral(
"Unloading certificate and host:port" ), 2 );
108 clearCertificateConfig();
111 wdgtSslConfig->setEnabled(
true );
112 QgsDebugMsgLevel( QStringLiteral(
"Loading certificate for host:port = %1" ).arg( mHostPort ), 2 );
113 wdgtSslConfig->setSslCertificate( mSslConfiguration.peerCertificate(), mHostPort );
114 if ( !mSslErrors.isEmpty() )
116 wdgtSslConfig->appendSslIgnoreErrors( mSslErrors );
120void QgsAuthSslErrorsDialog::showCertificateChainInfo()
122 QList<QSslCertificate> peerchain( mSslConfiguration.peerCertificateChain() );
124 if ( !peerchain.isEmpty() )
126 const QSslCertificate cert = peerchain.takeFirst();
127 if ( !cert.isNull() )
130 dlg->setWindowModality( Qt::WindowModal );
131 dlg->resize( 675, 500 );
138void QgsAuthSslErrorsDialog::showCertificateChainCAsInfo()
140 const QList< QSslCertificate > certificates = mSslConfiguration.caCertificates();
141 for (
const auto &cert : certificates )
143 qDebug() << cert.subjectInfo( QSslCertificate::SubjectInfo::CommonName );
147 dlg->setWindowModality( Qt::WindowModal );
148 dlg->resize( 675, 500 );
153void QgsAuthSslErrorsDialog::widgetReadyToSaveChanged(
bool cansave )
155 ignoreButton()->setDefault(
false );
156 abortButton()->setDefault( !cansave );
157 saveButton()->setEnabled( cansave );
158 saveButton()->setDefault( cansave );
161void QgsAuthSslErrorsDialog::checkCanSave()
163 widgetReadyToSaveChanged( wdgtSslConfig->readyToSave() );
166void QgsAuthSslErrorsDialog::clearCertificateConfig()
168 wdgtSslConfig->resetSslCertConfig();
169 wdgtSslConfig->setEnabled(
false );
173void QgsAuthSslErrorsDialog::buttonBox_clicked( QAbstractButton *button )
175 const QDialogButtonBox::StandardButton btnenum( buttonBox->standardButton( button ) );
178 case QDialogButtonBox::Ignore:
180 QStringLiteral(
"%1:%2" ).arg( mDigest, mHostPort ),
184 case QDialogButtonBox::Save:
186 wdgtSslConfig->saveSslCertConfig();
189 case QDialogButtonBox::Abort:
196 if ( btnenum == QDialogButtonBox::Abort &&
197 QgsSettings().value( QStringLiteral(
"clear_auth_cache_on_errors" ),
199 QgsSettings::Section::Auth ).toBool( ) )
205void QgsAuthSslErrorsDialog::populateErrorsList()
208 errs.reserve( mSslErrors.size() );
209 const auto constMSslErrors = mSslErrors;
210 for (
const QSslError &err : constMSslErrors )
212 errs << QStringLiteral(
"* %1: %2" )
216 teSslErrors->setPlainText( errs.join( QLatin1Char(
'\n' ) ) );
219QPushButton *QgsAuthSslErrorsDialog::ignoreButton()
221 return buttonBox->button( QDialogButtonBox::Ignore );
224QPushButton *QgsAuthSslErrorsDialog::saveButton()
226 return buttonBox->button( QDialogButtonBox::Save );
229QPushButton *QgsAuthSslErrorsDialog::abortButton()
231 return buttonBox->button( QDialogButtonBox::Abort );
234void QgsAuthSslErrorsDialog::btnChainInfo_clicked()
236 showCertificateChainInfo();
239void QgsAuthSslErrorsDialog::btnChainCAs_clicked()
241 showCertificateChainCAsInfo();
244void QgsAuthSslErrorsDialog::grpbxSslErrors_collapsedStateChanged(
bool collapsed )
248 btnChainInfo->setVisible(
false );
249 btnChainCAs->setVisible(
false );
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
Dialog wrapper for widget displaying detailed info on a certificate and its hierarchical trust chain.
static QString sslErrorEnumString(QSslError::SslError errenum)
Gets short strings describing an SSL error.
static QString shaHexForCert(const QSslCertificate &cert, bool formatted=false)
Gets the sha1 hash for certificate.
bool updateIgnoredSslErrorsCache(const QString &shahostport, const QList< QSslError > &errors)
Update ignored SSL error cache with possible ignored SSL errors, using sha:host:port key.
QgsAuthSslErrorsDialog(QNetworkReply *reply, const QList< QSslError > &sslErrors, QWidget *parent=nullptr, const QString &digest=QString(), const QString &hostport=QString())
Construct a dialog to handle SSL errors and saving SSL server certificate exceptions.
Widget for listing trusted Certificate (Intermediate) Authorities used in secure connections.
void collapsedStateChanged(bool collapsed)
Signal emitted when groupbox collapsed/expanded state is changed, and when first shown.
static QgsNetworkAccessManager * instance(Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection)
Returns a pointer to the active QgsNetworkAccessManager for the current thread.
This class is a composition of two QSettings instances:
#define QgsDebugMsgLevel(str, level)