19#include "moc_qgsauthcertificateinfo.cpp"
20#include "ui_qgsauthcertificateinfo.h"
23#include <QDialogButtonBox>
25#include <QPlainTextEdit>
36static void setItemBold_( QTreeWidgetItem *item )
38 item->setFirstColumnSpanned(
true );
39 QFont secf( item->font( 0 ) );
41 item->setFont( 0, secf );
44static void removeChildren_( QTreeWidgetItem *item )
46 const auto constTakeChildren = item->takeChildren();
47 for ( QTreeWidgetItem *child : constTakeChildren )
56 const QList<QSslCertificate> &connectionCAs )
58 , mConnectionCAs( connectionCAs )
59 , mDefaultItemForeground( QBrush() )
60 , mManageTrust( manageCertTrust )
61 , mTrustCacheRebuilt( false )
68 mAuthNotifyLayout =
new QVBoxLayout;
69 this->setLayout( mAuthNotifyLayout );
71 mAuthNotifyLayout->addWidget( mAuthNotify );
76 connect( btnSaveTrust, &QToolButton::clicked,
this, &QgsAuthCertInfo::btnSaveTrust_clicked );
78 lblError->setHidden(
true );
80 treeHierarchy->setRootIsDecorated(
false );
82 connect( treeHierarchy, &QTreeWidget::currentItemChanged,
83 this, &QgsAuthCertInfo::currentCertItemChanged );
87 setUpCertDetailsTree();
89 grpbxTrust->setVisible( mManageTrust );
96 res = populateQcaCertCollection();
98 res = setQcaCertificate( cert );
100 res = populateCertChain();
104 connect( cmbbxTrust,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
105 this, &QgsAuthCertInfo::currentPolicyIndexChanged );
109void QgsAuthCertInfo::setupError(
const QString &msg )
111 lblError->setVisible(
true );
112 QString out = tr(
"<b>Setup ERROR:</b>\n\n" );
114 lblError->setText( out );
118void QgsAuthCertInfo::currentCertItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *previous )
121 updateCurrentCert( current );
124void QgsAuthCertInfo::updateCurrentCert( QTreeWidgetItem *item )
127 item = treeHierarchy->currentItem();
131 const int indx( item->data( 0, Qt::UserRole ).toInt() );
132 updateCurrentCertInfo( indx );
135bool QgsAuthCertInfo::populateQcaCertCollection()
137 const QList<QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate> > &certpairs( mCaCertsCache.values() );
138 for (
int i = 0; i < certpairs.size(); ++i )
140 QCA::ConvertResult res;
141 const QCA::Certificate acert = QCA::Certificate::fromPEM( certpairs.at( i ).second.toPem(), &res, QStringLiteral(
"qca-ossl" ) );
142 if ( res == QCA::ConvertGood && !acert.isNull() )
144 mCaCerts.addCertificate( acert );
147 if ( !mConnectionCAs.isEmpty() )
149 const auto constMConnectionCAs = mConnectionCAs;
150 for (
const QSslCertificate &cert : constMConnectionCAs )
152 QCA::ConvertResult res;
153 const QCA::Certificate acert = QCA::Certificate::fromPEM( cert.toPem(), &res, QStringLiteral(
"qca-ossl" ) );
154 if ( res == QCA::ConvertGood && !acert.isNull() )
156 mCaCerts.addCertificate( acert );
161 if ( mCaCerts.certificates().empty() )
163 setupError( tr(
"Could not populate QCA certificate collection" ) );
169bool QgsAuthCertInfo::setQcaCertificate(
const QSslCertificate &cert )
171 QCA::ConvertResult res;
172 mCert = QCA::Certificate::fromPEM( cert.toPem(), &res, QStringLiteral(
"qca-ossl" ) );
173 if ( res != QCA::ConvertGood || mCert.isNull() )
175 setupError( tr(
"Could not set QCA certificate" ) );
181bool QgsAuthCertInfo::populateCertChain()
183 const QCA::CertificateChain certchain( mCert );
185 mACertChain = certchain.complete( mCaCerts.certificates(), &valid );
186 if ( valid != QCA::ValidityGood && valid != QCA::ErrorInvalidCA )
189 setupError( tr(
"Invalid population of QCA certificate chain.<br><br>"
194 if ( mACertChain.isEmpty() )
196 QgsDebugError( QStringLiteral(
"Could not populate QCA certificate chain" ) );
197 mACertChain = certchain;
200 if ( !mACertChain.last().isSelfSigned() )
203 mACertChain.append( QCA::Certificate() );
207 const auto constMACertChain = mACertChain;
208 for (
const QCA::Certificate &cert : constMACertChain )
210 QSslCertificate qcert;
211 if ( !cert.isNull() )
213 qcert = QSslCertificate( cert.toPEM().toLatin1() );
215 mQCertChain.append( qcert );
220void QgsAuthCertInfo::setCertHierarchy()
222 QListIterator<QSslCertificate> it( mQCertChain );
224 int i = mQCertChain.size();
225 QTreeWidgetItem *item =
nullptr;
226 QTreeWidgetItem *previtem =
nullptr;
227 while ( it.hasPrevious() )
229 const QSslCertificate cert( it.previous() );
230 const bool missingCA = cert.isNull();
232 if ( missingCA && it.hasPrevious() )
235 cert_source += QStringLiteral(
" (%1)" ).arg( tr(
"Missing CA" ) );
241 if ( mCaCertsCache.contains( sha ) )
243 const QPair<QgsAuthCertUtils::CaCertSource, QSslCertificate > &certpair( mCaCertsCache.value( sha ) );
246 else if ( mConnectionCAs.contains( cert ) )
248 cert_source += QStringLiteral(
" (%1)" )
255 item =
new QTreeWidgetItem( treeHierarchy, QStringList() << cert_source );
259 item =
new QTreeWidgetItem( previtem, QStringList() << cert_source );
261 if ( missingCA && it.hasPrevious() )
263 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
266 item->setData( 0, Qt::UserRole, --i );
268 if ( mDefaultItemForeground.style() == Qt::NoBrush )
270 mDefaultItemForeground = item->foreground( 0 );
275 item->setFirstColumnSpanned(
true );
277 treeHierarchy->addTopLevelItem( item );
280 treeHierarchy->setCurrentItem( item, 0, QItemSelectionModel::ClearAndSelect );
281 treeHierarchy->expandAll();
284void QgsAuthCertInfo::updateCurrentCertInfo(
int chainindx )
286 btnSaveTrust->setEnabled(
false );
288 mCurrentQCert = mQCertChain.at( chainindx );
289 mCurrentACert = mACertChain.at( chainindx );
293 grpbxTrust->setHidden( mCurrentQCert.isNull() );
296 if ( !mCurrentQCert.isNull() )
299 mCurrentTrustPolicy = trustpolicy;
301 cmbbxTrust->setTrustPolicy( trustpolicy );
311void QgsAuthCertInfo::setUpCertDetailsTree()
313 treeDetails->setColumnCount( 2 );
314 treeDetails->setHeaderLabels( QStringList() << tr(
"Field" ) << tr(
"Value" ) );
315 treeDetails->setColumnWidth( 0, 200 );
317 QTreeWidgetItem *headeritem = treeDetails->headerItem();
318 headeritem->setTextAlignment( 0, Qt::AlignRight );
319 headeritem->setTextAlignment( 1, Qt::AlignLeft );
321 treeDetails->setRootIsDecorated(
true );
322 treeDetails->setWordWrap(
true );
325 mSecGeneral =
new QTreeWidgetItem(
327 QStringList( tr(
"General" ) ),
328 static_cast<int>( DetailsSection ) );
329 setItemBold_( mSecGeneral );
330 mSecGeneral->setFirstColumnSpanned(
true );
331 mSecGeneral->setFlags( Qt::ItemIsEnabled );
332 mSecGeneral->setExpanded(
true );
333 treeDetails->insertTopLevelItem( 0, mSecGeneral );
335 mSecDetails =
new QTreeWidgetItem(
337 QStringList( tr(
"Details" ) ),
338 static_cast<int>( DetailsSection ) );
339 setItemBold_( mSecDetails );
340 mSecDetails->setFirstColumnSpanned(
true );
341 mSecDetails->setFlags( Qt::ItemIsEnabled );
342 mSecDetails->setExpanded(
false );
343 treeDetails->insertTopLevelItem( 0, mSecDetails );
346 mGrpSubj = addGroupItem( mSecDetails, tr(
"Subject Info" ) );
347 mGrpIssu = addGroupItem( mSecDetails, tr(
"Issuer Info" ) );
348 mGrpCert = addGroupItem( mSecDetails, tr(
"Certificate Info" ) );
349 mGrpPkey = addGroupItem( mSecDetails, tr(
"Public Key Info" ) );
350 mGrpExts = addGroupItem( mSecDetails, tr(
"Extensions" ) );
352 mSecPemText =
new QTreeWidgetItem(
354 QStringList( tr(
"PEM Text" ) ),
355 static_cast<int>( DetailsSection ) );
356 setItemBold_( mSecPemText );
357 mSecPemText->setFirstColumnSpanned(
true );
358 mSecPemText->setFlags( Qt::ItemIsEnabled );
359 mSecPemText->setExpanded(
false );
360 treeDetails->insertTopLevelItem( 0, mSecPemText );
363void QgsAuthCertInfo::populateCertInfo()
365 mSecDetails->setHidden(
false );
366 mSecPemText->setHidden(
false );
368 populateInfoGeneralSection();
369 populateInfoDetailsSection();
370 populateInfoPemTextSection();
373QTreeWidgetItem *QgsAuthCertInfo::addGroupItem( QTreeWidgetItem *parent,
const QString &group )
375 QTreeWidgetItem *grpitem =
new QTreeWidgetItem(
377 QStringList( group ),
378 static_cast<int>( DetailsGroup ) );
380 grpitem->setFirstColumnSpanned(
true );
381 grpitem->setFlags( Qt::ItemIsEnabled );
382 grpitem->setExpanded(
true );
384 QBrush orgb( grpitem->foreground( 0 ) );
385 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
386 grpitem->setForeground( 0, orgb );
387 QFont grpf( grpitem->font( 0 ) );
388 grpf.setItalic(
true );
389 grpitem->setFont( 0, grpf );
394void QgsAuthCertInfo::addFieldItem( QTreeWidgetItem *parent,
const QString &field,
const QString &value,
395 QgsAuthCertInfo::FieldWidget wdgt,
const QColor &color )
397 if ( value.isEmpty() )
400 QTreeWidgetItem *item =
new QTreeWidgetItem(
402 QStringList() << field << ( wdgt == NoWidget ? value : QString() ),
403 static_cast<int>( DetailsField ) );
405 item->setTextAlignment( 0, Qt::AlignRight );
406 item->setTextAlignment( 1, Qt::AlignLeft );
408 QBrush fieldb( item->foreground( 0 ) );
409 fieldb.setColor( QColor::fromRgb( 90, 90, 90 ) );
410 item->setForeground( 0, fieldb );
412 if ( wdgt == NoWidget )
414 if ( color.isValid() )
416 QBrush valueb( item->foreground( 1 ) );
417 valueb.setColor( color );
418 item->setForeground( 1, valueb );
421 else if ( wdgt == LineEdit )
423 QLineEdit *le =
new QLineEdit( value, treeDetails );
424 le->setReadOnly(
true );
425 le->setAlignment( Qt::AlignLeft );
426 le->setCursorPosition( 0 );
427 if ( color.isValid() )
429 le->setStyleSheet( QStringLiteral(
"QLineEdit { color: %1; }" ).arg( color.name() ) );
431 item->treeWidget()->setItemWidget( item, 1, le );
433 else if ( wdgt == TextEdit )
435 QPlainTextEdit *pte =
new QPlainTextEdit( value, treeDetails );
436 pte->setReadOnly(
true );
437 pte->setMinimumHeight( 75 );
438 pte->setMaximumHeight( 75 );
439 pte->moveCursor( QTextCursor::Start );
440 if ( color.isValid() )
442 pte->setStyleSheet( QStringLiteral(
"QPlainTextEdit { color: %1; }" ).arg( color.name() ) );
444 item->treeWidget()->setItemWidget( item, 1, pte );
449void QgsAuthCertInfo::populateInfoGeneralSection()
451 removeChildren_( mSecGeneral );
453 if ( mCurrentQCert.isNull() )
455 addFieldItem( mSecGeneral, tr(
"Type" ),
456 tr(
"Missing CA (incomplete local CA chain)" ),
458 mSecGeneral->setExpanded(
true );
459 mSecDetails->setHidden(
true );
460 mSecPemText->setHidden(
true );
465 const bool isselfsigned = mCurrentACert.isSelfSigned();
466 const QString selfsigned( tr(
"self-signed" ) );
468 const QList<QgsAuthCertUtils::CertUsageType> usagetypes(
483 if ( isissuer || ( isca && !isselfsigned ) )
487 if ( ( isissuer || isca ) && isselfsigned )
489 certype = QStringLiteral(
"%1 %2" )
495 certype.append( certype.isEmpty() ? selfsigned : QStringLiteral(
" (%1)" ).arg( selfsigned ) );
498 addFieldItem( mSecGeneral, tr(
"Usage type" ),
501 addFieldItem( mSecGeneral, tr(
"Subject" ),
504 addFieldItem( mSecGeneral, tr(
"Issuer" ),
507 addFieldItem( mSecGeneral, tr(
"Not valid after" ),
508 mCurrentQCert.expiryDate().toString(),
512 const QSslKey pubkey( mCurrentQCert.publicKey() );
513 const QString alg( pubkey.algorithm() == QSsl::Rsa ?
"RSA" :
"DSA" );
514 const int bitsize( pubkey.length() );
515 addFieldItem( mSecGeneral, tr(
"Public key" ),
516 QStringLiteral(
"%1, %2 bits" ).arg( alg, bitsize == -1 ? QStringLiteral(
"?" ) : QString::number( bitsize ) ),
518 addFieldItem( mSecGeneral, tr(
"Signature algorithm" ),
523void QgsAuthCertInfo::populateInfoDetailsSection()
525 removeChildren_( mGrpSubj );
526 removeChildren_( mGrpIssu );
527 removeChildren_( mGrpCert );
528 removeChildren_( mGrpPkey );
529 removeChildren_( mGrpExts );
531 if ( mCurrentQCert.isNull() )
535 addFieldItem( mGrpSubj, tr(
"Country (C)" ),
538 addFieldItem( mGrpSubj, tr(
"State/Province (ST)" ),
541 addFieldItem( mGrpSubj, tr(
"Locality (L)" ),
544 addFieldItem( mGrpSubj, tr(
"Organization (O)" ),
547 addFieldItem( mGrpSubj, tr(
"Organizational unit (OU)" ),
550 addFieldItem( mGrpSubj, tr(
"Common name (CN)" ),
553 addFieldItem( mGrpSubj, tr(
"Email address (E)" ),
554 mCurrentACert.subjectInfo().value( QCA::Email ),
556 addFieldItem( mGrpSubj, tr(
"Distinguished name" ),
559 addFieldItem( mGrpSubj, tr(
"Email Legacy" ),
560 mCurrentACert.subjectInfo().value( QCA::EmailLegacy ),
562 addFieldItem( mGrpSubj, tr(
"Incorporation Country" ),
563 mCurrentACert.subjectInfo().value( QCA::IncorporationCountry ),
565 addFieldItem( mGrpSubj, tr(
"Incorporation State/Province" ),
566 mCurrentACert.subjectInfo().value( QCA::IncorporationState ),
568 addFieldItem( mGrpSubj, tr(
"Incorporation Locality" ),
569 mCurrentACert.subjectInfo().value( QCA::IncorporationLocality ),
571 addFieldItem( mGrpSubj, tr(
"URI" ),
572 mCurrentACert.subjectInfo().value( QCA::URI ),
574 addFieldItem( mGrpSubj, tr(
"DNS" ),
575 mCurrentACert.subjectInfo().value( QCA::DNS ),
577 addFieldItem( mGrpSubj, tr(
"IP Address" ),
578 mCurrentACert.subjectInfo().value( QCA::IPAddress ),
580 addFieldItem( mGrpSubj, tr(
"XMPP" ),
581 mCurrentACert.subjectInfo().value( QCA::XMPP ),
584 const QMultiMap<QSsl::AlternativeNameEntryType, QString> alts( mCurrentQCert.subjectAlternativeNames() );
585 QStringList altslist;
586 const QString email( tr(
"Email: " ) );
587 const QStringList emails( alts.values( QSsl::EmailEntry ) );
588 if ( !emails.isEmpty() )
590 altslist << email + emails.join(
'\n' + email );
592 const QString dns( tr(
"DNS: " ) );
593 const QStringList dnss( alts.values( QSsl::DnsEntry ) );
594 if ( !dnss.isEmpty() )
596 altslist << dns + dnss.join(
'\n' + dns );
598 addFieldItem( mGrpSubj, tr(
"Alternate names" ),
599 altslist.join( QLatin1Char(
'\n' ) ),
603 addFieldItem( mGrpIssu, tr(
"Country (C)" ),
606 addFieldItem( mGrpIssu, tr(
"State/Province (ST)" ),
607 SSL_ISSUER_INFO( mCurrentQCert, QSslCertificate::StateOrProvinceName ),
609 addFieldItem( mGrpIssu, tr(
"Locality (L)" ),
612 addFieldItem( mGrpIssu, tr(
"Organization (O)" ),
615 addFieldItem( mGrpIssu, tr(
"Organizational unit (OU)" ),
616 SSL_ISSUER_INFO( mCurrentQCert, QSslCertificate::OrganizationalUnitName ),
618 addFieldItem( mGrpIssu, tr(
"Common name (CN)" ),
621 addFieldItem( mGrpIssu, tr(
"Email address (E)" ),
622 mCurrentACert.issuerInfo().value( QCA::Email ),
624 addFieldItem( mGrpIssu, tr(
"Distinguished name" ),
627 addFieldItem( mGrpIssu, tr(
"Email Legacy" ),
628 mCurrentACert.issuerInfo().value( QCA::EmailLegacy ),
630 addFieldItem( mGrpIssu, tr(
"Incorporation Country" ),
631 mCurrentACert.issuerInfo().value( QCA::IncorporationCountry ),
633 addFieldItem( mGrpIssu, tr(
"Incorporation State/Province" ),
634 mCurrentACert.issuerInfo().value( QCA::IncorporationState ),
636 addFieldItem( mGrpIssu, tr(
"Incorporation Locality" ),
637 mCurrentACert.issuerInfo().value( QCA::IncorporationLocality ),
639 addFieldItem( mGrpIssu, tr(
"URI" ),
640 mCurrentACert.issuerInfo().value( QCA::URI ),
642 addFieldItem( mGrpIssu, tr(
"DNS" ),
643 mCurrentACert.issuerInfo().value( QCA::DNS ),
645 addFieldItem( mGrpIssu, tr(
"IP Address" ),
646 mCurrentACert.issuerInfo().value( QCA::IPAddress ),
648 addFieldItem( mGrpIssu, tr(
"XMPP" ),
649 mCurrentACert.issuerInfo().value( QCA::XMPP ),
653 addFieldItem( mGrpCert, tr(
"Version" ),
654 mCurrentQCert.version(),
656 addFieldItem( mGrpCert, tr(
"Serial #" ),
657 mCurrentQCert.serialNumber(),
659 addFieldItem( mGrpCert, tr(
"Not valid before" ),
660 mCurrentQCert.effectiveDate().toString(),
663 addFieldItem( mGrpCert, tr(
"Not valid after" ),
664 mCurrentQCert.expiryDate().toString(),
667 addFieldItem( mGrpCert, tr(
"Signature algorithm" ),
670 addFieldItem( mGrpCert, tr(
"MD5 fingerprint" ),
673 addFieldItem( mGrpCert, tr(
"SHA1 fingerprint" ),
677 const QStringList crllocs( mCurrentACert.crlLocations() );
678 if ( !crllocs.isEmpty() )
680 addFieldItem( mGrpCert, tr(
"CRL locations" ),
681 crllocs.join( QLatin1Char(
'\n' ) ),
684 const QStringList issulocs( mCurrentACert.issuerLocations() );
685 if ( !issulocs.isEmpty() )
687 addFieldItem( mGrpCert, tr(
"Issuer locations" ),
688 issulocs.join( QLatin1Char(
'\n' ) ),
691 const QStringList ocsplocs( mCurrentACert.ocspLocations() );
692 if ( !ocsplocs.isEmpty() )
694 addFieldItem( mGrpCert, tr(
"OCSP locations" ),
695 ocsplocs.join( QLatin1Char(
'\n' ) ),
701 const QSslKey pubqkey( mCurrentQCert.publicKey() );
702 const QString alg( pubqkey.algorithm() == QSsl::Rsa ?
"RSA" :
"DSA" );
703 const int bitsize( pubqkey.length() );
704 addFieldItem( mGrpPkey, tr(
"Algorithm" ),
705 bitsize == -1 ? QStringLiteral(
"Unknown (possibly Elliptic Curve)" ) : alg,
707 addFieldItem( mGrpPkey, tr(
"Key size" ),
708 bitsize == -1 ? QStringLiteral(
"?" ) : QString::number( bitsize ),
712 const QCA::PublicKey pubakey( mCurrentACert.subjectPublicKey() );
714 if ( pubqkey.algorithm() == QSsl::Rsa )
716 const QCA::RSAPublicKey rsakey( pubakey.toRSA() );
717 const QCA::BigInteger modulus = rsakey.n();
718 QByteArray modarray( modulus.toArray().toByteArray().toHex() );
719 if ( modarray.size() > 2 && modarray.mid( 0, 2 ) == QByteArray(
"00" ) )
721 modarray = modarray.mid( 2 );
723 const QCA::BigInteger exponent = rsakey.e();
724 addFieldItem( mGrpPkey, tr(
"Public key" ),
727 addFieldItem( mGrpPkey, tr(
"Exponent" ),
741 if ( pubakey.canVerify() )
743 usage.append( tr(
"Verify" ) );
747 if ( pubakey.canEncrypt() )
749 usage.append( tr(
"Encrypt" ) );
751#if QCA_VERSION >= 0x020100
752 if ( pubakey.canDecrypt() )
754 usage.append( tr(
"Decrypt" ) );
757 if ( pubakey.canKeyAgree() )
759 usage.append( tr(
"Key agreement" ) );
761 if ( pubakey.canExport() )
763 usage.append( tr(
"Export" ) );
765 if ( !usage.isEmpty() )
767 addFieldItem( mGrpPkey, tr(
"Key usage" ),
768 usage.join( QLatin1String(
", " ) ),
774 QStringList basicconst;
775 basicconst << tr(
"Certificate Authority: %1" ).arg( mCurrentACert.isCA() ? tr(
"Yes" ) : tr(
"No" ) )
776 << tr(
"Chain Path Limit: %1" ).arg( mCurrentACert.pathLimit() );
777 addFieldItem( mGrpExts, tr(
"Basic constraints" ),
778 basicconst.join( QLatin1Char(
'\n' ) ),
781 QStringList keyusage;
782 QStringList extkeyusage;
783 const QList<QCA::ConstraintType> certconsts = mCurrentACert.constraints();
784 const auto constCertconsts = certconsts;
785 for (
const QCA::ConstraintType &certconst : constCertconsts )
787 if ( certconst.section() == QCA::ConstraintType::KeyUsage )
791 else if ( certconst.section() == QCA::ConstraintType::ExtendedKeyUsage )
796 if ( !keyusage.isEmpty() )
798 addFieldItem( mGrpExts, tr(
"Key usage" ),
799 keyusage.join( QLatin1Char(
'\n' ) ),
802 if ( !extkeyusage.isEmpty() )
804 addFieldItem( mGrpExts, tr(
"Extended key usage" ),
805 extkeyusage.join( QLatin1Char(
'\n' ) ),
809 addFieldItem( mGrpExts, tr(
"Subject key ID" ),
812 addFieldItem( mGrpExts, tr(
"Authority key ID" ),
817void QgsAuthCertInfo::populateInfoPemTextSection()
819 removeChildren_( mSecPemText );
821 if ( mCurrentQCert.isNull() )
824 QTreeWidgetItem *item =
new QTreeWidgetItem(
826 QStringList( QString() ),
827 static_cast<int>( DetailsField ) );
829 item->setFirstColumnSpanned(
true );
831 QPlainTextEdit *pte =
new QPlainTextEdit( mCurrentQCert.toPem(), treeDetails );
832 pte->setReadOnly(
true );
833 pte->setMinimumHeight( 150 );
834 pte->setMaximumHeight( 150 );
835 pte->moveCursor( QTextCursor::Start );
836 item->treeWidget()->setItemWidget( item, 0, pte );
839void QgsAuthCertInfo::btnSaveTrust_clicked()
844 QgsDebugError( QStringLiteral(
"Could not set trust policy for certificate" ) );
846 mCurrentTrustPolicy = newpolicy;
847 decorateCertTreeItem( mCurrentQCert, newpolicy,
nullptr );
848 btnSaveTrust->setEnabled(
false );
852 mTrustCacheRebuilt =
true;
856void QgsAuthCertInfo::currentPolicyIndexChanged(
int indx )
859 btnSaveTrust->setEnabled( newpolicy != mCurrentTrustPolicy );
862void QgsAuthCertInfo::decorateCertTreeItem(
const QSslCertificate &cert,
864 QTreeWidgetItem *item )
868 item = treeHierarchy->currentItem();
879 QBrush b( item->foreground( 0 ) );
880 b.setColor( QColor::fromRgb( 90, 90, 90 ) );
881 item->setForeground( 0, b );
882 QFont f( item->font( 0 ) );
884 item->setFont( 0, f );
913 bool manageCertTrust,
915 const QList<QSslCertificate> &connectionCAs )
919 setWindowTitle( tr(
"Certificate Information" ) );
920 QVBoxLayout *layout =
new QVBoxLayout(
this );
921 layout->setContentsMargins( 6, 6, 6, 6 );
923 mCertInfoWdgt =
new QgsAuthCertInfo( cert, manageCertTrust,
this, connectionCAs );
924 layout->addWidget( mCertInfoWdgt );
926 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Close,
927 Qt::Horizontal,
this );
928 buttonBox->button( QDialogButtonBox::Close )->setDefault(
true );
929 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QWidget::close );
930 layout->addWidget( buttonBox );
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.
QgsAuthCertInfoDialog(const QSslCertificate &cert, bool manageCertTrust, QWidget *parent=nullptr, const QList< QSslCertificate > &connectionCAs=QList< QSslCertificate >())
Construct a dialog displaying detailed info on a certificate and its hierarchical trust chain.
Widget for viewing detailed info on a certificate and its hierarchical trust chain.
QgsAuthCertInfo(const QSslCertificate &cert, bool manageCertTrust=false, QWidget *parent=nullptr, const QList< QSslCertificate > &connectionCAs=QList< QSslCertificate >())
Constructor for QgsAuthCertInfo.
Utilities for working with certificates and keys.
static QString qcaValidityMessage(QCA::Validity validity)
Certificate validity check messages per enum.
static QList< QgsAuthCertUtils::CertUsageType > certificateUsageTypes(const QSslCertificate &cert)
Try to determine the certificates usage types.
static QString qcaSignatureAlgorithm(QCA::SignatureAlgorithm algorithm)
Certificate signature algorithm strings per enum.
static QString resolvedCertName(const QSslCertificate &cert, bool issuer=false)
Gets the general name via RFC 5280 resolution.
static QString certificateUsageTypeString(QgsAuthCertUtils::CertUsageType usagetype)
Certificate usage type strings per enum.
static QString shaHexForCert(const QSslCertificate &cert, bool formatted=false)
Gets the sha1 hash for certificate.
CertTrustPolicy
Type of certificate trust policy.
static QString qcaKnownConstraint(QCA::ConstraintTypeKnown constraint)
Certificate well-known constraint strings per enum.
static bool certIsViable(const QSslCertificate &cert)
certIsViable checks for viability errors of cert and whether it is NULL
static QString getColonDelimited(const QString &txt)
Gets string with colon delimiters every 2 characters.
static QString getCaSourceName(QgsAuthCertUtils::CaCertSource source, bool single=false)
Gets the general name for CA source enum type.
static QString getCertDistinguishedName(const QSslCertificate &qcert, const QCA::Certificate &acert=QCA::Certificate(), bool issuer=false)
Gets combined distinguished name for certificate.
static QString redTextStyleSheet(const QString &selector="*")
Red text stylesheet representing invalid, untrusted, etc. certificate.
static QColor redColor()
Red color representing invalid, untrusted, etc. certificate.
QgsAuthCertUtils::CertTrustPolicy defaultCertTrustPolicy()
Gets the default certificate trust policy preferred by user.
bool rebuildCertTrustCache()
Rebuild certificate authority cache.
const QMap< QString, QPair< QgsAuthCertUtils::CaCertSource, QSslCertificate > > caCertsCache()
caCertsCache get all CA certs mapped to their sha1 from cache.
bool rebuildTrustedCaCertsCache()
Rebuild trusted certificate authorities cache.
#define SSL_SUBJECT_INFO(var, prop)
#define SSL_ISSUER_INFO(var, prop)
#define QgsDebugError(str)