18#include "moc_qgsauthtrustedcasdialog.cpp"
19#include "ui_qgsauthtrustedcasdialog.h"
33 const QList<QSslCertificate> &trustedCAs )
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 );
52 this, &QgsAuthTrustedCAsDialog::authMessageLog );
56 connect( treeTrustedCAs->selectionModel(), &QItemSelectionModel::selectionChanged,
57 this, &QgsAuthTrustedCAsDialog::selectionChanged );
59 connect( treeTrustedCAs, &QTreeWidget::itemDoubleClicked,
60 this, &QgsAuthTrustedCAsDialog::handleDoubleClick );
63 btnGroupByOrg->setChecked(
false );
66 btnGroupByOrg->setChecked( sortbyval.toBool() );
68 populateCaCertsView();
73static void setItemBold_( QTreeWidgetItem *item )
75 item->setFirstColumnSpanned(
true );
76 QFont secf( item->font( 0 ) );
78 item->setFont( 0, secf );
81void QgsAuthTrustedCAsDialog::setupCaCertsTree()
83 treeTrustedCAs->setColumnCount( 3 );
84 treeTrustedCAs->setHeaderLabels(
85 QStringList() << tr(
"Common Name" )
87 << tr(
"Expiry Date" ) );
88 treeTrustedCAs->setColumnWidth( 0, 300 );
89 treeTrustedCAs->setColumnWidth( 1, 75 );
92 mRootCaSecItem =
new QTreeWidgetItem(
94 QStringList( tr(
"Authorities/Issuers" ) ),
95 static_cast<int>( QgsAuthTrustedCAsDialog::Section ) );
96 setItemBold_( mRootCaSecItem );
97 mRootCaSecItem->setFlags( Qt::ItemIsEnabled );
98 mRootCaSecItem->setExpanded(
true );
99 treeTrustedCAs->insertTopLevelItem( 0, mRootCaSecItem );
102static void removeChildren_( QTreeWidgetItem *item )
104 const auto constTakeChildren = item->takeChildren();
105 for ( QTreeWidgetItem *child : constTakeChildren )
111void QgsAuthTrustedCAsDialog::populateCaCertsView()
113 removeChildren_( mRootCaSecItem );
115 if ( mTrustedCAs.isEmpty() )
120 populateCaCertsSection( mRootCaSecItem, mTrustedCAs, QgsAuthTrustedCAsDialog::CaCert );
123void QgsAuthTrustedCAsDialog::populateCaCertsSection( QTreeWidgetItem *item,
const QList<QSslCertificate> &certs,
124 QgsAuthTrustedCAsDialog::CaType catype )
126 if ( btnGroupByOrg->isChecked() )
128 appendCertsToGroup( certs, catype, item );
132 appendCertsToItem( certs, catype, item );
136void QgsAuthTrustedCAsDialog::appendCertsToGroup(
const QList<QSslCertificate> &certs,
137 QgsAuthTrustedCAsDialog::CaType catype,
138 QTreeWidgetItem *parent )
145 parent = treeTrustedCAs->currentItem();
149 const QMap< QString, QList<QSslCertificate> > orgcerts(
152 QMap< QString, QList<QSslCertificate> >::const_iterator it = orgcerts.constBegin();
153 for ( ; it != orgcerts.constEnd(); ++it )
155 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent,
156 QStringList() << it.key(),
157 static_cast<int>( QgsAuthTrustedCAsDialog::OrgName ) ) );
158 grpitem->setFirstColumnSpanned(
true );
159 grpitem->setFlags( Qt::ItemIsEnabled );
160 grpitem->setExpanded(
true );
162 QBrush orgb( grpitem->foreground( 0 ) );
163 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
164 grpitem->setForeground( 0, orgb );
165 QFont grpf( grpitem->font( 0 ) );
166 grpf.setItalic(
true );
167 grpitem->setFont( 0, grpf );
169 appendCertsToItem( it.value(), catype, grpitem );
172 parent->sortChildren( 0, Qt::AscendingOrder );
175void QgsAuthTrustedCAsDialog::appendCertsToItem(
const QList<QSslCertificate> &certs,
176 QgsAuthTrustedCAsDialog::CaType catype,
177 QTreeWidgetItem *parent )
184 parent = treeTrustedCAs->currentItem();
190 const auto constCerts = certs;
191 for (
const QSslCertificate &cert : constCerts )
197 coltxts << QString( cert.serialNumber() );
198 coltxts << cert.expiryDate().toString();
200 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( catype ) ) );
205 item->setForeground( 2, redb );
209 item->setData( 0, Qt::UserRole,
id );
212 parent->sortChildren( 0, Qt::AscendingOrder );
215void QgsAuthTrustedCAsDialog::showCertInfo( QTreeWidgetItem *item )
220 const QString digest( item->data( 0, Qt::UserRole ).toString() );
222 const QMap<QString, QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > cacertscache(
225 if ( !cacertscache.contains( digest ) )
227 QgsDebugError( QStringLiteral(
"Certificate Authority not in CA certs cache" ) );
231 const QSslCertificate cert( cacertscache.value( digest ).second );
234 dlg->setWindowModality( Qt::WindowModal );
235 dlg->resize( 675, 500 );
240void QgsAuthTrustedCAsDialog::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
243 Q_UNUSED( deselected )
247void QgsAuthTrustedCAsDialog::checkSelection()
250 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
252 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
254 switch ( ( QgsAuthTrustedCAsDialog::CaType )item->type() )
256 case QgsAuthTrustedCAsDialog::CaCert:
264 btnInfoCa->setEnabled( iscert );
267void QgsAuthTrustedCAsDialog::handleDoubleClick( QTreeWidgetItem *item,
int col )
272 switch ( ( QgsAuthTrustedCAsDialog::CaType )item->type() )
274 case QgsAuthTrustedCAsDialog::Section:
277 case QgsAuthTrustedCAsDialog::OrgName:
286 showCertInfo( item );
290void QgsAuthTrustedCAsDialog::btnInfoCa_clicked()
292 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
294 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
295 handleDoubleClick( item, 0 );
299void QgsAuthTrustedCAsDialog::btnGroupByOrg_toggled(
bool checked )
303 authMessageLog( QObject::tr(
"Could not store sort by preference" ),
304 QObject::tr(
"Trusted Authorities/Issuers" ),
307 populateCaCertsView();
310void QgsAuthTrustedCAsDialog::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
312 messageBar()->
pushMessage( authtag, message, level, 7 );
319 treeTrustedCAs->setFocus();
321 QDialog::showEvent( e );
329int QgsAuthTrustedCAsDialog::messageTimeout()
332 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.
Dialog wrapper for widget displaying detailed info on a certificate and its hierarchical trust chain.
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 QColor redColor()
Red color representing invalid, untrusted, etc. certificate.
QVariant authSetting(const QString &key, const QVariant &defaultValue=QVariant(), bool decrypt=false)
authSetting get an authentication setting (retrieved as string and returned as QVariant( QString ))
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.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.
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.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
#define QgsDebugError(str)