17#include "ui_qgsauthtrustedcasdialog.h"
31#include "moc_qgsauthtrustedcasdialog.cpp"
35 , mTrustedCAs( trustedCAs )
40 mAuthNotifyLayout =
new QVBoxLayout;
41 this->setLayout( mAuthNotifyLayout );
43 mAuthNotifyLayout->addWidget( mAuthNotify );
48 connect( btnInfoCa, &QToolButton::clicked,
this, &QgsAuthTrustedCAsDialog::btnInfoCa_clicked );
49 connect( btnGroupByOrg, &QToolButton::toggled,
this, &QgsAuthTrustedCAsDialog::btnGroupByOrg_toggled );
55 connect( treeTrustedCAs->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAuthTrustedCAsDialog::selectionChanged );
57 connect( treeTrustedCAs, &QTreeWidget::itemDoubleClicked,
this, &QgsAuthTrustedCAsDialog::handleDoubleClick );
60 btnGroupByOrg->setChecked(
false );
63 btnGroupByOrg->setChecked( sortbyval.toBool() );
65 populateCaCertsView();
70void QgsAuthTrustedCAsDialog::setupCaCertsTree()
72 treeTrustedCAs->setColumnCount( 3 );
73 treeTrustedCAs->setHeaderLabels(
74 QStringList() << tr(
"Common Name" )
76 << tr(
"Expiry Date" )
78 treeTrustedCAs->setColumnWidth( 0, 300 );
79 treeTrustedCAs->setColumnWidth( 1, 75 );
82 mRootCaSecItem =
new QTreeWidgetItem(
84 QStringList( tr(
"Authorities/Issuers" ) ),
85 static_cast<int>( QgsAuthTrustedCAsDialog::Section )
88 mRootCaSecItem->setFlags( Qt::ItemIsEnabled );
89 mRootCaSecItem->setExpanded(
true );
90 treeTrustedCAs->insertTopLevelItem( 0, mRootCaSecItem );
93void QgsAuthTrustedCAsDialog::populateCaCertsView()
97 if ( mTrustedCAs.isEmpty() )
102 populateCaCertsSection( mRootCaSecItem, mTrustedCAs, QgsAuthTrustedCAsDialog::CaCert );
105void QgsAuthTrustedCAsDialog::populateCaCertsSection( QTreeWidgetItem *item,
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype )
107 if ( btnGroupByOrg->isChecked() )
109 appendCertsToGroup( certs, catype, item );
113 appendCertsToItem( certs, catype, item );
117void QgsAuthTrustedCAsDialog::appendCertsToGroup(
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype, QTreeWidgetItem *parent )
124 parent = treeTrustedCAs->currentItem();
128 const QMap<QString, QList<QSslCertificate>> orgcerts(
132 QMap<QString, QList<QSslCertificate>>::const_iterator it = orgcerts.constBegin();
133 for ( ; it != orgcerts.constEnd(); ++it )
135 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent, QStringList() << it.key(),
static_cast<int>( QgsAuthTrustedCAsDialog::OrgName ) ) );
136 grpitem->setFirstColumnSpanned(
true );
137 grpitem->setFlags( Qt::ItemIsEnabled );
138 grpitem->setExpanded(
true );
140 QBrush orgb( grpitem->foreground( 0 ) );
141 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
142 grpitem->setForeground( 0, orgb );
143 QFont grpf( grpitem->font( 0 ) );
144 grpf.setItalic(
true );
145 grpitem->setFont( 0, grpf );
147 appendCertsToItem( it.value(), catype, grpitem );
150 parent->sortChildren( 0, Qt::AscendingOrder );
153void QgsAuthTrustedCAsDialog::appendCertsToItem(
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype, QTreeWidgetItem *parent )
160 parent = treeTrustedCAs->currentItem();
166 const auto constCerts = certs;
167 for (
const QSslCertificate &cert : constCerts )
173 coltxts << QString( cert.serialNumber() );
174 coltxts << cert.expiryDate().toString();
176 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( catype ) ) );
181 item->setForeground( 2, redb );
185 item->setData( 0, Qt::UserRole,
id );
188 parent->sortChildren( 0, Qt::AscendingOrder );
191void QgsAuthTrustedCAsDialog::showCertInfo( QTreeWidgetItem *item )
196 const QString digest( item->data( 0, Qt::UserRole ).toString() );
198 const QMap<QString, QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate>> cacertscache(
202 if ( !cacertscache.contains( digest ) )
204 QgsDebugError( QStringLiteral(
"Certificate Authority not in CA certs cache" ) );
208 const QSslCertificate cert( cacertscache.value( digest ).second );
210 QgsAuthCertInfoDialog *dlg =
new QgsAuthCertInfoDialog( cert,
false,
this );
211 dlg->setWindowModality( Qt::WindowModal );
212 dlg->resize( 675, 500 );
217void QgsAuthTrustedCAsDialog::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
220 Q_UNUSED( deselected )
224void QgsAuthTrustedCAsDialog::checkSelection()
227 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
229 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
231 switch ( ( QgsAuthTrustedCAsDialog::CaType ) item->type() )
233 case QgsAuthTrustedCAsDialog::CaCert:
241 btnInfoCa->setEnabled( iscert );
244void QgsAuthTrustedCAsDialog::handleDoubleClick( QTreeWidgetItem *item,
int col )
249 switch ( ( QgsAuthTrustedCAsDialog::CaType ) item->type() )
251 case QgsAuthTrustedCAsDialog::Section:
254 case QgsAuthTrustedCAsDialog::OrgName:
263 showCertInfo( item );
267void QgsAuthTrustedCAsDialog::btnInfoCa_clicked()
269 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
271 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
272 handleDoubleClick( item, 0 );
276void QgsAuthTrustedCAsDialog::btnGroupByOrg_toggled(
bool checked )
280 authMessageLog( QObject::tr(
"Could not store sort by preference" ), QObject::tr(
"Trusted Authorities/Issuers" ),
Qgis::MessageLevel::Warning );
282 populateCaCertsView();
285void QgsAuthTrustedCAsDialog::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
287 messageBar()->pushMessage( authtag, message, level, 7 );
294 treeTrustedCAs->setFocus();
296 QDialog::showEvent( e );
304int QgsAuthTrustedCAsDialog::messageTimeout()
306 const QgsSettings settings;
307 return settings.
value( QStringLiteral(
"qgis/messageTimeout" ), 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 QString resolvedCertName(const QSslCertificate &cert, bool issuer=false)
Gets the general name via RFC 5280 resolution.
static QMap< QString, QList< QSslCertificate > > certsGroupedByOrg(const QList< QSslCertificate > &certs)
Map certificates to their oraganization.
static QString shaHexForCert(const QSslCertificate &cert, bool formatted=false)
Gets the sha1 hash for certificate.
static bool certIsViable(const QSslCertificate &cert)
certIsViable checks for viability errors of cert and whether it is NULL
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)