Show import key dialog when clicking on WKD URL
This change extends WKD support for direct Web Key Directory URLs similarily to Facebook key URLs and HKP URLs. When a link with scheme `https` and path starting with `/.well-known/openpgpkey/hu/` is clicked Android will suggest importing the key with OpenKeychain. Fixes #2270.
This commit is contained in:
@@ -719,6 +719,21 @@
|
|||||||
<data android:pathPattern="/..*/publickey/download" />
|
<data android:pathPattern="/..*/publickey/download" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<!-- VIEW from Web Key Directory urls opened in a browser -->
|
||||||
|
<intent-filter android:label="@string/intent_import_key">
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|
||||||
|
<data android:scheme="https" />
|
||||||
|
|
||||||
|
<!-- if we don't specify a host, pathPattern will be ignored-->
|
||||||
|
<data android:host="*" />
|
||||||
|
|
||||||
|
<data android:pathPattern="/.well-known/openpgpkey/hu/.*" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
<!-- IMPORT_KEY with files TODO: does this work? -->
|
<!-- IMPORT_KEY with files TODO: does this work? -->
|
||||||
<intent-filter android:label="@string/intent_import_key">
|
<intent-filter android:label="@string/intent_import_key">
|
||||||
<action android:name="org.sufficientlysecure.keychain.action.IMPORT_KEY" />
|
<action android:name="org.sufficientlysecure.keychain.action.IMPORT_KEY" />
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
|||||||
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER = Constants.IMPORT_KEY_FROM_KEYSERVER;
|
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER = Constants.IMPORT_KEY_FROM_KEYSERVER;
|
||||||
public static final String ACTION_IMPORT_KEY_FROM_FACEBOOK
|
public static final String ACTION_IMPORT_KEY_FROM_FACEBOOK
|
||||||
= Constants.INTENT_PREFIX + "IMPORT_KEY_FROM_FACEBOOK";
|
= Constants.INTENT_PREFIX + "IMPORT_KEY_FROM_FACEBOOK";
|
||||||
|
public static final String ACTION_IMPORT_KEY_FROM_WEB_KEY_DIRECTORY
|
||||||
|
= Constants.INTENT_PREFIX + "ACTION_IMPORT_KEY_FROM_WEB_KEY_DIRECTORY";
|
||||||
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT =
|
public static final String ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT =
|
||||||
Constants.INTENT_PREFIX + "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN_RESULT";
|
Constants.INTENT_PREFIX + "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN_RESULT";
|
||||||
public static final String ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN = Constants.INTENT_PREFIX
|
public static final String ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN = Constants.INTENT_PREFIX
|
||||||
@@ -121,6 +123,8 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
|||||||
if (Intent.ACTION_VIEW.equals(action)) {
|
if (Intent.ACTION_VIEW.equals(action)) {
|
||||||
if (FacebookKeyserverClient.isFacebookHost(dataUri)) {
|
if (FacebookKeyserverClient.isFacebookHost(dataUri)) {
|
||||||
action = ACTION_IMPORT_KEY_FROM_FACEBOOK;
|
action = ACTION_IMPORT_KEY_FROM_FACEBOOK;
|
||||||
|
} else if ("https".equalsIgnoreCase(scheme) || dataUri.getPath().startsWith("/.well-known/openpgpkey/hu/")) {
|
||||||
|
action = ACTION_IMPORT_KEY_FROM_WEB_KEY_DIRECTORY;
|
||||||
} else if ("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme)) {
|
} else if ("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme)) {
|
||||||
action = ACTION_SEARCH_KEYSERVER_FROM_URL;
|
action = ACTION_SEARCH_KEYSERVER_FROM_URL;
|
||||||
} else if ("openpgp4fpr".equalsIgnoreCase(scheme)) {
|
} else if ("openpgp4fpr".equalsIgnoreCase(scheme)) {
|
||||||
@@ -208,6 +212,13 @@ public class ImportKeysActivity extends BaseActivity implements ImportKeysListen
|
|||||||
startListFragment(null, null, fbUsername, cloudSearchPrefs);
|
startListFragment(null, null, fbUsername, cloudSearchPrefs);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ACTION_IMPORT_KEY_FROM_WEB_KEY_DIRECTORY: {
|
||||||
|
Preferences.CloudSearchPrefs cloudSearchPrefs =
|
||||||
|
new Preferences.CloudSearchPrefs(false, false, false, true, null);
|
||||||
|
// search immediately
|
||||||
|
startListFragment(null, null, dataUri.toString(), cloudSearchPrefs);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ACTION_SEARCH_KEYSERVER_FROM_URL: {
|
case ACTION_SEARCH_KEYSERVER_FROM_URL: {
|
||||||
// get keyserver from URL
|
// get keyserver from URL
|
||||||
HkpKeyserverAddress keyserver = HkpKeyserverAddress.createFromUri(
|
HkpKeyserverAddress keyserver = HkpKeyserverAddress.createFromUri(
|
||||||
|
|||||||
@@ -24,6 +24,18 @@ public class WebKeyDirectoryUtil {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static URL toWebKeyDirectoryURL(String name) {
|
public static URL toWebKeyDirectoryURL(String name) {
|
||||||
|
if (name == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.startsWith("https://") && name.contains("/.well-known/openpgpkey/hu/")) {
|
||||||
|
try {
|
||||||
|
return new URL(name);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Matcher matcher = EMAIL_PATTERN.matcher(name);
|
Matcher matcher = EMAIL_PATTERN.matcher(name);
|
||||||
|
|
||||||
if (!matcher.matches()) {
|
if (!matcher.matches()) {
|
||||||
|
|||||||
@@ -27,4 +27,13 @@ public class WebKeyDirectoryUtilTest {
|
|||||||
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWkdDirectUrl() {
|
||||||
|
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("https://openkeychain.org/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1");
|
||||||
|
assertNotNull(url);
|
||||||
|
assertEquals("openkeychain.org", url.getHost());
|
||||||
|
assertEquals("https", url.getProtocol());
|
||||||
|
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user