From 724a547c5610c19a412a7c5a30ea64e527fdb246 Mon Sep 17 00:00:00 2001 From: Emanoil Kotsev Date: Sat, 5 May 2018 19:29:46 +0200 Subject: libkpgp: Fix signature key exctraction for GnuPG 2.1 This resolves bug 2883 Signed-off-by: Emanoil Kotsev (cherry picked from commit f09192b22acd8e7719f8eb31a2348a40f944df25) --- libkpgp/kpgpbaseG.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'libkpgp/kpgpbaseG.cpp') diff --git a/libkpgp/kpgpbaseG.cpp b/libkpgp/kpgpbaseG.cpp index 7e96b4e93..cd6eaf41c 100644 --- a/libkpgp/kpgpbaseG.cpp +++ b/libkpgp/kpgpbaseG.cpp @@ -313,8 +313,24 @@ BaseG::decrypt( Block& block, const char *passphrase ) index2 = error.find("using", index+15); block.setSignatureDate( error.mid(index+15, index2-(index+15)-1) ); kdDebug(5100) << "Message was signed on '" << block.signatureDate() << "'\n"; - index2 = error.find("key ID ", index2) + 7; - block.setSignatureKeyId( error.mid(index2,8) ); + // To handle gnupg > 2.1 + // gpg: Signature made Thu 05 Apr 2018 10:02:50 PM CEST + // gpg: using DSA key A0CF1DC09533E5E87F54DB40F1EEB8CD9FB16A50 + // gpg: Good signature from "deloptes " [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"; // move index to start of next line index = error.find('\n', index2)+1; @@ -333,7 +349,7 @@ BaseG::decrypt( Block& block, const char *passphrase ) index = error.find('"',index); index2 = error.find('\n',index+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 ) { @@ -343,7 +359,7 @@ BaseG::decrypt( Block& block, const char *passphrase ) index = error.find('"',index); index2 = error.find('\n',index+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 ) { -- cgit v1.2.1