25 #include <kmessagebox.h>
26 #include <kconfigbase.h>
27 #include <kconfiggroup.h>
33 #include <QApplication>
48 #include <sys/socket.h>
49 #include <sys/types.h>
60 ModuleStatic() : kpgpObject( 0 ) {}
61 ~ModuleStatic() {
delete kpgpObject; }
65 K_GLOBAL_STATIC( ModuleStatic, s_module )
69 mPublicKeysCached(
false),
71 mSecretKeysCached(
false),
72 passphrase(0), passphrase_buffer_len(0), havePassPhrase(
false)
85 if (!s_module.isDestroyed() && s_module->kpgpObject ==
this)
86 s_module->kpgpObject = 0;
120 KConfigGroup grp(config,
QString());
121 storePass = grp.readEntry(
"storePass",
false);
122 showEncryptionResult = grp.readEntry(
"showEncryptionResult",
true);
123 mShowKeyApprovalDlg = grp.readEntry(
"showKeysForApproval",
true );
128 flagEncryptToSelf = grp.readEntry(
"encryptToSelf",
true);
134 KConfigGroup grp(config,
QString());
135 grp.writeEntry(
"storePass", storePass);
136 grp.writeEntry(
"showEncryptionResult", showEncryptionResult);
137 grp.writeEntry(
"showKeysForApproval", mShowKeyApprovalDlg );
139 grp.writeEntry(
"encryptToSelf", flagEncryptToSelf);
153 if (pgpUser != keyID) {
169 flagEncryptToSelf = flag;
175 return flagEncryptToSelf;
192 Module::prepare(
bool needPassPhrase,
Block* block )
194 if (0 == pgp) assignPGPBase();
198 errMsg = i18n(
"Could not find PGP executable.\n"
199 "Please check your PATH is set correctly.");
206 if(needPassPhrase && !havePassPhrase) {
207 if( (
tGPG ==
pgpType ) && ( 0 != getenv(
"GPG_AGENT_INFO") ) ) {
209 kDebug( 5326 ) <<
"user uses gpg-agent -> don't ask for passphrase";
217 PassphraseDialog passdlg(0, i18n(
"OpenPGP Security Check"), ID);
221 int passdlgResult = passdlg.exec();
225 if (passdlgResult == QDialog::Accepted) {
226 if (!setPassPhrase(passdlg.passphrase())) {
227 if ( passdlg.passphrase().length() >= 1024)
228 errMsg = i18n(
"Passphrase is too long, it must contain fewer than 1024 characters.");
230 errMsg = i18n(
"Out of memory.");
243 Module::wipePassPhrase(
bool freeMem)
246 if ( passphrase_buffer_len )
247 memset( passphrase, 0x00, passphrase_buffer_len );
249 kDebug( 5326 ) <<
"wipePassPhrase: passphrase && !passphrase_buffer_len ???";
253 if ( freeMem && passphrase ) {
256 passphrase_buffer_len = 0;
258 havePassPhrase =
false;
266 if (0 == pgp) assignPGPBase();
269 if( !prepare(
false, &block ) )
272 retval = pgp->
verify( block );
287 if (0 == pgp) assignPGPBase();
292 if( prepare(
true, &block ) != 1 )
295 retval = pgp->
decrypt( block, passphrase );
302 int ret = KMessageBox::warningContinueCancel(0,
303 i18n(
"You just entered an invalid passphrase.\n"
304 "Do you want to try again, or "
305 "cancel and view the message undecrypted?"),
306 i18n(
"PGP Warning"), KGuiItem(i18n(
"&Retry")));
310 if ( ret == KMessageBox::Cancel )
break;
342 if( 0 == pgp ) assignPGPBase();
346 if( !receivers.
empty() ) {
354 status =
doEncSign( block, encryptionKeyIds, sign );
362 QString str = i18n(
"You entered an invalid passphrase.\n"
363 "Do you want to try again, continue and leave the "
364 "message unsigned, or cancel sending the message?");
368 int ret = KMessageBox::warningYesNoCancel( 0, str,
370 KGuiItem(i18n(
"&Retry")),
371 KGuiItem(i18n(
"Send &Unsigned")) );
375 if( ret == KMessageBox::Cancel ) {
378 if( ret == KMessageBox::No ) {
380 if( encryptionKeyIds.
isEmpty() ) {
389 status =
doEncSign( block, encryptionKeyIds, sign );
394 QString str = i18nc(
"%1 = 'signing failed' error message",
395 "%1\nDo you want to send the message unsigned, "
396 "or cancel sending the message?",
401 int ret = KMessageBox::warningContinueCancel( 0, str,
403 KGuiItem(i18n(
"Send &Unsigned")) );
407 if( ret == KMessageBox::Cancel ) {
411 status =
doEncSign( block, encryptionKeyIds, sign );
416 QString str = i18nc(
"%1 = 'bad keys' error message",
417 "%1\nDo you want to encrypt anyway, leave the "
418 "message as-is, or cancel sending the message?",
424 int ret = KMessageBox::warningYesNoCancel( 0, str,
426 KGuiItem(i18n(
"Send &Encrypted")),
427 KGuiItem(i18n(
"Send &Unencrypted")) );
431 if( ret == KMessageBox::Cancel ) {
434 if( ret == KMessageBox::No ) {
447 QString str = i18nc(
"%1 = 'missing keys' error message",
448 "%1\nDo you want to leave the message as-is, "
449 "or cancel sending the message?",
454 int ret = KMessageBox::warningContinueCancel( 0, str,
456 KGuiItem(i18n(
"&Send As-Is")) );
460 if( ret == KMessageBox::Cancel ) {
469 errMsg = i18n(
"The following error occurred:\n%1" ,
471 QString details = i18n(
"This is the error message of %1:\n%2" ,
477 KMessageBox::detailedSorry( 0, errMsg, details );
490 bool result = ( cipherTextDlg->exec() == QDialog::Accepted );
494 delete cipherTextDlg;
502 const KeyIDList& recipientKeyIds,
bool sign )
506 if( 0 == pgp ) assignPGPBase();
509 if( !havePgp )
return OK;
512 int result = prepare(
true, &block );
519 retval = pgp->
encsign( block, recipientKeyIds, passphrase );
522 if( !prepare(
false, &block ) )
return Kpgp::ERROR;
523 retval = pgp->
encrypt( block, recipientKeyIds );
536 if( recipients.
empty() ) {
537 encryptionKeyIds.
clear();
551 bool showKeysForApproval =
false;
554 it != recipients.
constEnd(); ++it, ++i ) {
557 showKeysForApproval =
true;
561 showKeysForApproval =
true;
563 recipientKeyIds[i] = keyIds;
566 kDebug( 5326 ) <<
"recipientKeyIds = (";
569 kDebug( 5326 ) <<
"( 0x" << (*kit).toStringList().join(
QLatin1String(
", 0x") )
572 kDebug( 5326 ) <<
")";
574 if( showKeysForApproval || mShowKeyApprovalDlg ) {
591 int ret = dlg.exec();
593 if( ret == QDialog::Rejected ) {
600 recipientKeyIds = dlg.
keys();
607 int emptyListCount = 0;
609 it != recipientKeyIds.constEnd(); ++it ) {
610 if( (*it).isEmpty() ) {
612 if( it != recipientKeyIds.constBegin() ) {
619 encryptionKeyIds.
append( *kit );
628 if( recipientKeyIds.size() == emptyListCount + 1 ) {
630 ? i18n(
"You did not select an encryption key for the "
631 "recipient of this message; therefore, the message "
632 "will not be encrypted.")
633 : i18n(
"You did not select an encryption key for any of the "
634 "recipients of this message; therefore, the message "
635 "will not be encrypted.");
639 int ret = KMessageBox::warningContinueCancel( 0, str,
641 KGuiItem(i18n(
"Send &Unencrypted")) );
645 if( ret == KMessageBox::Cancel ) {
649 encryptionKeyIds.
clear();
651 else if( emptyListCount > 0 ) {
652 QString str = ( emptyListCount == 1 )
653 ? i18n(
"You did not select an encryption key for one of "
654 "the recipients; this person will not be able to "
655 "decrypt the message if you encrypt it.")
656 : i18n(
"You did not select encryption keys for some of "
657 "the recipients; these persons will not be able to "
658 "decrypt the message if you encrypt it." );
662 int ret = KMessageBox::warningYesNoCancel( 0, str,
664 KGuiItem(i18n(
"Send &Encrypted")),
665 KGuiItem(i18n(
"Send &Unencrypted")) );
669 if( ret == KMessageBox::Cancel ) {
672 else if( ret == KMessageBox::No ) {
674 encryptionKeyIds.
clear();
684 if( 0 == pgp ) assignPGPBase();
689 if( recipients.
empty() )
692 int noKey = 0, never = 0, unknown = 0, always = 0, aip = 0, ask = 0,
695 it != recipients.
constEnd(); ++it) {
696 if( haveTrustedEncryptionKey( *it ) ) {
724 if( ( always+aip > 0 ) && ( never+unknown+ask+askwp+noKey == 0 ) ) {
728 if( ( unknown+ask+askwp > 0 ) && ( never+noKey == 0 ) ) {
732 if( ( never+noKey > 0 ) && ( always+ask == 0 ) ) {
742 if (0 == pgp) assignPGPBase();
744 if( prepare(
true ) != 1 )
758 if (0 == pgp) assignPGPBase();
760 if (!prepare())
return KeyList();
762 if( !mPublicKeysCached ) {
773 if (0 == pgp) assignPGPBase();
775 if (!prepare())
return KeyList();
777 if( !mSecretKeysCached ) {
790 foreach (
Key* key, mPublicKeys ) {
804 foreach (
Key* key, mPublicKeys ) {
817 foreach (
Key* key, mSecretKeys ) {
868 if( 0 == pgp ) assignPGPBase();
875 if( ( 0 == oldKey ) && ( 0 != newKey ) )
878 mPublicKeys.
insert( it, newKey );
879 kDebug( 5326 ) <<
"New public key 0x" << newKey->
primaryKeyID() <<
" ("
882 else if( ( 0 != oldKey ) && ( 0 == newKey ) )
884 kDebug( 5326 ) <<
"Public key 0x" << oldKey->
primaryKeyID() <<
" ("
895 if (0 == pgp) assignPGPBase();
901 bool Module::setPassPhrase(
const QString& aPass)
909 size_t newlen = aPass.
length();
910 if ( newlen >= 1024 ) {
916 if ( passphrase_buffer_len < newlen + 1 ) {
921 passphrase_buffer_len = (newlen + 1 + 15) & ~0xF;
922 passphrase = (
char*)malloc( passphrase_buffer_len );
924 passphrase_buffer_len = 0;
929 havePassPhrase =
true;
938 KMessageBox::information(0,i18n(
"This feature is\nstill missing"));
946 wipePassPhrase(
true);
964 showEncryptionResult = flag;
970 return showEncryptionResult;
986 KMessageBox::sorry( 0, i18n(
"You either do not have GnuPG/PGP installed "
987 "or you chose not to use GnuPG/PGP.") );
995 const KeyID& oldKeyId ,
997 const unsigned int allowedKeys )
1007 keyId = selectKey(
publicKeys(), title, text, oldKeyId, allowedKeys );
1010 bool rememberChoice;
1011 keyId = selectKey( rememberChoice,
publicKeys(), title, text, oldKeyId,
1013 if( !keyId.
isEmpty() && rememberChoice ) {
1014 setKeysForAddress( address,
KeyIDList( keyId ) );
1021 KMessageBox::sorry( 0, i18n(
"You either do not have GnuPG/PGP installed "
1022 "or you chose not to use GnuPG/PGP.") );
1033 const unsigned int allowedKeys )
1043 keyIds = selectKeys(
publicKeys(), title, text, oldKeyIds, allowedKeys );
1046 bool rememberChoice;
1047 keyIds = selectKeys( rememberChoice,
publicKeys(), title, text,
1048 oldKeyIds, allowedKeys );
1049 if( !keyIds.
isEmpty() && rememberChoice ) {
1050 setKeysForAddress( address, keyIds );
1057 KMessageBox::sorry( 0, i18n(
"You either do not have GnuPG/PGP installed "
1058 "or you chose not to use GnuPG/PGP.") );
1069 if (!s_module->kpgpObject)
1071 s_module->kpgpObject =
new Module();
1073 return s_module->kpgpObject;
1094 nonPgpBlocks.
clear();
1098 nonPgpBlocks.
append(
"" );
1102 if( !strncmp( msg.
data(),
"-----BEGIN PGP ", 15 ) )
1106 start = msg.
indexOf(
"\n-----BEGIN PGP" ) + 1;
1109 nonPgpBlocks.
append( msg );
1114 while( start != -1 )
1116 int nextEnd, nextStart;
1119 if( !strncmp( msg.
data() + start + 15,
"SIGNED", 6 ) )
1124 nextEnd = msg.
indexOf(
"\n-----END PGP", start + 15 );
1127 nonPgpBlocks.
append( msg.
mid( lastEnd+1 ) );
1130 nextStart = msg.
indexOf(
"\n-----BEGIN PGP", start + 15 );
1132 if( ( nextStart == -1 ) || ( nextEnd < nextStart ) ||
1136 nonPgpBlocks.
append( msg.
mid( lastEnd+1, start-lastEnd-1 ) );
1137 lastEnd = msg.
indexOf(
"\n", nextEnd + 14 );
1141 nonPgpBlocks.
append(
"" );
1147 if( ( nextStart != -1 ) && ( nextEnd > nextStart ) )
1148 nextStart = msg.
indexOf(
"\n-----BEGIN PGP", lastEnd+1 );
1154 nonPgpBlocks.
append( msg.
mid( lastEnd+1 ) );
1159 return ( !pgpBlocks.
isEmpty() );
1166 Module::haveTrustedEncryptionKey(
const QString& person )
1168 if( 0 == pgp ) assignPGPBase();
1170 if( !
usePGP() )
return false;
1177 KeyIDList keyIds = keysForAddress( address );
1195 for(; it != mPublicKeys.
end(); ++it ) {
1197 if( (*it)->matchesUserID( person,
false ) ) {
1200 if( ( (*it)->isValidEncryptionKey() ) &&
1209 for( it = mPublicKeys.
begin(); it != mPublicKeys.
end(); ++it ) {
1211 if( (*it)->matchesUserID( address,
false ) ) {
1214 if( ( (*it)->isValidEncryptionKey() ) &&
1228 if( 0 == pgp ) assignPGPBase();
1230 if( !
usePGP() )
return KeyIDList();
1248 KeyIDList keyIds = keysForAddress( address );
1249 if( !keyIds.isEmpty() ) {
1250 kDebug( 5326 ) <<
"Using encryption keys 0x"
1256 it != keyIds.constEnd(); ++it ) {
1260 if( !( key && ( key->isValidEncryptionKey() ) &&
1268 bool rememberChoice;
1269 keyIds = selectKeys( rememberChoice, mPublicKeys,
1270 i18n(
"Encryption Key Selection"),
1271 i18nc(
"if in your language something like "
1272 "'key(s)' isn't possible please "
1273 "use the plural in the translation",
1274 "There is a problem with the "
1275 "encryption key(s) for \"%1\".\n\n"
1276 "Please re-select the key(s) which should "
1277 "be used for this recipient."
1281 if( !keyIds.isEmpty() ) {
1282 if( rememberChoice ) {
1283 setKeysForAddress( person, keyIds );
1295 kDebug( 5326 ) <<
"Looking for keys matching" << person <<
" ...";
1296 for( ; it != mPublicKeys.
end(); ++it ) {
1298 if( (*it)->matchesUserID( person,
false ) ) {
1301 if( ( (*it)->isValidEncryptionKey() ) &&
1303 kDebug( 5326 ) <<
"Matching trusted key found:"
1304 << (*it)->primaryKeyID();
1305 matchingKeys.append( *it );
1312 kDebug( 5326 ) <<
"Looking for keys matching" << address <<
" ...";
1313 if( matchingKeys.isEmpty() ) {
1314 for ( it = mPublicKeys.
begin(); it != mPublicKeys.
end(); ++it ) {
1316 if( (*it)->matchesUserID( address,
false ) ) {
1319 if( ( (*it)->isValidEncryptionKey() ) &&
1321 kDebug( 5326 ) <<
"Matching trusted key found:"
1322 << (*it)->primaryKeyID();
1323 matchingKeys.append( *it );
1330 if( matchingKeys.isEmpty() ) {
1332 bool rememberChoice;
1333 KeyIDList keyIds = selectKeys( rememberChoice, mPublicKeys,
1334 i18n(
"Encryption Key Selection"),
1335 i18nc(
"if in your language something like "
1336 "'key(s)' isn't possible please "
1337 "use the plural in the translation",
1338 "No valid and trusted OpenPGP key was "
1339 "found for \"%1\".\n\n"
1340 "Select the key(s) which should "
1341 "be used for this recipient."
1345 if( !keyIds.isEmpty() ) {
1346 if( rememberChoice ) {
1347 setKeysForAddress( person, keyIds );
1353 else if( matchingKeys.count() == 1 ) {
1354 return KeyIDList( matchingKeys.first()->primaryKeyID() );
1358 bool rememberChoice;
1359 KeyIDList keyIds = selectKeys( rememberChoice, matchingKeys,
1360 i18n(
"Encryption Key Selection"),
1361 i18nc(
"if in your language something like "
1362 "'key(s)' isn't possible please "
1363 "use the plural in the translation",
1364 "More than one key matches \"%1\".\n\n"
1365 "Select the key(s) which should "
1366 "be used for this recipient."
1370 if( !keyIds.isEmpty() ) {
1371 if( rememberChoice ) {
1372 setKeysForAddress( person, keyIds );
1384 Module::checkForPGP(
void)
1393 pSearchPaths = path.
split(
QLatin1Char(KPATH_SEPARATOR), QString::SkipEmptyParts );
1398 foreach(
const QString& curPath, pSearchPaths )
1404 kDebug( 5326 ) <<
"Kpgp: gpg found";
1413 foreach(
const QString& curPath, pSearchPaths )
1419 kDebug( 5326 ) <<
"Kpgp: pgp 5 found";
1428 foreach(
const QString& curPath, pSearchPaths )
1434 kDebug( 5326 ) <<
"Kpgp: pgp 2 or 6 found";
1443 kDebug( 5326 ) <<
"Kpgp: no pgp found";
1450 Module::assignPGPBase(
void)
1460 kDebug( 5326 ) <<
"Kpgp: assign pgp - gpg";
1465 kDebug( 5326 ) <<
"Kpgp: assign pgp - pgp 2";
1470 kDebug( 5326 ) <<
"Kpgp: assign pgp - pgp 5";
1475 kDebug( 5326 ) <<
"Kpgp: assign pgp - pgp 6";
1481 kDebug( 5326 ) <<
"Kpgp: pgpBase is dummy";
1486 kDebug( 5326 ) <<
"Kpgp: assign pgp - auto";
1489 kDebug( 5326 ) <<
"Kpgp: assign pgp - default";
1492 kDebug( 5326 ) <<
"Kpgp: pgpBase is gpg";
1498 kDebug( 5326 ) <<
"Kpgp: pgpBase is pgp 5";
1504 Base6 *pgp_v6 =
new Base6();
1505 if (!pgp_v6->isVersion6())
1507 kDebug( 5326 ) <<
"Kpgp: pgpBase is pgp 2";
1514 kDebug( 5326 ) <<
"Kpgp: pgpBase is pgp 6";
1524 kDebug( 5326 ) <<
"Kpgp: pgpBase is dummy";
1531 Module::canonicalAddress(
const QString& _adress )
1542 return address.
mid(index,index2-index+1);
1556 if(index2 == -1) index2 = address.
length();
1564 if( 0 == pgp ) assignPGPBase();
1568 qDeleteAll( mPublicKeys );
1569 mPublicKeys.
clear();
1570 mPublicKeysCached =
false;
1574 if( !mPublicKeysCached || reread )
1596 qDeleteAll( mPublicKeys );
1597 mPublicKeys = newPublicKeyList;
1600 mPublicKeysCached =
true;
1607 if( 0 == pgp ) assignPGPBase();
1611 qDeleteAll( mSecretKeys );
1612 mSecretKeys.
clear();
1613 mSecretKeysCached =
false;
1617 if( mSecretKeys.
isEmpty() || reread )
1639 qDeleteAll( mSecretKeys );
1640 mSecretKeys = newSecretKeyList;
1643 mSecretKeysCached =
true;
1648 Module::selectKey(
const KeyList& keys,
1651 const KeyID& keyId ,
1652 const unsigned int allowedKeys )
1656 #ifndef QT_NO_TREEWIDGET
1658 allowedKeys,
false );
1660 #ifndef QT_NO_CURSOR
1663 bool rej = ( dlg.exec() == QDialog::Rejected );
1664 #ifndef QT_NO_CURSOR
1677 Module::selectKeys(
const KeyList& keys,
1680 const KeyIDList& keyIds ,
1681 const unsigned int allowedKeys )
1683 KeyIDList retval = KeyIDList();
1685 #ifndef QT_NO_TREEWIDGET
1686 KeySelectionDialog dlg( keys, title, text, keyIds,
false, allowedKeys,
1689 #ifndef QT_NO_CURSOR
1692 bool rej = ( dlg.exec() == QDialog::Rejected );
1693 #ifndef QT_NO_CURSOR
1698 retval = dlg.keys();
1707 Module::selectKey(
bool& rememberChoice,
1711 const KeyID& keyId ,
1712 const unsigned int allowedKeys )
1716 #ifndef QT_NO_TREEWIDGET
1717 KeySelectionDialog dlg( keys, title, text, KeyIDList( keyId ),
false,
1718 allowedKeys,
false );
1720 #ifndef QT_NO_CURSOR
1723 bool rej = ( dlg.exec() == QDialog::Rejected );
1724 #ifndef QT_NO_CURSOR
1730 rememberChoice = dlg.rememberSelection();
1733 rememberChoice =
false;
1741 Module::selectKeys(
bool& rememberChoice,
1745 const KeyIDList& keyIds ,
1746 const unsigned int allowedKeys )
1748 KeyIDList retval = KeyIDList();
1750 #ifndef QT_NO_TREEWIDGET
1751 KeySelectionDialog dlg( keys, title, text, keyIds,
true, allowedKeys,
1754 #ifndef QT_NO_CURSOR
1757 bool rej = ( dlg.exec() == QDialog::Rejected );
1758 #ifndef QT_NO_CURSOR
1763 retval = dlg.keys();
1764 rememberChoice = dlg.rememberSelection();
1767 rememberChoice =
false;
1775 Module::keysForAddress(
const QString& address )
1781 if( addressDataDict.
contains( addr ) ) {
1782 return addressDataDict[addr].keyIds;
1790 Module::setKeysForAddress(
const QString& address,
const KeyIDList& keyIds )
1796 if( addressDataDict.
contains( addr ) ) {
1797 addressDataDict[addr].keyIds = keyIds;
1802 data.keyIds = keyIds;
1803 addressDataDict.
insert( addr, data );
1810 Module::readAddressData()
1815 KConfigGroup general( config,
"General" );
1816 int num = general.readEntry(
"addressEntries", 0 );
1818 addressDataDict.
clear();
1819 for(
int i=1; i<=num; ++i ) {
1821 address = addrGroup.readEntry(
"Address" );
1823 data.encrPref = (
EncryptPref) addrGroup.readEntry(
"EncryptionPreference",
1829 addressDataDict.
insert( address, data );
1835 Module::writeAddressData()
1837 KConfigGroup general( config,
"General" );
1838 general.writeEntry(
"addressEntries", addressDataDict.
count() );
1842 for ( i=1, it = addressDataDict.
begin();
1843 it != addressDataDict.
end();
1846 addrGroup.writeEntry(
"Address", it.key() );
1847 addrGroup.writeEntry(
"Key IDs", it.value().keyIds.toStringList() );
1848 addrGroup.writeEntry(
"EncryptionPreference", (
int)it.value().encrPref );
1858 if( addressDataDict.
contains( addr ) ) {
1859 return addressDataDict[addr].encrPref;
1874 if( addressDataDict.
contains( addr ) ) {
1875 addressDataDict[addr].encrPref = pref;
1879 data.encrPref = pref;
1880 addressDataDict.
insert( addr, data );
bool isValidEncryptionKey() const
Returns true if the key is a valid encryption key.
int encryptionPossible(const QStringList &recipients)
checks if encrypting to the given list of persons is possible and desired, i.e.
Validity
These are the possible validity values for a PGP user id and for the owner trust. ...
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
static KeyIDList fromStringList(const QStringList &)
Converts from a QStringList to a KeyIDList.
virtual KeyList publicKeys(const QStringList &=QStringList())
Returns the list of public keys in the users public keyring.
bool contains(const Key &key) const
Key * secretKey(const KeyID &keyID)
Returns the secret key with the given key ID or null if no matching key is found. ...
virtual int encsign(Block &, const KeyIDList &, const char *=0)
Encrypts and signs the message with the given keys.
bool encryptToSelf(void) const
virtual int decrypt(Block &, const char *=0)
Decrypts the message.
static bool prepareMessageForDecryption(const QByteArray &msg, QList< Block > &pgpBlocks, QList< QByteArray > &nonPgpBlocks)
Parses the given message and splits it into OpenPGP blocks and Non-OpenPGP blocks.
virtual int verify(Block &block)
Verifies the message.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
const KeyID user() const
Returns the actual key ID of the currently set key.
virtual QString lastErrorMessage() const
Returns an error message if an error occurred during the last operation.
void readPublicKeys(bool reread=false)
Reads the list of public keys if necessary or if reread is true.
void setUser(const KeyID &keyID)
set a user identity to use (if you have more than one...) by default, pgp uses the identity which was...
const_iterator constEnd() const
QString simplified() const
void setEncryptionPreference(const QString &address, const EncryptPref pref)
Writes the given encryption preference for the given address to the config file.
bool showCipherText(void) const
const QString lastErrorMsg(void) const
returns the last error that occurred
Kpgp::Result encrypt(Block &block, const QStringList &receivers, const KeyID &keyId, bool sign, const QByteArray &charset=0)
encrypts the given OpenPGP block for a list of persons.
virtual void readConfig()
the following virtual function form the interface to the application using Kpgp
KeyID selectSecretKey(const QString &title, const QString &text=QString(), const KeyID &keyId=KeyID())
Shows a key selection dialog with all secret keys and the given title and the (optional) text...
Key * rereadKey(const KeyID &keyID, const bool readTrust=true)
Rereads the key data for the given key and returns the reread data.
void setStorePassPhrase(bool)
store passphrase in pgp object Problem: passphrase stays in memory.
const KeyList publicKeys()
get the list of cached public keys.
static Kpgp::Module * getKpgp()
return the actual pgp object
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
const KeyList secretKeys()
get the list of cached secret keys.
int indexOf(char ch, int from) const
virtual Key * readPublicKey(const KeyID &, const bool=false, Key *=0)
Reads the key data for the given key and returns it.
int count(const T &value) const
QString fromLocal8Bit(const char *str, int size)
bool KeyCompare(Key *left, Key *right)
void append(const T &value)
virtual int signKey(const KeyID &, const char *)
Signs the given key with the currently set user key.
KeyIDList selectPublicKeys(const QString &title, const QString &text=QString(), const KeyIDList &oldKeyIds=KeyIDList(), const QString &address=QString(), const unsigned int allowedKeys=AllKeys)
Shows a key selection dialog with all public keys and the given title and the (optional) text...
int removeAll(const T &value)
virtual QByteArray getAsciiPublicKey(const KeyID &)
Returns the ascii armored data of the public key with the given key id.
void setOverrideCursor(const QCursor &cursor)
enum Kpgp::Module::PGPType pgpType
void restoreOverrideCursor()
void setShowCipherText(const bool flag)
QString primaryUserID() const
Returns the primary user ID or a null string if there are no user IDs.
QByteArray mid(int pos, int len) const
Validity keyTrust() const
Returns the trust value of this key.
Kpgp::Result clearsign(Block &block, const KeyID &keyId, const QByteArray &charset=0)
clearsigns the given OpenPGP block with the key corresponding to the given key id.
int doEncSign(Block &block, const KeyIDList &recipientKeyIds, bool sign)
void reset()
Resets all information about this OpenPGP block.
QByteArray toLocal8Bit() const
QVector< KeyIDList > keys() const
void setEncryptToSelf(bool flag)
always encrypt message to oneself?
EncryptPref encryptionPreference(const QString &address)
Reads the encryption preference for the given address from the config file.
bool verify(Block &block)
Tries to verify the given OpenPGP block.
virtual void writeConfig(bool sync)
bool changePassPhrase()
Request the change of the passphrase of the actual secret key.
const_iterator constBegin() const
Validity keyTrust(const KeyID &keyID)
Returns the trust value for the given key.
QString mid(int position, int n) const
QByteArray primaryFingerprint() const
Returns the fingerprint of the primary key or a null string if there are no subkeys.
EncryptPref
These are the possible preferences for encryption.
void insert(int i, const T &value)
virtual int encrypt(Block &, const KeyIDList &)
Encrypts the message with the given keys.
This class is used to store information about a PGP key.
QString fromLatin1(const char *str, int size)
iterator insert(const Key &key, const T &value)
KeyID selectPublicKey(const QString &title, const QString &text=QString(), const KeyID &oldKeyId=KeyID(), const QString &address=QString(), const unsigned int allowedKeys=AllKeys)
Shows a key selection dialog with all public keys and the given title and the (optional) text...
void clear(const bool erasePassPhrase=false)
clears everything from memory
Kpgp::Result getEncryptionKeys(KeyIDList &encryptionKeyIds, const QStringList &recipients, const KeyID &keyId)
Determines the keys which should be used for encrypting the message to the given list of recipients...
QByteArray getAsciiPublicKey(const KeyID &keyID)
try to get an ascii armored key block for the given public key
const_iterator constEnd() const
const_iterator constBegin() const
bool isTrusted(const KeyID &keyID)
Returns TRUE if the given key is at least trusted marginally.
Key * publicKey(const KeyID &keyID)
Returns the public key with the given key ID or null if no matching key is found. ...
static KConfig * getConfig()
get the kpgp config object
void readSecretKeys(bool reread=false)
Reads the list of secret keys if necessary or if reread is true.
int count(const Key &key) const
QString requiredUserId() const
bool matchesUserID(const QString &str, bool cs=true)
Returns true if the given string matches one of the user IDs.
bool storePassPhrase(void) const
bool signKey(const KeyID &keyID)
sign a key in the keyring with users signature.
virtual KeyList secretKeys(const QStringList &=QStringList())
Returns the list of secret keys in the users secret keyring.
void cloneKeyTrust(const Key *key)
Set the validity values for the user ids to the validity values of the given key. ...
bool usePGP(void) const
Should PGP/GnuPG be used?
bool decrypt(Block &block)
decrypts the given OpenPGP block if the passphrase is good.
KeyID primaryKeyID() const
Returns the key ID of the primary key or a null string if there are no subkeys.