Beispiel #1
0
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();
  }
}
Beispiel #2
0
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();
}