21 #include <QDialogButtonBox> 23 #include <QPushButton> 25 #include <QToolButton> 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 );
102 void QgsAuthSslErrorsDialog::loadUnloadCertificate(
bool load )
104 grpbxSslErrors->setCollapsed( load );
107 QgsDebugMsg( QStringLiteral(
"Unloading certificate and host:port" ) );
108 clearCertificateConfig();
111 wdgtSslConfig->setEnabled(
true );
112 QgsDebugMsg( QStringLiteral(
"Loading certificate for host:port = %1" ).arg( mHostPort ) );
113 wdgtSslConfig->setSslCertificate( mSslConfiguration.peerCertificate(), mHostPort );
114 if ( !mSslErrors.isEmpty() )
116 wdgtSslConfig->appendSslIgnoreErrors( mSslErrors );
120 void QgsAuthSslErrorsDialog::showCertificateChainInfo()
122 QList<QSslCertificate> peerchain( mSslConfiguration.peerCertificateChain() );
124 if ( !peerchain.isEmpty() )
126 QSslCertificate cert = peerchain.takeFirst();
127 if ( !cert.isNull() )
130 dlg->setWindowModality( Qt::WindowModal );
131 dlg->resize( 675, 500 );
138 void 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 );
153 void QgsAuthSslErrorsDialog::widgetReadyToSaveChanged(
bool cansave )
155 ignoreButton()->setDefault(
false );
156 abortButton()->setDefault( !cansave );
157 saveButton()->setEnabled( cansave );
158 saveButton()->setDefault( cansave );
161 void QgsAuthSslErrorsDialog::checkCanSave()
163 widgetReadyToSaveChanged( wdgtSslConfig->readyToSave() );
166 void QgsAuthSslErrorsDialog::clearCertificateConfig()
168 wdgtSslConfig->resetSslCertConfig();
169 wdgtSslConfig->setEnabled(
false );
173 void QgsAuthSslErrorsDialog::buttonBox_clicked( QAbstractButton *button )
175 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( ) )
205 void QgsAuthSslErrorsDialog::populateErrorsList()
208 errs.reserve( mSslErrors.size() );
209 Q_FOREACH (
const QSslError &err, mSslErrors )
211 errs << QStringLiteral(
"* %1: %2" )
215 teSslErrors->setPlainText( errs.join( QStringLiteral(
"\n" ) ) );
218 QPushButton *QgsAuthSslErrorsDialog::ignoreButton()
220 return buttonBox->button( QDialogButtonBox::Ignore );
223 QPushButton *QgsAuthSslErrorsDialog::saveButton()
225 return buttonBox->button( QDialogButtonBox::Save );
228 QPushButton *QgsAuthSslErrorsDialog::abortButton()
230 return buttonBox->button( QDialogButtonBox::Abort );
233 void QgsAuthSslErrorsDialog::btnChainInfo_clicked()
235 showCertificateChainInfo();
238 void QgsAuthSslErrorsDialog::btnChainCAs_clicked()
240 showCertificateChainCAsInfo();
243 void QgsAuthSslErrorsDialog::grpbxSslErrors_collapsedStateChanged(
bool collapsed )
247 btnChainInfo->setVisible(
false );
248 btnChainCAs->setVisible(
false );
This class is a composition of two QSettings instances:
static QString sslErrorEnumString(QSslError::SslError errenum)
Gets short strings describing an SSL error.
void collapsedStateChanged(bool collapsed)
Signal emitted when groupbox collapsed/expanded state is changed, and when first shown.
Dialog wrapper for widget displaying detailed info on a certificate and its hierarchical trust chain...
static QString shaHexForCert(const QSslCertificate &cert, bool formatted=false)
Gets the sha1 hash for certificate.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
static QgsNetworkAccessManager * instance(Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection)
Returns a pointer to the active QgsNetworkAccessManager for the current thread.
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.