summaryrefslogtreecommitdiffstats
path: root/libkpgp
diff options
context:
space:
mode:
Diffstat (limited to 'libkpgp')
-rw-r--r--libkpgp/kpgp.cpp40
-rw-r--r--libkpgp/kpgp.h5
-rw-r--r--libkpgp/kpgpbase.cpp22
-rw-r--r--libkpgp/kpgpbase.h38
-rw-r--r--libkpgp/kpgpbase2.cpp18
-rw-r--r--libkpgp/kpgpbase5.cpp18
-rw-r--r--libkpgp/kpgpbase6.cpp2
-rw-r--r--libkpgp/kpgpbaseG.cpp18
-rw-r--r--libkpgp/kpgpui.cpp2
-rw-r--r--libkpgp/kpgpui.h2
10 files changed, 73 insertions, 92 deletions
diff --git a/libkpgp/kpgp.cpp b/libkpgp/kpgp.cpp
index 293b36811..a42429573 100644
--- a/libkpgp/kpgp.cpp
+++ b/libkpgp/kpgp.cpp
@@ -55,7 +55,7 @@ Module::Module()
mPublicKeysCached(false),
mSecretKeys(),
mSecretKeysCached(false),
- passphrase(0), passphrase_buffer_len(0), havePassPhrase(false)
+ passphrase(0), havePassPhrase(false)
{
if (!kpgpObject) {
kdDebug(5100) << "creating new pgp object" << endl;
@@ -209,7 +209,7 @@ Module::prepare( bool needPassPhrase, Block* block )
TQApplication::restoreOverrideCursor();
if (passdlgResult == TQDialog::Accepted) {
if (!setPassPhrase(passdlg.passphrase())) {
- if (strlen(passdlg.passphrase()) >= 1024)
+ if (passdlg.passphrase().length() >= 1024)
errMsg = i18n("Passphrase is too long, it must contain fewer than 1024 characters.");
else
errMsg = i18n("Out of memory.");
@@ -227,18 +227,11 @@ Module::prepare( bool needPassPhrase, Block* block )
void
Module::wipePassPhrase(bool freeMem)
{
- if ( passphrase ) {
- if ( passphrase_buffer_len )
- memset( passphrase, 0x00, passphrase_buffer_len );
- else {
- kdDebug(5100) << "wipePassPhrase: passphrase && !passphrase_buffer_len ???" << endl;
- passphrase = 0;
- }
+ if (!passphrase.isEmpty()) {
+ passphrase.fill(' ');
}
- if ( freeMem && passphrase ) {
- free( passphrase );
- passphrase = 0;
- passphrase_buffer_len = 0;
+ if (freeMem && !passphrase.isNull()) {
+ passphrase = TQString();
}
havePassPhrase = false;
}
@@ -837,34 +830,21 @@ Module::getAsciiPublicKey(const KeyID& keyID)
}
-bool Module::setPassPhrase(const char * aPass)
+bool Module::setPassPhrase(const TQString& aPass)
{
// null out old buffer before we touch the new string. So in case
// aPass isn't properly null-terminated, we don't leak secret data.
wipePassPhrase();
- if (aPass)
+ if (!aPass.isNull())
{
- size_t newlen = strlen( aPass );
- if ( newlen >= 1024 ) {
+ if (aPass.length() >= 1024) {
// rediculously long passphrase.
// Maybe someone wants to trick us in malloc()'ing
// huge buffers...
return false;
}
- if ( passphrase_buffer_len < newlen + 1 ) {
- // too little space in current buffer:
- // allocate a larger one.
- if ( passphrase )
- free( passphrase );
- passphrase_buffer_len = (newlen + 1 + 15) & ~0xF; // make it a multiple of 16.
- passphrase = (char*)malloc( passphrase_buffer_len );
- if (!passphrase) {
- passphrase_buffer_len = 0;
- return false;
- }
- }
- memcpy( passphrase, aPass, newlen + 1 );
+ passphrase = aPass;
havePassPhrase = true;
}
return true;
diff --git a/libkpgp/kpgp.h b/libkpgp/kpgp.h
index 6628f41e5..1ea49664e 100644
--- a/libkpgp/kpgp.h
+++ b/libkpgp/kpgp.h
@@ -332,7 +332,7 @@ private:
KeyIDList getEncryptionKeys( const TQString& person );
/** Set pass phrase */
- bool setPassPhrase(const char* pass);
+ bool setPassPhrase(const TQString& pass);
/** test if the PGP executable is found and if there is a passphrase
set or given. Returns:
@@ -431,8 +431,7 @@ private:
bool mSecretKeysCached : 1; // did we already read the secret keys?
bool storePass : 1;
- char * passphrase;
- size_t passphrase_buffer_len;
+ TQString passphrase;
TQString errMsg;
diff --git a/libkpgp/kpgpbase.cpp b/libkpgp/kpgpbase.cpp
index c8efdfa4a..5b28bd540 100644
--- a/libkpgp/kpgpbase.cpp
+++ b/libkpgp/kpgpbase.cpp
@@ -59,7 +59,7 @@ Base::clear()
int
-Base::run( const char *cmd, const char *passphrase, bool onlyReadFromPGP )
+Base::run( const char *cmd, const TQString& passphrase, bool onlyReadFromPGP )
{
/* the pipe ppass is used for to pass the password to
* pgp. passing the password together with the normal input through
@@ -74,7 +74,7 @@ Base::run( const char *cmd, const char *passphrase, bool onlyReadFromPGP )
struct pollfd pollin, pollout, pollerr;
int pollstatus;
- if(passphrase)
+ if (!passphrase.isNull())
{
if (pipe(ppass) < 0) {
// An error occurred
@@ -83,7 +83,8 @@ Base::run( const char *cmd, const char *passphrase, bool onlyReadFromPGP )
}
pass = fdopen(ppass[1], "w");
- fwrite(passphrase, sizeof(char), strlen(passphrase), pass);
+ TQCString pass2 = passphrase.local8Bit();
+ fwrite(pass2, sizeof(char), pass2.length(), pass);
fwrite("\n", sizeof(char), 1, pass);
fclose(pass);
close(ppass[1]);
@@ -368,7 +369,7 @@ Base::run( const char *cmd, const char *passphrase, bool onlyReadFromPGP )
close(perr[0]);
unsetenv("PGPPASSFD");
- if(passphrase)
+ if (!passphrase.isNull())
close(ppass[0]);
// Did the child exit normally?
@@ -397,7 +398,7 @@ Base::run( const char *cmd, const char *passphrase, bool onlyReadFromPGP )
int
-Base::runGpg( const char *cmd, const char *passphrase, bool onlyReadFromGnuPG )
+Base::runGpg( const char *cmd, const TQString& passphrase, bool onlyReadFromGnuPG )
{
/* the pipe ppass is used for to pass the password to
* pgp. passing the password together with the normal input through
@@ -417,7 +418,7 @@ Base::runGpg( const char *cmd, const char *passphrase, bool onlyReadFromGnuPG )
const int STD_IN = 2;
int pollstatus;
- if(passphrase)
+ if (!passphrase.isNull())
{
if (pipe(ppass) < 0) {
// An error occurred
@@ -426,7 +427,8 @@ Base::runGpg( const char *cmd, const char *passphrase, bool onlyReadFromGnuPG )
}
pass = fdopen(ppass[1], "w");
- fwrite(passphrase, sizeof(char), strlen(passphrase), pass);
+ TQCString pass2 = passphrase.local8Bit();
+ fwrite(pass2, sizeof(char), pass2.length(), pass);
fwrite("\n", sizeof(char), 1, pass);
fclose(pass);
close(ppass[1]);
@@ -459,7 +461,7 @@ Base::runGpg( const char *cmd, const char *passphrase, bool onlyReadFromGnuPG )
printf("Something went wrong in libkpgp/kpgpbase.cpp\n");
}
- if( passphrase ) {
+ if (!passphrase.isNull()) {
if( mVersion >= "1.0.7" ) {
// GnuPG >= 1.0.7 supports the gpg-agent, so we look for it.
if( 0 == getenv("GPG_AGENT_INFO") ) {
@@ -504,7 +506,7 @@ Base::runGpg( const char *cmd, const char *passphrase, bool onlyReadFromGnuPG )
//#warning FIXME: there has to be a better way to do this
/* this is nasty nasty nasty (but it works) */
- if( passphrase ) {
+ if (!passphrase.isNull()) {
if( mVersion >= "1.0.7" ) {
// GnuPG >= 1.0.7 supports the gpg-agent, so we look for it.
if( 0 == getenv("GPG_AGENT_INFO") ) {
@@ -682,7 +684,7 @@ Base::runGpg( const char *cmd, const char *passphrase, bool onlyReadFromGnuPG )
close(pout[0]);
close(perr[0]);
- if(passphrase)
+ if (!passphrase.isNull())
close(ppass[0]);
// Did the child exit normally?
diff --git a/libkpgp/kpgpbase.h b/libkpgp/kpgpbase.h
index 14f849cc8..3f99073a4 100644
--- a/libkpgp/kpgpbase.h
+++ b/libkpgp/kpgpbase.h
@@ -41,14 +41,14 @@ public:
virtual int encrypt( Block& , const KeyIDList& ) { return OK; }
/** Clearsigns the message with the currently set key. */
- virtual int clearsign( Block& , const char *) { return OK; }
+ virtual int clearsign( Block& , const TQString& ) { return OK; }
/** Encrypts and signs the message with the given keys. */
virtual int encsign( Block& , const KeyIDList& ,
- const char * = 0) { return OK; }
+ const TQString& = 0) { return OK; }
/** Decrypts the message. */
- virtual int decrypt( Block& , const char * = 0) { return OK; }
+ virtual int decrypt( Block& , const TQString& = 0) { return OK; }
/** Verifies the message. */
virtual int verify( Block& block ) { return decrypt( block, 0 ); }
@@ -77,7 +77,7 @@ public:
/** Signs the given key with the currently set user key. This is currently
not implemented. */
- virtual int signKey(const KeyID& , const char *) { return OK; }
+ virtual int signKey(const KeyID& , const TQString& ) { return OK; }
/** Returns an error message if an error occurred during the last
@@ -86,9 +86,9 @@ public:
protected:
- virtual int run( const char *cmd, const char *passphrase = 0,
+ virtual int run( const char *cmd, const TQString& passphrase = 0,
bool onlyReadFromPGP = false );
- virtual int runGpg( const char *cmd, const char *passphrase = 0,
+ virtual int runGpg( const char *cmd, const TQString& passphrase = 0,
bool onlyReadFromGnuPG = false );
virtual void clear();
@@ -115,10 +115,10 @@ public:
virtual ~Base2();
virtual int encrypt( Block& block, const KeyIDList& recipients );
- virtual int clearsign( Block& block, const char *passphrase );
+ virtual int clearsign( Block& block, const TQString& passphrase );
virtual int encsign( Block& block, const KeyIDList& recipients,
- const char *passphrase = 0 );
- virtual int decrypt( Block& block, const char *passphrase = 0 );
+ const TQString& passphrase = 0 );
+ virtual int decrypt( Block& block, const TQString& passphrase = 0 );
virtual int verify( Block& block ) { return decrypt( block, 0 ); }
virtual Key* readPublicKey( const KeyID& keyID,
@@ -127,7 +127,7 @@ public:
virtual KeyList publicKeys( const TQStringList & patterns = TQStringList() );
virtual KeyList secretKeys( const TQStringList & patterns = TQStringList() );
virtual TQCString getAsciiPublicKey( const KeyID& keyID );
- virtual int signKey( const KeyID& keyID, const char *passphrase );
+ virtual int signKey( const KeyID& keyID, const TQString& passphrase );
protected:
KeyList doGetPublicKeys( const TQCString & cmd,
@@ -147,10 +147,10 @@ public:
virtual ~BaseG();
virtual int encrypt( Block& block, const KeyIDList& recipients );
- virtual int clearsign( Block& block, const char *passphrase );
+ virtual int clearsign( Block& block, const TQString& passphrase );
virtual int encsign( Block& block, const KeyIDList& recipients,
- const char *passphrase = 0 );
- virtual int decrypt( Block& block, const char *passphrase = 0 );
+ const TQString& passphrase = 0 );
+ virtual int decrypt( Block& block, const TQString& passphrase = 0 );
virtual int verify( Block& block ) { return decrypt( block, 0 ); }
virtual Key* readPublicKey( const KeyID& keyID,
@@ -159,7 +159,7 @@ public:
virtual KeyList publicKeys( const TQStringList & patterns = TQStringList() );
virtual KeyList secretKeys( const TQStringList & patterns = TQStringList() );
virtual TQCString getAsciiPublicKey( const KeyID& keyID );
- virtual int signKey( const KeyID& keyID, const char *passphrase );
+ virtual int signKey( const KeyID& keyID, const TQString& passphrase );
private:
Key* parseKeyData( const TQCString& output, int& offset, Key* key = 0 );
@@ -175,10 +175,10 @@ public:
virtual ~Base5();
virtual int encrypt( Block& block, const KeyIDList& recipients );
- virtual int clearsign( Block& block, const char *passphrase );
+ virtual int clearsign( Block& block, const TQString& passphrase );
virtual int encsign( Block& block, const KeyIDList& recipients,
- const char *passphrase = 0 );
- virtual int decrypt( Block& block, const char *passphrase = 0 );
+ const TQString& passphrase = 0 );
+ virtual int decrypt( Block& block, const TQString& passphrase = 0 );
virtual int verify( Block& block ) { return decrypt( block, 0 ); }
virtual Key* readPublicKey( const KeyID& keyID,
@@ -187,7 +187,7 @@ public:
virtual KeyList publicKeys( const TQStringList & patterns = TQStringList() );
virtual KeyList secretKeys( const TQStringList & patterns = TQStringList() );
virtual TQCString getAsciiPublicKey( const KeyID& keyID );
- virtual int signKey( const KeyID& keyID, const char *passphrase );
+ virtual int signKey( const KeyID& keyID, const TQString& passphrase );
private:
Key* parseKeyData( const TQCString& output, int& offset, Key* key = 0 );
@@ -204,7 +204,7 @@ public:
Base6();
virtual ~Base6();
- virtual int decrypt( Block& block, const char *passphrase = 0 );
+ virtual int decrypt( Block& block, const TQString& passphrase = 0 );
virtual int verify( Block& block ) { return decrypt( block, 0 ); }
virtual Key* readPublicKey( const KeyID& keyID,
diff --git a/libkpgp/kpgpbase2.cpp b/libkpgp/kpgpbase2.cpp
index 2d16951c4..d0d08a0ff 100644
--- a/libkpgp/kpgpbase2.cpp
+++ b/libkpgp/kpgpbase2.cpp
@@ -55,7 +55,7 @@ Base2::encrypt( Block& block, const KeyIDList& recipients )
int
-Base2::clearsign( Block& block, const char *passphrase )
+Base2::clearsign( Block& block, const TQString& passphrase )
{
return encsign( block, KeyIDList(), passphrase );
}
@@ -63,16 +63,16 @@ Base2::clearsign( Block& block, const char *passphrase )
int
Base2::encsign( Block& block, const KeyIDList& recipients,
- const char *passphrase )
+ const TQString& passphrase )
{
TQCString cmd;
int exitStatus = 0;
- if(!recipients.isEmpty() && passphrase != 0)
+ if (!recipients.isEmpty() && !passphrase.isNull())
cmd = PGP2 " +batchmode +language=en +verbose=1 -seat";
else if(!recipients.isEmpty())
cmd = PGP2 " +batchmode +language=en +verbose=1 -eat";
- else if(passphrase != 0)
+ else if (!passphrase.isNull())
cmd = PGP2 " +batchmode +language=en +verbose=1 -sat";
else
{
@@ -80,7 +80,7 @@ Base2::encsign( Block& block, const KeyIDList& recipients,
return OK;
}
- if(passphrase != 0)
+ if (!passphrase.isNull())
cmd += addUserId();
if(!recipients.isEmpty()) {
@@ -185,7 +185,7 @@ Base2::encsign( Block& block, const KeyIDList& recipients,
}
}
#endif
- if(passphrase != 0)
+ if (!passphrase.isNull())
{
if(error.find("Pass phrase is good") != -1)
{
@@ -224,7 +224,7 @@ Base2::encsign( Block& block, const KeyIDList& recipients,
int
-Base2::decrypt( Block& block, const char *passphrase )
+Base2::decrypt( Block& block, const TQString& passphrase )
{
int index, index2;
int exitStatus = 0;
@@ -294,7 +294,7 @@ Base2::decrypt( Block& block, const char *passphrase )
block.setRequiredUserId( error.mid(index, index2 - index) );
//kdDebug(5100) << "Base: key needed is \"" << block.requiredUserId() << "\"!\n";
- if((passphrase != 0) && (error.find("Bad pass phrase") != -1))
+ if ((!passphrase.isNull()) && (error.find("Bad pass phrase") != -1))
{
errMsg = i18n("Bad passphrase; could not decrypt.");
kdDebug(5100) << "Base: passphrase is bad" << endl;
@@ -573,7 +573,7 @@ Base2::secretKeys( const TQStringList & patterns )
int
-Base2::signKey(const KeyID& keyID, const char *passphrase)
+Base2::signKey(const KeyID& keyID, const TQString& passphrase)
{
TQCString cmd;
int exitStatus = 0;
diff --git a/libkpgp/kpgpbase5.cpp b/libkpgp/kpgpbase5.cpp
index 7f8e405a6..dad10b3fd 100644
--- a/libkpgp/kpgpbase5.cpp
+++ b/libkpgp/kpgpbase5.cpp
@@ -55,7 +55,7 @@ Base5::encrypt( Block& block, const KeyIDList& recipients )
int
-Base5::clearsign( Block& block, const char *passphrase )
+Base5::clearsign( Block& block, const TQString& passphrase )
{
return encsign( block, KeyIDList(), passphrase );
}
@@ -63,7 +63,7 @@ Base5::clearsign( Block& block, const char *passphrase )
int
Base5::encsign( Block& block, const KeyIDList& recipients,
- const char *passphrase )
+ const TQString& passphrase )
{
TQCString cmd;
int exitStatus = 0;
@@ -73,11 +73,11 @@ Base5::encsign( Block& block, const KeyIDList& recipients,
// we want a clear signature
bool signonly = false;
- if(!recipients.isEmpty() && passphrase != 0)
+ if (!recipients.isEmpty() && !passphrase.isNull())
cmd = "pgpe +batchmode -afts ";
else if(!recipients.isEmpty())
cmd = "pgpe +batchmode -aft ";
- else if(passphrase != 0)
+ else if (!passphrase.isNull())
{
cmd = "pgps +batchmode -abft ";
signonly = true;
@@ -88,7 +88,7 @@ Base5::encsign( Block& block, const KeyIDList& recipients,
return OK;
}
- if(passphrase != 0)
+ if (!passphrase.isNull())
cmd += addUserId();
if(!recipients.isEmpty())
@@ -191,7 +191,7 @@ Base5::encsign( Block& block, const KeyIDList& recipients,
int
-Base5::decrypt( Block& block, const char *passphrase )
+Base5::decrypt( Block& block, const TQString& passphrase )
{
int exitStatus = 0;
@@ -222,7 +222,7 @@ Base5::decrypt( Block& block, const char *passphrase )
// or do we not have the secret key?
if(error.find("Need a pass phrase") != -1)
{
- if(passphrase != 0)
+ if (!passphrase.isNull())
{
errMsg = i18n("Bad passphrase; could not decrypt.");
kdDebug(5100) << "Base: passphrase is bad" << endl;
@@ -433,12 +433,12 @@ TQCString Base5::getAsciiPublicKey(const KeyID& keyID)
int
-Base5::signKey(const KeyID& keyID, const char *passphrase)
+Base5::signKey(const KeyID& keyID, const TQString& passphrase)
{
TQCString cmd;
int exitStatus = 0;
- if(passphrase == 0) return false;
+ if (passphrase.isNull()) return false;
cmd = "pgpk -s -f +batchmode=1 0x";
cmd += keyID;
diff --git a/libkpgp/kpgpbase6.cpp b/libkpgp/kpgpbase6.cpp
index 40bef7abc..4d00441f9 100644
--- a/libkpgp/kpgpbase6.cpp
+++ b/libkpgp/kpgpbase6.cpp
@@ -46,7 +46,7 @@ Base6::~Base6()
int
-Base6::decrypt( Block& block, const char *passphrase )
+Base6::decrypt( Block& block, const TQString& passphrase )
{
int index, index2;
int exitStatus = 0;
diff --git a/libkpgp/kpgpbaseG.cpp b/libkpgp/kpgpbaseG.cpp
index cd6eaf41c..e63c30153 100644
--- a/libkpgp/kpgpbaseG.cpp
+++ b/libkpgp/kpgpbaseG.cpp
@@ -62,7 +62,7 @@ BaseG::encrypt( Block& block, const KeyIDList& recipients )
int
-BaseG::clearsign( Block& block, const char *passphrase )
+BaseG::clearsign( Block& block, const TQString& passphrase )
{
return encsign( block, KeyIDList(), passphrase );
}
@@ -70,16 +70,16 @@ BaseG::clearsign( Block& block, const char *passphrase )
int
BaseG::encsign( Block& block, const KeyIDList& recipients,
- const char *passphrase )
+ const TQString& passphrase )
{
TQCString cmd;
int exitStatus = 0;
- if(!recipients.isEmpty() && passphrase != 0)
+ if (!recipients.isEmpty() && !passphrase.isNull())
cmd = "--batch --armor --sign --encrypt --textmode";
else if(!recipients.isEmpty())
cmd = "--batch --armor --encrypt --textmode";
- else if(passphrase != 0)
+ else if (!passphrase.isNull())
cmd = "--batch --escape-from --clearsign";
else
{
@@ -87,7 +87,7 @@ BaseG::encsign( Block& block, const KeyIDList& recipients,
return OK;
}
- if(passphrase != 0)
+ if (!passphrase.isNull())
cmd += addUserId();
if(!recipients.isEmpty())
@@ -164,7 +164,7 @@ BaseG::encsign( Block& block, const KeyIDList& recipients,
}
}
#endif
- if( passphrase != 0 )
+ if (!passphrase.isNull())
{
// Example 1 (bad passphrase, clearsign only):
// gpg: skipped `0x12345678': bad passphrase
@@ -205,7 +205,7 @@ BaseG::encsign( Block& block, const KeyIDList& recipients,
int
-BaseG::decrypt( Block& block, const char *passphrase )
+BaseG::decrypt( Block& block, const TQString& passphrase )
{
int index, index2;
int exitStatus = 0;
@@ -252,7 +252,7 @@ BaseG::decrypt( Block& block, const char *passphrase )
{
if( ( index = error.find( "bad passphrase" ) ) != -1 )
{
- if( passphrase != 0 )
+ if (!passphrase.isNull())
{
errMsg = i18n( "Bad passphrase; could not decrypt." );
kdDebug(5100) << "Base: passphrase is bad" << endl;
@@ -483,7 +483,7 @@ BaseG::secretKeys( const TQStringList & patterns )
int
-BaseG::signKey(const KeyID& keyID, const char *passphrase)
+BaseG::signKey(const KeyID& keyID, const TQString& passphrase)
{
TQCString cmd;
int exitStatus = 0;
diff --git a/libkpgp/kpgpui.cpp b/libkpgp/kpgpui.cpp
index f4b40a708..3c099d6bc 100644
--- a/libkpgp/kpgpui.cpp
+++ b/libkpgp/kpgpui.cpp
@@ -95,7 +95,7 @@ PassphraseDialog::~PassphraseDialog()
{
}
-const char * PassphraseDialog::passphrase()
+const TQString PassphraseDialog::passphrase()
{
return lineedit->password();
}
diff --git a/libkpgp/kpgpui.h b/libkpgp/kpgpui.h
index 57c13fbaf..bf2b4213e 100644
--- a/libkpgp/kpgpui.h
+++ b/libkpgp/kpgpui.h
@@ -62,7 +62,7 @@ class KDE_EXPORT PassphraseDialog : public KDialogBase
bool modal=true, const TQString &keyID=TQString());
virtual ~PassphraseDialog();
- const char * passphrase();
+ const TQString passphrase();
private:
KPasswordEdit *lineedit;