Page MenuHome GnuPG

No OneTemporary

This document is not UTF8. It was detected as Shift JIS and converted to UTF8 for display.
diff --git a/certificateinfowidgetimpl.cpp b/certificateinfowidgetimpl.cpp
index b042cf97b..c0faee648 100644
--- a/certificateinfowidgetimpl.cpp
+++ b/certificateinfowidgetimpl.cpp
@@ -1,183 +1,186 @@
/* -*- Mode: C -*-
$Id$
Copyright (C) 2001 by Klar舁vdalens Datakonsult AB
GPGMEPLUG is free software; you can redistribute it and/or modify
it under the terms of GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
GPGMEPLUG is distributed in the hope that it will be useful,
it under the terms of GNU General Public License as published by
the Free Software Foundation; version 2 of the License
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <qlistview.h>
#include <qtextedit.h>
#include <qheader.h>
#include <qpushbutton.h>
#include <qcursor.h>
#include <qapplication.h>
#include <klocale.h>
#include <kdialogbase.h>
#include <kmessagebox.h>
#include "certificateinfowidgetimpl.h"
#include "certmanager.h"
CertificateInfoWidgetImpl::CertificateInfoWidgetImpl( CertManager* manager, bool external,
QWidget* parent, const char* name )
: CertificateInfoWidget( parent, name ), _manager(manager), _external( external )
{
if( !external ) importButton->setEnabled(false);
listView->setColumnWidthMode( 1, QListView::Manual );
listView->setResizeMode( QListView::LastColumn );
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::Manual );
pathView->setResizeMode( QListView::LastColumn );
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() ) );
}
void CertificateInfoWidgetImpl::setCert( const CryptPlugWrapper::CertificateInfo& info )
{
listView->clear();
pathView->clear();
_info = info;
/* Check if we already have the cert in question */
if( _manager ) {
importButton->setEnabled( !_manager->haveCertificate( info.fingerprint ) );
} else {
importButton->setEnabled( false );
}
// These will show in the opposite order
new QListViewItem( listView, i18n("Fingerprint"), info.fingerprint );
new QListViewItem( listView, i18n("Can be used for certification"),
info.certify?i18n("Yes"):i18n("No") );
new QListViewItem( listView, i18n("Can be used for encryption"),
info.encrypt?i18n("Yes"):i18n("No") );
new QListViewItem( listView, i18n("Can be used for signing"),
info.sign?i18n("Yes"):i18n("No") );
new QListViewItem( listView, i18n("Valid"), QString("From %1 to %2")
.arg( info.created.toString() ).arg(info.expire.toString()) );
//new QListViewItem( listView, i18n("Email"), info.dn["1.2.840.113549.1.9.1"] );
new QListViewItem( listView, i18n("Country"), info.dn["C"] );
new QListViewItem( listView, i18n("Organizational Unit"), info.dn["OU"] );
new QListViewItem( listView, i18n("Organization"), info.dn["O"] );
new QListViewItem( listView, i18n("Location"), info.dn["L"] );
new QListViewItem( listView, i18n("Name"), info.dn["CN"] );
new QListViewItem( listView, i18n("Issuer"), info.issuer.stripWhiteSpace() );
QStringList::ConstIterator it = info.userid.begin();
QListViewItem* item = new QListViewItem( listView, i18n("Subject"),
(*it).stripWhiteSpace() );
++it;
while( it != info.userid.end() ) {
if( (*it)[0] == '<' ) {
item = new QListViewItem( listView, item, i18n("EMail"), (*it).mid(1,(*it).length()-2));
} else {
item = new QListViewItem( listView, item, i18n("Aka"), (*it).stripWhiteSpace() );
}
++it;
}
// Set up cert. path
if( !_manager ) return;
const CryptPlugWrapper::CertificateInfoList& lst = _manager->certList();
QString issuer = info.issuer;
QStringList items;
items << info.userid[0];
while( true ) {
bool found = false;
CryptPlugWrapper::CertificateInfo info;
for( CryptPlugWrapper::CertificateInfoList::ConstIterator it = lst.begin();
it != lst.end(); ++it ) {
if( (*it).userid[0] == issuer && !items.contains( info.userid[0] ) ) {
info = (*it);
found = true;
break;
}
}
if( found ) {
items.prepend( info.userid[0] );
issuer = info.issuer;
// FIXME(steffen): Use real DN comparison
if( info.userid[0] == info.issuer ) {
// Root item
break;
}
} else break;
}
item = 0;
for( QStringList::Iterator it = items.begin(); it != items.end(); ++it ) {
if( item ) item = new QListViewItem( item, (*it) );
else item = new QListViewItem( pathView, (*it) );
item->setOpen( true );
}
}
void CertificateInfoWidgetImpl::slotShowInfo( QListViewItem* item )
{
textView->setText( item->text(1) );
}
void CertificateInfoWidgetImpl::slotShowCertPathDetails( QListViewItem* item )
{
if( !_manager ) return;
const CryptPlugWrapper::CertificateInfoList& lst = _manager->certList();
for( CryptPlugWrapper::CertificateInfoList::ConstIterator it = lst.begin();
it != lst.end(); ++it ) {
if( (*it).userid[0] == item->text(0) ) {
KDialogBase* dialog = new KDialogBase( this, "dialog", true, i18n("Additional Information for Key"), KDialogBase::Close, KDialogBase::Close );
CertificateInfoWidgetImpl* top = new CertificateInfoWidgetImpl( _manager, _manager->isRemote(), dialog );
dialog->setMainWidget( top );
top->setCert( *it );
dialog->exec();
delete dialog;
}
}
}
void CertificateInfoWidgetImpl::slotImportCertificate()
{
if( !_manager ) return;
QApplication::setOverrideCursor( QCursor::WaitCursor );
int retval = _manager->importCertificateWithFingerprint( _info.fingerprint );
QApplication::restoreOverrideCursor();
- if( retval == -1 ) {
- KMessageBox::error( this, i18n("Error importing certificate.\nYou probably need to import the issuer certificate %1 first.").arg( _info.issuer ), i18n("Import error") );
+ if( retval == -42 ) {
+ KMessageBox::error( this, i18n("Cryptplug returned success, but no certiftcate was imported.\nYou may need to import the issuer certificate %1 first.").arg( _info.issuer ), i18n("Import error") );
} else if( retval ) {
KMessageBox::error( this, i18n("Error importing certificate.\nCryptPlug returned %1.").arg(retval), i18n("Import error") );
- }
+ } else {
+ KMessageBox::information( this, i18n("Certificate %1 with fingerprint %2 is imported to the local databse.").arg(_info.userid[0]).arg(_info.fingerprint), i18n("Certificate Imported") );
+ importButton->setEnabled( false );
+ }
}
#include "certificateinfowidgetimpl.moc"
diff --git a/certmanager.cpp b/certmanager.cpp
index 6c68722e9..93ab85c6e 100644
--- a/certmanager.cpp
+++ b/certmanager.cpp
@@ -1,397 +1,400 @@
#include "certmanager.h"
#include "certbox.h"
#include "certitem.h"
#include "agent.h"
#include "certificatewizardimpl.h"
// kdenetwork
#include <cryptplugwrapper.h>
// KDE
#include <kmenubar.h>
#include <kurlrequester.h>
#include <kfiledialog.h>
#include <kprocess.h>
#include <kaction.h>
#include <kapplication.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <ktempfile.h>
#include <dcopclient.h>
#include <ktoolbar.h>
#include <klineedit.h>
#include <kstatusbar.h>
#include <kcombobox.h>
// Qt
#include <qtextedit.h>
#include <qlineedit.h>
#include <qradiobutton.h>
#include <qwizard.h>
#include <qgrid.h>
#include <qcursor.h>
extern CryptPlugWrapper* pWrapper;
static const int ID_LINEEDIT = 1;
static const int ID_BUTTON = 2;
static const int ID_COMBO = 3;
static const int ID_LABEL = 10;
CertManager::CertManager( bool remote, const QString& query,
QWidget* parent, const char* name ) :
KMainWindow( parent, name ),
gpgsmProc( 0 ), _certBox(0), _remote( remote )
{
KMenuBar* bar = menuBar();
// File Menu
QPopupMenu* fileMenu = new QPopupMenu( bar, "fileMenu" );
bar->insertItem( i18n("&File"), fileMenu );
KAction* update = KStdAction::redisplay( this, SLOT( loadCertificates() ), actionCollection());
update->plug( fileMenu );
/*
KToggleAction* remoteaction = new KToggleAction( i18n("Remote lookup"), KShortcut(), this);
connect( remoteaction, SIGNAL( toggled(bool) ), this, SLOT( slotToggleRemote( bool ) ) );
remoteaction->setChecked( _remote );
remoteaction->plug( fileMenu );
*/
fileMenu->insertSeparator();
KAction* quit = KStdAction::quit( this, SLOT( quit() ), actionCollection());
quit->plug( fileMenu );
// Certificate Menu --------------------------------------------------
QPopupMenu* certMenu = new QPopupMenu( bar, "certMenu" );
bar->insertItem( i18n("Certificates"), certMenu );
// New Certificate
KAction* newCert = new KAction( i18n("New Certificate"), QIconSet(), 0, this, SLOT( newCertificate() ),
actionCollection(), "newCert" );
newCert->plug( certMenu );
// Revoke Certificate
KAction* revokeCert = new KAction( i18n("Revoke Certificate"), QIconSet(), 0, this, SLOT( revokeCertificate() ),
actionCollection(), "revokeCert" );
revokeCert->plug( certMenu );
revokeCert->setEnabled( false );
// Extend Certificate
KAction* extendCert = new KAction( i18n("Extend Certificate"), QIconSet(), 0, this, SLOT( extendCertificate() ),
actionCollection(), "extendCert" );
extendCert->plug( certMenu );
extendCert->setEnabled( false );
// Import Certificates
QPopupMenu* certImportMenu = new QPopupMenu( certMenu, "certImportMenu" );
certMenu->insertItem( i18n("&Import" ), certImportMenu );
// Import from file
KAction* importCertFromFile = new KAction( i18n("From &File..."), QIconSet(),
0, this,
SLOT( importCertFromFile() ),
actionCollection(),
"importCertFromFile" );
importCertFromFile->plug( certImportMenu );
importCertFromFile->setEnabled( true );
// CRL menu --------------------------------------------------
QPopupMenu* crlMenu = new QPopupMenu( bar, "crlMenu" );
bar->insertItem( i18n( "CRL" ), crlMenu );
// Import CRLs
QPopupMenu* crlImportMenu = new QPopupMenu( crlMenu, "crlImportMenu" );
crlMenu->insertItem( i18n("&Import" ), crlImportMenu );
// Import from file
KAction* importCRLFromFile = new KAction( i18n("From &File..."), QIconSet(), 0, this, SLOT( importCRLFromFile() ),
actionCollection(), "importCRLFromFile" );
importCRLFromFile->plug( crlImportMenu );
importCRLFromFile->setEnabled( false );
// Import from file
KAction* importCRLFromLDAP = new KAction( i18n("From &LDAP"), QIconSet(), 0, this, SLOT( importCRLFromLDAP() ),
actionCollection(), "importCRLFromLDAP" );
importCRLFromLDAP->plug( crlImportMenu );
importCRLFromLDAP->setEnabled( false );
// Toolbar
_toolbar = toolBar( "mainToolBar" );
_toolbar->insertWidget( ID_LABEL, -1, new QLabel( i18n("Look for"), _toolbar ) );
_toolbar->insertLined( query, ID_LINEEDIT, SIGNAL( returnPressed() ), this,
SLOT( loadCertificates() ) );
_toolbar->setItemAutoSized( ID_LINEEDIT, true );
QStringList lst;
lst << i18n("in local certificates") << i18n("in external certificates");
_toolbar->insertCombo( lst, ID_COMBO, false, SIGNAL( highlighted(int) ),
this, SLOT( slotToggleRemote(int) ) );
_toolbar->getCombo( ID_COMBO )->setCurrentItem( _remote?1:0 );
KAction* find = KStdAction::find( this, SLOT( loadCertificates() ), actionCollection());
_toolbar->insertButton( find->icon(), ID_BUTTON, SIGNAL( clicked() ), this,
SLOT( loadCertificates() ),
true, i18n("Search") );
_toolbar->alignItemRight( ID_BUTTON, true );
// Main Window --------------------------------------------------
_certBox = new CertBox( this, "certBox" );
setCentralWidget( _certBox );
if( !query.isEmpty() ) loadCertificates();
}
CertItem* CertManager::fillInOneItem( CertBox* lv, CertItem* parent,
const CryptPlugWrapper::CertificateInfo& info )
{
if( parent ) {
//qDebug("New with parent");
return new CertItem( /*info.userid[0].stripWhiteSpace(),
info.serial.stripWhiteSpace(),
info.issuer.stripWhiteSpace(),
info.dn["CN"],
info.dn["L"],
info.dn["O"],
info.dn["OU"],
info.dn["C"],
info.dn["1.2.840.113549.1.9.1"],
info.created,info.expire,
info.sign, info.encrypt, info.certify,*/
info,
0, this, parent );
} else {
//qDebug("New root");
return new CertItem( /*info.userid[0].stripWhiteSpace(),
info.serial.stripWhiteSpace(),
info.issuer.stripWhiteSpace(),
info.dn["CN"],
info.dn["L"],
info.dn["O"],
info.dn["OU"],
info.dn["C"],
info.dn["1.2.840.113549.1.9.1"],
info.created,info.expire,
info.sign, info.encrypt, info.certify,*/
info,
0, this, lv );
}
}
void CertManager::slotToggleRemote( int idx )
{
_remote = idx==0?false:true;
}
/**
This is an internal function, which loads the certificates that
match the current query, local or remote.
*/
void CertManager::loadCertificates()
{
// These are just some demonstration data
/*
Agent* root = new Agent( "Root Agent", 0, this );
Agent* sub = new Agent( "Sub Agent", root, this );
Agent* subsub = new Agent( "SubSub Agent", sub, this );
*/
QApplication::setOverrideCursor( QCursor::WaitCursor );
_toolbar->setItemEnabled( ID_LINEEDIT, false );
_toolbar->setItemEnabled( ID_BUTTON, false );
// Clear display
_certBox->clear();
QString text = _toolbar->getLinedText( ID_LINEEDIT ).stripWhiteSpace();
//qDebug("About to query plugin");
bool truncated;
if( text.isEmpty() ) {
_certList = pWrapper->listKeys(QString::null, _remote, &truncated );
} else {
_certList = pWrapper->listKeys(text, _remote, &truncated );
}
//qDebug("Done");
if( truncated ) {
//statusBar()->message();
KMessageBox::information( this, i18n("The server returned truncated output.\nPlease use a more specific search string to get all results.") );
} else {
//statusBar()->message( i18n("Query OK") );
}
//lst = fillInListView( _certBox, 0, lst );
for( CryptPlugWrapper::CertificateInfoList::Iterator it = _certList.begin();
it != _certList.end(); ++it ) {
//qDebug("New CertItem %s", (*it).userid.latin1() );
fillInOneItem( _certBox, 0, *it );
}
_toolbar->setItemEnabled( ID_LINEEDIT, true );
_toolbar->setItemEnabled( ID_BUTTON, true );
KLineEdit* le = _toolbar->getLined( ID_LINEEDIT );
le->selectAll();
le->setFocus();
QApplication::restoreOverrideCursor();
}
/**
This slot is invoked when the user selects "New certificate"
*/
void CertManager::newCertificate()
{
CertificateWizardImpl* wizard = new CertificateWizardImpl( this );
if( wizard->exec() == QDialog::Accepted ) {
if( wizard->sendToCARB->isChecked() ) {
// Ask KMail to send this key to the CA.
DCOPClient* dcopClient = kapp->dcopClient();
QByteArray data;
QDataStream arg( data, IO_WriteOnly );
arg << wizard->caEmailED->text();
arg << wizard->keyData();
if( !dcopClient->send( "kmail*", "KMailIface",
"sendCertificate(QString,QByteArray)", data ) ) {
KMessageBox::error( this,
i18n( "DCOP Communication Error, unable to send certificate using KMail" ) );
return;
}
} else {
// Store in file
QFile file( wizard->storeUR->url() );
if( file.open( IO_WriteOnly ) ) {
file.writeBlock( wizard->keyData().data(),
wizard->keyData().count() );
file.close();
} else {
KMessageBox::error( this,
i18n( "Could not open output file for writing" ) );
return;
}
}
}
}
/**
This slot is invoked when the user chooses File->Quit
*/
void CertManager::quit()
{
qApp->quit();
}
/**
This slot is invoked when the user selects revoke certificate.
The slot will revoke the selected certificates
*/
void CertManager::revokeCertificate()
{
qDebug("Not Yet Implemented");
}
/**
This slot is invoked when the user selects extend certificate.
It will send an extension request for the selected certificates
*/
void CertManager::extendCertificate()
{
qDebug("Not Yet Implemented");
}
/**
This slot is invoke dwhen the user selects Certificates/Import/From File.
*/
void CertManager::importCertFromFile()
{
QString certFilename = KFileDialog::getOpenFileName( QString::null,
QString::null,
this,
i18n( "Select Certificate File" ) );
if( !certFilename.isEmpty() ) {
gpgsmProc = new KProcess();
*gpgsmProc << "gpgsm";
*gpgsmProc << "--import" << certFilename;
connect( gpgsmProc, SIGNAL( processExited( KProcess* ) ),
this, SLOT( slotGPGSMExited() ) );
if( !gpgsmProc->start() ) { // NotifyOnExit, NoCommunication
// are defaults
KMessageBox::error( this, i18n( "Couldn't start gpgsm process. Please check your installation." ), i18n( "Certificate Manager Error" ) );
delete gpgsmProc;
gpgsmProc = 0;
}
}
}
/**
This slot is called when the gpgsm process that imports a
certificate file exists.
*/
void CertManager::slotGPGSMExited()
{
if( !gpgsmProc->normalExit() )
KMessageBox::error( this, i18n( "The GPGSM process that tried to import the certificate file ended prematurely because of an unexpected error." ), i18n( "Certificate Manager Error" ) );
else
if( gpgsmProc->exitStatus() )
KMessageBox::error( this, i18n( "An error occurred when trying to import the certificate file." ), i18n( "Certificate Manager Error" ) );
else
KMessageBox::information( this, i18n( "Certificate file imported successfully." ), i18n( "Certificate Manager Error" ) );
if( gpgsmProc )
delete gpgsmProc;
}
/**
This slot will import CRLs from a file.
*/
void CertManager::importCRLFromFile()
{
qDebug("Not Yet Implemented");
}
/**
This slot will import CRLs from an LDAP server.
*/
void CertManager::importCRLFromLDAP()
{
qDebug("Not Yet Implemented");
}
int CertManager::importCertificateWithFingerprint( const QString& fingerprint )
{
bool truncated;
qDebug("Importing certificate with fpr %s", fingerprint.latin1() );
int retval = pWrapper->importCertificate( fingerprint );
+
CryptPlugWrapper::CertificateInfoList lst = pWrapper->listKeys( fingerprint, false, &truncated );
- if( !retval && !lst.isEmpty() && lst.first().fingerprint == fingerprint ) {
+ if( !retval ) return retval;
+ if( haveCertificate( fingerprint ) ) {
// It seems everyting went OK!
qDebug("Got cert with DN=%s", lst.first().userid[0].latin1() );
} else {
- if( !retval ) retval = -1;
+ // Everything went OK, but the certificate wasn't imported
+ retval = -42;
}
if( !isRemote() ) loadCertificates();
return retval;
}
bool CertManager::haveCertificate( const QString& fingerprint )
{
bool truncated;
CryptPlugWrapper::CertificateInfoList lst = pWrapper->listKeys( fingerprint, false, &truncated );
return !lst.isEmpty();
}
#include "certmanager.moc"

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jul 17, 1:35 AM (8 h, 7 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f7/68/37cf5cc90030448156af8711ecd3

Event Timeline