18#include "moc_qgsauthtrustedcasdialog.cpp" 
   19#include "ui_qgsauthtrustedcasdialog.h" 
   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 );
 
   54    connect( treeTrustedCAs->selectionModel(), &QItemSelectionModel::selectionChanged, 
this, &QgsAuthTrustedCAsDialog::selectionChanged );
 
   56    connect( treeTrustedCAs, &QTreeWidget::itemDoubleClicked, 
this, &QgsAuthTrustedCAsDialog::handleDoubleClick );
 
   59    btnGroupByOrg->setChecked( 
false );
 
   62      btnGroupByOrg->setChecked( sortbyval.toBool() );
 
   64    populateCaCertsView();
 
 
   69void QgsAuthTrustedCAsDialog::setupCaCertsTree()
 
   71  treeTrustedCAs->setColumnCount( 3 );
 
   72  treeTrustedCAs->setHeaderLabels(
 
   73    QStringList() << tr( 
"Common Name" )
 
   75                  << tr( 
"Expiry Date" )
 
   77  treeTrustedCAs->setColumnWidth( 0, 300 );
 
   78  treeTrustedCAs->setColumnWidth( 1, 75 );
 
   81  mRootCaSecItem = 
new QTreeWidgetItem(
 
   83    QStringList( tr( 
"Authorities/Issuers" ) ),
 
   84    static_cast<int>( QgsAuthTrustedCAsDialog::Section )
 
   87  mRootCaSecItem->setFlags( Qt::ItemIsEnabled );
 
   88  mRootCaSecItem->setExpanded( 
true );
 
   89  treeTrustedCAs->insertTopLevelItem( 0, mRootCaSecItem );
 
   92void QgsAuthTrustedCAsDialog::populateCaCertsView()
 
   96  if ( mTrustedCAs.isEmpty() )
 
  101  populateCaCertsSection( mRootCaSecItem, mTrustedCAs, QgsAuthTrustedCAsDialog::CaCert );
 
  104void QgsAuthTrustedCAsDialog::populateCaCertsSection( QTreeWidgetItem *item, 
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype )
 
  106  if ( btnGroupByOrg->isChecked() )
 
  108    appendCertsToGroup( certs, catype, item );
 
  112    appendCertsToItem( certs, catype, item );
 
  116void QgsAuthTrustedCAsDialog::appendCertsToGroup( 
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype, QTreeWidgetItem *parent )
 
  123    parent = treeTrustedCAs->currentItem();
 
  127  const QMap<QString, QList<QSslCertificate>> orgcerts(
 
  131  QMap<QString, QList<QSslCertificate>>::const_iterator it = orgcerts.constBegin();
 
  132  for ( ; it != orgcerts.constEnd(); ++it )
 
  134    QTreeWidgetItem *grpitem( 
new QTreeWidgetItem( parent, QStringList() << it.key(), 
static_cast<int>( QgsAuthTrustedCAsDialog::OrgName ) ) );
 
  135    grpitem->setFirstColumnSpanned( 
true );
 
  136    grpitem->setFlags( Qt::ItemIsEnabled );
 
  137    grpitem->setExpanded( 
true );
 
  139    QBrush orgb( grpitem->foreground( 0 ) );
 
  140    orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
 
  141    grpitem->setForeground( 0, orgb );
 
  142    QFont grpf( grpitem->font( 0 ) );
 
  143    grpf.setItalic( 
true );
 
  144    grpitem->setFont( 0, grpf );
 
  146    appendCertsToItem( it.value(), catype, grpitem );
 
  149  parent->sortChildren( 0, Qt::AscendingOrder );
 
  152void QgsAuthTrustedCAsDialog::appendCertsToItem( 
const QList<QSslCertificate> &certs, QgsAuthTrustedCAsDialog::CaType catype, QTreeWidgetItem *parent )
 
  159    parent = treeTrustedCAs->currentItem();
 
  165  const auto constCerts = certs;
 
  166  for ( 
const QSslCertificate &cert : constCerts )
 
  172    coltxts << QString( cert.serialNumber() );
 
  173    coltxts << cert.expiryDate().toString();
 
  175    QTreeWidgetItem *item( 
new QTreeWidgetItem( parent, coltxts, 
static_cast<int>( catype ) ) );
 
  180      item->setForeground( 2, redb );
 
  184    item->setData( 0, Qt::UserRole, 
id );
 
  187  parent->sortChildren( 0, Qt::AscendingOrder );
 
  190void QgsAuthTrustedCAsDialog::showCertInfo( QTreeWidgetItem *item )
 
  195  const QString digest( item->data( 0, Qt::UserRole ).toString() );
 
  197  const QMap<QString, QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate>> cacertscache(
 
  201  if ( !cacertscache.contains( digest ) )
 
  203    QgsDebugError( QStringLiteral( 
"Certificate Authority not in CA certs cache" ) );
 
  207  const QSslCertificate cert( cacertscache.value( digest ).second );
 
  210  dlg->setWindowModality( Qt::WindowModal );
 
  211  dlg->resize( 675, 500 );
 
  216void QgsAuthTrustedCAsDialog::selectionChanged( 
const QItemSelection &selected, 
const QItemSelection &deselected )
 
  219  Q_UNUSED( deselected )
 
  223void QgsAuthTrustedCAsDialog::checkSelection()
 
  226  if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
 
  228    QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
 
  230    switch ( ( QgsAuthTrustedCAsDialog::CaType ) item->type() )
 
  232      case QgsAuthTrustedCAsDialog::CaCert:
 
  240  btnInfoCa->setEnabled( iscert );
 
  243void QgsAuthTrustedCAsDialog::handleDoubleClick( QTreeWidgetItem *item, 
int col )
 
  248  switch ( ( QgsAuthTrustedCAsDialog::CaType ) item->type() )
 
  250    case QgsAuthTrustedCAsDialog::Section:
 
  253    case QgsAuthTrustedCAsDialog::OrgName:
 
  262    showCertInfo( item );
 
  266void QgsAuthTrustedCAsDialog::btnInfoCa_clicked()
 
  268  if ( treeTrustedCAs->selectionModel()->selection().length() > 0 )
 
  270    QTreeWidgetItem *item( treeTrustedCAs->currentItem() );
 
  271    handleDoubleClick( item, 0 );
 
  275void QgsAuthTrustedCAsDialog::btnGroupByOrg_toggled( 
bool checked )
 
  279    authMessageLog( QObject::tr( 
"Could not store sort by preference" ), QObject::tr( 
"Trusted Authorities/Issuers" ), 
Qgis::MessageLevel::Warning );
 
  281  populateCaCertsView();
 
  284void QgsAuthTrustedCAsDialog::authMessageLog( 
const QString &message, 
const QString &authtag, 
Qgis::MessageLevel level )
 
  286  messageBar()->
pushMessage( authtag, message, level, 7 );
 
  293    treeTrustedCAs->setFocus();
 
  295  QDialog::showEvent( e );
 
 
  303int QgsAuthTrustedCAsDialog::messageTimeout()
 
  306  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 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.
 
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.
 
Stores settings for use within QGIS.
 
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)