void SubKeysWidget::setKey(const GpgME::Key &key) { d->key = key; for (const auto &subkey : key.subkeys()) { auto item = new QTreeWidgetItem(); item->setData(0, Qt::DisplayRole, Formatting::prettyID(subkey.keyID())); item->setData(0, Qt::UserRole, QVariant::fromValue(subkey)); item->setData(1, Qt::DisplayRole, Kleo::Formatting::type(subkey)); item->setData(2, Qt::DisplayRole, Kleo::Formatting::creationDateString(subkey)); item->setData(3, Qt::DisplayRole, Kleo::Formatting::expirationDateString(subkey)); item->setData(4, Qt::DisplayRole, Kleo::Formatting::validityShort(subkey)); switch (subkey.publicKeyAlgorithm()) { case GpgME::Subkey::AlgoECDSA: case GpgME::Subkey::AlgoEDDSA: case GpgME::Subkey::AlgoECDH: item->setData(5, Qt::DisplayRole, QString::fromStdString(subkey.algoName())); break; default: item->setData(5, Qt::DisplayRole, QString::number(subkey.length())); } item->setData(6, Qt::DisplayRole, Kleo::Formatting::usageString(subkey)); item->setData(7, Qt::DisplayRole, subkey.keyID() == key.keyID() ? QStringLiteral("✓") : QString()); d->ui.subkeysTree->addTopLevelItem(item); } const auto subkey = key.subkey(0); if (const char *card = subkey.cardSerialNumber()) { d->ui.stored->setText(i18nc("stored...", "on SmartCard with serial no. %1", QString::fromUtf8(card))); } else { d->ui.stored->setText(i18nc("stored...", "on this computer")); } d->ui.subkeysTree->resizeColumnToContents(0); }
void CertificateInfoWidgetImpl::slotKeyExistanceCheckNextCandidate( const GpgME::Key & key ) { if ( key.isNull() || mChain.empty() || !key.primaryFingerprint() ) return; if ( qstrcmp( key.primaryFingerprint(), mChain.back().primaryFingerprint() ) == 0 ) mHaveKeyLocally = true; }
void Kleo::HierarchicalKeyListJob::slotNextKey( const GpgME::Key & key ) { if ( const char * chain_id = key.chainID() ) mNextSet.insert( chain_id ); if ( const char * fpr = key.primaryFingerprint() ) if ( mSentSet.find( fpr ) == mSentSet.end() ) { mSentSet.insert( fpr ); emit nextKey( key ); } }
void CertificateInfoWidgetImpl::slotNextKey( const GpgME::Key & key ) { kdDebug() << "CertificateInfoWidgetImpl::slotNextKey( \"" << key.userID(0).id() << "\" )" << endl; if ( key.isNull() ) return; mFoundIssuer = true; mChain.push_front( key ); updateChainView(); // FIXME: cancel the keylisting. We're only interested in _one_ key. }
void Kleo::KeyListView::doHierarchicalInsert( const GpgME::Key & key ) { const QCString fpr = key.primaryFingerprint(); if ( fpr.isEmpty() ) return; KeyListViewItem * item = 0; if ( !key.isRoot() ) if ( KeyListViewItem * parent = itemByFingerprint( key.chainID() ) ) { item = new KeyListViewItem( parent, key ); parent->setOpen( true ); } if ( !item ) item = new KeyListViewItem( this, key ); // top-level (for now) d->itemMap.insert( std::make_pair( fpr, item ) ); }
QString Formatting::formatForComboBox( const GpgME::Key & key ) { const QString name = prettyName( key ); QString mail = prettyEMail( key ); if ( !mail.isEmpty() ) mail = '<' + mail + '>'; return i18nc( "name, email, key id", "%1 %2 (%3)", name, mail, key.shortKeyID() ).simplified(); }
CertificateInfoWidgetImpl::CertificateInfoWidgetImpl( const GpgME::Key & key, bool external, QWidget * parent, const char * name ) : CertificateInfoWidget( parent, name ), mExternal( external ), mFoundIssuer( true ), mHaveKeyLocally( false ) { importButton->setEnabled( false ); listView->setColumnWidthMode( 1, QListView::Maximum ); QFontMetrics fm = fontMetrics(); listView->setColumnWidth( 1, fm.width( i18n("Information") ) * 5 ); listView->header()->setClickEnabled( false ); listView->setSorting( -1 ); connect( listView, SIGNAL( selectionChanged( QListViewItem* ) ), this, SLOT( slotShowInfo( QListViewItem* ) ) ); pathView->setColumnWidthMode( 0, QListView::Maximum ); pathView->header()->hide(); connect( pathView, SIGNAL( doubleClicked( QListViewItem* ) ), this, SLOT( slotShowCertPathDetails( QListViewItem* ) ) ); connect( pathView, SIGNAL( returnPressed( QListViewItem* ) ), this, SLOT( slotShowCertPathDetails( QListViewItem* ) ) ); connect( importButton, SIGNAL( clicked() ), this, SLOT( slotImportCertificate() ) ); dumpView->setFont( KGlobalSettings::fixedFont() ); if ( !key.isNull() ) setKey( key ); }
void Kleo::KeyListView::slotAddKey( const GpgME::Key & key ) { if ( key.isNull() ) return; d->keyBuffer.push_back( key ); if ( !d->updateTimer->isActive() ) d->updateTimer->start( updateDelayMilliSecs, true /* single-shot */ ); }
void Kleo::KeyListView::slotRefreshKey( const GpgME::Key & key ) { const char * fpr = key.primaryFingerprint(); if ( !fpr ) return; if ( KeyListViewItem * item = itemByFingerprint( fpr ) ) item->setKey ( key ); else // none found -> add it slotAddKey( key ); }
void Identity::setKey(const GpgME::Key &key) { if (key.isNull()) { m_identity->setPGPEncryptionKey(QByteArray()); m_identity->setPGPSigningKey(QByteArray()); m_identity->setSMIMEEncryptionKey(QByteArray()); m_identity->setSMIMESigningKey(QByteArray()); } else if (key.protocol() == GpgME::OpenPGP) { m_identity->setPGPSigningKey(key.primaryFingerprint()); m_identity->setPGPEncryptionKey(key.primaryFingerprint()); } else if (key.protocol() == GpgME::CMS) { m_identity->setSMIMESigningKey(key.primaryFingerprint()); m_identity->setSMIMEEncryptionKey(key.primaryFingerprint()); } }
bool Kleo::KConfigBasedKeyFilter::matches( const GpgME::Key & key ) const { #ifdef MATCH #undef MATCH #endif #define MATCH(member,method) \ if ( member != DoesNotMatter && key.method() != bool( member == Set ) ) \ return false #define IS_MATCH(what) MATCH( m##what, is##what ) #define CAN_MATCH(what) MATCH( mCan##what, can##what ) IS_MATCH( Revoked ); IS_MATCH( Expired ); IS_MATCH( Disabled ); IS_MATCH( Root ); CAN_MATCH( Encrypt ); CAN_MATCH( Sign ); CAN_MATCH( Certify ); CAN_MATCH( Authenticate ); MATCH( mHasSecret, isSecret ); #undef MATCH if ( mIsOpenPGP != DoesNotMatter && bool( key.protocol() == GpgME::Context::OpenPGP ) != bool( mIsOpenPGP == Set ) ) return false; if ( mWasValidated != DoesNotMatter && bool( key.keyListMode() & GpgME::Context::Validate ) != bool( mWasValidated == Set ) ) return false; switch ( mOwnerTrust ) { default: case LevelDoesNotMatter: break; case Is: if ( key.ownerTrust() != mOwnerTrustReferenceLevel ) return false; break; case IsNot: if ( key.ownerTrust() == mOwnerTrustReferenceLevel ) return false; break; case IsAtLeast: if ( (int)key.ownerTrust() < (int)mOwnerTrustReferenceLevel ) return false; break; case IsAtMost: if ( (int)key.ownerTrust() > (int)mOwnerTrustReferenceLevel ) return false; break; } const GpgME::UserID uid = key.userID(0); switch ( mValidity ) { default: case LevelDoesNotMatter: break; case Is: if ( uid.validity() != mValidityReferenceLevel ) return false; break; case IsNot: if ( uid.validity() == mValidityReferenceLevel ) return false; break; case IsAtLeast: if ( (int)uid.validity() < (int)mValidityReferenceLevel ) return false; break; case IsAtMost: if ( (int)uid.validity() > (int)mValidityReferenceLevel ) return false; break; } return true; }
void KGPGFile::keyList(QStringList& list, bool secretKeys, const QString& pattern) { d->m_keys.clear(); list.clear(); if (d->ctx && !d->ctx->startKeyListing(pattern.toUtf8().constData(), secretKeys)) { GpgME::Error error; for (;;) { GpgME::Key key; key = d->ctx->nextKey(error); if (error.encodedError() != GPG_ERR_NO_ERROR) break; bool needPushBack = true; std::vector<GpgME::UserID> userIDs = key.userIDs(); std::vector<GpgME::Subkey> subkeys = key.subkeys(); for (unsigned int i = 0; i < userIDs.size(); ++i) { if (subkeys.size() > 0) { for (unsigned int j = 0; j < subkeys.size(); ++j) { const GpgME::Subkey& skey = subkeys[j]; if (((skey.canEncrypt() && !secretKeys) || (skey.isSecret() && secretKeys)) && !(skey.isRevoked() || skey.isExpired() || skey.isInvalid() || skey.isDisabled())) { QString entry = QString("%1:%2").arg(key.shortKeyID()).arg(userIDs[i].id()); list += entry; if (needPushBack) { d->m_keys.push_back(key); needPushBack = false; } } else { // qDebug("Skip key '%s'", key.shortKeyID()); } } } else { // we have no subkey, so we operate on the main key if (((key.canEncrypt() && !secretKeys) || (key.hasSecret() && secretKeys)) && !(key.isRevoked() || key.isExpired() || key.isInvalid() || key.isDisabled())) { QString entry = QString("%1:%2").arg(key.shortKeyID()).arg(userIDs[i].id()); list += entry; if (needPushBack) { d->m_keys.push_back(key); needPushBack = false; } } else { // qDebug("Skip key '%s'", key.shortKeyID()); } } } } d->ctx->endKeyListing(); } }
void CertificateInfoWidgetImpl::setKey( const GpgME::Key & key ) { mChain.clear(); mFoundIssuer = true; mHaveKeyLocally = false; listView->clear(); pathView->clear(); importButton->setEnabled( false ); if ( key.isNull() ) return; mChain.push_front( key ); startKeyExistanceCheck(); // starts a local keylisting to enable the // importButton if needed QListViewItem * item = 0; item = new QListViewItem( listView, item, i18n("Valid"), QString("From %1 to %2") .arg( time_t2string( key.subkey(0).creationTime() ), time_t2string( key.subkey(0).expirationTime() ) ) ); item = new QListViewItem( listView, item, i18n("Can be used for signing"), key.canSign() ? i18n("Yes") : i18n("No") ); item = new QListViewItem( listView, item, i18n("Can be used for encryption"), key.canEncrypt() ? i18n("Yes") : i18n("No") ); item = new QListViewItem( listView, item, i18n("Can be used for certification"), key.canCertify() ? i18n("Yes") : i18n("No") ); item = new QListViewItem( listView, item, i18n("Can be used for authentication"), key.canAuthenticate() ? i18n("Yes") : i18n("No" ) ); item = new QListViewItem( listView, item, i18n("Fingerprint"), key.primaryFingerprint() ); item = new QListViewItem( listView, item, i18n("Issuer"), Kleo::DN( key.issuerName() ).prettyDN() ); item = new QListViewItem( listView, item, i18n("Serial Number"), key.issuerSerial() ); const Kleo::DN dn = key.userID(0).id(); // FIXME: use the attributeLabelMap from certificatewizardimpl.cpp: static QMap<QString,QString> dnComponentNames; if ( dnComponentNames.isEmpty() ) { dnComponentNames["C"] = i18n("Country"); dnComponentNames["OU"] = i18n("Organizational Unit"); dnComponentNames["O"] = i18n("Organization"); dnComponentNames["L"] = i18n("Location"); dnComponentNames["CN"] = i18n("Common Name"); dnComponentNames["EMAIL"] = i18n("Email"); } for ( Kleo::DN::const_iterator dnit = dn.begin() ; dnit != dn.end() ; ++dnit ) { QString displayName = (*dnit).name(); if( dnComponentNames.contains(displayName) ) displayName = dnComponentNames[displayName]; item = new QListViewItem( listView, item, displayName, (*dnit).value() ); } const std::vector<GpgME::UserID> uids = key.userIDs(); if ( !uids.empty() ) { item = new QListViewItem( listView, item, i18n("Subject"), Kleo::DN( uids.front().id() ).prettyDN() ); for ( std::vector<GpgME::UserID>::const_iterator it = uids.begin() + 1 ; it != uids.end() ; ++it ) { if ( !(*it).id() ) continue; const QString email = QString::fromUtf8( (*it).id() ).stripWhiteSpace(); if ( email.isEmpty() ) continue; if ( email.startsWith( "<" ) ) item = new QListViewItem( listView, item, i18n("Email"), email.mid( 1, email.length()-2 ) ); else item = new QListViewItem( listView, item, i18n("A.k.a."), email ); } } updateChainView(); startCertificateChainListing(); startCertificateDump(); }