Adding support for WKD Advanced method

This change extends the WKD support with Advanced mode stated in
RFC Draft: draft-koch-openpgp-webkey-service-08 section 3.1
This commit is contained in:
Anders Lindén
2019-09-28 21:59:26 +02:00
parent b35292f107
commit ff4c6684e1
3 changed files with 55 additions and 9 deletions

View File

@@ -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,

View File

@@ -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) {