aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java12
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java21
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java10
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/TestDataUtil.java21
-rw-r--r--OpenKeychain/src/main/res/layout/import_keys_activity.xml2
-rw-r--r--OpenKeychain/src/main/res/values/strings.xml4
-rw-r--r--OpenKeychain/src/test/java/tests/ProviderHelperKeyringTest.java68
m---------OpenKeychain/src/test/resources/extern/OpenPGP-Haskell0
8 files changed, 112 insertions, 26 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java
index 80f52f914..5d281d5b0 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java
@@ -57,11 +57,13 @@ public class EmailKeyHelper {
}
}
- // Most users don't have the SRV record, so ask a default server as well
- String[] servers = Preferences.getPreferences(context).getKeyServers();
- if (servers != null && servers.length != 0) {
- HkpKeyserver hkp = new HkpKeyserver(servers[0]);
- keys.addAll(getEmailKeys(mail, hkp));
+ if (keys.isEmpty()) {
+ // Most users don't have the SRV record, so ask a default server as well
+ String[] servers = Preferences.getPreferences(context).getKeyServers();
+ if (servers != null && servers.length != 0) {
+ HkpKeyserver hkp = new HkpKeyserver(servers[0]);
+ keys.addAll(getEmailKeys(mail, hkp));
+ }
}
return new ArrayList<ImportKeysListEntry>(keys);
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java
index df1a7e937..e49085a0e 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java
@@ -18,6 +18,10 @@
package org.sufficientlysecure.keychain.keyimport;
+import de.measite.minidns.Client;
+import de.measite.minidns.Question;
+import de.measite.minidns.Record;
+import de.measite.minidns.record.SRV;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
@@ -33,10 +37,6 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.util.Log;
-import org.xbill.DNS.Lookup;
-import org.xbill.DNS.Record;
-import org.xbill.DNS.SRVRecord;
-import org.xbill.DNS.Type;
import java.io.IOException;
import java.io.InputStream;
@@ -402,19 +402,20 @@ public class HkpKeyserver extends Keyserver {
*/
public static HkpKeyserver resolve(String domain) {
try {
- Record[] records = new Lookup("_hkp._tcp." + domain, Type.SRV).run();
+ Record[] records = new Client().query(new Question("_hkp._tcp." + domain, Record.TYPE.SRV)).getAnswers();
if (records.length > 0) {
Arrays.sort(records, new Comparator<Record>() {
@Override
public int compare(Record lhs, Record rhs) {
- if (!(lhs instanceof SRVRecord)) return 1;
- if (!(rhs instanceof SRVRecord)) return -1;
- return ((SRVRecord) lhs).getPriority() - ((SRVRecord) rhs).getPriority();
+ if (lhs.getPayload().getType() != Record.TYPE.SRV) return 1;
+ if (rhs.getPayload().getType() != Record.TYPE.SRV) return -1;
+ return ((SRV) lhs.getPayload()).getPriority() - ((SRV) rhs.getPayload()).getPriority();
}
});
Record record = records[0]; // This is our best choice
- if (record instanceof SRVRecord) {
- return new HkpKeyserver(((SRVRecord) record).getTarget().toString(), (short) ((SRVRecord) record).getPort());
+ if (record.getPayload().getType() == Record.TYPE.SRV) {
+ return new HkpKeyserver(((SRV) record.getPayload()).getName(),
+ (short) ((SRV) record.getPayload()).getPort());
}
}
} catch (Exception ignored) {
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java
index d4bc6c541..a565f0707 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/KeyringTestingHelper.java
@@ -5,9 +5,10 @@ import android.content.Context;
import org.sufficientlysecure.keychain.pgp.NullProgressable;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
-import org.sufficientlysecure.keychain.remote.AppSettings;
import org.sufficientlysecure.keychain.service.OperationResults;
+import java.util.Collection;
+
/**
* Helper for tests of the Keyring import in ProviderHelper.
*/
@@ -19,13 +20,11 @@ public class KeyringTestingHelper {
this.context = robolectricContext;
}
- public boolean addKeyring() throws Exception {
+ public boolean addKeyring(Collection<String> blobFiles) throws Exception {
ProviderHelper providerHelper = new ProviderHelper(context);
-// providerHelper.insertApiApp(new AppSettings("robo-test-package", new byte[]{5, 4, 3, 2, 1}));
-
- byte[] data = TestDataUtil.readFully(getClass().getResourceAsStream("/public-key-for-sample.blob"));
+ byte[] data = TestDataUtil.readAllFully(blobFiles);
UncachedKeyRing ring = UncachedKeyRing.decodeFromData(data);
long masterKeyId = ring.getMasterKeyId();
@@ -45,6 +44,7 @@ public class KeyringTestingHelper {
return saveSuccess;
}
+
private void retrieveKeyAndExpectNotFound(ProviderHelper providerHelper, long masterKeyId) {
try {
providerHelper.getWrappedPublicKeyRing(masterKeyId);
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/TestDataUtil.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/TestDataUtil.java
index 06dc08eab..9e6ede761 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/TestDataUtil.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/testsupport/TestDataUtil.java
@@ -3,6 +3,7 @@ package org.sufficientlysecure.keychain.testsupport;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Collection;
/**
* Misc support functions. Would just use Guava / Apache Commons but
@@ -10,9 +11,14 @@ import java.io.InputStream;
*/
public class TestDataUtil {
public static byte[] readFully(InputStream input) {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ appendToOutput(input, output);
+ return output.toByteArray();
+ }
+
+ private static void appendToOutput(InputStream input, ByteArrayOutputStream output) {
byte[] buffer = new byte[8192];
int bytesRead;
- ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
while ((bytesRead = input.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
@@ -20,6 +26,19 @@ public class TestDataUtil {
} catch (IOException e) {
throw new RuntimeException(e);
}
+ }
+
+ public static byte[] readAllFully(Collection<String> inputResources) {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+
+ for (String inputResource : inputResources) {
+ appendToOutput(getResourceAsStream(inputResource), output);
+ }
return output.toByteArray();
}
+
+
+ public static InputStream getResourceAsStream(String resourceName) {
+ return TestDataUtil.class.getResourceAsStream(resourceName);
+ }
}
diff --git a/OpenKeychain/src/main/res/layout/import_keys_activity.xml b/OpenKeychain/src/main/res/layout/import_keys_activity.xml
index fc9d21e23..b076debfe 100644
--- a/OpenKeychain/src/main/res/layout/import_keys_activity.xml
+++ b/OpenKeychain/src/main/res/layout/import_keys_activity.xml
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/content_frame"
- android:layout_marginLeft="@dimen/drawer_content_padding"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml
index e24ac6925..a6b16a421 100644
--- a/OpenKeychain/src/main/res/values/strings.xml
+++ b/OpenKeychain/src/main/res/values/strings.xml
@@ -10,7 +10,7 @@
<string name="title_create_key">Create Key</string>
<string name="title_edit_key">Edit Key</string>
<string name="title_preferences">Preferences</string>
- <string name="title_api_registered_apps">Registered Applications</string>
+ <string name="title_api_registered_apps">Apps</string>
<string name="title_key_server_preference">Keyserver Preference</string>
<string name="title_change_passphrase">Change Passphrase</string>
<string name="title_set_passphrase">Set Passphrase</string>
@@ -476,7 +476,7 @@
<string name="nav_encrypt">Sign and Encrypt</string>
<string name="nav_decrypt">Decrypt and Verify</string>
<string name="nav_import">Import Keys</string>
- <string name="nav_apps">Registered Apps</string>
+ <string name="nav_apps">Apps</string>
<string name="drawer_open">Open navigation drawer</string>
<string name="drawer_close">Close navigation drawer</string>
<string name="edit">Edit</string>
diff --git a/OpenKeychain/src/test/java/tests/ProviderHelperKeyringTest.java b/OpenKeychain/src/test/java/tests/ProviderHelperKeyringTest.java
index 265e01170..3d48c2f97 100644
--- a/OpenKeychain/src/test/java/tests/ProviderHelperKeyringTest.java
+++ b/OpenKeychain/src/test/java/tests/ProviderHelperKeyringTest.java
@@ -1,5 +1,10 @@
package tests;
+import java.util.Collections;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.ArrayList;
+
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -14,7 +19,68 @@ public class ProviderHelperKeyringTest {
@Test
public void testSavePublicKeyring() throws Exception {
- Assert.assertTrue(new KeyringTestingHelper(Robolectric.application).addKeyring());
+ Assert.assertTrue(new KeyringTestingHelper(Robolectric.application).addKeyring(Collections.singleton(
+ "/public-key-for-sample.blob"
+ )));
+ }
+
+ @Test
+ public void testSavePublicKeyringRsa() throws Exception {
+ Assert.assertTrue(new KeyringTestingHelper(Robolectric.application).addKeyring(prependResourcePath(Arrays.asList(
+ "000001-006.public_key",
+ "000002-013.user_id",
+ "000003-002.sig",
+ "000004-012.ring_trust",
+ "000005-002.sig",
+ "000006-012.ring_trust",
+ "000007-002.sig",
+ "000008-012.ring_trust",
+ "000009-002.sig",
+ "000010-012.ring_trust",
+ "000011-002.sig",
+ "000012-012.ring_trust",
+ "000013-014.public_subkey",
+ "000014-002.sig",
+ "000015-012.ring_trust"
+ ))));
}
+ @Test
+ public void testSavePublicKeyringDsa() throws Exception {
+ Assert.assertTrue(new KeyringTestingHelper(Robolectric.application).addKeyring(prependResourcePath(Arrays.asList(
+ "000016-006.public_key",
+ "000017-002.sig",
+ "000018-012.ring_trust",
+ "000019-013.user_id",
+ "000020-002.sig",
+ "000021-012.ring_trust",
+ "000022-002.sig",
+ "000023-012.ring_trust",
+ "000024-014.public_subkey",
+ "000025-002.sig",
+ "000026-012.ring_trust"
+ ))));
+ }
+
+ @Test
+ public void testSavePublicKeyringDsa2() throws Exception {
+ Assert.assertTrue(new KeyringTestingHelper(Robolectric.application).addKeyring(prependResourcePath(Arrays.asList(
+ "000027-006.public_key",
+ "000028-002.sig",
+ "000029-012.ring_trust",
+ "000030-013.user_id",
+ "000031-002.sig",
+ "000032-012.ring_trust",
+ "000033-002.sig",
+ "000034-012.ring_trust"
+ ))));
+ }
+
+ private static Collection<String> prependResourcePath(Collection<String> files) {
+ Collection<String> prependedFiles = new ArrayList<String>();
+ for (String file: files) {
+ prependedFiles.add("/extern/OpenPGP-Haskell/tests/data/" + file);
+ }
+ return prependedFiles;
+ }
}
diff --git a/OpenKeychain/src/test/resources/extern/OpenPGP-Haskell b/OpenKeychain/src/test/resources/extern/OpenPGP-Haskell
new file mode 160000
+Subproject eba7e4fdce3de6622b4ec3862b405b0acd01637