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
This commit is contained in:
Wiktor Kwapisiewicz
2018-05-10 15:22:09 +02:00
parent f2cda5dd6c
commit 01aadf6a1f

View File

@@ -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);
}