From 5955da3519787bd2b0c6d5b1cc879137f4e946da Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 8 Mar 2014 00:31:29 +0100 Subject: [PATCH] fixed a couple of pgp bugs --- res/layout/activity_contact_details.xml | 13 +++++++++---- .../siacs/conversations/crypto/PgpEngine.java | 17 +++++++++++------ .../services/XmppConnectionService.java | 4 +--- src/eu/siacs/conversations/ui/XmppActivity.java | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/res/layout/activity_contact_details.xml b/res/layout/activity_contact_details.xml index 1c38f4a33..cfa77a4d7 100644 --- a/res/layout/activity_contact_details.xml +++ b/res/layout/activity_contact_details.xml @@ -1,9 +1,13 @@ - + android:background="#e5e5e5"> + + - \ No newline at end of file + + \ No newline at end of file diff --git a/src/eu/siacs/conversations/crypto/PgpEngine.java b/src/eu/siacs/conversations/crypto/PgpEngine.java index 5e480ae5e..fa5a93b36 100644 --- a/src/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/eu/siacs/conversations/crypto/PgpEngine.java @@ -40,7 +40,6 @@ public class PgpEngine { } public String encrypt(long keyId, String message) { - Log.d("xmppService","encrypt message: "+message+" for key "+keyId); long[] keys = {keyId}; Intent params = new Intent(); params.setAction(OpenPgpApi.ACTION_ENCRYPT); @@ -51,8 +50,6 @@ public class PgpEngine { ByteArrayOutputStream os = new ByteArrayOutputStream(); Intent result = api.executeApi(params, is, os); StringBuilder encryptedMessageBody = new StringBuilder(); - Log.d("xmppService","intent: "+result.toString()); - Log.d("xmppService","output: "+os.toString()); String[] lines = os.toString().split("\n"); for (int i = 3; i < lines.length - 1; ++i) { encryptedMessageBody.append(lines[i].trim()); @@ -62,11 +59,15 @@ public class PgpEngine { public long fetchKeyId(String status, String signature) throws OpenPgpException { + if (signature==null) { + return 0; + } + if (status==null) { + status=""; + } StringBuilder pgpSig = new StringBuilder(); pgpSig.append("-----BEGIN PGP SIGNED MESSAGE-----"); pgpSig.append('\n'); - pgpSig.append("Hash: SHA1"); - pgpSig.append('\n'); pgpSig.append('\n'); pgpSig.append(status); pgpSig.append('\n'); @@ -86,7 +87,11 @@ public class PgpEngine { case OpenPgpApi.RESULT_CODE_SUCCESS: OpenPgpSignatureResult sigResult = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE); - return sigResult.getKeyId(); + if (sigResult==null) { + return 0; + } else { + return sigResult.getKeyId(); + } case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: break; case OpenPgpApi.RESULT_CODE_ERROR: diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index c6af9d1de..d0a879b4d 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -253,7 +253,6 @@ public class XmppConnectionService extends Service { if ((x != null) && (x.getAttribute("xmlns").equals("jabber:x:signed"))) { try { - Log.d(LOGTAG,"pgp signature for contact" +packet.getAttribute("from")); contact.setPgpKeyId(pgp.fetchKeyId(packet.findChild("status") .getContent(), x.getContent())); } catch (OpenPgpException e) { @@ -287,7 +286,7 @@ public class XmppConnectionService extends Service { // TODO: ask user to handle it maybe } } else { - //Log.d(LOGTAG, packet.toString()); + Log.d(LOGTAG, packet.toString()); } replaceContactInConversation(contact.getJid(), contact); } @@ -508,7 +507,6 @@ public class XmppConnectionService extends Service { x.setContent(this.getPgpEngine().encrypt(keyId, message.getBody())); packet.addChild(x); - Log.d(LOGTAG,"pgp message"+packet.toString()); account.getXmppConnection().sendMessagePacket(packet); message.setStatus(Message.STATUS_SEND); message.setEncryption(Message.ENCRYPTION_DECRYPTED); diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index c1b64f228..18df6f5b6 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -71,7 +71,7 @@ public abstract class XmppActivity extends Activity { if (xmppConnectionService.getPgpEngine()!=null) { return true; } else { - Builder builder = new AlertDialog.Builder(getApplicationContext()); + Builder builder = new AlertDialog.Builder(this); builder.setTitle("OpenKeychain not found"); builder.setIconAttribute(android.R.attr.alertDialogIcon); builder.setMessage("Please make sure you have installed OpenKeychain");