18#include "moc_qgsauthimportcertdialog.cpp"
42 mAuthNotifyLayout =
new QVBoxLayout;
43 this->setLayout( mAuthNotifyLayout );
45 mAuthNotifyLayout->addWidget( mAuthNotify );
50 connect( btnImportFile, &QToolButton::clicked,
this, &QgsAuthImportCertDialog::btnImportFile_clicked );
51 connect( chkAllowInvalid, &QCheckBox::toggled,
this, &QgsAuthImportCertDialog::chkAllowInvalid_toggled );
53 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
54 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
56 connect( teCertText, &QPlainTextEdit::textChanged,
this, &QgsAuthImportCertDialog::validateCertificates );
58 connect( radioImportFile, &QAbstractButton::toggled,
this, &QgsAuthImportCertDialog::updateGui );
59 connect( radioImportText, &QAbstractButton::toggled,
this, &QgsAuthImportCertDialog::updateGui );
64 radioImportText->setHidden(
true );
65 teCertText->setHidden(
true );
69 radioImportFile->setHidden(
true );
70 frameImportFile->setHidden(
true );
73 radioImportFile->setChecked(
true );
78 grpbxImportCert->setTitle( tr(
"Import Certificate Authorities" ) );
81 okButton()->setText( tr(
"Import" ) );
82 okButton()->setEnabled(
false );
83 teValidation->setFocus();
91 return QList<QSslCertificate>();
102 if ( !radioImportFile->isChecked() )
105 return leImportFile->text();
114 if ( !radioImportText->isChecked() )
117 return teCertText->toPlainText().trimmed();
126 return chkAllowInvalid->isChecked();
135 return cmbbxTrust->trustPolicy();
138void QgsAuthImportCertDialog::updateGui()
140 frameImportFile->setEnabled( radioImportFile->isChecked() );
141 teCertText->setEnabled( radioImportText->isChecked() );
142 validateCertificates();
145void QgsAuthImportCertDialog::validateCertificates()
148 teValidation->clear();
149 teValidation->setStyleSheet( QString() );
152 QList<QSslCertificate> certs;
153 QList<QSslCertificate> nixcerts;
155 const bool allowinvalid = chkAllowInvalid->isChecked();
156 const bool filterCAs = ( mFilter ==
CaFilter );
159 if ( radioImportFile->isChecked() && !leImportFile->text().isEmpty() )
163 else if ( radioImportText->isChecked() && !teCertText->toPlainText().trimmed().isEmpty() )
168 const int certssize = certs.size();
170 const auto constCerts = certs;
171 for (
const QSslCertificate &cert : constCerts )
189 valid = ( certssize > 0 && ( allowinvalid || certssize == validcerts ) && ( !filterCAs || nixcerts.size() < certssize ) );
191 if ( !nixcerts.isEmpty() )
193 const auto constNixcerts = nixcerts;
194 for (
const QSslCertificate &nixcert : constNixcerts )
196 certs.removeOne( nixcert );
205 teValidation->setStyleSheet(
211 QString msg = tr(
"Certificates found: %1\n"
212 "Certificates valid: %2" )
218 msg += tr(
"\nAuthorities/Issuers: %1%2" ).arg( cas ).arg( !nixcerts.isEmpty() && nixcerts.size() < certssize ?
" (others not imported)" :
"" );
221 teValidation->setText( msg );
223 okButton()->setEnabled( valid );
226void QgsAuthImportCertDialog::btnImportFile_clicked()
228 const QString &fn = getOpenFileName( tr(
"Open Certificate File" ), tr(
"All files (*.*);;PEM (*.pem);;DER (*.der)" ) );
231 leImportFile->setText( fn );
233 validateCertificates();
236void QgsAuthImportCertDialog::chkAllowInvalid_toggled(
bool checked )
239 validateCertificates();
242QString QgsAuthImportCertDialog::getOpenFileName(
const QString &title,
const QString &extfilter )
245 const QString recentdir = settings.
value( QStringLiteral(
"UI/lastAuthImportCertOpenFileDir" ), QDir::homePath() ).toString();
246 QString f = QFileDialog::getOpenFileName(
this, title, recentdir, extfilter );
250 this->activateWindow();
254 settings.
setValue( QStringLiteral(
"UI/lastAuthImportCertOpenFileDir" ), QFileInfo( f ).absoluteDir().path() );
259QPushButton *QgsAuthImportCertDialog::okButton()
261 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.