fixed a couple of pgp bugs

This commit is contained in:
Daniel Gultsch 2014-03-08 00:31:29 +01:00
parent 100059b530
commit 5955da3519
4 changed files with 22 additions and 14 deletions

View File

@ -1,10 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:background="#e5e5e5"> android:background="#e5e5e5">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView <TextView
style="@style/sectionHeader" style="@style/sectionHeader"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -108,3 +112,4 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView>

View File

@ -40,7 +40,6 @@ public class PgpEngine {
} }
public String encrypt(long keyId, String message) { public String encrypt(long keyId, String message) {
Log.d("xmppService","encrypt message: "+message+" for key "+keyId);
long[] keys = {keyId}; long[] keys = {keyId};
Intent params = new Intent(); Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_ENCRYPT); params.setAction(OpenPgpApi.ACTION_ENCRYPT);
@ -51,8 +50,6 @@ public class PgpEngine {
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
Intent result = api.executeApi(params, is, os); Intent result = api.executeApi(params, is, os);
StringBuilder encryptedMessageBody = new StringBuilder(); StringBuilder encryptedMessageBody = new StringBuilder();
Log.d("xmppService","intent: "+result.toString());
Log.d("xmppService","output: "+os.toString());
String[] lines = os.toString().split("\n"); String[] lines = os.toString().split("\n");
for (int i = 3; i < lines.length - 1; ++i) { for (int i = 3; i < lines.length - 1; ++i) {
encryptedMessageBody.append(lines[i].trim()); encryptedMessageBody.append(lines[i].trim());
@ -62,11 +59,15 @@ public class PgpEngine {
public long fetchKeyId(String status, String signature) public long fetchKeyId(String status, String signature)
throws OpenPgpException { throws OpenPgpException {
if (signature==null) {
return 0;
}
if (status==null) {
status="";
}
StringBuilder pgpSig = new StringBuilder(); StringBuilder pgpSig = new StringBuilder();
pgpSig.append("-----BEGIN PGP SIGNED MESSAGE-----"); pgpSig.append("-----BEGIN PGP SIGNED MESSAGE-----");
pgpSig.append('\n'); pgpSig.append('\n');
pgpSig.append("Hash: SHA1");
pgpSig.append('\n');
pgpSig.append('\n'); pgpSig.append('\n');
pgpSig.append(status); pgpSig.append(status);
pgpSig.append('\n'); pgpSig.append('\n');
@ -86,7 +87,11 @@ public class PgpEngine {
case OpenPgpApi.RESULT_CODE_SUCCESS: case OpenPgpApi.RESULT_CODE_SUCCESS:
OpenPgpSignatureResult sigResult OpenPgpSignatureResult sigResult
= result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE); = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
if (sigResult==null) {
return 0;
} else {
return sigResult.getKeyId(); return sigResult.getKeyId();
}
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
break; break;
case OpenPgpApi.RESULT_CODE_ERROR: case OpenPgpApi.RESULT_CODE_ERROR:

View File

@ -253,7 +253,6 @@ public class XmppConnectionService extends Service {
if ((x != null) if ((x != null)
&& (x.getAttribute("xmlns").equals("jabber:x:signed"))) { && (x.getAttribute("xmlns").equals("jabber:x:signed"))) {
try { try {
Log.d(LOGTAG,"pgp signature for contact" +packet.getAttribute("from"));
contact.setPgpKeyId(pgp.fetchKeyId(packet.findChild("status") contact.setPgpKeyId(pgp.fetchKeyId(packet.findChild("status")
.getContent(), x.getContent())); .getContent(), x.getContent()));
} catch (OpenPgpException e) { } catch (OpenPgpException e) {
@ -287,7 +286,7 @@ public class XmppConnectionService extends Service {
// TODO: ask user to handle it maybe // TODO: ask user to handle it maybe
} }
} else { } else {
//Log.d(LOGTAG, packet.toString()); Log.d(LOGTAG, packet.toString());
} }
replaceContactInConversation(contact.getJid(), contact); replaceContactInConversation(contact.getJid(), contact);
} }
@ -508,7 +507,6 @@ public class XmppConnectionService extends Service {
x.setContent(this.getPgpEngine().encrypt(keyId, x.setContent(this.getPgpEngine().encrypt(keyId,
message.getBody())); message.getBody()));
packet.addChild(x); packet.addChild(x);
Log.d(LOGTAG,"pgp message"+packet.toString());
account.getXmppConnection().sendMessagePacket(packet); account.getXmppConnection().sendMessagePacket(packet);
message.setStatus(Message.STATUS_SEND); message.setStatus(Message.STATUS_SEND);
message.setEncryption(Message.ENCRYPTION_DECRYPTED); message.setEncryption(Message.ENCRYPTION_DECRYPTED);

View File

@ -71,7 +71,7 @@ public abstract class XmppActivity extends Activity {
if (xmppConnectionService.getPgpEngine()!=null) { if (xmppConnectionService.getPgpEngine()!=null) {
return true; return true;
} else { } else {
Builder builder = new AlertDialog.Builder(getApplicationContext()); Builder builder = new AlertDialog.Builder(this);
builder.setTitle("OpenKeychain not found"); builder.setTitle("OpenKeychain not found");
builder.setIconAttribute(android.R.attr.alertDialogIcon); builder.setIconAttribute(android.R.attr.alertDialogIcon);
builder.setMessage("Please make sure you have installed OpenKeychain"); builder.setMessage("Please make sure you have installed OpenKeychain");