summaryrefslogtreecommitdiffstats
path: root/certmanager/lib/backends/chiasmus
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /certmanager/lib/backends/chiasmus
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'certmanager/lib/backends/chiasmus')
-rw-r--r--certmanager/lib/backends/chiasmus/Makefile.am16
-rw-r--r--certmanager/lib/backends/chiasmus/chiasmusbackend.cpp480
-rw-r--r--certmanager/lib/backends/chiasmus/chiasmusbackend.h86
-rw-r--r--certmanager/lib/backends/chiasmus/chiasmusjob.cpp220
-rw-r--r--certmanager/lib/backends/chiasmus/chiasmusjob.h116
-rw-r--r--certmanager/lib/backends/chiasmus/chiasmuslibrary.cpp115
-rw-r--r--certmanager/lib/backends/chiasmus/chiasmuslibrary.h68
-rw-r--r--certmanager/lib/backends/chiasmus/config_data.c95
-rw-r--r--certmanager/lib/backends/chiasmus/config_data.h34
-rw-r--r--certmanager/lib/backends/chiasmus/configure.in.in16
-rw-r--r--certmanager/lib/backends/chiasmus/obtainkeysjob.cpp126
-rw-r--r--certmanager/lib/backends/chiasmus/obtainkeysjob.h101
-rw-r--r--certmanager/lib/backends/chiasmus/symcryptrunprocessbase.cpp109
-rw-r--r--certmanager/lib/backends/chiasmus/symcryptrunprocessbase.h81
14 files changed, 1663 insertions, 0 deletions
diff --git a/certmanager/lib/backends/chiasmus/Makefile.am b/certmanager/lib/backends/chiasmus/Makefile.am
new file mode 100644
index 000000000..8a5d85bd4
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/Makefile.am
@@ -0,0 +1,16 @@
+INCLUDES = -I$(top_srcdir)/certmanager/lib -I$(top_srcdir)/libkdenetwork $(GPGME_CFLAGS) $(all_includes)
+
+KDE_CXXFLAGS = '-DGPG_ERR_SOURCE_DEFAULT=((gpg_err_source_t)176)'
+
+noinst_LTLIBRARIES = libkleopatra_backend_chiasmus.la
+
+libkleopatra_backend_chiasmus_la_SOURCES = \
+ config_data.c \
+ obtainkeysjob.cpp \
+ symcryptrunprocessbase.cpp \
+ chiasmusjob.cpp \
+ chiasmuslibrary.cpp \
+ chiasmusbackend.cpp
+
+
+METASOURCES = AUTO
diff --git a/certmanager/lib/backends/chiasmus/chiasmusbackend.cpp b/certmanager/lib/backends/chiasmus/chiasmusbackend.cpp
new file mode 100644
index 000000000..15a63de53
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/chiasmusbackend.cpp
@@ -0,0 +1,480 @@
+/*
+ chiasmusbackend.cpp
+
+ This file is part of libkleopatra, the KDE keymanagement library
+ Copyright (c) 2005 Klarälvdalens Datakonsult AB
+
+ Libkleopatra is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Libkleopatra is distributed in the hope that it will be useful,
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "chiasmusbackend.h"
+
+#include "config_data.h"
+#include "obtainkeysjob.h"
+#include "chiasmusjob.h"
+
+#include "kleo/cryptoconfig.h"
+
+#include <klocale.h>
+#include <kconfig.h>
+#include <kshell.h>
+#include <kdebug.h>
+
+#include <qstringlist.h>
+#include <qvariant.h>
+#include <qfileinfo.h>
+
+#include <map>
+#include <memory>
+
+#include <cassert>
+
+namespace {
+
+ //
+ // The usual QVariant template helpers:
+ //
+
+ // to<> is a demarshaller. It's a class b/c you can't partially
+ // specialise function templates yet. However, to<> can be used as if
+ // it was a function: QString s = to<QString>( myVariant );
+ template <typename T> class to {};
+
+#define MAKE_TO( type, func ) \
+ template <> \
+ class to< type > { \
+ type m; \
+ public: \
+ to( const QVariant & v ) : m( v.func() ) {} \
+ operator type() const { return m; } \
+ }
+
+ MAKE_TO( int, toInt );
+ MAKE_TO( unsigned int, toUInt );
+
+ template <>
+ class to<KURL> {
+ KURL m;
+ public:
+ to( const QVariant & v ) {
+ m.setPath( v.toString() );
+ }
+ operator KURL() const { return m; }
+ };
+
+ template <typename T>
+ class to< QValueList<T> > {
+ QValueList<T> m;
+ public:
+ to( const QVariant & v ) {
+ const QValueList<QVariant> vl = v.toList();
+ for ( QValueList<QVariant>::const_iterator it = vl.begin(), end = vl.end() ; it != end ; ++it )
+ m.push_back( to<T>( *it ) );
+ }
+ operator QValueList<T> () const { return m; }
+ };
+
+ template <>
+ class to<KURL::List> {
+ KURL::List m;
+ public:
+ to( const QVariant & v ) {
+ // wow, KURL::List is broken... it lacks conversion from and to QVL<KURL>...
+ m += to< QValueList<KURL> >( v );
+ }
+ operator KURL::List() const { return m; }
+ };
+
+
+ // from<> is the demarshaller. See to<> for why this is a class...
+
+ template <typename T>
+ struct from_helper : public QVariant {
+ from_helper( const T & t ) : QVariant( t ) {}
+ };
+
+ template <typename T>
+ QVariant from( const T & t ) {
+ return from_helper<T>( t );
+ }
+
+ // some special types:
+ template <> struct from_helper<bool> : public QVariant {
+ from_helper( bool b ) : QVariant( b, int() ) {}
+ };
+ template <> struct from_helper<KURL> : public QVariant {
+ from_helper( const KURL & url ) : QVariant( url.path() ) {}
+ };
+ template <typename T> struct from_helper< QValueList<T> > : public QVariant {
+ from_helper( const QValueList<T> & l ) {
+ QValueList<QVariant> result;
+ for ( typename QValueList<T>::const_iterator it = l.begin(), end = l.end() ; it != end ; ++it )
+ result.push_back( from( *it ) );
+ QVariant::operator=( result );
+ }
+ };
+ template <> struct from_helper<KURL::List> : public from_helper< QValueList<KURL> > {
+ from_helper( const KURL::List & l ) : from_helper< QValueList<KURL> >( l ) {}
+ };
+
+ class ChiasmusConfigEntry : public Kleo::CryptoConfigEntry {
+ unsigned int mIdx;
+ QVariant mValue;
+ bool mDirty;
+ public:
+ ChiasmusConfigEntry( unsigned int i )
+ : Kleo::CryptoConfigEntry(),
+ mIdx( i ), mValue( defaultValue() ), mDirty( false )
+ {
+ assert( i < kleo_chiasmus_config_entries_dim );
+ }
+ QString name() const { return kleo_chiasmus_config_entries[mIdx].name; }
+ QString description() const { return i18n( kleo_chiasmus_config_entries[mIdx].description ); }
+ bool isOptional() const { return kleo_chiasmus_config_entries[mIdx].is_optional; }
+ bool isReadOnly() const { return false; }
+ bool isList() const { return kleo_chiasmus_config_entries[mIdx].is_list; }
+ bool isRuntime() const { return kleo_chiasmus_config_entries[mIdx].is_runtime; }
+ Level level() const { return static_cast<Level>( kleo_chiasmus_config_entries[mIdx].level ); }
+ ArgType argType() const { return static_cast<ArgType>( kleo_chiasmus_config_entries[mIdx].type ); }
+ bool isSet() const { return mValue != defaultValue(); }
+ bool boolValue() const { return mValue.toBool(); }
+ QString stringValue() const { return mValue.toString(); }
+ int intValue() const { return mValue.toInt(); }
+ unsigned int uintValue() const { return mValue.toUInt(); }
+ KURL urlValue() const {
+ if ( argType() != ArgType_Path && argType() != ArgType_DirPath ) return KURL( mValue.toString() );
+ KURL u; u.setPath( mValue.toString() ); return u;
+ }
+ unsigned int numberOfTimesSet() const { return 0; }
+ QStringList stringValueList() const { return mValue.toStringList(); }
+ QValueList<int> intValueList() const { return to< QValueList<int> >( mValue ); }
+ QValueList<unsigned int> uintValueList() const { return to< QValueList<unsigned int> >( mValue ); }
+ KURL::List urlValueList() const {
+ if ( argType() != ArgType_Path && argType()!= ArgType_DirPath ) return mValue.toStringList();
+ else return to<KURL::List>( mValue ); }
+ void resetToDefault() { mValue = defaultValue(); mDirty = false; }
+ void setBoolValue( bool value ) { setValue( QVariant( value, int() ) ); }
+ void setStringValue( const QString & value ) { setValue( value ); }
+ void setIntValue( int value ) { setValue( value ); }
+ void setUIntValue( unsigned int value ) { setValue( value ); }
+ void setURLValue( const KURL & value ) {
+ if ( argType() != ArgType_Path && argType()!= ArgType_DirPath ) setValue( value.url() );
+ else setValue( value.path() );
+ }
+ void setNumberOfTimesSet( unsigned int ) {}
+ void setStringValueList( const QStringList & value ) { setValue( value ); }
+ void setIntValueList( const QValueList<int> & l ) { setValue( from( l ) ); }
+ void setUIntValueList( const QValueList<unsigned int> & l ) { setValue( from( l ) ); }
+ void setURLValueList( const KURL::List & l ) { setValue( from( l ) ); }
+ bool isDirty() const { return mDirty; }
+
+ QVariant value() const { return mValue; }
+
+ void sync( KConfigBase * config ) {
+ if ( !mDirty )
+ return;
+ mDirty = false;
+ config->writeEntry( kleo_chiasmus_config_entries[mIdx].name, mValue );
+ }
+ void read( const KConfigBase * config ) {
+ mDirty = false;
+ mValue = config->readPropertyEntry( kleo_chiasmus_config_entries[mIdx].name, defaultValue() );
+ }
+ private:
+ QVariant defaultValue() const;
+ void setValue( const QVariant & value ) { mValue = value; mDirty = true; }
+ };
+
+ QVariant ChiasmusConfigEntry::defaultValue() const {
+ const kleo_chiasmus_config_data & data = kleo_chiasmus_config_entries[mIdx];
+ switch ( data.type ) {
+ default:
+ return QVariant();
+ case ArgType_None:
+ if ( isList() )
+ return QValueList<QVariant>() << QVariant( data.defaults.boolean.value, int() );
+ else
+ return QVariant( data.defaults.boolean.value, int() );
+ case ArgType_String:
+ if ( isList() )
+ return QStringList( QString::fromLatin1( data.defaults.string ) );
+ else
+ return QString::fromLatin1( data.defaults.string );
+ case ArgType_Int:
+ if ( isList() )
+ return QValueList<QVariant>() << data.defaults.integer;
+ else
+ return data.defaults.integer;
+ case ArgType_UInt:
+ if ( isList() )
+ return QValueList<QVariant>() << data.defaults.unsigned_integer;
+ else
+ return data.defaults.unsigned_integer;
+ case ArgType_Path:
+ case ArgType_DirPath:
+ if ( isList() )
+ return QValueList<QVariant>() << QString::fromLatin1( data.defaults.path );
+ else
+ return QString::fromLatin1( data.defaults.path );
+ case ArgType_URL:
+ case ArgType_LDAPURL:
+ if ( isList() )
+ return QValueList<QVariant>() << QString::fromLatin1( data.defaults.url );
+ else
+ return QString::fromLatin1( data.defaults.url );
+ }
+ }
+
+ class ChiasmusGeneralGroup : public Kleo::CryptoConfigGroup {
+ mutable std::map<QString,ChiasmusConfigEntry*> mCache;
+ mutable KConfig * mConfigObject;
+ public:
+ ChiasmusGeneralGroup() : Kleo::CryptoConfigGroup(), mConfigObject( 0 ) {}
+ ~ChiasmusGeneralGroup() { clear(); delete mConfigObject; }
+ QString name() const { return "General"; }
+ QString iconName() const { return "chiasmus_chi"; }
+ QString description() const { return i18n( "General" ); }
+ Kleo::CryptoConfigEntry::Level level() const { return Kleo::CryptoConfigEntry::Level_Basic; }
+ QStringList entryList() const {
+ QStringList result;
+ for ( unsigned int i = 0 ; i < kleo_chiasmus_config_entries_dim ; ++i )
+ result.push_back( kleo_chiasmus_config_entries[i].name );
+ return result;
+ }
+ Kleo::CryptoConfigEntry * entry( const QString & name ) const {
+ if ( ChiasmusConfigEntry * entry = mCache[name] )
+ return entry;
+ const KConfigGroup group( configObject(), "Chiasmus" );
+ for ( unsigned int i = 0 ; i < kleo_chiasmus_config_entries_dim ; ++i )
+ if ( name == kleo_chiasmus_config_entries[i].name ) {
+ ChiasmusConfigEntry * entry = new ChiasmusConfigEntry( i );
+ entry->read( &group );
+ return mCache[name] = entry;
+ }
+ return 0;
+ }
+
+ void sync() {
+ KConfigGroup group( configObject(), "Chiasmus" );
+ for ( std::map<QString,ChiasmusConfigEntry*>::const_iterator it = mCache.begin(), end = mCache.end() ; it != end ; ++it )
+ it->second->sync( &group );
+ group.sync();
+ clear();
+ }
+ private:
+ KConfig * configObject() const {
+ if ( !mConfigObject )
+ // this is unsafe. We're a lib, used by concurrent apps.
+ mConfigObject = new KConfig( "chiasmusbackendrc" );
+ return mConfigObject;
+ }
+ void clear() {
+ for ( std::map<QString,ChiasmusConfigEntry*>::const_iterator it = mCache.begin(), end = mCache.end() ; it != end ; ++it )
+ delete it->second;
+ mCache.clear();
+ }
+ };
+
+ class ChiasmusComponent : public Kleo::CryptoConfigComponent {
+ mutable ChiasmusGeneralGroup * mGeneralGroup;
+ public:
+ ChiasmusComponent() : Kleo::CryptoConfigComponent(), mGeneralGroup( 0 ) {}
+ ~ChiasmusComponent() { delete mGeneralGroup; }
+
+ void sync() {
+ if ( mGeneralGroup )
+ mGeneralGroup->sync();
+ }
+
+ QString name() const { return "Chiasmus"; }
+ QString iconName() const { return "chiasmus_chi"; }
+ QString description() const { return i18n( "Chiasmus" ); }
+ QStringList groupList() const { return QStringList() << "General"; }
+ Kleo::CryptoConfigGroup * group( const QString & name ) const {
+ if ( name != "General" )
+ return 0;
+ if ( !mGeneralGroup )
+ mGeneralGroup = new ChiasmusGeneralGroup();
+ return mGeneralGroup;
+ }
+ };
+
+}
+
+class Kleo::ChiasmusBackend::CryptoConfig : public Kleo::CryptoConfig {
+ mutable ChiasmusComponent * mComponent;
+public:
+ CryptoConfig() : Kleo::CryptoConfig(), mComponent( 0 ) {}
+ ~CryptoConfig() { delete mComponent; }
+
+ QStringList componentList() const { return QStringList() << "Chiasmus" ; }
+ ChiasmusComponent * component( const QString & name ) const {
+ if ( name != "Chiasmus" )
+ return 0;
+ if ( !mComponent )
+ mComponent = new ChiasmusComponent();
+ return mComponent;
+ }
+ void sync( bool ) {
+ if ( mComponent )
+ mComponent->sync();
+ }
+ void clear() { delete mComponent; mComponent = 0; }
+};
+
+class Kleo::ChiasmusBackend::Protocol : public Kleo::CryptoBackend::Protocol {
+ Kleo::CryptoConfig * mCryptoConfig;
+public:
+ Protocol( Kleo::CryptoConfig * config )
+ : Kleo::CryptoBackend::Protocol(), mCryptoConfig( config )
+ {
+ assert( config );
+ }
+ ~Protocol() {}
+
+ QString name() const { return "Chiasmus"; }
+ QString displayName() const { return i18n( "Chiasmus command line tool" ); }
+ KeyListJob * keyListJob( bool, bool, bool ) const { return 0; }
+ EncryptJob * encryptJob( bool, bool ) const { return 0; }
+ DecryptJob * decryptJob() const { return 0; }
+ SignJob * signJob( bool, bool ) const { return 0; }
+ VerifyDetachedJob * verifyDetachedJob( bool ) const { return 0; }
+ VerifyOpaqueJob * verifyOpaqueJob( bool ) const { return 0; }
+ KeyGenerationJob * keyGenerationJob() const { return 0; }
+ ImportJob * importJob() const { return 0; }
+ ExportJob * publicKeyExportJob( bool ) const { return 0; }
+ ExportJob * secretKeyExportJob( bool, const QString& ) const { return 0; }
+ DownloadJob * downloadJob( bool ) const { return 0; }
+ DeleteJob * deleteJob() const { return 0; }
+ SignEncryptJob * signEncryptJob( bool, bool ) const { return 0; }
+ DecryptVerifyJob * decryptVerifyJob( bool ) const { return 0; }
+ RefreshKeysJob * refreshKeysJob() const { return 0; }
+
+ SpecialJob * specialJob( const char * type, const QMap<QString,QVariant> & args ) const {
+ if ( qstricmp( type, "x-obtain-keys" ) == 0 && args.size() == 0 )
+ return new ObtainKeysJob();
+ if ( qstricmp( type, "x-encrypt" ) == 0 && args.size() == 0 )
+ return new ChiasmusJob( ChiasmusJob::Encrypt );
+ if ( qstricmp( type, "x-decrypt" ) == 0 && args.size() == 0 )
+ return new ChiasmusJob( ChiasmusJob::Decrypt );
+ kdDebug(5150) << "ChiasmusBackend::Protocol: tried to instantiate unknown job type \""
+ << type << "\"" << endl;
+
+ return 0;
+ }
+};
+
+Kleo::ChiasmusBackend * Kleo::ChiasmusBackend::self = 0;
+
+Kleo::ChiasmusBackend::ChiasmusBackend()
+ : Kleo::CryptoBackend(),
+ mCryptoConfig( 0 ),
+ mProtocol( 0 )
+{
+ self = this;
+}
+
+Kleo::ChiasmusBackend::~ChiasmusBackend() {
+ self = 0;
+ delete mCryptoConfig;
+ delete mProtocol;
+}
+
+QString Kleo::ChiasmusBackend::name() const {
+ return "Chiasmus";
+}
+
+QString Kleo::ChiasmusBackend::displayName() const {
+ return i18n( "Chiasmus" );
+}
+
+Kleo::CryptoConfig * Kleo::ChiasmusBackend::config() const {
+ if ( !mCryptoConfig )
+ mCryptoConfig = new CryptoConfig();
+ return mCryptoConfig;
+}
+
+Kleo::CryptoBackend::Protocol * Kleo::ChiasmusBackend::protocol( const char * name ) const {
+ if ( qstricmp( name, "Chiasmus" ) != 0 )
+ return 0;
+ if ( !mProtocol )
+ if ( checkForChiasmus() )
+ mProtocol = new Protocol( config() );
+ return mProtocol;
+}
+
+bool Kleo::ChiasmusBackend::checkForOpenPGP( QString * reason ) const {
+ if ( reason )
+ *reason = i18n( "Unsupported protocol \"%1\"" ).arg( "OpenPGP" );
+ return false;
+}
+
+bool Kleo::ChiasmusBackend::checkForSMIME( QString * reason ) const {
+ if ( reason )
+ *reason = i18n( "Unsupported protocol \"%1\"" ).arg( "SMIME" );
+ return false;
+}
+
+bool Kleo::ChiasmusBackend::checkForChiasmus( QString * reason ) const {
+
+ // kills the protocol instance when we return false:
+ std::auto_ptr<Protocol> tmp( mProtocol );
+ mProtocol = 0;
+
+ const CryptoConfigEntry * path = config()->entry( "Chiasmus", "General", "path" );
+ assert( path ); assert( path->argType() == CryptoConfigEntry::ArgType_Path );
+ const QString chiasmus = path->urlValue().path();
+ const QFileInfo fi( KShell::tildeExpand( chiasmus ) );
+ if ( !fi.isExecutable() ) {
+ if ( reason )
+ *reason = i18n( "File \"%1\" does not exist or is not executable." ).arg( chiasmus );
+ return false;
+ }
+
+ // FIXME: more checks?
+ mProtocol = tmp.release();
+ return true;
+}
+
+bool Kleo::ChiasmusBackend::checkForProtocol( const char * name, QString * reason ) const {
+ if ( qstricmp( name, "Chiasmus" ) == 0 )
+ return checkForChiasmus( reason );
+ if ( reason )
+ *reason = i18n( "Unsupported protocol \"%1\"" ).arg( name );
+ return 0;
+}
+
+bool Kleo::ChiasmusBackend::supportsProtocol( const char * name ) const {
+ return qstricmp( name, "Chiasmus" ) == 0;
+}
+
+const char * Kleo::ChiasmusBackend::enumerateProtocols( int i ) const {
+ return i == 0 ? "Chiasmus" : 0 ;
+}
diff --git a/certmanager/lib/backends/chiasmus/chiasmusbackend.h b/certmanager/lib/backends/chiasmus/chiasmusbackend.h
new file mode 100644
index 000000000..6d51cad77
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/chiasmusbackend.h
@@ -0,0 +1,86 @@
+/* -*- mode: C++; c-file-style: "gnu" -*-
+ chiasmusbackend.h
+
+ This file is part of libkleopatra, the KDE keymanagement library
+ Copyright (c) 2005 Klarälvdalens Datakonsult AB
+
+ Libkleopatra is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Libkleopatra is distributed in the hope that it will be useful,
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+
+#ifndef __KLEO_CHIASMUSBACKEND_H__
+#define __KLEO_CHIASMUSBACKEND_H__
+
+#include "kleo/cryptobackend.h"
+
+class CryptPlugWrapper;
+
+namespace Kleo {
+ class CryptoConfig;
+}
+class QString;
+
+namespace Kleo {
+
+ class ChiasmusBackend : public Kleo::CryptoBackend {
+ public:
+ ChiasmusBackend();
+ ~ChiasmusBackend();
+
+ static const ChiasmusBackend * instance() { return self; }
+
+ QString name() const;
+ QString displayName() const;
+
+ Kleo::CryptoConfig * config() const;
+
+ Kleo::CryptoBackend::Protocol * openpgp() const { return 0; }
+ Kleo::CryptoBackend::Protocol * smime() const { return 0; }
+ Kleo::CryptoBackend::Protocol * protocol( const char * name ) const;
+
+ bool checkForOpenPGP( QString * reason=0 ) const;
+ bool checkForSMIME( QString * reason=0 ) const;
+ bool checkForChiasmus( QString * reason=0 ) const;
+ bool checkForProtocol( const char * name, QString * reason=0 ) const;
+
+ bool supportsOpenPGP() const { return false; }
+ bool supportsSMIME() const { return false; }
+ bool supportsProtocol( const char * name ) const;
+
+ const char * enumerateProtocols( int i ) const;
+
+ private:
+ class CryptoConfig;
+ class Protocol;
+ mutable CryptoConfig * mCryptoConfig;
+ mutable Protocol * mProtocol;
+ static ChiasmusBackend * self;
+ };
+
+}
+
+
+#endif // __KLEO_CHIASMUSBACKEND_H__
diff --git a/certmanager/lib/backends/chiasmus/chiasmusjob.cpp b/certmanager/lib/backends/chiasmus/chiasmusjob.cpp
new file mode 100644
index 000000000..3ac7513df
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/chiasmusjob.cpp
@@ -0,0 +1,220 @@
+/*
+ chiasmusjob.cpp
+
+ This file is part of libkleopatra, the KDE keymanagement library
+ Copyright (c) 2005 Klarälvdalens Datakonsult AB
+
+ Libkleopatra is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Libkleopatra is distributed in the hope that it will be useful,
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "chiasmusjob.h"
+#include "chiasmusbackend.h"
+#include "symcryptrunprocessbase.h"
+
+#include "kleo/cryptoconfig.h"
+#include "ui/passphrasedialog.h"
+
+#include <gpg-error.h>
+
+#include <kshell.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kmessagebox.h>
+
+#include <qtimer.h>
+#include <qfileinfo.h>
+#include <qvariant.h>
+
+#include <memory>
+
+#include <cassert>
+
+Kleo::ChiasmusJob::ChiasmusJob( Mode mode )
+ : Kleo::SpecialJob( 0, 0 ),
+ mSymCryptRun( 0 ),
+ mError( 0 ),
+ mCanceled( false ),
+ mTimeout( false ),
+ mMode( mode )
+{
+
+}
+
+Kleo::ChiasmusJob::~ChiasmusJob() {}
+
+GpgME::Error Kleo::ChiasmusJob::setup() {
+ if ( !checkPreconditions() )
+ return mError = gpg_error( GPG_ERR_INV_VALUE );
+
+ const Kleo::CryptoConfigEntry * class_
+ = ChiasmusBackend::instance()->config()->entry( "Chiasmus", "General", "symcryptrun-class" );
+ const Kleo::CryptoConfigEntry * chiasmus
+ = ChiasmusBackend::instance()->config()->entry( "Chiasmus", "General", "path" );
+ const Kleo::CryptoConfigEntry * timeoutEntry
+ = ChiasmusBackend::instance()->config()->entry( "Chiasmus", "General", "timeout" );
+ if ( !class_ || !chiasmus || !timeoutEntry )
+ return mError = gpg_error( GPG_ERR_INTERNAL );
+
+ mSymCryptRun = new SymCryptRunProcessBase( class_->stringValue(),
+ KShell::tildeExpand( chiasmus->urlValue().path() ),
+ mKey, mOptions,
+ mMode == Encrypt
+ ? SymCryptRunProcessBase::Encrypt
+ : SymCryptRunProcessBase::Decrypt,
+ this, "symcryptrun" );
+ QTimer::singleShot( timeoutEntry->uintValue() * 1000, this,
+ SLOT( slotTimeout() ) );
+ return 0;
+}
+
+namespace {
+ struct LaterDeleter {
+ QObject * _this;
+ LaterDeleter( QObject * o ) : _this( o ) {}
+ ~LaterDeleter() { if ( _this ) _this->deleteLater(); }
+ void disable() { _this = 0; }
+ };
+}
+
+GpgME::Error Kleo::ChiasmusJob::start() {
+
+ LaterDeleter d( this );
+
+ if ( const GpgME::Error err = setup() )
+ return mError = err;
+
+ connect( mSymCryptRun, SIGNAL(processExited(KProcess*)),
+ this, SLOT(slotProcessExited(KProcess*)) );
+
+ if ( !mSymCryptRun->launch( mInput ) )
+ return mError = gpg_error( GPG_ERR_ENOENT ); // what else?
+
+ d.disable();
+ return mError = 0;
+}
+
+GpgME::Error Kleo::ChiasmusJob::slotProcessExited( KProcess * proc ) {
+ if ( proc != mSymCryptRun )
+ mError = gpg_error( GPG_ERR_INTERNAL );
+ else if ( mCanceled )
+ mError = gpg_error( GPG_ERR_CANCELED );
+ else if ( mTimeout )
+ mError = gpg_error( GPG_ERR_TIMEOUT );
+ else if ( !proc->normalExit() )
+ mError = gpg_error( GPG_ERR_GENERAL );
+ else
+ switch ( proc->exitStatus() ) {
+ case 0: // success
+ mOutput = mSymCryptRun->output();
+ mError = 0;
+ break;
+ default:
+ case 1: // Some error occured
+ mStderr = mSymCryptRun->stdErr();
+ mError = gpg_error( GPG_ERR_GENERAL );
+ break;
+ case 2: // No valid passphrase was provided
+ mError = gpg_error( GPG_ERR_INV_PASSPHRASE );
+ break;
+ case 3: // Canceled
+ mError = gpg_error( GPG_ERR_CANCELED );
+ break;
+ }
+
+ const Kleo::CryptoConfigEntry * showOutput
+ = ChiasmusBackend::instance()->config()->entry( "Chiasmus", "General", "show-output" );
+ if ( showOutput && showOutput->boolValue() ) {
+ showChiasmusOutput();
+ }
+
+ emit done();
+ emit SpecialJob::result( mError, QVariant( mOutput ) );
+ return mError;
+}
+
+void Kleo::ChiasmusJob::showChiasmusOutput() {
+ kdDebug() << k_funcinfo << endl;
+ if ( mStderr.isEmpty() )
+ return;
+ KMessageBox::information( 0 /*how to get a parent widget?*/,
+ mStderr,
+ i18n( "Output from chiasmus" ) );
+}
+
+GpgME::Error Kleo::ChiasmusJob::exec() {
+ if ( const GpgME::Error err = setup() )
+ return mError = err;
+
+ if ( !mSymCryptRun->launch( mInput, KProcess::Block ) ) {
+ delete mSymCryptRun; mSymCryptRun = 0;
+ return mError = gpg_error( GPG_ERR_ENOENT ); // what else?
+ }
+
+ const GpgME::Error err = slotProcessExited( mSymCryptRun );
+ delete mSymCryptRun; mSymCryptRun = 0;
+ return err;
+}
+
+bool Kleo::ChiasmusJob::checkPreconditions() const {
+ return !mKey.isEmpty();
+}
+
+void Kleo::ChiasmusJob::slotCancel() {
+ if ( mSymCryptRun )
+ mSymCryptRun->kill();
+ mCanceled = true;
+}
+
+void Kleo::ChiasmusJob::slotTimeout() {
+ if ( !mSymCryptRun )
+ return;
+ mSymCryptRun->kill();
+ mTimeout = true;
+}
+
+
+void Kleo::ChiasmusJob::showErrorDialog( QWidget * parent, const QString & caption ) const {
+ if ( !mError )
+ return;
+ if ( mError.isCanceled() )
+ return;
+ const QString msg = ( mMode == Encrypt
+ ? i18n( "Encryption failed: %1" )
+ : i18n( "Decryption failed: %1" ) )
+ .arg( QString::fromLocal8Bit( mError.asString() ) );
+ if ( !mStderr.isEmpty() ) {
+ const QString details = i18n( "The following was received on stderr:\n%1" ).arg( mStderr );
+ KMessageBox::detailedError( parent, msg, details, caption );
+ } else {
+ KMessageBox::error( parent, msg, caption );
+ }
+}
+
+#include "chiasmusjob.moc"
diff --git a/certmanager/lib/backends/chiasmus/chiasmusjob.h b/certmanager/lib/backends/chiasmus/chiasmusjob.h
new file mode 100644
index 000000000..6393a0905
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/chiasmusjob.h
@@ -0,0 +1,116 @@
+/* -*- mode: C++; c-file-style: "gnu" -*-
+ chiasmusjob.h
+
+ This file is part of libkleopatra, the KDE keymanagement library
+ Copyright (c) 2005 Klarälvdalens Datakonsult AB
+
+ Libkleopatra is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Libkleopatra is distributed in the hope that it will be useful,
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+
+#ifndef __KLEO_CHIASMUSJOB_H__
+#define __KLEO_CHIASMUSJOB_H__
+
+#include "kleo/specialjob.h"
+
+#include <qstringlist.h>
+
+#include <gpgmepp/context.h>
+
+class KProcess;
+
+namespace Kleo {
+
+ class SymCryptRunProcessBase;
+
+ /**
+ @short SpecialJob for Chiasmus operations
+ */
+ class ChiasmusJob : public Kleo::SpecialJob {
+ Q_OBJECT
+ Q_ENUMS( Mode )
+ Q_PROPERTY( Mode mode READ mode )
+ Q_PROPERTY( QString key READ key WRITE setKey )
+ Q_PROPERTY( QString options READ options WRITE setOptions )
+ Q_PROPERTY( QByteArray input READ input WRITE setInput )
+ Q_PROPERTY( QByteArray result READ result )
+ public:
+ enum Mode {
+ Encrypt, Decrypt
+ };
+ ChiasmusJob( Mode op );
+ ~ChiasmusJob();
+
+ /*!\reimp SpecialJob */
+ GpgME::Error start();
+ /*!\reimp SpecialJob */
+ GpgME::Error exec();
+
+ /*!\reimp Kleo::Job */
+ void showErrorDialog( QWidget *, const QString & ) const;
+
+ Mode mode() const { return mMode; }
+
+ QString key() const { return mKey; }
+ void setKey( const QString & key ) { mKey = key; }
+
+ QString options() const { return mOptions; }
+ void setOptions( const QString & options ) { mOptions = options; }
+
+ QByteArray input() const { return mInput; }
+ void setInput( const QByteArray & input ) { mInput = input; }
+
+ //using SpecialJob::result;
+ QByteArray result() const { return mOutput; }
+
+ public slots:
+ void slotCancel();
+
+ private slots:
+ GpgME::Error slotProcessExited( KProcess * );
+ void slotTimeout();
+
+ private:
+ bool checkPreconditions() const;
+ GpgME::Error setup();
+ void showChiasmusOutput();
+
+ private:
+ SymCryptRunProcessBase * mSymCryptRun;
+ QString mKey;
+ QString mOptions;
+ QByteArray mInput, mOutput;
+ GpgME::Error mError;
+ QString mStderr;
+ bool mCanceled;
+ bool mTimeout;
+ const Mode mMode;
+ };
+
+}
+
+
+#endif // __KLEO_CHIASMUSJOB_H__
diff --git a/certmanager/lib/backends/chiasmus/chiasmuslibrary.cpp b/certmanager/lib/backends/chiasmus/chiasmuslibrary.cpp
new file mode 100644
index 000000000..2e3225492
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/chiasmuslibrary.cpp
@@ -0,0 +1,115 @@
+/*
+ chiasmuslibrary.cpp
+
+ This file is part of libkleopatra, the KDE keymanagement library
+ Copyright (c) 2005 Klarälvdalens Datakonsult AB
+
+ Libkleopatra is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Libkleopatra is distributed in the hope that it will be useful,
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+
+#include "chiasmuslibrary.h"
+
+#include "chiasmusbackend.h"
+
+#include "kleo/cryptoconfig.h"
+
+#include <klibloader.h>
+#include <kdebug.h>
+#include <klocale.h>
+
+#include <qfile.h>
+
+#include <vector>
+#include <algorithm>
+
+#include <cassert>
+#include <cstdlib>
+#include <cstring>
+
+Kleo::ChiasmusLibrary * Kleo::ChiasmusLibrary::self = 0;
+
+Kleo::ChiasmusLibrary::ChiasmusLibrary() : mXiaLibrary( 0 ) {
+ self = this;
+}
+
+Kleo::ChiasmusLibrary::~ChiasmusLibrary() {
+ //delete mXiaLibrary; // hmm, how to get rid of it, then?
+}
+
+Kleo::ChiasmusLibrary::main_func Kleo::ChiasmusLibrary::chiasmus( QString * reason ) const {
+ assert( ChiasmusBackend::instance() );
+ assert( ChiasmusBackend::instance()->config() );
+ const CryptoConfigEntry * lib = ChiasmusBackend::instance()->config()->entry( "Chiasmus", "General", "lib" );
+ assert( lib );
+ const QString libfile = lib->urlValue().path();
+ if ( !mXiaLibrary )
+ mXiaLibrary = KLibLoader::self()->library( QFile::encodeName( libfile ) );
+ if ( !mXiaLibrary ) {
+ if ( reason )
+ *reason = i18n( "Failed to load %1: %2" )
+ .arg( libfile,KLibLoader::self()->lastErrorMessage() );
+ kdDebug(5150) << "ChiasmusLibrary: loading \"" << libfile
+ << "\" failed: " << KLibLoader::self()->lastErrorMessage() << endl;
+ return 0;
+ }
+ if ( !mXiaLibrary->hasSymbol( "Chiasmus" ) ) {
+ if ( reason )
+ *reason = i18n( "Failed to load %1: %2" )
+ .arg( libfile, i18n( "Library does not contain the symbol \"Chiasmus\"." ) );
+ kdDebug(5150) << "ChiasmusLibrary: loading \"" << libfile
+ << "\" failed: " << "Library does not contain the symbol \"Chiasmus\"." << endl;
+ return 0;
+ }
+ void * symbol = mXiaLibrary->symbol( "Chiasmus" );
+ assert( symbol );
+ return ( main_func )symbol;
+}
+
+namespace {
+ class ArgvProvider {
+ char ** mArgv;
+ int mArgc;
+ public:
+ ArgvProvider( const QValueVector<QCString> & args ) {
+ mArgv = new char * [args.size()];
+ for ( unsigned int i = 0 ; i < args.size() ; ++i )
+ mArgv[i] = strdup( args[i].data() );
+ }
+ ~ArgvProvider() {
+ std::for_each( mArgv, mArgv + mArgc, std::free );
+ delete[] mArgv;
+ }
+ char ** argv() const { return mArgv; }
+ };
+}
+
+int Kleo::ChiasmusLibrary::perform( const QValueVector<QCString> & args ) const {
+ if ( main_func func = chiasmus() )
+ return func( args.size(), ArgvProvider( args ).argv() );
+ else
+ return -1;
+}
diff --git a/certmanager/lib/backends/chiasmus/chiasmuslibrary.h b/certmanager/lib/backends/chiasmus/chiasmuslibrary.h
new file mode 100644
index 000000000..b04e162b4
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/chiasmuslibrary.h
@@ -0,0 +1,68 @@
+/* -*- mode: C++; c-file-style: "gnu" -*-
+ chiasmuslibrary.h
+
+ This file is part of libkleopatra, the KDE keymanagement library
+ Copyright (c) 2005 Klarälvdalens Datakonsult AB
+
+ Libkleopatra is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Libkleopatra is distributed in the hope that it will be useful,
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+
+#ifndef __KLEO_CHIASMUSLIBRARY_H__
+#define __KLEO_CHIASMUSLIBRARY_H__
+
+#include <qvaluevector.h>
+#include <qcstring.h>
+
+class KLibrary;
+
+namespace Kleo {
+
+ /**
+ @short small helper class to load xia.o through xia.so and make
+ the functionality available.
+ */
+ class ChiasmusLibrary {
+ ChiasmusLibrary();
+ ~ChiasmusLibrary();
+ public:
+ static const ChiasmusLibrary * instance();
+ static void deleteInstance();
+
+ int perform( const QValueVector<QCString> & args ) const;
+ private:
+ typedef int ( *main_func )( int, char** );
+ main_func chiasmus( QString * reason=0 ) const;
+
+ private:
+ static ChiasmusLibrary * self;
+ mutable KLibrary * mXiaLibrary;
+ };
+
+}
+
+
+#endif // __KLEO_CHIASMUSLIBRARY_H__
diff --git a/certmanager/lib/backends/chiasmus/config_data.c b/certmanager/lib/backends/chiasmus/config_data.c
new file mode 100644
index 000000000..bb3f33916
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/config_data.c
@@ -0,0 +1,95 @@
+/*
+ chiasmusbackend.cpp
+
+ This file is part of libkleopatra, the KDE keymanagement library
+ Copyright (c) 2005 Klarälvdalens Datakonsult AB
+
+ Libkleopatra is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Libkleopatra is distributed in the hope that it will be useful,
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "config_data.h"
+
+#include "kleo/cryptoconfig.h" /* for the enum values */
+
+/*
+ This data structure uses C99 designated initializers. This is why
+ it's in a .c file, and not in a .cpp file. If your compiler doesn't
+ like this, just don't compile Chiasmus support, or live without the
+ wrapper option :) Sorry.
+*/
+
+#ifdef PATH
+# undef PATH
+#endif
+#ifdef HAVE_C99_INITIALIZERS
+# define PATH .path =
+#else
+# define PATH
+#endif
+
+#define I18N_NOOP(x) (x)
+
+const struct kleo_chiasmus_config_data kleo_chiasmus_config_entries[] = {
+ {
+ "path", I18N_NOOP( "Path to Chiasmus executable" ),
+ Level_Basic, ArgType_Path,
+ { PATH "/usr/local/bin/chiasmus" }, /* in the absence of C99, we assume path is first in the union here */
+ 0, 0, 1
+ },
+ {
+ "keydir", I18N_NOOP( "Key directory" ),
+ Level_Basic, ArgType_DirPath,
+ { PATH "~/.chiasmus/keys" },
+ 0, 0, 1 /* FIXME: should be a list */
+ },
+#ifdef HAVE_C99_INITIALIZERS
+ {
+ "show-output", I18N_NOOP( "Show output from chiasmus operations" ),
+ Level_Expert, ArgType_None,
+ { .boolean = { .value = 0, .numTimesSet = 0 } },
+ 0, 0, 1
+ },
+ {
+ "symcryptrun-class", I18N_NOOP( "SymCryptRun class to use" ),
+ Level_Expert, ArgType_String,
+ { .string = "confucius" },
+ 0, 0, 1
+ },
+ {
+ "timeout", I18N_NOOP( "Timeout in seconds for Chiasmus operations" ),
+ Level_Advanced, ArgType_UInt,
+ { .unsigned_integer = 60 },
+ 0, 0, 1
+ },
+#endif /* HAVE_C99_INITIALIZERS */
+};
+const unsigned int kleo_chiasmus_config_entries_dim
+ = sizeof kleo_chiasmus_config_entries / sizeof *kleo_chiasmus_config_entries ;
+
diff --git a/certmanager/lib/backends/chiasmus/config_data.h b/certmanager/lib/backends/chiasmus/config_data.h
new file mode 100644
index 000000000..c5c7b6c4e
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/config_data.h
@@ -0,0 +1,34 @@
+#ifndef __KLEO__CHIASMUS_CONFIG_DATA_H__
+#define __KLEO__CHIASMUS_CONFIG_DATA_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct kleo_chiasmus_config_data {
+ const char * name;
+ const char * description;
+ int level;
+ int type;
+ union {
+ const char * path; /* must be first, see config_data.c */
+ const char * string;
+ const char * url;
+ struct { unsigned int value : 1; unsigned int numTimesSet : 31; } boolean;
+ int integer;
+ unsigned int unsigned_integer;
+ } defaults;
+ unsigned int is_optional : 1;
+ unsigned int is_list : 1;
+ unsigned int is_runtime : 1;
+};
+
+extern const struct kleo_chiasmus_config_data kleo_chiasmus_config_entries[];
+extern const unsigned int kleo_chiasmus_config_entries_dim;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __KLEO__CHIASMUS_CONFIG_DATA_H__ */
+
diff --git a/certmanager/lib/backends/chiasmus/configure.in.in b/certmanager/lib/backends/chiasmus/configure.in.in
new file mode 100644
index 000000000..8cea56ad3
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/configure.in.in
@@ -0,0 +1,16 @@
+dnl
+dnl Check for C99 designated initializers:
+dnl
+AC_LANG_SAVE
+AC_LANG_C
+AC_MSG_CHECKING([for C99 designated initializers])
+AC_TRY_COMPILE([
+ union { int one; const char * two } foo = { .two = "Hello" };
+], [], [
+ AC_DEFINE(HAVE_C99_INITIALIZERS, 1, [Define to 1 if your C compiler support C99 designated initializers])
+ AC_MSG_RESULT([yes])
+], [
+ AC_MSG_RESULT([no])
+])
+
+AC_LANG_RESTORE
diff --git a/certmanager/lib/backends/chiasmus/obtainkeysjob.cpp b/certmanager/lib/backends/chiasmus/obtainkeysjob.cpp
new file mode 100644
index 000000000..a9de8d658
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/obtainkeysjob.cpp
@@ -0,0 +1,126 @@
+/*
+ obtainkeysjob.cpp
+
+ This file is part of libkleopatra, the KDE keymanagement library
+ Copyright (c) 2005 Klarälvdalens Datakonsult AB
+
+ Libkleopatra is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Libkleopatra is distributed in the hope that it will be useful,
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "obtainkeysjob.h"
+
+#include "chiasmusbackend.h"
+
+#include "kleo/cryptoconfig.h"
+
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kshell.h>
+
+#include <qdir.h>
+#include <qstringlist.h>
+#include <qvariant.h>
+#include <qtimer.h>
+#include <qfileinfo.h>
+
+#include <gpg-error.h>
+
+#include <cassert>
+
+Kleo::ObtainKeysJob::ObtainKeysJob()
+ : SpecialJob( 0, 0 ),
+ mIndex( 0 ),
+ mCanceled( false )
+{
+ assert( ChiasmusBackend::instance() );
+ assert( ChiasmusBackend::instance()->config() );
+ const CryptoConfigEntry * keypaths =
+ ChiasmusBackend::instance()->config()->entry( "Chiasmus", "General", "keydir" );
+ assert( keypaths );
+ mKeyPaths = QStringList( keypaths->urlValue().path() );
+}
+
+Kleo::ObtainKeysJob::~ObtainKeysJob() {}
+
+GpgME::Error Kleo::ObtainKeysJob::start() {
+ QTimer::singleShot( 0, this, SLOT(slotPerform()) );
+ return mError = 0;
+}
+
+GpgME::Error Kleo::ObtainKeysJob::exec() {
+ slotPerform( false );
+ return mError;
+}
+
+void Kleo::ObtainKeysJob::slotCancel() {
+ mCanceled = true;
+}
+
+void Kleo::ObtainKeysJob::slotPerform() {
+ slotPerform( true );
+}
+
+void Kleo::ObtainKeysJob::slotPerform( bool async ) {
+ if ( mCanceled && !mError )
+ mError = gpg_error( GPG_ERR_CANCELED );
+ if ( mIndex >= mKeyPaths.size() || mError ) {
+ emit done();
+ emit SpecialJob::result( mError, QVariant( mResult ) );
+ return;
+ }
+
+ emit progress( i18n( "Scanning directory %1..." ).arg( mKeyPaths[mIndex] ),
+ mIndex, mKeyPaths.size() );
+
+ const QDir dir( KShell::tildeExpand( mKeyPaths[mIndex] ) );
+
+ if ( const QFileInfoList * xisFiles = dir.entryInfoList( "*.xis;*.XIS", QDir::Files ) )
+ for ( QFileInfoList::const_iterator it = xisFiles->begin(), end = xisFiles->end() ; it != end ; ++it )
+ if ( (*it)->isReadable() )
+ mResult.push_back( (*it)->absFilePath() );
+
+ ++mIndex;
+
+ if ( async )
+ QTimer::singleShot( 0, this, SLOT(slotPerform()) );
+ else
+ slotPerform( false );
+}
+
+void Kleo::ObtainKeysJob::showErrorDialog( QWidget * parent, const QString & caption ) const {
+ if ( !mError )
+ return;
+ if ( mError.isCanceled() )
+ return;
+ const QString msg = QString::fromUtf8( mError.asString() );
+ KMessageBox::error( parent, msg, caption );
+}
+
+#include "obtainkeysjob.moc"
diff --git a/certmanager/lib/backends/chiasmus/obtainkeysjob.h b/certmanager/lib/backends/chiasmus/obtainkeysjob.h
new file mode 100644
index 000000000..4b8392d46
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/obtainkeysjob.h
@@ -0,0 +1,101 @@
+/* -*- mode: C++; c-file-style: "gnu" -*-
+ obtainkeysjob.h
+
+ This file is part of libkleopatra, the KDE keymanagement library
+ Copyright (c) 2005 Klarälvdalens Datakonsult AB
+
+ Libkleopatra is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Libkleopatra is distributed in the hope that it will be useful,
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+
+#ifndef __KLEO_OBTAINKEYSJOB_H__
+#define __KLEO_OBTAINKEYSJOB_H__
+
+#include "kleo/specialjob.h"
+
+#include <qstringlist.h>
+
+#include <gpgmepp/context.h>
+
+namespace Kleo {
+
+ /**
+ @short SpecialJob for listing Chiasmus key files.
+
+ In the Chiasmus system, keys are mapped 1:1 to
+ files. Furthermore, we have to definition of the format of those
+ keys, so we cannot display more than the filename anyway. Due to
+ all of these limitations, we don't use KeyListJob here, but roll
+ our own interface.
+
+ The name of the function is x-obtain-keys. It takes no parameters.
+
+ To use, create an ObtainKeysJob instance like this:
+ <code>
+ Kleo::SpecialJob * job =
+ protocol->specialJob("x-obtain-keys", QMap<QString,QVariant>());
+ </code>
+
+ The resulting QVariant will contain a QStringList containing the
+ absolute filenames of the keys found in the configured key files.
+ */
+ class ObtainKeysJob : public Kleo::SpecialJob {
+ Q_OBJECT
+ Q_PROPERTY( QStringList result READ result )
+ public:
+ ObtainKeysJob();
+ ~ObtainKeysJob();
+
+ /*!\reimp SpecialJob */
+ GpgME::Error start();
+ /*!\reimp SpecialJob */
+ GpgME::Error exec();
+
+ /*!\reimp Kleo::Job */
+ void showErrorDialog( QWidget *, const QString & ) const;
+
+ //using SpecialJob::result;
+ QStringList result() const { return mResult; }
+
+ public slots:
+ void slotCancel();
+
+ private slots:
+ void slotPerform();
+ void slotPerform( bool async );
+
+ private:
+ GpgME::Error mError;
+ QStringList mKeyPaths;
+ unsigned int mIndex;
+ QStringList mResult;
+ bool mCanceled;
+ };
+
+}
+
+
+#endif // __KLEO_OBTAINKEYSJOB_H__
diff --git a/certmanager/lib/backends/chiasmus/symcryptrunprocessbase.cpp b/certmanager/lib/backends/chiasmus/symcryptrunprocessbase.cpp
new file mode 100644
index 000000000..1b8627252
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/symcryptrunprocessbase.cpp
@@ -0,0 +1,109 @@
+/*
+ symcryptrunbackend.cpp
+
+ This file is part of libkleopatra, the KDE keymanagement library
+ Copyright (c) 2005 Klarälvdalens Datakonsult AB
+
+ Libkleopatra is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Libkleopatra is distributed in the hope that it will be useful,
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#include "symcryptrunprocessbase.h"
+
+#include <ktempfile.h>
+#include <kdebug.h>
+#include <kshell.h>
+
+#include <qtimer.h>
+#include <qfile.h>
+
+#include <cstring>
+
+Kleo::SymCryptRunProcessBase::SymCryptRunProcessBase( const QString & class_, const QString & program,
+ const QString & keyFile, const QString & options,
+ Operation mode,
+ QObject * parent, const char * name )
+ : KProcess( parent, name ),
+ mOperation( mode ), mOptions( options )
+{
+ *this << "symcryptrun"
+ << "--class" << class_
+ << "--program" << program
+ << "--keyfile" << keyFile
+ << ( mode == Encrypt ? "--encrypt" : "--decrypt" );
+}
+
+Kleo::SymCryptRunProcessBase::~SymCryptRunProcessBase() {}
+
+bool Kleo::SymCryptRunProcessBase::launch( const QByteArray & input, RunMode rm ) {
+ connect( this, SIGNAL(receivedStdout(KProcess*,char*,int)),
+ this, SLOT(slotReceivedStdout(KProcess*,char*,int)) );
+ connect( this, SIGNAL(receivedStderr(KProcess*,char*,int)),
+ this, SLOT(slotReceivedStderr(KProcess*,char*,int)) );
+ if ( rm == Block ) {
+ KTempFile tempfile;
+ tempfile.setAutoDelete( true );
+ if ( QFile * file = tempfile.file() )
+ file->writeBlock( input );
+ else
+ return false;
+ tempfile.close();
+ *this << "--input" << tempfile.name();
+ addOptions();
+ return KProcess::start( Block, All );
+ } else {
+ addOptions();
+ const bool ok = KProcess::start( rm, All );
+ if ( !ok )
+ return ok;
+ mInput = input.copy();
+ writeStdin( mInput.begin(), mInput.size() );
+ connect( this, SIGNAL(wroteStdin(KProcess*)), this, SLOT(closeStdin()) );
+ return true;
+ }
+}
+
+void Kleo::SymCryptRunProcessBase::addOptions() {
+ if ( !mOptions.isEmpty() )
+ {
+ const QStringList args = KShell::splitArgs( mOptions );
+ *this << "--" << args;
+ }
+}
+
+void Kleo::SymCryptRunProcessBase::slotReceivedStdout( KProcess * proc, char * buf, int len ) {
+ Q_ASSERT( proc == this );
+ const int oldsize = mOutput.size();
+ mOutput.resize( oldsize + len );
+ memcpy( mOutput.data() + oldsize, buf, len );
+}
+
+void Kleo::SymCryptRunProcessBase::slotReceivedStderr( KProcess * proc, char * buf, int len ) {
+ Q_ASSERT( proc == this );
+ if ( len > 0 )
+ mStderr += QString::fromLocal8Bit( buf, len );
+}
+
+#include "symcryptrunprocessbase.moc"
diff --git a/certmanager/lib/backends/chiasmus/symcryptrunprocessbase.h b/certmanager/lib/backends/chiasmus/symcryptrunprocessbase.h
new file mode 100644
index 000000000..d74db60cc
--- /dev/null
+++ b/certmanager/lib/backends/chiasmus/symcryptrunprocessbase.h
@@ -0,0 +1,81 @@
+/*
+ symcryptrunbackend.h
+
+ This file is part of libkleopatra, the KDE keymanagement library
+ Copyright (c) 2005 Klarälvdalens Datakonsult AB
+
+ Libkleopatra is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Libkleopatra is distributed in the hope that it will be useful,
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#ifndef __KLEO_BACKEND_CHIASMUS__SYMCRYPTRUNPROCESSBASE_H__
+#define __KLEO_BACKEND_CHIASMUS__SYMCRYPTRUNPROCESSBASE_H__
+
+#include <kprocess.h>
+
+#include <qcstring.h>
+
+class QString;
+
+namespace Kleo {
+
+class SymCryptRunProcessBase : public KProcess {
+ Q_OBJECT
+public:
+ enum Operation {
+ Encrypt, Decrypt
+ };
+ SymCryptRunProcessBase( const QString & class_, const QString & program,
+ const QString & keyFile, const QString& options,
+ Operation op,
+ QObject * parent=0, const char * name=0 );
+ ~SymCryptRunProcessBase();
+
+ bool launch( const QByteArray & input, RunMode rm=NotifyOnExit );
+
+ const QByteArray & output() const { return mOutput; }
+ const QString & stdErr() const { return mStderr; }
+
+public slots:
+ /*! upgraded to slot */
+ void closeStdin() { KProcess::closeStdin(); }
+
+private slots:
+ void slotReceivedStdout( KProcess *, char *, int );
+ void slotReceivedStderr( KProcess *, char *, int );
+
+private:
+ void addOptions();
+
+ QByteArray mInput;
+ QByteArray mOutput;
+ QString mStderr;
+ const Operation mOperation;
+ QString mOptions;
+};
+
+}
+
+#endif // __KLEO_BACKEND_CHIASMUS__SYMCRYPTRUNPROCESSBASE_H__