18 #include "ui_qgsauthtrustedcasdialog.h" 20 #include <QPushButton> 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 );
64 if ( !sortbyval.isNull() )
65 btnGroupByOrg->setChecked( sortbyval.toBool() );
67 populateCaCertsView();
72 static void setItemBold_( QTreeWidgetItem *item )
74 item->setFirstColumnSpanned(
true );
75 QFont secf( item->font( 0 ) );
77 item->setFont( 0, secf );
80 void 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 (
int )QgsAuthTrustedCAsDialog::Section );
95 setItemBold_( mRootCaSecItem );
96 mRootCaSecItem->setFlags( Qt::ItemIsEnabled );
97 mRootCaSecItem->setExpanded(
true );
98 treeTrustedCAs->insertTopLevelItem( 0, mRootCaSecItem );
101 static void removeChildren_( QTreeWidgetItem *item )
103 Q_FOREACH ( QTreeWidgetItem *child, item->takeChildren() )
109 void QgsAuthTrustedCAsDialog::populateCaCertsView()
111 removeChildren_( mRootCaSecItem );
113 if ( mTrustedCAs.isEmpty() )
118 populateCaCertsSection( mRootCaSecItem, mTrustedCAs, QgsAuthTrustedCAsDialog::CaCert );
121 void QgsAuthTrustedCAsDialog::populateCaCertsSection( QTreeWidgetItem *item,
const QList<QSslCertificate> &certs,
122 QgsAuthTrustedCAsDialog::CaType catype )
124 if ( btnGroupByOrg->isChecked() )
126 appendCertsToGroup( certs, catype, item );
130 appendCertsToItem( certs, catype, item );
134 void QgsAuthTrustedCAsDialog::appendCertsToGroup(
const QList<QSslCertificate> &certs,
135 QgsAuthTrustedCAsDialog::CaType catype,
136 QTreeWidgetItem *parent )
143 parent = treeTrustedCAs->currentItem();
147 QMap< QString, QList<QSslCertificate> > orgcerts(
150 QMap< QString, QList<QSslCertificate> >::const_iterator it = orgcerts.constBegin();
151 for ( ; it != orgcerts.constEnd(); ++it )
153 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent,
154 QStringList() << it.key(),
155 ( int )QgsAuthTrustedCAsDialog::OrgName ) );
156 grpitem->setFirstColumnSpanned(
true );
157 grpitem->setFlags( Qt::ItemIsEnabled );
158 grpitem->setExpanded(
true );
160 QBrush orgb( grpitem->foreground( 0 ) );
161 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
162 grpitem->setForeground( 0, orgb );
163 QFont grpf( grpitem->font( 0 ) );
164 grpf.setItalic(
true );
165 grpitem->setFont( 0, grpf );
167 appendCertsToItem( it.value(), catype, grpitem );
170 parent->sortChildren( 0, Qt::AscendingOrder );
173 void QgsAuthTrustedCAsDialog::appendCertsToItem(
const QList<QSslCertificate> &certs,
174 QgsAuthTrustedCAsDialog::CaType catype,
175 QTreeWidgetItem *parent )
182 parent = treeTrustedCAs->currentItem();
188 Q_FOREACH (
const QSslCertificate &cert, certs )
194 coltxts << QString( cert.serialNumber() );
195 coltxts << cert.expiryDate().toString();
197 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts, (
int )catype ) );
202 item->setForeground( 2, redb );
206 item->setData( 0, Qt::UserRole,
id );
209 parent->sortChildren( 0, Qt::AscendingOrder );
212 void QgsAuthTrustedCAsDialog::showCertInfo( QTreeWidgetItem *item )
217 QString digest( item->data( 0, Qt::UserRole ).toString() );
219 QMap<QString, QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > cacertscache(
222 if ( !cacertscache.contains( digest ) )
224 QgsDebugMsg(
"Certificate Authority not in CA certs cache" );
228 QSslCertificate cert( cacertscache.value( digest ).second );
231 dlg->setWindowModality( Qt::WindowModal );
232 dlg->resize( 675, 500 );
237 void QgsAuthTrustedCAsDialog::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
239 Q_UNUSED( selected );
240 Q_UNUSED( deselected );
244 void QgsAuthTrustedCAsDialog::checkSelection()
247 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
249 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
251 switch ( ( QgsAuthTrustedCAsDialog::CaType )item->type() )
253 case QgsAuthTrustedCAsDialog::CaCert:
261 btnInfoCa->setEnabled( iscert );
264 void QgsAuthTrustedCAsDialog::handleDoubleClick( QTreeWidgetItem *item,
int col )
269 switch ( ( QgsAuthTrustedCAsDialog::CaType )item->type() )
271 case QgsAuthTrustedCAsDialog::Section:
274 case QgsAuthTrustedCAsDialog::OrgName:
283 showCertInfo( item );
287 void QgsAuthTrustedCAsDialog::btnInfoCa_clicked()
289 if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
291 QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
292 handleDoubleClick( item, 0 );
296 void QgsAuthTrustedCAsDialog::btnGroupByOrg_toggled(
bool checked )
300 authMessageOut( QObject::tr(
"Could not store sort by preference" ),
301 QObject::tr(
"Trusted Authorities/Issuers" ),
304 populateCaCertsView();
309 int levelint = ( int )level;
317 treeTrustedCAs->setFocus();
319 QDialog::showEvent( e );
327 int QgsAuthTrustedCAsDialog::messageTimeout()
330 return settings.
value( QStringLiteral(
"qgis/messageTimeout" ), 5 ).toInt();
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.
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.
A bar for displaying non-blocking messages to the user.
void showEvent(QShowEvent *e) override
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
MessageLevel
Message log level (mirrors that of QgsMessageLog, so it can also output there)
const QList< QSslCertificate > trustedCaCerts(bool includeinvalid=false)
trustedCaCerts get list of all trusted CA certificates
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.
Dialog wrapper for widget displaying detailed info on a certificate and its hierarchical trust chain...
QgsAuthTrustedCAsDialog(QWidget *parent=nullptr, const QList< QSslCertificate > &trustedCAs=QList< QSslCertificate >())
Construct a dialog that will list the trusted Certificate Authorities.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::Info, int duration=5)
convenience method for pushing a message to the bar
static QString shaHexForCert(const QSslCertificate &cert, bool formatted=false)
Gets the sha1 hash for certificate.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
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 )) ...
static QMap< QString, QList< QSslCertificate > > certsGroupedByOrg(const QList< QSslCertificate > &certs)
Map certificates to their oraganization.
static QString resolvedCertName(const QSslCertificate &cert, bool issuer=false)
Gets the general name via RFC 5280 resolution.