libkpgp: Fix signature key exctraction for GnuPG 2.1

This resolves bug 2883

Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
pull/1/head
Emanoil Kotsev 7 years ago committed by Slávek Banko
parent e0c1fe7ab9
commit f09192b22a

@ -313,8 +313,24 @@ BaseG::decrypt( Block& block, const char *passphrase )
index2 = error.find("using", index+15); index2 = error.find("using", index+15);
block.setSignatureDate( error.mid(index+15, index2-(index+15)-1) ); block.setSignatureDate( error.mid(index+15, index2-(index+15)-1) );
kdDebug(5100) << "Message was signed on '" << block.signatureDate() << "'\n"; kdDebug(5100) << "Message was signed on '" << block.signatureDate() << "'\n";
index2 = error.find("key ID ", index2) + 7; // To handle gnupg > 2.1
block.setSignatureKeyId( error.mid(index2,8) ); // gpg: Signature made Thu 05 Apr 2018 10:02:50 PM CEST
// gpg: using DSA key A0CF1DC09533E5E87F54DB40F1EEB8CD9FB16A50
// gpg: Good signature from "deloptes <deloptes@gmail.com>" [ultimate]
// so we need extra check
if (error.contains("key ID") > 0) {
index2 = error.find("key ID ", index2) + 7;
block.setSignatureKeyId( error.mid(index2,8) );
}
else {
index2 = error.find("key ", index2) + 4;
// handle variable key size
// gpg: Signature made Mon 02 Apr 2018 03:15:08 PM CEST
// gpg: using DSA key 05C82CF57AD1DA46
// gpg: Can't check signature: No public key
int end = error.find("\n", index2);
block.setSignatureKeyId( error.mid(index2,end-index2) );
}
kdDebug(5100) << "Message was signed with key '" << block.signatureKeyId() << "'\n"; kdDebug(5100) << "Message was signed with key '" << block.signatureKeyId() << "'\n";
// move index to start of next line // move index to start of next line
index = error.find('\n', index2)+1; index = error.find('\n', index2)+1;
@ -333,7 +349,7 @@ BaseG::decrypt( Block& block, const char *passphrase )
index = error.find('"',index); index = error.find('"',index);
index2 = error.find('\n',index+1); index2 = error.find('\n',index+1);
index2 = error.findRev('"', index2-1); index2 = error.findRev('"', index2-1);
block.setSignatureUserId( error.mid( index+1, index2-index-1 ) ); block.setSignatureUserId( TQString::fromLocal8Bit( error.mid( index+1, index2-index-1 ) ) );
} }
else if( error.find("BAD signature", index) != -1 ) else if( error.find("BAD signature", index) != -1 )
{ {
@ -343,7 +359,7 @@ BaseG::decrypt( Block& block, const char *passphrase )
index = error.find('"',index); index = error.find('"',index);
index2 = error.find('\n',index+1); index2 = error.find('\n',index+1);
index2 = error.findRev('"', index2-1); index2 = error.findRev('"', index2-1);
block.setSignatureUserId( error.mid( index+1, index2-index-1 ) ); block.setSignatureUserId( TQString::fromLocal8Bit( error.mid( index+1, index2-index-1 ) ) );
} }
else if( error.find("Can't find the right public key", index) != -1 ) else if( error.find("Can't find the right public key", index) != -1 )
{ {

Loading…
Cancel
Save