commit
d44cb1dc24
|
@ -55,7 +55,7 @@ public class WebKeyDirectoryClient implements KeyserverClient {
|
|||
@Override
|
||||
public List<ImportKeysListEntry> search(String name, ParcelableProxy proxy)
|
||||
throws QueryFailedException {
|
||||
URL webKeyDirectoryURL = WebKeyDirectoryUtil.toWebKeyDirectoryURL(name);
|
||||
URL webKeyDirectoryURL = WebKeyDirectoryUtil.toWebKeyDirectoryURL(name, true);
|
||||
|
||||
if (webKeyDirectoryURL == null) {
|
||||
Timber.d("Name not supported by Web Key Directory Client: " + name);
|
||||
|
@ -64,11 +64,22 @@ public class WebKeyDirectoryClient implements KeyserverClient {
|
|||
|
||||
Timber.d("Web Key Directory import: " + name + " using Proxy: " + proxy.getProxy());
|
||||
|
||||
Timber.d("Query Web Key Directory Advanced method for: " + name);
|
||||
byte[] data = query(webKeyDirectoryURL, proxy.getProxy());
|
||||
|
||||
if (data == null) {
|
||||
Timber.d("No Web Key Directory endpoint for: " + name);
|
||||
return Collections.emptyList();
|
||||
// Retry with direct mode
|
||||
URL webKeyDirectoryURLDirect = WebKeyDirectoryUtil.toWebKeyDirectoryURL(name, false);
|
||||
|
||||
Timber.d("Query Web Key Directory fallback Direct method for: " + name);
|
||||
byte[] dataDirect = query(webKeyDirectoryURLDirect, proxy.getProxy());
|
||||
|
||||
if (dataDirect == null) {
|
||||
Timber.d("No Web Key Directory endpoint for: " + name);
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
data = dataDirect;
|
||||
}
|
||||
}
|
||||
|
||||
// if we're here that means key retrieval succeeded,
|
||||
|
|
|
@ -23,12 +23,12 @@ public class WebKeyDirectoryUtil {
|
|||
* @see <a href="https://tools.ietf.org/html/draft-koch-openpgp-webkey-service-05#section-3.1">Key Discovery</a>
|
||||
*/
|
||||
@Nullable
|
||||
public static URL toWebKeyDirectoryURL(String name) {
|
||||
public static URL toWebKeyDirectoryURL(String name, Boolean wkdMethodAdvanced) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name.startsWith("https://") && name.contains("/.well-known/openpgpkey/hu/")) {
|
||||
if (name.startsWith("https://") && name.contains("/.well-known/openpgpkey/")) {
|
||||
try {
|
||||
return new URL(name);
|
||||
} catch (MalformedURLException e) {
|
||||
|
@ -47,10 +47,18 @@ public class WebKeyDirectoryUtil {
|
|||
String domain = matcher.group(2);
|
||||
|
||||
try {
|
||||
return new URL("https://" + domain + "/.well-known/openpgpkey/hu/" + encodedPart);
|
||||
|
||||
if(wkdMethodAdvanced) {
|
||||
// Advanced method
|
||||
return new URL("https://openpgpkey." + domain + "/.well-known/openpgpkey/" + domain + "/hu/" + encodedPart);
|
||||
}else{
|
||||
// Direct method
|
||||
return new URL("https://" + domain + "/.well-known/openpgpkey/hu/" + encodedPart);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static byte[] toSHA1(byte[] input) {
|
||||
|
|
|
@ -11,29 +11,56 @@ public class WebKeyDirectoryUtilTest {
|
|||
|
||||
@Test
|
||||
public void testWkd() {
|
||||
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("test-wkd@openkeychain.org");
|
||||
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("test-wkd@openkeychain.org", false);
|
||||
assertNotNull(url);
|
||||
assertEquals("openkeychain.org", url.getHost());
|
||||
assertEquals("https", url.getProtocol());
|
||||
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdvancedWkd() {
|
||||
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("test-wkd@openkeychain.org", true);
|
||||
assertNotNull(url);
|
||||
assertEquals("openpgpkey.openkeychain.org", url.getHost());
|
||||
assertEquals("https", url.getProtocol());
|
||||
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWkdWithSpaces() {
|
||||
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL(" test-wkd@openkeychain.org ");
|
||||
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL(" test-wkd@openkeychain.org ", false);
|
||||
assertNotNull(url);
|
||||
assertEquals("openkeychain.org", url.getHost());
|
||||
assertEquals("https", url.getProtocol());
|
||||
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWkdAdvancedWithSpaces() {
|
||||
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL(" test-wkd@openkeychain.org ", true);
|
||||
assertNotNull(url);
|
||||
assertEquals("openpgpkey.openkeychain.org", url.getHost());
|
||||
assertEquals("https", url.getProtocol());
|
||||
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWkdDirectUrl() {
|
||||
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("https://openkeychain.org/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1");
|
||||
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("https://openkeychain.org/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", false);
|
||||
assertNotNull(url);
|
||||
assertEquals("openkeychain.org", url.getHost());
|
||||
assertEquals("https", url.getProtocol());
|
||||
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWkdAdvancedURL() {
|
||||
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("https://openpgpkey.openkeychain.org/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", false);
|
||||
assertNotNull(url);
|
||||
assertEquals("openpgpkey.openkeychain.org", url.getHost());
|
||||
assertEquals("https", url.getProtocol());
|
||||
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue