| Summary: | Ask for passphrase at startup (a patch) | ||
|---|---|---|---|
| Product: | [Unmaintained] kopete | Reporter: | Gregor Kališnik <gregor> |
| Component: | Cryptography Plugin | Assignee: | Kopete Developers <kopete-bugs-null> |
| Status: | RESOLVED FIXED | ||
| Severity: | wishlist | ||
| Priority: | NOR | ||
| Version First Reported In: | unspecified | ||
| Target Milestone: | --- | ||
| Platform: | Gentoo Packages | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
| Attachments: | Passphrase dialog at starzup | ||
Please attach the patch to the bug report so we can download it separately rather than having to copy and paste it from the bug report itself. Thanks. :) Created attachment 18963 [details]
Passphrase dialog at starzup
I hope this is ok.
I will implement this as a non-default option. SVN commit 689243 by cconnell:
Optionally ask user for secret key password at startup, also some changes from QByteArray to QString
FEATURE:126639
M +2 -42 cryptographyconfig.cpp
M +9 -9 cryptographyconfig.h
M +25 -9 cryptographyplugin.cpp
M +5 -6 cryptographyplugin.h
M +12 -10 cryptographypreferences.cpp
M +2 -2 cryptographypreferences.h
M +8 -9 gpginterface.cpp
M +0 -1 gpginterface.h
--- trunk/KDE/kdenetwork/kopete/plugins/cryptography/cryptographyconfig.cpp #689242:689243
@@ -34,7 +34,7 @@
KConfigGroup config(KGlobal::config(), "Cryptography Plugin");
mFingerprint = config.readEntry ("Private key fingerprint", "");
- mAskPassPhrase = config.readEntry ("Ask for passphrase", false);
+ mAskPassphraseOnStartup = config.readEntry ("Ask for passphrase on startup", false);
mCacheMode = (CryptographyConfig::CacheMode)config.readEntry ("Cache mode", (uint)CryptographyConfig::Close);
mCacheTime = config.readEntry ("Cache time", 15);
}
@@ -44,49 +44,9 @@
KConfigGroup config(KGlobal::config(), "Cryptography Plugin");
config.writeEntry("Private key fingerprint", mFingerprint );
- config.writeEntry("Ask for passphrase", mAskPassPhrase);
+ config.writeEntry("Ask for passphrase on startup", mAskPassphraseOnStartup);
config.writeEntry("Cache mode", (uint)mCacheMode);
config.writeEntry("Cache time", mCacheTime);
config.sync();
}
-
-QString CryptographyConfig::fingerprint() const
-{
- return mFingerprint;
-}
-
-bool CryptographyConfig::askPassPhrase() const
-{
- return mAskPassPhrase;
-}
-
-CryptographyConfig::CacheMode CryptographyConfig::cacheMode() const
-{
- return mCacheMode;
-}
-
-uint CryptographyConfig::cacheTime() const
-{
- return mCacheTime;
-}
-
-void CryptographyConfig::setFingerprint(QString f)
-{
- mFingerprint = f;
-}
-
-void CryptographyConfig::setAskPassPhrase(bool b)
-{
- mAskPassPhrase = b;
-}
-
-void CryptographyConfig::setCacheMode(CacheMode m)
-{
- mCacheMode = m;
-}
-
-void CryptographyConfig::setCacheTime(uint t)
-{
- mCacheTime = t;
-}
--- trunk/KDE/kdenetwork/kopete/plugins/cryptography/cryptographyconfig.h #689242:689243
@@ -34,21 +34,21 @@
void save();
//accessor functions
- QString fingerprint() const;
- bool askPassPhrase() const;
- CacheMode cacheMode() const;
- uint cacheTime() const;
+ QString fingerprint() const { return mFingerprint; }
+ CacheMode cacheMode() const { return mCacheMode; }
+ uint cacheTime() const { return mCacheTime; }
+ bool askPassphraseOnStartup() const { return mAskPassphraseOnStartup; }
- void setFingerprint(QString f);
- void setAskPassPhrase(bool b);
- void setCacheMode(CacheMode mode);
- void setCacheTime(uint time);
+ void setFingerprint(QString f) { mFingerprint = f; }
+ void setCacheMode(CacheMode mode) { mCacheMode = mode; }
+ void setCacheTime(uint time) { mCacheTime = time; }
+ void setAskPassphraseOnStartup (bool b) { mAskPassphraseOnStartup = b; }
private:
QString mFingerprint;
- bool mAskPassPhrase;
CacheMode mCacheMode;
uint mCacheTime;
+ bool mAskPassphraseOnStartup;
};
--- trunk/KDE/kdenetwork/kopete/plugins/cryptography/cryptographyplugin.cpp #689242:689243
@@ -19,7 +19,6 @@
#include <qtimer.h>
#include <qregexp.h>
#include <QList>
-#include <QByteArray>
#include <kdebug.h>
#include <kaction.h>
@@ -30,6 +29,8 @@
#include <kicon.h>
#include <kiconloader.h>
#include <kmessagebox.h>
+#include <kpassworddialog.h>
+#include <kleo/ui/keylistview.h>
#include "kopetemetacontact.h"
#include "kopetecontactlist.h"
@@ -86,6 +87,9 @@
connect ( this, SIGNAL ( settingsChanged() ), this, SLOT ( loadSettings() ) );
connect ( Kopete::ChatSessionManager::self(), SIGNAL ( chatSessionCreated ( Kopete::ChatSession * ) ) , SLOT ( slotNewKMM ( Kopete::ChatSession * ) ) );
+
+ slotAskPassphraseOnStartup();
+
//Add GUI action to all already existing kmm (if the plugin is launched when kopete already rining)
QList<Kopete::ChatSession*> sessions = Kopete::ChatSessionManager::self()->sessions();
foreach ( Kopete::ChatSession *session, sessions )
@@ -106,7 +110,7 @@
CryptographyConfig c;
mPrivateKeyID = c.fingerprint();
- mAskPassPhrase = c.askPassPhrase();
+ mAskPassPhraseOnStartup = c.askPassphraseOnStartup();
mCachePassPhrase = c.cacheMode();
mCacheTime = c.cacheTime();
}
@@ -123,7 +127,7 @@
return pluginStatic_->m_cachedPass;
}
-void CryptographyPlugin::setCachedPass ( const QByteArray& p )
+void CryptographyPlugin::setCachedPass ( const QString& p )
{
if ( pluginStatic_->mCachePassPhrase == CryptographyConfig::Never )
return;
@@ -136,11 +140,6 @@
pluginStatic_->m_cachedPass=p;
}
-bool CryptographyPlugin::passphraseHandling()
-{
- return !pluginStatic_->mAskPassPhrase;
-}
-
void CryptographyPlugin::slotIncomingMessage ( Kopete::Message& msg )
{
QString body = msg.plainBody();
@@ -221,6 +220,13 @@
}
}
+class MyColumnStrategy : public Kleo::KeyListView::ColumnStrategy
+{
+ public:
+ QString title () { return "Select Key"; }
+
+};
+
void CryptographyPlugin::slotSelectContactKey()
{
Kopete::MetaContact *m=Kopete::ContactList::self()->selectedMetaContacts().first();
@@ -239,10 +245,20 @@
void CryptographyPlugin::slotForgetCachedPass()
{
- m_cachedPass=QByteArray();
+ m_cachedPass=QString();
m_cachedPass_timer->stop();
}
+void CryptographyPlugin::slotAskPassphraseOnStartup()
+{
+ if (mAskPassPhraseOnStartup && !mPrivateKeyID.isEmpty() ){
+ KPasswordDialog dialog ( Kopete::UI::Global::mainWidget() );
+ dialog.setPrompt ( i18n ("Enter password for GPG private key") );
+ dialog.exec ();
+ setCachedPass( dialog.password() );
+ }
+}
+
void CryptographyPlugin::slotNewKMM ( Kopete::ChatSession *KMM )
{
connect ( this , SIGNAL ( destroyed ( QObject* ) ) ,
--- trunk/KDE/kdenetwork/kopete/plugins/cryptography/cryptographyplugin.h #689242:689243
@@ -20,8 +20,7 @@
#include "kopeteplugin.h"
-//Added by qt3to4:
-#include <QByteArray>
+
#include "cryptographyconfig.h"
class QStringList;
@@ -48,8 +47,7 @@
public:
static CryptographyPlugin *plugin();
static QString cachedPass();
- static void setCachedPass(const QByteArray &pass);
- static bool passphraseHandling();
+ static void setCachedPass(const QString &pass);
static const QRegExp isHTML;
CryptographyPlugin( QObject *parent, const QStringList &args );
@@ -61,7 +59,8 @@
void slotOutgoingMessage( Kopete::Message& msg );
private slots:
-
+ // implemented as a slot so it can be hooked to a timer
+ void slotAskPassphraseOnStartup ();
void slotSelectContactKey();
void slotForgetCachedPass();
void loadSettings();
@@ -78,7 +77,7 @@
//Settings
QString mPrivateKeyID;
unsigned int mCacheTime;
- bool mAskPassPhrase;
+ bool mAskPassPhraseOnStartup;
CryptographyConfig::CacheMode mCachePassPhrase;
};
--- trunk/KDE/kdenetwork/kopete/plugins/cryptography/cryptographypreferences.cpp #689242:689243
@@ -48,22 +48,22 @@
QLabel * label = new QLabel ( i18n ("With this plugin you can encrypt messages so that nobody but your intended recipient can read them, and you can also sign messages, so that recipients can verify that a given message has actually come from you. <a href=\"http://en.wikipedia.org/wiki/Public-key_cryptography\">How this works</a>.\n\nBefore you can send encrypted messages to someone, you must select their public key by right-clicking on their name in your contact list, and choosing \"Select Public Key.\"\n\nNote: All messages become plain text when used with this plugin"), this );
label->setWordWrap (true);
- mAskPassPhrase = new QCheckBox ( i18n ("Ask for passphrase every time" ), this);
-
+ mAskPassphraseOnStartup = new QCheckBox ( i18n ("Ask for passphrase on Kopete startup" ), this);
+
mPreferencesDialog = new Ui::CryptographyPrefsUI;
mPreferencesDialog->setupUi ( w );
l->addWidget ( key );
l->addWidget ( label );
- l->addWidget ( mAskPassPhrase );
+ l->addWidget ( mAskPassphraseOnStartup );
l->addWidget ( w );
l->addStretch ();
- connect ( mAskPassPhrase, SIGNAL ( toggled ( bool ) ), this, SLOT ( slotAskPressed ( bool ) ) );
+ connect ( mAskPassphraseOnStartup, SIGNAL ( toggled ( bool ) ), this, SLOT ( slotAskOnStartupPressed ( bool ) ) );
connect ( key->dialogButton(), SIGNAL ( clicked() ), this, SLOT ( slotModified() ) );
connect ( key->eraseButton(), SIGNAL ( clicked() ), this, SLOT ( slotModified() ) );
- connect ( mAskPassPhrase, SIGNAL ( toggled ( bool ) ), this, SLOT ( slotModified() ) );
+ connect ( mAskPassphraseOnStartup, SIGNAL ( toggled ( bool ) ), this, SLOT ( slotModified() ) );
connect ( mPreferencesDialog->onClose, SIGNAL ( toggled ( bool ) ), this, SLOT ( slotModified() ) );
connect ( mPreferencesDialog->time, SIGNAL ( toggled ( bool ) ), this, SLOT ( slotModified() ) );
connect ( mPreferencesDialog->never, SIGNAL ( toggled ( bool ) ), this, SLOT ( slotModified() ) );
@@ -83,7 +83,7 @@
mConfig->load();
key->setFingerprint ( mConfig->fingerprint() );
- mAskPassPhrase->setChecked ( mConfig->askPassPhrase() );
+ mAskPassphraseOnStartup->setChecked ( mConfig->askPassphraseOnStartup() );
mPreferencesDialog->cacheTime->setValue ( mConfig->cacheTime() );
if ( mConfig->cacheTime() == CryptographyConfig::Close )
@@ -101,7 +101,7 @@
void CryptographyPreferences::save()
{
mConfig->setFingerprint ( key->fingerprint() );
- mConfig->setAskPassPhrase ( mAskPassPhrase->isChecked() );
+ mConfig->setAskPassphraseOnStartup ( mAskPassphraseOnStartup->isChecked() );
mConfig->setCacheTime ( mPreferencesDialog->cacheTime->value() );
if ( mPreferencesDialog->onClose->isChecked() )
@@ -120,15 +120,17 @@
void CryptographyPreferences::defaults()
{
key->eraseButton()->click();
- mAskPassPhrase->setChecked ( false );
+ mAskPassphraseOnStartup->setChecked ( false );
mPreferencesDialog->onClose->setChecked ( true );
mPreferencesDialog->cacheTime->setValue ( 15 );
slotModified();
}
-void CryptographyPreferences::slotAskPressed ( bool b )
+void CryptographyPreferences::slotAskOnStartupPressed ( bool b )
{
- mPreferencesDialog->cacheBehavior->setEnabled ( !b );
+ mPreferencesDialog->never->setEnabled (!b);
+ if (b)
+ mPreferencesDialog->onClose->setChecked (true);
}
void CryptographyPreferences::slotModified()
--- trunk/KDE/kdenetwork/kopete/plugins/cryptography/cryptographypreferences.h #689242:689243
@@ -46,13 +46,13 @@
private:
Kleo::EncryptionKeyRequester * key;
- QCheckBox * mAskPassPhrase;
+ QCheckBox * mAskPassphraseOnStartup;
Ui::CryptographyPrefsUI *mPreferencesDialog;
CryptographyConfig *mConfig;
private slots:
void slotModified();
- void slotAskPressed (bool b);
+ void slotAskOnStartupPressed (bool b);
};
#endif
--- trunk/KDE/kdenetwork/kopete/plugins/cryptography/gpginterface.cpp #689242:689243
@@ -57,7 +57,8 @@
{
counter++;
password = getPassword ( password, privateKey, counter );
- gpgcmd = "gpg --no-secmem-warning --no-tty " + options.toLocal8Bit() + " -e " + dests.toLocal8Bit(); gpgcmd += " --passphrase " + password + " -s ";
+ gpgcmd = "gpg --no-secmem-warning --no-tty " + options + " -e " + dests;
+ gpgcmd += " --passphrase " + password + " -s ";
QProcess fp;
fp.start ( gpgcmd, QIODevice::ReadWrite );
@@ -72,7 +73,7 @@
}
else
{
- gpgcmd = "gpg --no-secmem-warning --no-tty " + options.toLocal8Bit() + " -e " + dests.toLocal8Bit();
+ gpgcmd = "gpg --no-secmem-warning --no-tty " + options + " -e " + dests;
QProcess fp;
fp.start ( gpgcmd, QIODevice::ReadWrite );
fp.waitForStarted();
@@ -193,22 +194,20 @@
{
Q_OBJECT
public:
- CryptographyPasswordDialog ( QWidget *parent=0L, const KPasswordDialogFlags &flags=0, const KDialog::ButtonCodes otherButtons=0 ) : KPasswordDialog ( parent, flags, otherButtons ) {}};
+ CryptographyPasswordDialog ( QWidget *parent=0L, const KPasswordDialogFlags &flags=0, const KDialog::ButtonCodes otherButtons=0 ) : KPasswordDialog ( parent, flags, otherButtons ) {}
+};
QString GpgInterface::getPassword ( QString password, QString userID, int counter )
{
if ( !password.isEmpty() && counter <= 1 )
return password;
- bool passphraseHandling = CryptographyPlugin::passphraseHandling();
- QString passdlg=i18n ( "Enter passphrase for secret key %1:", "0x" + userID.right ( 8 ) );
- if ( counter>1 )
- passdlg.prepend ( i18n ( "<b>Bad passphrase</b><br> You have %1 tries left.<br>", 4-counter ) );
+
+ QString passdlg=i18n ( "Enter passphrase for secret key %1:\nYou have %2 tries left.", "0x" + userID.right ( 8 ), 4 - counter );
CryptographyPasswordDialog dlg ( Kopete::UI::Global::mainWidget(), KPasswordDialog::NoFlags );
dlg.setPrompt ( passdlg );
if ( !dlg.exec() )
return QString(); //the user canceled
- if ( passphraseHandling )
- CryptographyPlugin::setCachedPass ( dlg.password().toLocal8Bit() );
+ CryptographyPlugin::setCachedPass ( dlg.password() );
// if there is already a password dialog open, get password and send it to that
QList<CryptographyPasswordDialog*> otherDialogs = Kopete::UI::Global::mainWidget()->findChildren <CryptographyPasswordDialog *> ();
--- trunk/KDE/kdenetwork/kopete/plugins/cryptography/gpginterface.h #689242:689243
@@ -63,7 +63,6 @@
static QString checkForUtf8 ( QString s );
- private:
static QString getPassword (QString password, QString userID, int counter);
};
|
Version: (using KDE KDE 3.5.2) Installed from: Gentoo Packages I made a patch to crypto plugin. It asks you for the passphrase at the startup so when someone starts the conversation with you, you don't get 3-inf opened passphrase dialogs. The patch could be updated :P It's tested under 0.11.1 but should work with the 0.12. (I looked and both cryptoplugin.cpp files are the same...) The patch: --- cryptographyplugin.cpp 2006-04-14 18:19:41.000000000 +0200 +++ cryptographyplugin.cpp.new 2006-05-02 22:09:30.000000000 +0200 @@ -25,6 +25,8 @@ #include <kgenericfactory.h> #include <kdeversion.h> #include <kaboutdata.h> +#include <kpassdlg.h> +#include <kmessagebox.h> #include "kopetemetacontact.h" #include "kopetecontactlist.h" @@ -84,6 +86,22 @@ slotNewKMM(*it); } + QCString password = cachedPass(); + bool passphraseHandling = CryptographyPlugin::passphraseHandling(); + + if(passphraseHandling && password.isNull()) + { + /// pipe for passphrase + QString passdlg=i18n("Enter passphrase:"); + + /// pipe for passphrase + int code=KPasswordDialog::getPassword(password,passdlg); + if (code==QDialog::Accepted) + CryptographyPlugin::setCachedPass(password); + else + KMessageBox::error(0, i18n("Passphrase is invalid!")); + } + }