From 01aadf6a1fef5be78193a560d988137a9b0d17ce Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Thu, 10 May 2018 15:22:09 +0200 Subject: [PATCH] Extend QR scanner to support VCards with KEY field Currently QR scanner supports only `openpgp4fpr` URIs. VCard specification allows embedding public key information as an URI in `KEY` field [0]. Two schemes used with this field - `https` and `data` are either insecure or not practical [1]. As the value of `KEY` field is a URI one can use `openpgp4fpr` URI there to have both secure and small links. This change will extract URI from `KEY` field from a scanned VCard and process it just like it would be a URI scanned directly. When a `openpgp4fpr` URI is put there the UI would search and import the key and show the confirm dialog. Example VCard with this URI: BEGIN:VCARD FN:Test WKD EMAIL:test-wkd@metacode.biz KEY:OPENPGP4FPR:74EC8D3DA82A79DAA25DF10C6BA55ED83ABAE1BB END:VCARD [0]: https://tools.ietf.org/html/rfc6350#section-6.8.1 [1]: https://www.av8n.com/computer/htm/distributing-keys.htm#sec-fing --- .../keychain/ui/ImportKeysProxyActivity.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java index 0eb74f8a5..1fd172191 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysProxyActivity.java @@ -49,6 +49,8 @@ import org.sufficientlysecure.keychain.util.Preferences; import java.util.ArrayList; import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Proxy activity (just a transparent content view) to scan QR Codes using the Barcode Scanner app @@ -134,7 +136,16 @@ public class ImportKeysProxyActivity extends FragmentActivity } } + private static final Pattern VCARD_KEY_PATTERN = Pattern.compile("\nKEY:(.*)\n"); + private void processScannedContent(String content) { + // if a VCard was scanned try to extract the KEY field + if (content.startsWith("BEGIN:VCARD")) { + Matcher matcher = VCARD_KEY_PATTERN.matcher(content); + if (matcher.find()) { + content = matcher.group(1); + } + } Uri uri = Uri.parse(content); processScannedContent(uri); }