51 int exitStatus =
run(
PGP6 " +batchmode +language=C -f", passphrase);
56 if(exitStatus == -1) {
57 errMsg = i18n(
"error running PGP");
64 if(
error.contains(
"File is encrypted.") )
68 if((index =
error.indexOf(
"Key for user ID")) != -1 )
71 index =
error.indexOf(
':', index) + 2;
72 index2 =
error.indexOf(
'\n', index);
80 if (!passphrase || !
output.length())
82 errMsg = i18n(
"Bad passphrase; could not decrypt.");
88 else if(
error.contains(
"You do not have the secret key needed to decrypt this file.") )
90 errMsg = i18n(
"You do not have the secret key for this message.");
121 if(((index =
error.indexOf(
"File is signed.")) != -1 )
122 || (
error.contains(
"Good signature") ))
127 if( ( index2 =
error.indexOf(
"Signature made", index ) ) != -1 )
130 int eol =
error.indexOf(
'\n', index2 );
132 kDebug( 5326 ) <<
"Message was signed on '" << block.
signatureDate() <<
"'";
137 if(
error.contains(
"signature not checked") )
139 index =
error.indexOf(
"KeyID:",index);
145 else if((index =
error.indexOf(
"Good signature")) != -1 )
149 index =
error.indexOf(
'"',index)+1;
150 index2 =
error.indexOf(
'"', index);
154 index =
error.indexOf(
"KeyID:",index2);
160 else if(
error.contains(
"Can't find the right public key") )
185 const bool readTrust ,
189 int exitStatus =
run(
PGP6 " +batchmode -compatible +verbose=0 +language=C -kvvc "
190 "0x" + keyID, 0,
true );
192 if(exitStatus != 0) {
197 key = parseSingleKey(
output, key );
206 exitStatus =
run(
PGP6 " +batchmode -compatible +verbose=0 +language=C -kc "
207 "0x" + keyID, 0,
true );
209 if(exitStatus != 0) {
214 parseTrustDataForKey( key,
output );
225 "+language=C -kvvc", patterns );
348 int exitStatus =
run(
PGP6, 0,
true );
350 if(exitStatus == -1) {
351 errMsg = i18n(
"error running PGP");
356 if(
error.contains(
"Version 6") )
368 Base6::parseKeyData(
const QByteArray& output,
int& offset,
Key* key )
375 if( ( strncmp( output.data() + offset,
"DSS", 3 ) != 0 ) &&
376 ( strncmp( output.data() + offset,
"RSA", 3 ) != 0 ) )
378 kDebug( 5326 ) <<
"Unknown key type or corrupt key data.";
383 bool firstLine =
true;
384 bool canSign =
false;
385 bool canEncr =
false;
393 if( ( eol = output.indexOf(
'\n', offset ) ) == -1 )
398 if( firstLine && ( !strncmp( output.data() + offset,
"DSS", 3 ) ||
399 !strncmp( output.data() + offset,
"RSA", 3 ) ) )
422 if( !strncmp( output.data() + offset,
"DSS", 3 ) )
424 if( !strncmp( output.data() + offset,
"RSA", 3 ) )
437 subkey =
new Subkey(
"",
false );
440 subkey->setExpirationDate( -1 );
443 switch( output[offset+3] )
448 subkey->setDisabled(
true );
452 kDebug( 5326 ) <<
"Unknown key flag.";
457 while( output[pos] ==
' ' )
459 pos2 = output.indexOf(
' ', pos );
460 subkey->setKeyLength( output.mid( pos, pos2-pos ).toUInt() );
465 while( output[pos] ==
' ' )
468 pos2 = output.indexOf(
' ', pos );
469 subkey->setKeyID( output.mid( pos, pos2-pos ) );
474 while( output[pos] ==
' ' )
476 pos2 = output.indexOf(
' ', pos );
477 int year = output.mid( pos, 4 ).toInt();
478 int month = output.mid( pos+5, 2 ).toInt();
479 int day = output.mid( pos+8, 2 ).toInt();
480 QDateTime dt( QDate( year, month, day ), QTime( 00, 00 ) );
481 QDateTime epoch( QDate( 1970, 01, 01 ), QTime( 00, 00 ) );
486 subkey->setCreationDate( epoch.secsTo( dt ) );
490 while( output[pos] ==
' ' )
494 if( !strncmp( output.data() + pos,
"*** KEY REVOKED ***", 19 ) )
498 subkey->setRevoked(
true );
503 else if( !strncmp( output.data() + pos,
"*** KEY EXPIRED ***", 19 ) )
507 subkey->setExpired(
true );
512 else if( !strncmp( output.data() + pos,
"expires ", 8 ) )
515 int year = output.mid( pos, 4 ).toInt();
516 int month = output.mid( pos+5, 2 ).toInt();
517 int day = output.mid( pos+8, 2 ).toInt();
518 QDateTime dt( QDate( year, month, day ), QTime( 00, 00 ) );
520 subkey->setExpirationDate( epoch.secsTo( dt ) );
524 else if( !strncmp( output.data() + pos,
"*** DEFAULT SIGNING KEY ***", 27 ) )
531 QByteArray uid = output.mid( pos, eol-pos );
538 subkey->setCanEncrypt( encr );
539 subkey->setCanSign( sign );
540 subkey->setCanCertify( sign );
545 else if( !strncmp( output.data() + offset,
"DSS", 3 ) ||
546 !strncmp( output.data() + offset,
" DH", 3 ) ||
547 !strncmp( output.data() + offset,
"RSA", 3 ) )
560 if( !strncmp( output.data() + offset,
"DSS", 3 ) )
562 if( !strncmp( output.data() + offset,
" DH", 3 ) )
564 if( !strncmp( output.data() + offset,
"RSA", 3 ) )
574 while( output[pos] ==
' ' )
576 pos2 = output.indexOf(
' ', pos );
580 while( output[pos] ==
' ' )
582 pos2 = output.indexOf(
' ', pos );
586 while( output[pos] ==
' ' )
588 pos2 = output.indexOf(
' ', pos );
592 while( output[pos] ==
' ' )
596 if( !strncmp( output.data() + pos,
"*** KEY REVOKED ***", 19 ) )
603 else if( !strncmp( output.data() + pos,
"*** KEY EXPIRED ***", 19 ) )
610 else if( !strncmp( output.data() + pos,
"expires ", 8 ) )
615 else if( !strncmp( output.data() + pos,
"*** DEFAULT SIGNING KEY ***", 27 ) )
622 QByteArray uid = output.mid( pos, eol-pos );
629 canSign = canSign || sign;
630 canEncr = canEncr || encr;
632 else if( !strncmp( output.data() + offset,
"Unknown type", 12 ) )
634 kDebug( 5326 )<<
"Unknown key type.";
636 else if( output[offset] ==
' ' )
642 int pos = offset + 1;
643 while( output[pos] ==
' ' )
646 if( !strncmp( output.data() + pos,
"Key fingerprint = ", 18 ) )
654 QByteArray fingerprint = output.mid( pos, eol-pos );
656 for (
int idx = 0 ; (idx = fingerprint.indexOf(
' ', idx)) != -1; )
657 fingerprint.replace( idx, 1,
"" );
660 assert( subkey != 0 );
661 subkey->setFingerprint( fingerprint );
669 key->
addUserID( QLatin1String(output.mid( pos, eol-pos )) );
672 else if( !strncmp( output.data() + offset,
"sig", 3 ) )
697 Base6::parseSingleKey(
const QByteArray& output, Key* key )
702 if( !strncmp( output.data(),
"Type bits", 9 ) )
706 offset = output.indexOf(
"\nType bits" );
714 offset = output.indexOf(
'\n', offset ) + 1;
718 key = parseKeyData( output, offset, key );
729 kDebug( 5326 ) <<
"Kpgp::Base6::parseKeyList()";
735 if( !strncmp( output.data(),
"Type bits", 9 ) )
739 offset = output.indexOf(
"\nType bits" ) + 1;
745 offset = output.indexOf(
'\n', offset ) + 1;
751 key = parseKeyData( output, offset );
767 Base6::parseTrustDataForKey(
Key* key,
const QByteArray& str )
769 if( ( key == 0 ) || str.isEmpty() )
776 int offset = str.indexOf(
"\n\n KeyID" );
780 offset = str.indexOf(
'\n', offset ) + 1;
784 bool ultimateTrust =
false;
785 if( !strncmp( str.data() + offset+13,
"ultimate", 8 ) )
786 ultimateTrust =
true;
794 if( ( eol = str.indexOf(
'\n', offset ) ) == -1 )
797 if( str[offset+23] !=
' ' )
802 if( !strncmp( str.data() + offset+23,
"complete", 8 ) )
807 else if( !strncmp( str.data() + offset+23,
"marginal", 8 ) )
809 else if( !strncmp( str.data() + offset+23,
"invalid", 7 ) )
813 int pos = offset + 33;
814 QString uid = QLatin1String(str.mid( pos, eol-pos ));
817 for( UserIDList::Iterator it = userIDs.begin(); it != userIDs.end(); ++it )
818 if( (*it)->text() == uid )
820 kDebug( 5326 )<<
"Setting the validity of"<<uid<<
" to"<<validity;
821 (*it)->setValidity( validity );
Validity
These are the possible validity values for a PGP user id and for the owner trust. ...
void setCanCertify(const bool canCertify)
Sets the flag if the key can be used to certify keys to canCertify .
void setError(const QByteArray &str)
const UserIDList userIDs() const
Returns the list of userIDs.
void setSignatureDate(const QByteArray &date)
void setCanEncrypt(const bool canEncrypt)
Sets the flag if the key can be used to encrypt data to canEncrypt .
void setRequiredUserId(const QString &userId)
void setSecret(const bool secret)
Sets the flag if the key is a secret key to secret .
void setDisabled(const bool disabled)
Sets the flag if the key has been disabled to disabled .
virtual KeyList secretKeys(const QStringList &patterns=QStringList())
Returns the list of secret keys in the users secret keyring.
virtual int run(const char *cmd, const char *passphrase=0, bool onlyReadFromPGP=false)
virtual int decrypt(Block &block, const char *passphrase=0)
Decrypts the message.
virtual KeyList publicKeys(const QStringList &patterns=QStringList())
Returns the list of public keys in the users public keyring.
void setSignatureUserId(const QString &userId)
void addUserID(const QString &uid, const Validity validity=KPGP_VALIDITY_UNKNOWN, const bool revoked=false, const bool invalid=false)
Adds a user ID with the given values to the key if uid isn't an empty string.
KeyList doGetPublicKeys(const QByteArray &cmd, const QStringList &patterns)
QList< UserID * > UserIDList
QByteArray signatureDate() const
date of the signature WARNING: Will most likely be changed to QDateTime
void setSignatureKeyId(const QByteArray &keyId)
virtual KeyList parseKeyList(const QByteArray &, bool)
void addSubkey(const KeyID &keyID, const bool secret=false)
Adds a subkey with the given values to the key if keyID isn't an empty string.
virtual Key * readPublicKey(const KeyID &keyID, const bool readTrust=false, Key *key=0)
Reads the key data for the given key and returns it.
void setExpired(const bool expired)
Sets the flag if the key has expired to expired .
void setProcessedText(const QByteArray &str)
void setRevoked(const bool revoked)
Sets the flag if the key has been revoked to revoked .
This class is used to store information about a PGP key.
void setCanSign(const bool canSign)
Sets the flag if the key can be used to sign data to canSign .
void clear()
Clears/resets all key data.
void setStatus(const int status)
KeyID primaryKeyID() const
Returns the key ID of the primary key or a null string if there are no subkeys.