18#include "ui_qgsauthtrustedcasdialog.h"
32 const QList<QSslCertificate> &trustedCAs )
34 , mTrustedCAs( trustedCAs )
39 mAuthNotifyLayout =
new QVBoxLayout;
40 this->setLayout( mAuthNotifyLayout );
42 mAuthNotifyLayout->addWidget( mAuthNotify );
47 connect( btnInfoCa, &QToolButton::clicked,
this, &QgsAuthTrustedCAsDialog::btnInfoCa_clicked );
48 connect( btnGroupByOrg, &QToolButton::toggled,
this, &QgsAuthTrustedCAsDialog::btnGroupByOrg_toggled );
51 this, &QgsAuthTrustedCAsDialog::authMessageOut );
55 connect( treeTrustedCAs->selectionModel(), &QItemSelectionModel::selectionChanged,
56 this, &QgsAuthTrustedCAsDialog::selectionChanged );
58 connect( treeTrustedCAs, &QTreeWidget::itemDoubleClicked,
59 this, &QgsAuthTrustedCAsDialog::handleDoubleClick );
62 btnGroupByOrg->setChecked(
false );
65 btnGroupByOrg->setChecked( sortbyval.toBool() );
67 populateCaCertsView();
72static void setItemBold_( QTreeWidgetItem *item )
74 item->setFirstColumnSpanned(
true );
75 QFont secf( item->font( 0 ) );
77 item->setFont( 0, secf );
80void QgsAuthTrustedCAsDialog::setupCaCertsTree()
82 treeTrustedCAs->setColumnCount( 3 );
83 treeTrustedCAs->setHeaderLabels(
84 QStringList() << tr(
"Common Name" )
86 << tr(
"Expiry Date" ) );
87 treeTrustedCAs->setColumnWidth( 0, 300 );
88 treeTrustedCAs->setColumnWidth( 1, 75 );
91 mRootCaSecItem =
new QTreeWidgetItem(
93 QStringList( tr(
"Authorities/Issuers" ) ),
94 static_cast<int>( QgsAuthTrustedCAsDialog::Section ) );
95 setItemBold_( mRootCaSecItem );
96 mRootCaSecItem->setFlags( Qt::ItemIsEnabled );
97 mRootCaSecItem->setExpanded(
true );
98 treeTrustedCAs->insertTopLevelItem( 0, mRootCaSecItem );
101static void removeChildren_( QTreeWidgetItem *item )
103 const auto constTakeChildren = item->takeChildren();
104 for ( QTreeWidgetItem *child : constTakeChildren )
110void QgsAuthTrustedCAsDialog::populateCaCertsView()
112 removeChildren_( mRootCaSecItem );
114 if ( mTrustedCAs.isEmpty() )
119 populateCaCertsSection( mRootCaSecItem, mTrustedCAs, QgsAuthTrustedCAsDialog::CaCert );
122void QgsAuthTrustedCAsDialog::populateCaCertsSection( QTreeWidgetItem *item,
const QList<QSslCertificate> &certs,
123 QgsAuthTrustedCAsDialog::CaType catype )
125 if ( btnGroupByOrg->isChecked() )
127 appendCertsToGroup( certs, catype, item );
131 appendCertsToItem( certs, catype, item );
135void QgsAuthTrustedCAsDialog::appendCertsToGroup(
const QList<QSslCertificate> &certs,
136 QgsAuthTrustedCAsDialog::CaType catype,
137 QTreeWidgetItem *parent )
144 parent = treeTrustedCAs->currentItem();
148 const QMap< QString, QList<QSslCertificate> > orgcerts(
151 QMap< QString, QList<QSslCertificate> >::const_iterator it = orgcerts.constBegin();
152 for ( ; it != orgcerts.constEnd(); ++it )
154 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent,
155 QStringList() << it.key(),
156 static_cast<int>( QgsAuthTrustedCAsDialog::OrgName ) ) );
157 grpitem->setFirstColumnSpanned(
true );
158 grpitem->setFlags( Qt::ItemIsEnabled );
159 grpitem->setExpanded(
true );
161 QBrush orgb( grpitem->foreground( 0 ) );
162 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
163 grpitem->setForeground( 0, orgb );
164 QFont grpf( grpitem->font( 0 ) );
165 grpf.setItalic(
true );
166 grpitem->setFont( 0, grpf );
168 appendCertsToItem( it.value(), catype, grpitem );
171 parent->sortChildren( 0, Qt::AscendingOrder );
174void QgsAuthTrustedCAsDialog::appendCertsToItem(
const QList<QSslCertificate> &certs,
175 QgsAuthTrustedCAsDialog::CaType catype,
176 QTreeWidgetItem *parent )
183 parent = treeTrustedCAs->currentItem();
189 const auto constCerts = certs;
190 for (
const QSslCertificate &cert : constCerts )
196 coltxts << QString( cert.serialNumber() );
197 coltxts << cert.expiryDate().toString();
199 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( catype ) ) );
204 item->setForeground( 2, redb );
208 item->setData( 0, Qt::UserRole,
id );
211 parent->sortChildren( 0, Qt::AscendingOrder );
214void QgsAuthTrustedCAsDialog::showCertInfo( QTreeWidgetItem *item )
219 const QString digest( item->data( 0, Qt::UserRole ).toString() );
221 const QMap<QString, QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > cacertscache(
224 if ( !cacertscache.contains( digest ) )
226 QgsDebugError( QStringLiteral(
"Certificate Authority not in CA certs cache" ) );
230 const QSslCertificate cert( cacertscache.value( digest ).second );
233 dlg->setWindowModality( Qt::WindowModal );
234 dlg->resize( 675, 500 );
239void QgsAuthTrustedCAsDialog::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
242 Q_UNUSED( deselected )
246void QgsAuthTrustedCAsDialog::checkSelection()
249 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
251 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
253 switch ( ( QgsAuthTrustedCAsDialog::CaType )item->type() )
255 case QgsAuthTrustedCAsDialog::CaCert:
263 btnInfoCa->setEnabled( iscert );
266void QgsAuthTrustedCAsDialog::handleDoubleClick( QTreeWidgetItem *item,
int col )
271 switch ( ( QgsAuthTrustedCAsDialog::CaType )item->type() )
273 case QgsAuthTrustedCAsDialog::Section:
276 case QgsAuthTrustedCAsDialog::OrgName:
285 showCertInfo( item );
289void QgsAuthTrustedCAsDialog::btnInfoCa_clicked()
291 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
293 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
294 handleDoubleClick( item, 0 );
298void QgsAuthTrustedCAsDialog::btnGroupByOrg_toggled(
bool checked )
302 authMessageOut( QObject::tr(
"Could not store sort by preference" ),
303 QObject::tr(
"Trusted Authorities/Issuers" ),
306 populateCaCertsView();
311 const int levelint =
static_cast<int>( level );
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.
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.
MessageLevel
Message log level (mirrors that of QgsMessageLog, so it can also output there)
void messageOut(const QString &message, const QString &tag=QgsAuthManager::AUTH_MAN_TAG, QgsAuthManager::MessageLevel level=QgsAuthManager::INFO) const
Custom logging signal to relay to console output and QgsMessageLog.
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 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)