Add query parameter to WKD URLs

This change adds the l=LOCAL-PART query parameter to WKD URLs as
specified in RFC Draft: draft-koch-openpgp-webkey-service-09 section 3.1
since version 07.
This commit is contained in:
Eero Häkkinen 2020-02-17 00:11:24 +02:00
parent 2f0c1415b4
commit e901322ea3
2 changed files with 34 additions and 4 deletions

View file

@ -2,8 +2,10 @@ package org.sufficientlysecure.keychain.util;
import android.support.annotation.Nullable;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
@ -50,13 +52,15 @@ public class WebKeyDirectoryUtil {
if(wkdMethodAdvanced) {
// Advanced method
return new URL("https://openpgpkey." + domain + "/.well-known/openpgpkey/" + domain + "/hu/" + encodedPart);
return new URL("https://openpgpkey." + domain + "/.well-known/openpgpkey/" + domain + "/hu/" + encodedPart + "?l=" + URLEncoder.encode(localPart, "UTF-8"));
}else{
// Direct method
return new URL("https://" + domain + "/.well-known/openpgpkey/hu/" + encodedPart);
return new URL("https://" + domain + "/.well-known/openpgpkey/hu/" + encodedPart + "?l=" + URLEncoder.encode(localPart, "UTF-8"));
}
} catch (MalformedURLException e) {
return null;
} catch (UnsupportedEncodingException e) {
return null;
}
}

View file

@ -16,6 +16,7 @@ public class WebKeyDirectoryUtilTest {
assertEquals("openkeychain.org", url.getHost());
assertEquals("https", url.getProtocol());
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
assertEquals("l=test-wkd", url.getQuery());
}
@Test
@ -25,6 +26,7 @@ public class WebKeyDirectoryUtilTest {
assertEquals("openpgpkey.openkeychain.org", url.getHost());
assertEquals("https", url.getProtocol());
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
assertEquals("l=test-wkd", url.getQuery());
}
@Test
@ -34,6 +36,7 @@ public class WebKeyDirectoryUtilTest {
assertEquals("openkeychain.org", url.getHost());
assertEquals("https", url.getProtocol());
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
assertEquals("l=test-wkd", url.getQuery());
}
@Test
@ -43,24 +46,47 @@ public class WebKeyDirectoryUtilTest {
assertEquals("openpgpkey.openkeychain.org", url.getHost());
assertEquals("https", url.getProtocol());
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
assertEquals("l=test-wkd", url.getQuery());
}
@Test
public void testWkdWithUnicode() {
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("test\u2013wkd@openkeychain.org", false);
assertNotNull(url);
assertEquals("openkeychain.org", url.getHost());
assertEquals("https", url.getProtocol());
assertEquals("/.well-known/openpgpkey/hu/nb7e5p4jhz3i3micncnfy5dfkp1ug53i", url.getPath());
assertEquals("l=test%E2%80%93wkd", url.getQuery());
}
@Test
public void testWkdAdvancedWithUnicode() {
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("test\u2013wkd@openkeychain.org", true);
assertNotNull(url);
assertEquals("openpgpkey.openkeychain.org", url.getHost());
assertEquals("https", url.getProtocol());
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/nb7e5p4jhz3i3micncnfy5dfkp1ug53i", url.getPath());
assertEquals("l=test%E2%80%93wkd", url.getQuery());
}
@Test
public void testWkdDirectUrl() {
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("https://openkeychain.org/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", false);
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("https://openkeychain.org/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1?l=test-wkd", false);
assertNotNull(url);
assertEquals("openkeychain.org", url.getHost());
assertEquals("https", url.getProtocol());
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
assertEquals("l=test-wkd", url.getQuery());
}
@Test
public void testWkdAdvancedURL() {
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("https://openpgpkey.openkeychain.org/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", false);
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("https://openpgpkey.openkeychain.org/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1?l=test-wkd", false);
assertNotNull(url);
assertEquals("openpgpkey.openkeychain.org", url.getHost());
assertEquals("https", url.getProtocol());
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
assertEquals("l=test-wkd", url.getQuery());
}
}