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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user