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(
77 QStringList() << tr(
"Common Name" )
79 << tr(
"Expiry Date" )
81 treeTrustedCAs->setColumnWidth( 0, 300 );
82 treeTrustedCAs->setColumnWidth( 1, 75 );
85 mRootCaSecItem =
new QTreeWidgetItem(
87 QStringList( tr(
"Authorities/Issuers" ) ),
88 static_cast<int>( QgsAuthTrustedCAsDialog::Section )
91 mRootCaSecItem->setFlags( Qt::ItemIsEnabled );
92 mRootCaSecItem->setExpanded(
true );
93 treeTrustedCAs->insertTopLevelItem( 0, mRootCaSecItem );
96void QgsAuthTrustedCAsDialog::populateCaCertsView()
100 if ( mTrustedCAs.isEmpty() )
105 populateCaCertsSection( mRootCaSecItem, mTrustedCAs, QgsAuthTrustedCAsDialog::CaCert );
108void QgsAuthTrustedCAsDialog::populateCaCertsSection( QTreeWidgetItem *item,
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype )
110 if ( btnGroupByOrg->isChecked() )
112 appendCertsToGroup( certs, catype, item );
116 appendCertsToItem( certs, catype, item );
120void QgsAuthTrustedCAsDialog::appendCertsToGroup(
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype, QTreeWidgetItem *parent )
127 parent = treeTrustedCAs->currentItem();
131 const QMap<QString, QList<QSslCertificate>> orgcerts(
132 QgsAuthCertUtils::certsGroupedByOrg( certs )
135 QMap<QString, QList<QSslCertificate>>::const_iterator it = orgcerts.constBegin();
136 for ( ; it != orgcerts.constEnd(); ++it )
138 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent, QStringList() << it.key(),
static_cast<int>( QgsAuthTrustedCAsDialog::OrgName ) ) );
139 grpitem->setFirstColumnSpanned(
true );
140 grpitem->setFlags( Qt::ItemIsEnabled );
141 grpitem->setExpanded(
true );
143 QBrush orgb( grpitem->foreground( 0 ) );
144 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
145 grpitem->setForeground( 0, orgb );
146 QFont grpf( grpitem->font( 0 ) );
147 grpf.setItalic(
true );
148 grpitem->setFont( 0, grpf );
150 appendCertsToItem( it.value(), catype, grpitem );
153 parent->sortChildren( 0, Qt::AscendingOrder );
156void QgsAuthTrustedCAsDialog::appendCertsToItem(
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype, QTreeWidgetItem *parent )
163 parent = treeTrustedCAs->currentItem();
169 const auto constCerts = certs;
170 for (
const QSslCertificate &cert : constCerts )
172 const QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
175 coltxts << QgsAuthCertUtils::resolvedCertName( cert );
176 coltxts << QString( cert.serialNumber() );
177 coltxts << cert.expiryDate().toString();
179 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( catype ) ) );
182 if ( !QgsAuthCertUtils::certIsViable( cert ) )
184 item->setForeground( 2, redb );
188 item->setData( 0, Qt::UserRole,
id );
191 parent->sortChildren( 0, Qt::AscendingOrder );
194void QgsAuthTrustedCAsDialog::showCertInfo( QTreeWidgetItem *item )
199 const QString digest( item->data( 0, Qt::UserRole ).toString() );
201 const QMap<QString, QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate>> cacertscache(
205 if ( !cacertscache.contains( digest ) )
207 QgsDebugError( u
"Certificate Authority not in CA certs cache"_s );
211 const QSslCertificate cert( cacertscache.value( digest ).second );
213 QgsAuthCertInfoDialog *dlg =
new QgsAuthCertInfoDialog( cert,
false,
this );
214 dlg->setWindowModality( Qt::WindowModal );
215 dlg->resize( 675, 500 );
220void QgsAuthTrustedCAsDialog::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
223 Q_UNUSED( deselected )
227void QgsAuthTrustedCAsDialog::checkSelection()
230 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
232 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
234 switch ( ( QgsAuthTrustedCAsDialog::CaType ) item->type() )
236 case QgsAuthTrustedCAsDialog::CaCert:
244 btnInfoCa->setEnabled( iscert );
247void QgsAuthTrustedCAsDialog::handleDoubleClick( QTreeWidgetItem *item,
int col )
252 switch ( ( QgsAuthTrustedCAsDialog::CaType ) item->type() )
254 case QgsAuthTrustedCAsDialog::Section:
257 case QgsAuthTrustedCAsDialog::OrgName:
266 showCertInfo( item );
270void QgsAuthTrustedCAsDialog::btnInfoCa_clicked()
272 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
274 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
275 handleDoubleClick( item, 0 );
279void QgsAuthTrustedCAsDialog::btnGroupByOrg_toggled(
bool checked )
283 authMessageLog( QObject::tr(
"Could not store sort by preference" ), QObject::tr(
"Trusted Authorities/Issuers" ),
Qgis::MessageLevel::Warning );
285 populateCaCertsView();
288void QgsAuthTrustedCAsDialog::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
290 messageBar()->pushMessage( authtag, message, level, 7 );
297 treeTrustedCAs->setFocus();
299 QDialog::showEvent( e );
307int QgsAuthTrustedCAsDialog::messageTimeout()
309 const QgsSettings settings;
310 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)