19#include "moc_qgsauthsslerrorsdialog.cpp"
22#include <QDialogButtonBox>
39 , mSslConfiguration( reply->sslConfiguration() )
40 , mSslErrors( sslErrors )
42 , mHostPort( hostport )
44 if ( mDigest.isEmpty() )
48 if ( mHostPort.isEmpty() )
50 mHostPort = QStringLiteral(
"%1:%2" )
51 .arg( reply->url().host() )
52 .arg( reply->url().port() != -1 ? reply->url().port() : 443 )
57 connect( buttonBox, &QDialogButtonBox::clicked,
this, &QgsAuthSslErrorsDialog::buttonBox_clicked );
58 connect( btnChainInfo, &QToolButton::clicked,
this, &QgsAuthSslErrorsDialog::btnChainInfo_clicked );
59 connect( btnChainCAs, &QToolButton::clicked,
this, &QgsAuthSslErrorsDialog::btnChainCAs_clicked );
61 QStyle *style = QApplication::style();
62 lblWarningIcon->setPixmap( style->standardIcon( QStyle::SP_MessageBoxWarning ).pixmap( 48, 48 ) );
63 lblWarningIcon->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
65 lblErrorsText->setStyleSheet( QStringLiteral(
"QLabel{ font-weight: bold; }" ) );
66 leUrl->setText( reply->request().url().toString() );
68 ignoreButton()->setDefault(
false );
69 abortButton()->setDefault(
true );
73 saveButton()->setEnabled(
false );
75 saveButton()->setText( QStringLiteral(
"%1 && %2" ).arg( saveButton()->text(), ignoreButton()->text() ) );
77 grpbxSslConfig->setChecked(
false );
78 grpbxSslConfig->setCollapsed(
true );
79 connect( grpbxSslConfig, &QGroupBox::toggled,
this, &QgsAuthSslErrorsDialog::loadUnloadCertificate );
82 wdgtSslConfig->setConfigCheckable(
false );
83 wdgtSslConfig->certificateGroupBox()->setFlat(
true );
87 btnChainInfo->setVisible(
false );
88 btnChainCAs->setVisible(
false );
89 grpbxSslConfig->setVisible(
false );
90 saveButton()->setVisible(
false );
96void QgsAuthSslErrorsDialog::loadUnloadCertificate(
bool load )
98 grpbxSslErrors->setCollapsed( load );
101 QgsDebugMsgLevel( QStringLiteral(
"Unloading certificate and host:port" ), 2 );
102 clearCertificateConfig();
105 wdgtSslConfig->setEnabled(
true );
106 QgsDebugMsgLevel( QStringLiteral(
"Loading certificate for host:port = %1" ).arg( mHostPort ), 2 );
107 wdgtSslConfig->setSslCertificate( mSslConfiguration.peerCertificate(), mHostPort );
108 if ( !mSslErrors.isEmpty() )
110 wdgtSslConfig->appendSslIgnoreErrors( mSslErrors );
114void QgsAuthSslErrorsDialog::showCertificateChainInfo()
116 QList<QSslCertificate> peerchain( mSslConfiguration.peerCertificateChain() );
118 if ( !peerchain.isEmpty() )
120 const QSslCertificate cert = peerchain.takeFirst();
121 if ( !cert.isNull() )
124 dlg->setWindowModality( Qt::WindowModal );
125 dlg->resize( 675, 500 );
132void QgsAuthSslErrorsDialog::showCertificateChainCAsInfo()
134 const QList<QSslCertificate> certificates = mSslConfiguration.caCertificates();
135 for (
const auto &cert : certificates )
137 qDebug() << cert.subjectInfo( QSslCertificate::SubjectInfo::CommonName );
141 dlg->setWindowModality( Qt::WindowModal );
142 dlg->resize( 675, 500 );
147void QgsAuthSslErrorsDialog::widgetReadyToSaveChanged(
bool cansave )
149 ignoreButton()->setDefault(
false );
150 abortButton()->setDefault( !cansave );
151 saveButton()->setEnabled( cansave );
152 saveButton()->setDefault( cansave );
155void QgsAuthSslErrorsDialog::checkCanSave()
157 widgetReadyToSaveChanged( wdgtSslConfig->readyToSave() );
160void QgsAuthSslErrorsDialog::clearCertificateConfig()
162 wdgtSslConfig->resetSslCertConfig();
163 wdgtSslConfig->setEnabled(
false );
167void QgsAuthSslErrorsDialog::buttonBox_clicked( QAbstractButton *button )
169 const QDialogButtonBox::StandardButton btnenum( buttonBox->standardButton( button ) );
172 case QDialogButtonBox::Ignore:
174 QStringLiteral(
"%1:%2" ).arg( mDigest, mHostPort ),
179 case QDialogButtonBox::Save:
181 wdgtSslConfig->saveSslCertConfig();
184 case QDialogButtonBox::Abort:
197void QgsAuthSslErrorsDialog::populateErrorsList()
200 errs.reserve( mSslErrors.size() );
201 const auto constMSslErrors = mSslErrors;
202 for (
const QSslError &err : constMSslErrors )
204 errs << QStringLiteral(
"* %1: %2" )
207 teSslErrors->setPlainText( errs.join( QLatin1Char(
'\n' ) ) );
210QPushButton *QgsAuthSslErrorsDialog::ignoreButton()
212 return buttonBox->button( QDialogButtonBox::Ignore );
215QPushButton *QgsAuthSslErrorsDialog::saveButton()
217 return buttonBox->button( QDialogButtonBox::Save );
220QPushButton *QgsAuthSslErrorsDialog::abortButton()
222 return buttonBox->button( QDialogButtonBox::Abort );
225void QgsAuthSslErrorsDialog::btnChainInfo_clicked()
227 showCertificateChainInfo();
230void QgsAuthSslErrorsDialog::btnChainCAs_clicked()
232 showCertificateChainCAsInfo();
235void QgsAuthSslErrorsDialog::grpbxSslErrors_collapsedStateChanged(
bool collapsed )
239 btnChainInfo->setVisible(
false );
240 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)