17#include "ui_qgsauthtrustedcasdialog.h"
32#include "moc_qgsauthtrustedcasdialog.cpp"
34using namespace Qt::StringLiterals;
38 , mTrustedCAs( trustedCAs )
43 mAuthNotifyLayout =
new QVBoxLayout;
44 this->setLayout( mAuthNotifyLayout );
46 mAuthNotifyLayout->addWidget( mAuthNotify );
51 connect( btnInfoCa, &QToolButton::clicked,
this, &QgsAuthTrustedCAsDialog::btnInfoCa_clicked );
52 connect( btnGroupByOrg, &QToolButton::toggled,
this, &QgsAuthTrustedCAsDialog::btnGroupByOrg_toggled );
58 connect( treeTrustedCAs->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAuthTrustedCAsDialog::selectionChanged );
60 connect( treeTrustedCAs, &QTreeWidget::itemDoubleClicked,
this, &QgsAuthTrustedCAsDialog::handleDoubleClick );
63 btnGroupByOrg->setChecked(
false );
66 btnGroupByOrg->setChecked( sortbyval.toBool() );
68 populateCaCertsView();
73void QgsAuthTrustedCAsDialog::setupCaCertsTree()
75 treeTrustedCAs->setColumnCount( 3 );
76 treeTrustedCAs->setHeaderLabels( QStringList() << tr(
"Common Name" ) << tr(
"Serial #" ) << tr(
"Expiry Date" ) );
77 treeTrustedCAs->setColumnWidth( 0, 300 );
78 treeTrustedCAs->setColumnWidth( 1, 75 );
81 mRootCaSecItem =
new QTreeWidgetItem( treeTrustedCAs, QStringList( tr(
"Authorities/Issuers" ) ),
static_cast<int>( QgsAuthTrustedCAsDialog::Section ) );
83 mRootCaSecItem->setFlags( Qt::ItemIsEnabled );
84 mRootCaSecItem->setExpanded(
true );
85 treeTrustedCAs->insertTopLevelItem( 0, mRootCaSecItem );
88void QgsAuthTrustedCAsDialog::populateCaCertsView()
92 if ( mTrustedCAs.isEmpty() )
97 populateCaCertsSection( mRootCaSecItem, mTrustedCAs, QgsAuthTrustedCAsDialog::CaCert );
100void QgsAuthTrustedCAsDialog::populateCaCertsSection( QTreeWidgetItem *item,
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype )
102 if ( btnGroupByOrg->isChecked() )
104 appendCertsToGroup( certs, catype, item );
108 appendCertsToItem( certs, catype, item );
112void QgsAuthTrustedCAsDialog::appendCertsToGroup(
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype, QTreeWidgetItem *parent )
119 parent = treeTrustedCAs->currentItem();
123 const QMap<QString, QList<QSslCertificate>> orgcerts( QgsAuthCertUtils::certsGroupedByOrg( certs ) );
125 QMap<QString, QList<QSslCertificate>>::const_iterator it = orgcerts.constBegin();
126 for ( ; it != orgcerts.constEnd(); ++it )
128 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent, QStringList() << it.key(),
static_cast<int>( QgsAuthTrustedCAsDialog::OrgName ) ) );
129 grpitem->setFirstColumnSpanned(
true );
130 grpitem->setFlags( Qt::ItemIsEnabled );
131 grpitem->setExpanded(
true );
133 QBrush orgb( grpitem->foreground( 0 ) );
134 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
135 grpitem->setForeground( 0, orgb );
136 QFont grpf( grpitem->font( 0 ) );
137 grpf.setItalic(
true );
138 grpitem->setFont( 0, grpf );
140 appendCertsToItem( it.value(), catype, grpitem );
143 parent->sortChildren( 0, Qt::AscendingOrder );
146void QgsAuthTrustedCAsDialog::appendCertsToItem(
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype, QTreeWidgetItem *parent )
153 parent = treeTrustedCAs->currentItem();
159 const auto constCerts = certs;
160 for (
const QSslCertificate &cert : constCerts )
162 const QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
165 coltxts << QgsAuthCertUtils::resolvedCertName( cert );
166 coltxts << QString( cert.serialNumber() );
167 coltxts << cert.expiryDate().toString();
169 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( catype ) ) );
172 if ( !QgsAuthCertUtils::certIsViable( cert ) )
174 item->setForeground( 2, redb );
178 item->setData( 0, Qt::UserRole,
id );
181 parent->sortChildren( 0, Qt::AscendingOrder );
184void QgsAuthTrustedCAsDialog::showCertInfo( QTreeWidgetItem *item )
189 const QString digest( item->data( 0, Qt::UserRole ).toString() );
191 const QMap<QString, QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate>> cacertscache(
QgsApplication::authManager()->caCertsCache() );
193 if ( !cacertscache.contains( digest ) )
195 QgsDebugError( u
"Certificate Authority not in CA certs cache"_s );
199 const QSslCertificate cert( cacertscache.value( digest ).second );
201 QgsAuthCertInfoDialog *dlg =
new QgsAuthCertInfoDialog( cert,
false,
this );
202 dlg->setWindowModality( Qt::WindowModal );
203 dlg->resize( 675, 500 );
208void QgsAuthTrustedCAsDialog::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
211 Q_UNUSED( deselected )
215void QgsAuthTrustedCAsDialog::checkSelection()
218 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
220 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
222 switch ( ( QgsAuthTrustedCAsDialog::CaType ) item->type() )
224 case QgsAuthTrustedCAsDialog::CaCert:
232 btnInfoCa->setEnabled( iscert );
235void QgsAuthTrustedCAsDialog::handleDoubleClick( QTreeWidgetItem *item,
int col )
240 switch ( ( QgsAuthTrustedCAsDialog::CaType ) item->type() )
242 case QgsAuthTrustedCAsDialog::Section:
245 case QgsAuthTrustedCAsDialog::OrgName:
254 showCertInfo( item );
258void QgsAuthTrustedCAsDialog::btnInfoCa_clicked()
260 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
262 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
263 handleDoubleClick( item, 0 );
267void QgsAuthTrustedCAsDialog::btnGroupByOrg_toggled(
bool checked )
271 authMessageLog( QObject::tr(
"Could not store sort by preference" ), QObject::tr(
"Trusted Authorities/Issuers" ),
Qgis::MessageLevel::Warning );
273 populateCaCertsView();
276void QgsAuthTrustedCAsDialog::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
278 messageBar()->pushMessage( authtag, message, level, 7 );
285 treeTrustedCAs->setFocus();
287 QDialog::showEvent( e );
295int QgsAuthTrustedCAsDialog::messageTimeout()
297 const QgsSettings settings;
298 return settings.
value( u
"qgis/messageTimeout"_s, 5 ).toInt();
MessageLevel
Level for messages This will be used both for message log and message bar in application.
@ Warning
Warning message.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
static void setItemBold(QTreeWidgetItem *item)
Call setFirstColumnSpanned(true) on the item and make its font bold.
static void removeChildren(QTreeWidgetItem *item)
Remove the children of the passed item.
static QColor redColor()
Red color representing invalid, untrusted, etc. certificate.
QVariant authSetting(const QString &key, const QVariant &defaultValue=QVariant(), bool decrypt=false)
Returns a previously set authentication setting.
const QList< QSslCertificate > trustedCaCerts(bool includeinvalid=false)
trustedCaCerts get list of all trusted CA certificates
void messageLog(const QString &message, const QString &tag=QgsAuthManager::AUTH_MAN_TAG, Qgis::MessageLevel level=Qgis::MessageLevel::Info) const
Custom logging signal to relay to console output and QgsMessageLog.
void showEvent(QShowEvent *e) override
QgsAuthTrustedCAsDialog(QWidget *parent=nullptr, const QList< QSslCertificate > &trustedCAs=QList< QSslCertificate >())
Construct a dialog that will list the trusted Certificate Authorities.
A bar for displaying non-blocking messages to the user.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
#define QgsDebugError(str)