18#include "moc_qgsauthimportcertdialog.cpp"
44 mAuthNotifyLayout =
new QVBoxLayout;
45 this->setLayout( mAuthNotifyLayout );
47 mAuthNotifyLayout->addWidget( mAuthNotify );
52 connect( btnImportFile, &QToolButton::clicked,
this, &QgsAuthImportCertDialog::btnImportFile_clicked );
53 connect( chkAllowInvalid, &QCheckBox::toggled,
this, &QgsAuthImportCertDialog::chkAllowInvalid_toggled );
55 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
56 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
58 connect( teCertText, &QPlainTextEdit::textChanged,
this, &QgsAuthImportCertDialog::validateCertificates );
60 connect( radioImportFile, &QAbstractButton::toggled,
this, &QgsAuthImportCertDialog::updateGui );
61 connect( radioImportText, &QAbstractButton::toggled,
this, &QgsAuthImportCertDialog::updateGui );
66 radioImportText->setHidden(
true );
67 teCertText->setHidden(
true );
71 radioImportFile->setHidden(
true );
72 frameImportFile->setHidden(
true );
75 radioImportFile->setChecked(
true );
80 grpbxImportCert->setTitle( tr(
"Import Certificate Authorities" ) );
83 okButton()->setText( tr(
"Import" ) );
84 okButton()->setEnabled(
false );
85 teValidation->setFocus();
93 return QList<QSslCertificate>();
104 if ( !radioImportFile->isChecked() )
107 return leImportFile->text();
116 if ( !radioImportText->isChecked() )
119 return teCertText->toPlainText().trimmed();
128 return chkAllowInvalid->isChecked();
137 return cmbbxTrust->trustPolicy();
140void QgsAuthImportCertDialog::updateGui()
142 frameImportFile->setEnabled( radioImportFile->isChecked() );
143 teCertText->setEnabled( radioImportText->isChecked() );
144 validateCertificates();
147void QgsAuthImportCertDialog::validateCertificates()
150 teValidation->clear();
151 teValidation->setStyleSheet( QString() );
154 QList<QSslCertificate> certs;
155 QList<QSslCertificate> nixcerts;
157 const bool allowinvalid = chkAllowInvalid->isChecked();
158 const bool filterCAs = ( mFilter ==
CaFilter );
161 if ( radioImportFile->isChecked() && !leImportFile->text().isEmpty() )
165 else if ( radioImportText->isChecked() && !teCertText->toPlainText().trimmed().isEmpty() )
170 const int certssize = certs.size();
172 const auto constCerts = certs;
173 for (
const QSslCertificate &cert : constCerts )
191 valid = ( certssize > 0
192 && ( allowinvalid || certssize == validcerts )
193 && ( !filterCAs || nixcerts.size() < certssize ) );
195 if ( !nixcerts.isEmpty() )
197 const auto constNixcerts = nixcerts;
198 for (
const QSslCertificate &nixcert : constNixcerts )
200 certs.removeOne( nixcert );
209 teValidation->setStyleSheet(
211 :
QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral(
"QTextEdit" ) ) );
214 QString msg = tr(
"Certificates found: %1\n"
215 "Certificates valid: %2" ).arg( certssize ).arg( validcerts );
219 msg += tr(
"\nAuthorities/Issuers: %1%2" ).arg( cas )
220 .arg( !nixcerts.isEmpty() && nixcerts.size() < certssize ?
" (others not imported)" :
"" );
223 teValidation->setText( msg );
225 okButton()->setEnabled( valid );
228void QgsAuthImportCertDialog::btnImportFile_clicked()
230 const QString &fn = getOpenFileName( tr(
"Open Certificate File" ), tr(
"All files (*.*);;PEM (*.pem);;DER (*.der)" ) );
233 leImportFile->setText( fn );
235 validateCertificates();
238void QgsAuthImportCertDialog::chkAllowInvalid_toggled(
bool checked )
241 validateCertificates();
244QString QgsAuthImportCertDialog::getOpenFileName(
const QString &title,
const QString &extfilter )
247 const QString recentdir = settings.
value( QStringLiteral(
"UI/lastAuthImportCertOpenFileDir" ), QDir::homePath() ).toString();
248 QString f = QFileDialog::getOpenFileName(
this, title, recentdir, extfilter );
252 this->activateWindow();
256 settings.
setValue( QStringLiteral(
"UI/lastAuthImportCertOpenFileDir" ), QFileInfo( f ).absoluteDir().path() );
261QPushButton *QgsAuthImportCertDialog::okButton()
263 return buttonBox->button( QDialogButtonBox::Ok );
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
CertTrustPolicy
Type of certificate trust policy.
static bool certIsViable(const QSslCertificate &cert)
certIsViable checks for viability errors of cert and whether it is NULL
static QList< QSslCertificate > certsFromFile(const QString &certspath)
Returns a list of concatenated certs from a PEM or DER formatted file.
static bool certificateIsAuthorityOrIssuer(const QSslCertificate &cert)
Gets whether a certificate is an Authority or can at least sign other certificates.
static QList< QSslCertificate > certsFromString(const QString &pemtext)
Returns a list of concatenated certs from a PEM Base64 text block.
Utility functions for use by authentication GUI widgets or standalone apps.
static QString greenTextStyleSheet(const QString &selector="*")
Green text stylesheet representing valid, trusted, etc. certificate.
QgsAuthCertUtils::CertTrustPolicy certTrustPolicy()
Defined trust policy for imported certificates.
const QString certFileToImport()
Gets the file path to a certificate to import.
CertFilter
Type of filter to apply to dialog.
QgsAuthImportCertDialog(QWidget *parent=nullptr, QgsAuthImportCertDialog::CertFilter filter=NoFilter, QgsAuthImportCertDialog::CertInput input=AllInputs)
Construct a dialog for importing certificates.
const QList< QSslCertificate > certificatesToImport()
Gets list of certificate objects to import.
const QString certTextToImport()
Gets certificate text to import.
CertInput
Type of inputs for certificates.
bool allowInvalidCerts()
Whether to allow importation of invalid certificates (so trust policy can be overridden)
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.