Merge pull request #2529 from eehakkin/feature/add-query-parameter-to-wkd-urls
Add query parameter to WKD URLs
This commit is contained in:
commit
46a25451ba
|
@ -2,8 +2,10 @@ package org.sufficientlysecure.keychain.util;
|
||||||
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -50,13 +52,15 @@ public class WebKeyDirectoryUtil {
|
||||||
|
|
||||||
if(wkdMethodAdvanced) {
|
if(wkdMethodAdvanced) {
|
||||||
// Advanced method
|
// 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{
|
}else{
|
||||||
// Direct method
|
// 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) {
|
} catch (MalformedURLException e) {
|
||||||
return null;
|
return null;
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ public class WebKeyDirectoryUtilTest {
|
||||||
assertEquals("openkeychain.org", url.getHost());
|
assertEquals("openkeychain.org", url.getHost());
|
||||||
assertEquals("https", url.getProtocol());
|
assertEquals("https", url.getProtocol());
|
||||||
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||||
|
assertEquals("l=test-wkd", url.getQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -25,6 +26,7 @@ public class WebKeyDirectoryUtilTest {
|
||||||
assertEquals("openpgpkey.openkeychain.org", url.getHost());
|
assertEquals("openpgpkey.openkeychain.org", url.getHost());
|
||||||
assertEquals("https", url.getProtocol());
|
assertEquals("https", url.getProtocol());
|
||||||
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||||
|
assertEquals("l=test-wkd", url.getQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -34,6 +36,7 @@ public class WebKeyDirectoryUtilTest {
|
||||||
assertEquals("openkeychain.org", url.getHost());
|
assertEquals("openkeychain.org", url.getHost());
|
||||||
assertEquals("https", url.getProtocol());
|
assertEquals("https", url.getProtocol());
|
||||||
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||||
|
assertEquals("l=test-wkd", url.getQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -43,24 +46,47 @@ public class WebKeyDirectoryUtilTest {
|
||||||
assertEquals("openpgpkey.openkeychain.org", url.getHost());
|
assertEquals("openpgpkey.openkeychain.org", url.getHost());
|
||||||
assertEquals("https", url.getProtocol());
|
assertEquals("https", url.getProtocol());
|
||||||
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
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
|
@Test
|
||||||
public void testWkdDirectUrl() {
|
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);
|
assertNotNull(url);
|
||||||
assertEquals("openkeychain.org", url.getHost());
|
assertEquals("openkeychain.org", url.getHost());
|
||||||
assertEquals("https", url.getProtocol());
|
assertEquals("https", url.getProtocol());
|
||||||
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||||
|
assertEquals("l=test-wkd", url.getQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWkdAdvancedURL() {
|
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);
|
assertNotNull(url);
|
||||||
assertEquals("openpgpkey.openkeychain.org", url.getHost());
|
assertEquals("openpgpkey.openkeychain.org", url.getHost());
|
||||||
assertEquals("https", url.getProtocol());
|
assertEquals("https", url.getProtocol());
|
||||||
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
assertEquals("/.well-known/openpgpkey/openkeychain.org/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||||
|
assertEquals("l=test-wkd", url.getQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue