diff --git a/.gitmodules b/.gitmodules
index 572293f94..a549f6cec 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -25,3 +25,9 @@
[submodule "extern/openkeychain-api-lib"]
path = extern/openkeychain-api-lib
url = https://github.com/open-keychain/openkeychain-api-lib.git
+[submodule "extern/SuperToasts"]
+ path = extern/SuperToasts
+ url = https://github.com/open-keychain/SuperToasts.git
+[submodule "extern/dnsjava"]
+ path = extern/dnsjava
+ url = https://github.com/open-keychain/dnsjava.git
diff --git a/.travis.yml b/.travis.yml
index df700368c..36e8f8fcf 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,13 +4,13 @@ before_install:
# Install base Android SDK
- sudo apt-get update -qq
- if [ `uname -m` = x86_64 ]; then sudo apt-get install -qq --force-yes libgd2-xpm lib32z1 lib32stdc++6; fi
- - wget http://dl.google.com/android/android-sdk_r22.3-linux.tgz
- - tar xzf android-sdk_r22.3-linux.tgz
+ - wget http://dl.google.com/android/android-sdk_r22.6.2-linux.tgz
+ - tar xzf android-sdk_r22.6.2-linux.tgz
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
# Install required Android components.
- - echo "y" | android update sdk -a --filter build-tools-19.0.3,android-19,platform-tools,extra-android-support,extra-android-m2repository --no-ui --force
+ - echo "y" | android update sdk -a --filter build-tools-19.1.0,android-19,platform-tools,extra-android-support,extra-android-m2repository --no-ui --force
install: echo "Installation done"
script: gradle assemble -S -q
diff --git a/OpenKeychain/build.gradle b/OpenKeychain/build.gradle
index c8ef7b418..32b60e915 100644
--- a/OpenKeychain/build.gradle
+++ b/OpenKeychain/build.gradle
@@ -1,12 +1,12 @@
apply plugin: 'android'
-apply plugin: 'android-test'
+//apply plugin: 'android-test'
sourceSets {
- androidTest {
- java.srcDir file('src/test/java')
+ //androidTest {
+ //java.srcDir file('src/test/java')
// configure the set of classes for JUnit tests
// include '**/*Test.class'
- }
+ //}
}
dependencies {
@@ -26,6 +26,8 @@ dependencies {
compile project(':extern:spongycastle:pkix')
compile project(':extern:spongycastle:prov')
compile project(':extern:AppMsg:library')
+ compile project(':extern:SuperToasts:supertoasts')
+ compile project(':extern:dnsjava')
// Dependencies for the `instrumentTest` task, make sure to list all your global dependencies here as well
androidTestCompile 'junit:junit:4.10'
@@ -46,11 +48,13 @@ dependencies {
androidTestCompile project(':extern:spongycastle:pkix')
androidTestCompile project(':extern:spongycastle:prov')
androidTestCompile project(':extern:AppMsg:library')
+ androidTestCompile project(':extern:SuperToasts:supertoasts')
+
}
android {
compileSdkVersion 19
- buildToolsVersion "19.0.3"
+ buildToolsVersion "19.1"
defaultConfig {
minSdkVersion 9
diff --git a/OpenKeychain/src/main/AndroidManifest.xml b/OpenKeychain/src/main/AndroidManifest.xml
index f4007c098..b3a4d5960 100644
--- a/OpenKeychain/src/main/AndroidManifest.xml
+++ b/OpenKeychain/src/main/AndroidManifest.xml
@@ -53,6 +53,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java
index 0fd109484..c769da421 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java
@@ -46,6 +46,8 @@ public final class Constants {
public static final String INTENT_PREFIX = PACKAGE_NAME + ".action.";
+ public static final String CUSTOM_CONTACT_DATA_MIME_TYPE = "vnd.android.cursor.item/vnd.org.sufficientlysecure.keychain.key";
+
public static final class Path {
public static final String APP_DIR = Environment.getExternalStorageDirectory()
+ "/OpenKeychain";
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java
index f911318a0..5d6a62f9c 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java
@@ -17,6 +17,8 @@
package org.sufficientlysecure.keychain;
+import android.accounts.Account;
+import android.accounts.AccountManager;
import android.app.Application;
import android.content.Context;
import android.graphics.PorterDuff;
@@ -24,6 +26,7 @@ import android.graphics.drawable.Drawable;
import android.os.Environment;
import org.spongycastle.jce.provider.BouncyCastleProvider;
+import org.sufficientlysecure.keychain.helper.ContactHelper;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.PRNGFixes;
@@ -76,6 +79,17 @@ public class KeychainApplication extends Application {
brandGlowEffect(getApplicationContext(),
getApplicationContext().getResources().getColor(R.color.emphasis));
+
+ setupAccountAsNeeded(this);
+ }
+
+ public static void setupAccountAsNeeded(Context context) {
+ AccountManager manager = AccountManager.get(context);
+ Account[] accounts = manager.getAccountsByType(Constants.PACKAGE_NAME);
+ if (accounts == null || accounts.length == 0) {
+ Account dummy = new Account(context.getString(R.string.app_name), Constants.PACKAGE_NAME);
+ manager.addAccountExplicitly(dummy, null, null);
+ }
}
static void brandGlowEffect(Context context, int brandColor) {
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java
index a92ea5408..f50ccf6f8 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/ContactHelper.java
@@ -19,8 +19,18 @@ package org.sufficientlysecure.keychain.helper;
import android.accounts.Account;
import android.accounts.AccountManager;
-import android.content.Context;
+import android.content.*;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.RemoteException;
+import android.provider.ContactsContract;
import android.util.Patterns;
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.pgp.KeyRing;
+import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
+import org.sufficientlysecure.keychain.provider.KeychainContract;
+import org.sufficientlysecure.keychain.util.Log;
import java.util.ArrayList;
import java.util.HashSet;
@@ -29,6 +39,15 @@ import java.util.Set;
public class ContactHelper {
+ public static final String[] KEYS_TO_CONTACT_PROJECTION = new String[]{
+ KeychainContract.KeyRings.USER_ID,
+ KeychainContract.KeyRings.FINGERPRINT,
+ KeychainContract.KeyRings.KEY_ID,
+ KeychainContract.KeyRings.MASTER_KEY_ID};
+ public static final String[] RAW_CONTACT_ID_PROJECTION = new String[]{ContactsContract.RawContacts._ID};
+ public static final String FIND_RAW_CONTACT_SELECTION =
+ ContactsContract.RawContacts.ACCOUNT_TYPE + "=? AND " + ContactsContract.RawContacts.SOURCE_ID + "=?";
+
public static final List getMailAccounts(Context context) {
final Account[] accounts = AccountManager.get(context).getAccounts();
final Set emailSet = new HashSet();
@@ -39,4 +58,92 @@ public class ContactHelper {
}
return new ArrayList(emailSet);
}
+
+ public static List getContactMails(Context context) {
+ ContentResolver resolver = context.getContentResolver();
+ Cursor mailCursor = resolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
+ new String[]{ContactsContract.CommonDataKinds.Email.DATA},
+ null, null, null);
+ if (mailCursor == null) return null;
+
+ Set mails = new HashSet();
+ while (mailCursor.moveToNext()) {
+ String email = mailCursor.getString(0);
+ if (email != null) {
+ mails.add(email);
+ }
+ }
+ mailCursor.close();
+ return new ArrayList(mails);
+ }
+
+ public static Uri dataUriFromContactUri(Context context, Uri contactUri) {
+ Cursor contactMasterKey = context.getContentResolver().query(contactUri, new String[]{ContactsContract.Data.DATA2}, null, null, null, null);
+ if (contactMasterKey != null) {
+ if (contactMasterKey.moveToNext()) {
+ return KeychainContract.KeyRings.buildGenericKeyRingUri(contactMasterKey.getLong(0));
+ }
+ contactMasterKey.close();
+ }
+ return null;
+ }
+
+ public static void writeKeysToContacts(Context context) {
+ ContentResolver resolver = context.getContentResolver();
+ Cursor cursor = resolver.query(KeychainContract.KeyRings.buildUnifiedKeyRingsUri(), KEYS_TO_CONTACT_PROJECTION,
+ null, null, null);
+ if (cursor != null) {
+ while (cursor.moveToNext()) {
+ String[] userId = KeyRing.splitUserId(cursor.getString(0));
+ String fingerprint = PgpKeyHelper.convertFingerprintToHex(cursor.getBlob(1));
+ String keyIdShort = PgpKeyHelper.convertKeyIdToHexShort(cursor.getLong(2));
+ long masterKeyId = cursor.getLong(3);
+ int rawContactId = -1;
+ Cursor raw = resolver.query(ContactsContract.RawContacts.CONTENT_URI, RAW_CONTACT_ID_PROJECTION,
+ FIND_RAW_CONTACT_SELECTION, new String[]{Constants.PACKAGE_NAME, fingerprint}, null, null);
+ if (raw != null) {
+ if (raw.moveToNext()) {
+ rawContactId = raw.getInt(0);
+ }
+ raw.close();
+ }
+ ArrayList ops = new ArrayList();
+ if (rawContactId == -1) {
+ ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
+ .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, context.getString(R.string.app_name))
+ .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, Constants.PACKAGE_NAME)
+ .withValue(ContactsContract.RawContacts.SOURCE_ID, fingerprint)
+ .build());
+ if (userId[0] != null) {
+ ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
+ .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
+ .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
+ .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, userId[0])
+ .build());
+ }
+ if (userId[1] != null) {
+ ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
+ .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
+ .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
+ .withValue(ContactsContract.CommonDataKinds.Email.DATA, userId[1])
+ .build());
+ }
+ ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
+ .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
+ .withValue(ContactsContract.Data.MIMETYPE, Constants.CUSTOM_CONTACT_DATA_MIME_TYPE)
+ .withValue(ContactsContract.Data.DATA1, String.format(context.getString(R.string.contact_show_key), keyIdShort))
+ .withValue(ContactsContract.Data.DATA2, masterKeyId)
+ .build());
+ }
+ try {
+ resolver.applyBatch(ContactsContract.AUTHORITY, ops);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ } catch (OperationApplicationException e) {
+ e.printStackTrace();
+ }
+ }
+ cursor.close();
+ }
+ }
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java
new file mode 100644
index 000000000..80f52f914
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.sufficientlysecure.keychain.helper;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Messenger;
+import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
+import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
+import org.sufficientlysecure.keychain.keyimport.Keyserver;
+import org.sufficientlysecure.keychain.service.KeychainIntentService;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class EmailKeyHelper {
+
+ public static void importContacts(Context context, Messenger messenger) {
+ importAll(context, messenger, ContactHelper.getContactMails(context));
+ }
+
+ public static void importAll(Context context, Messenger messenger, List mails) {
+ Set keys = new HashSet();
+ for (String mail : mails) {
+ keys.addAll(getEmailKeys(context, mail));
+ }
+ importKeys(context, messenger, new ArrayList(keys));
+ }
+
+ public static List getEmailKeys(Context context, String mail) {
+ Set keys = new HashSet();
+
+ // Try _hkp._tcp SRV record first
+ String[] mailparts = mail.split("@");
+ if (mailparts.length == 2) {
+ HkpKeyserver hkp = HkpKeyserver.resolve(mailparts[1]);
+ if (hkp != null) {
+ keys.addAll(getEmailKeys(mail, hkp));
+ }
+ }
+
+ // Most users don't have the SRV record, so ask a default server as well
+ String[] servers = Preferences.getPreferences(context).getKeyServers();
+ if (servers != null && servers.length != 0) {
+ HkpKeyserver hkp = new HkpKeyserver(servers[0]);
+ keys.addAll(getEmailKeys(mail, hkp));
+ }
+ return new ArrayList(keys);
+ }
+
+ private static void importKeys(Context context, Messenger messenger, List keys) {
+ Intent importIntent = new Intent(context, KeychainIntentService.class);
+ importIntent.setAction(KeychainIntentService.ACTION_DOWNLOAD_AND_IMPORT_KEYS);
+ Bundle importData = new Bundle();
+ importData.putParcelableArrayList(KeychainIntentService.DOWNLOAD_KEY_LIST,
+ new ArrayList(keys));
+ importIntent.putExtra(KeychainIntentService.EXTRA_DATA, importData);
+ importIntent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
+
+ context.startService(importIntent);
+ }
+
+ public static List getEmailKeys(String mail, Keyserver keyServer) {
+ Set keys = new HashSet();
+ try {
+ for (ImportKeysListEntry key : keyServer.search(mail)) {
+ if (key.isRevoked() || key.isExpired()) continue;
+ for (String userId : key.getUserIds()) {
+ if (userId.toLowerCase().contains(mail.toLowerCase())) {
+ keys.add(key);
+ }
+ }
+ }
+ } catch (Keyserver.QueryFailedException ignored) {
+ } catch (Keyserver.QueryNeedsRepairException ignored) {
+ }
+ return new ArrayList(keys);
+ }
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java
index 5969455bd..2ec9e1c07 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java
@@ -33,6 +33,10 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.util.Log;
+import org.xbill.DNS.Lookup;
+import org.xbill.DNS.Record;
+import org.xbill.DNS.SRVRecord;
+import org.xbill.DNS.Type;
import java.io.IOException;
import java.io.InputStream;
@@ -45,6 +49,8 @@ import java.net.URLDecoder;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
@@ -75,6 +81,7 @@ public class HkpKeyserver extends Keyserver {
private String mHost;
private short mPort;
+ private boolean mSecure;
/**
* pub:%keyid%:%algo%:%keylen%:%creationdate%:%expirationdate%:%flags%
@@ -109,7 +116,7 @@ public class HkpKeyserver extends Keyserver {
*/
public static final Pattern PUB_KEY_LINE = Pattern
.compile("pub:([0-9a-fA-F]+):([0-9]+):([0-9]+):([0-9]+):([0-9]*):([rde]*)[ \n\r]*" // pub line
- + "(uid:(.*):([0-9]+):([0-9]*):([rde]*))+", // one or more uid lines
+ + "((uid:([^:]*):([0-9]+):([0-9]*):([rde]*)[ \n\r]*)+)", // one or more uid lines
Pattern.CASE_INSENSITIVE);
/**
@@ -137,10 +144,11 @@ public class HkpKeyserver extends Keyserver {
*
*/
public static final Pattern UID_LINE = Pattern
- .compile("uid:(.*):([0-9]+):([0-9]*):([rde]*)",
+ .compile("uid:([^:]*):([0-9]+):([0-9]*):([rde]*)",
Pattern.CASE_INSENSITIVE);
private static final short PORT_DEFAULT = 11371;
+ private static final short PORT_DEFAULT_HKPS = 443;
/**
* @param hostAndPort may be just
@@ -151,31 +159,68 @@ public class HkpKeyserver extends Keyserver {
public HkpKeyserver(String hostAndPort) {
String host = hostAndPort;
short port = PORT_DEFAULT;
- final int colonPosition = hostAndPort.lastIndexOf(':');
- if (colonPosition > 0) {
- host = hostAndPort.substring(0, colonPosition);
- final String portStr = hostAndPort.substring(colonPosition + 1);
- port = Short.decode(portStr);
+ boolean secure = false;
+ String[] parts = hostAndPort.split(":");
+ if (parts.length > 1) {
+ if (!parts[0].contains(".")) { // This is not a domain or ip, so it must be a protocol name
+ if (parts[0].equalsIgnoreCase("hkps") || parts[0].equalsIgnoreCase("https")) {
+ secure = true;
+ port = PORT_DEFAULT_HKPS;
+ } else if (!parts[0].equalsIgnoreCase("hkp") && !parts[0].equalsIgnoreCase("http")) {
+ throw new IllegalArgumentException("Protocol " + parts[0] + " is unknown");
+ }
+ host = parts[1];
+ if (host.startsWith("//")) { // People tend to type https:// and hkps://, so we'll support that as well
+ host = host.substring(2);
+ }
+ if (parts.length > 2) {
+ port = Short.decode(parts[2]);
+ }
+ } else {
+ host = parts[0];
+ port = Short.decode(parts[1]);
+ }
}
mHost = host;
mPort = port;
+ mSecure = secure;
}
public HkpKeyserver(String host, short port) {
+ this(host, port, false);
+ }
+
+ public HkpKeyserver(String host, short port, boolean secure) {
mHost = host;
mPort = port;
+ mSecure = secure;
+ }
+
+ private String getUrlPrefix() {
+ return mSecure ? "https://" : "http://";
}
private String query(String request) throws QueryFailedException, HttpError {
- InetAddress ips[];
- try {
- ips = InetAddress.getAllByName(mHost);
- } catch (UnknownHostException e) {
- throw new QueryFailedException(e.toString());
- }
- for (int i = 0; i < ips.length; ++i) {
+ List urls = new ArrayList();
+ if (mSecure) {
+ urls.add(getUrlPrefix() + mHost + ":" + mPort + request);
+ } else {
+ InetAddress ips[];
+ try {
+ ips = InetAddress.getAllByName(mHost);
+ } catch (UnknownHostException e) {
+ throw new QueryFailedException(e.toString());
+ }
+ for (InetAddress ip : ips) {
+ // Note: This is actually not HTTP 1.1 compliant, as we hide the real "Host" value,
+ // but Android's HTTPUrlConnection does not support any other way to set
+ // Socket's remote IP address...
+ urls.add(getUrlPrefix() + ip.getHostAddress() + ":" + mPort + request);
+ }
+ }
+
+ for (String url : urls) {
try {
- String url = "http://" + ips[i].getHostAddress() + ":" + mPort + request;
Log.d(Constants.TAG, "hkp keyserver query: " + url);
URL realUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
@@ -238,6 +283,7 @@ public class HkpKeyserver extends Keyserver {
while (matcher.find()) {
final ImportKeysListEntry entry = new ImportKeysListEntry();
entry.setQuery(query);
+ entry.setOrigin(getUrlPrefix() + mHost + ":" + mPort);
entry.setBitStrength(Integer.parseInt(matcher.group(3)));
@@ -262,6 +308,7 @@ public class HkpKeyserver extends Keyserver {
entry.setDate(tmpGreg.getTime());
entry.setRevoked(matcher.group(6).contains("r"));
+ entry.setExpired(matcher.group(6).contains("e"));
ArrayList userIds = new ArrayList();
final String uidLines = matcher.group(7);
@@ -290,7 +337,7 @@ public class HkpKeyserver extends Keyserver {
public String get(String keyIdHex) throws QueryFailedException {
HttpClient client = new DefaultHttpClient();
try {
- String query = "http://" + mHost + ":" + mPort +
+ String query = getUrlPrefix() + mHost + ":" + mPort +
"/pks/lookup?op=get&options=mr&search=" + keyIdHex;
Log.d(Constants.TAG, "hkp keyserver get: " + query);
HttpGet get = new HttpGet(query);
@@ -319,7 +366,7 @@ public class HkpKeyserver extends Keyserver {
public void add(String armoredKey) throws AddKeyException {
HttpClient client = new DefaultHttpClient();
try {
- String query = "http://" + mHost + ":" + mPort + "/pks/add";
+ String query = getUrlPrefix() + mHost + ":" + mPort + "/pks/add";
HttpPost post = new HttpPost(query);
Log.d(Constants.TAG, "hkp keyserver add: " + query);
List nameValuePairs = new ArrayList(2);
@@ -336,4 +383,36 @@ public class HkpKeyserver extends Keyserver {
client.getConnectionManager().shutdown();
}
}
+
+ @Override
+ public String toString() {
+ return mHost + ":" + mPort;
+ }
+
+ /**
+ * Tries to find a server responsible for a given domain
+ *
+ * @return A responsible Keyserver or null if not found.
+ */
+ public static HkpKeyserver resolve(String domain) {
+ try {
+ Record[] records = new Lookup("_hkp._tcp." + domain, Type.SRV).run();
+ if (records.length > 0) {
+ Arrays.sort(records, new Comparator() {
+ @Override
+ public int compare(Record lhs, Record rhs) {
+ if (!(lhs instanceof SRVRecord)) return 1;
+ if (!(rhs instanceof SRVRecord)) return -1;
+ return ((SRVRecord) lhs).getPriority() - ((SRVRecord) rhs).getPriority();
+ }
+ });
+ Record record = records[0]; // This is our best choice
+ if (record instanceof SRVRecord) {
+ return new HkpKeyserver(((SRVRecord) record).getTarget().toString(), (short) ((SRVRecord) record).getPort());
+ }
+ }
+ } catch (Exception ignored) {
+ }
+ return null;
+ }
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java
index c43f72235..47265c3aa 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java
@@ -32,18 +32,20 @@ import java.util.Date;
public class ImportKeysListEntry implements Serializable, Parcelable {
private static final long serialVersionUID = -7797972103284992662L;
- public ArrayList userIds;
- public long keyId;
- public String keyIdHex;
- public boolean revoked;
- public Date date; // TODO: not displayed
- public String fingerprintHex;
- public int bitStrength;
- public String algorithm;
- public boolean secretKey;
- public String mPrimaryUserId;
+ private ArrayList mUserIds;
+ private long mKeyId;
+ private String mKeyIdHex;
+ private boolean mRevoked;
+ private boolean mExpired;
+ private Date mDate; // TODO: not displayed
+ private String mFingerprintHex;
+ private int mBitStrength;
+ private String mAlgorithm;
+ private boolean mSecretKey;
+ private String mPrimaryUserId;
private String mExtraData;
private String mQuery;
+ private String mOrigin;
private boolean mSelected;
@@ -54,35 +56,39 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mPrimaryUserId);
- dest.writeStringList(userIds);
- dest.writeLong(keyId);
- dest.writeByte((byte) (revoked ? 1 : 0));
- dest.writeSerializable(date);
- dest.writeString(fingerprintHex);
- dest.writeString(keyIdHex);
- dest.writeInt(bitStrength);
- dest.writeString(algorithm);
- dest.writeByte((byte) (secretKey ? 1 : 0));
+ dest.writeStringList(mUserIds);
+ dest.writeLong(mKeyId);
+ dest.writeByte((byte) (mRevoked ? 1 : 0));
+ dest.writeByte((byte) (mExpired ? 1 : 0));
+ dest.writeSerializable(mDate);
+ dest.writeString(mFingerprintHex);
+ dest.writeString(mKeyIdHex);
+ dest.writeInt(mBitStrength);
+ dest.writeString(mAlgorithm);
+ dest.writeByte((byte) (mSecretKey ? 1 : 0));
dest.writeByte((byte) (mSelected ? 1 : 0));
dest.writeString(mExtraData);
+ dest.writeString(mOrigin);
}
public static final Creator CREATOR = new Creator() {
public ImportKeysListEntry createFromParcel(final Parcel source) {
ImportKeysListEntry vr = new ImportKeysListEntry();
vr.mPrimaryUserId = source.readString();
- vr.userIds = new ArrayList();
- source.readStringList(vr.userIds);
- vr.keyId = source.readLong();
- vr.revoked = source.readByte() == 1;
- vr.date = (Date) source.readSerializable();
- vr.fingerprintHex = source.readString();
- vr.keyIdHex = source.readString();
- vr.bitStrength = source.readInt();
- vr.algorithm = source.readString();
- vr.secretKey = source.readByte() == 1;
+ vr.mUserIds = new ArrayList();
+ source.readStringList(vr.mUserIds);
+ vr.mKeyId = source.readLong();
+ vr.mRevoked = source.readByte() == 1;
+ vr.mExpired = source.readByte() == 1;
+ vr.mDate = (Date) source.readSerializable();
+ vr.mFingerprintHex = source.readString();
+ vr.mKeyIdHex = source.readString();
+ vr.mBitStrength = source.readInt();
+ vr.mAlgorithm = source.readString();
+ vr.mSecretKey = source.readByte() == 1;
vr.mSelected = source.readByte() == 1;
vr.mExtraData = source.readString();
+ vr.mOrigin = source.readString();
return vr;
}
@@ -93,7 +99,7 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
};
public String getKeyIdHex() {
- return keyIdHex;
+ return mKeyIdHex;
}
public boolean isSelected() {
@@ -104,72 +110,80 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
this.mSelected = selected;
}
+ public boolean isExpired() {
+ return mExpired;
+ }
+
+ public void setExpired(boolean expired) {
+ this.mExpired = expired;
+ }
+
public long getKeyId() {
- return keyId;
+ return mKeyId;
}
public void setKeyId(long keyId) {
- this.keyId = keyId;
+ this.mKeyId = keyId;
}
public void setKeyIdHex(String keyIdHex) {
- this.keyIdHex = keyIdHex;
+ this.mKeyIdHex = keyIdHex;
}
public boolean isRevoked() {
- return revoked;
+ return mRevoked;
}
public void setRevoked(boolean revoked) {
- this.revoked = revoked;
+ this.mRevoked = revoked;
}
public Date getDate() {
- return date;
+ return mDate;
}
public void setDate(Date date) {
- this.date = date;
+ this.mDate = date;
}
public String getFingerprintHex() {
- return fingerprintHex;
+ return mFingerprintHex;
}
public void setFingerprintHex(String fingerprintHex) {
- this.fingerprintHex = fingerprintHex;
+ this.mFingerprintHex = fingerprintHex;
}
public int getBitStrength() {
- return bitStrength;
+ return mBitStrength;
}
public void setBitStrength(int bitStrength) {
- this.bitStrength = bitStrength;
+ this.mBitStrength = bitStrength;
}
public String getAlgorithm() {
- return algorithm;
+ return mAlgorithm;
}
public void setAlgorithm(String algorithm) {
- this.algorithm = algorithm;
+ this.mAlgorithm = algorithm;
}
public boolean isSecretKey() {
- return secretKey;
+ return mSecretKey;
}
public void setSecretKey(boolean secretKey) {
- this.secretKey = secretKey;
+ this.mSecretKey = secretKey;
}
public ArrayList getUserIds() {
- return userIds;
+ return mUserIds;
}
public void setUserIds(ArrayList userIds) {
- this.userIds = userIds;
+ this.mUserIds = userIds;
}
public String getPrimaryUserId() {
@@ -196,15 +210,23 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
mQuery = query;
}
+ public String getOrigin() {
+ return mOrigin;
+ }
+
+ public void setOrigin(String origin) {
+ mOrigin = origin;
+ }
+
/**
* Constructor for later querying from keyserver
*/
public ImportKeysListEntry() {
// keys from keyserver are always public keys; from keybase too
- secretKey = false;
+ mSecretKey = false;
// do not select by default
mSelected = false;
- userIds = new ArrayList();
+ mUserIds = new ArrayList();
}
/**
@@ -215,24 +237,24 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
// selected is default
this.mSelected = true;
- secretKey = ring.isSecret();
+ mSecretKey = ring.isSecret();
UncachedPublicKey key = ring.getPublicKey();
mPrimaryUserId = key.getPrimaryUserId();
- userIds = key.getUnorderedUserIds();
+ mUserIds = key.getUnorderedUserIds();
// if there was no user id flagged as primary, use the first one
if (mPrimaryUserId == null) {
- mPrimaryUserId = userIds.get(0);
+ mPrimaryUserId = mUserIds.get(0);
}
- this.keyId = key.getKeyId();
- this.keyIdHex = PgpKeyHelper.convertKeyIdToHex(keyId);
+ this.mKeyId = key.getKeyId();
+ this.mKeyIdHex = PgpKeyHelper.convertKeyIdToHex(mKeyId);
- this.revoked = key.maybeRevoked();
- this.fingerprintHex = PgpKeyHelper.convertFingerprintToHex(key.getFingerprint());
- this.bitStrength = key.getBitStrength();
+ this.mRevoked = key.isRevoked();
+ this.mFingerprintHex = PgpKeyHelper.convertFingerprintToHex(key.getFingerprint());
+ this.mBitStrength = key.getBitStrength();
final int algorithm = key.getAlgorithm();
- this.algorithm = PgpKeyHelper.getAlgorithmInfo(context, algorithm);
+ this.mAlgorithm = PgpKeyHelper.getAlgorithmInfo(context, algorithm);
}
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java
index f9b6abf18..43557279f 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/KeybaseKeyserver.java
@@ -31,6 +31,7 @@ import java.net.URLEncoder;
import java.util.ArrayList;
public class KeybaseKeyserver extends Keyserver {
+ public static final String ORIGIN = "keybase:keybase.io";
private String mQuery;
@Override
@@ -87,6 +88,7 @@ public class KeybaseKeyserver extends Keyserver {
final ImportKeysListEntry entry = new ImportKeysListEntry();
entry.setQuery(mQuery);
+ entry.setOrigin(ORIGIN);
String keybaseId = JWalk.getString(match, "components", "username", "val");
String fullName = JWalk.getString(match, "components", "full_name", "val");
@@ -144,7 +146,8 @@ public class KeybaseKeyserver extends Keyserver {
try {
JSONObject json = new JSONObject(text);
if (JWalk.getInt(json, "status", "code") != 0) {
- throw new QueryFailedException("Keybase autocomplete search failed");
+ throw new QueryFailedException("Keybase.io query failed: " + path + "?" +
+ query);
}
return json;
} catch (JSONException e) {
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java
index 868f543f0..842e7d922 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java
@@ -48,12 +48,12 @@ public abstract class Keyserver {
private static final long serialVersionUID = -507574859137295530L;
}
- abstract List search(String query) throws QueryFailedException,
+ public abstract List search(String query) throws QueryFailedException,
QueryNeedsRepairException;
- abstract String get(String keyIdHex) throws QueryFailedException;
+ public abstract String get(String keyIdHex) throws QueryFailedException;
- abstract void add(String armoredKey) throws AddKeyException;
+ public abstract void add(String armoredKey) throws AddKeyException;
public static String readAll(InputStream in, String encoding) throws IOException {
ByteArrayOutputStream raw = new ByteArrayOutputStream();
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ParcelableKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ParcelableKeyRing.java
index 5da6c4cd3..fdf561aaf 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ParcelableKeyRing.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ParcelableKeyRing.java
@@ -3,7 +3,7 @@ package org.sufficientlysecure.keychain.keyimport;
import android.os.Parcel;
import android.os.Parcelable;
-/** This is a trivial wrapper around UncachedKeyRing which implements Parcelable. It exists
+/** This is a trivial wrapper around keyring bytes which implements Parcelable. It exists
* for the sole purpose of keeping spongycastle and android imports in separate packages.
*/
public class ParcelableKeyRing implements Parcelable {
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java
index 14ec67e64..e1967429a 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java
@@ -33,6 +33,9 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
+import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog;
+import org.sufficientlysecure.keychain.service.OperationResults.ImportResult;
+import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult;
import org.sufficientlysecure.keychain.util.Log;
import java.io.ByteArrayOutputStream;
@@ -55,10 +58,6 @@ public class PgpImportExport {
private ProviderHelper mProviderHelper;
- public static final int RETURN_OK = 0;
- public static final int RETURN_BAD = -2;
- public static final int RETURN_UPDATED = 1;
-
public PgpImportExport(Context context, Progressable progressable) {
super();
this.mContext = context;
@@ -115,26 +114,20 @@ public class PgpImportExport {
if (aos != null) {
aos.close();
}
- if (bos != null) {
- bos.close();
- }
+ bos.close();
} catch (IOException e) {
+ // this is just a finally thing, no matter if it doesn't work out.
}
}
}
- /**
- * Imports keys from given data. If keyIds is given only those are imported
- */
- public Bundle importKeyRings(List entries)
+ /** Imports keys from given data. If keyIds is given only those are imported */
+ public ImportResult importKeyRings(List entries)
throws PgpGeneralException, PGPException, IOException {
- Bundle returnData = new Bundle();
updateProgress(R.string.progress_importing, 0, 100);
- int newKeys = 0;
- int oldKeys = 0;
- int badKeys = 0;
+ int newKeys = 0, oldKeys = 0, badKeys = 0;
int position = 0;
for (ParcelableKeyRing entry : entries) {
@@ -152,14 +145,19 @@ public class PgpImportExport {
}
}
- mProviderHelper.savePublicKeyRing(key);
- /*switch(status) {
- case RETURN_UPDATED: oldKeys++; break;
- case RETURN_OK: newKeys++; break;
- case RETURN_BAD: badKeys++; break;
- }*/
- // TODO proper import feedback
- newKeys += 1;
+ SaveKeyringResult result;
+ if (key.isSecret()) {
+ result = mProviderHelper.saveSecretKeyRing(key);
+ } else {
+ result = mProviderHelper.savePublicKeyRing(key);
+ }
+ if (!result.success()) {
+ badKeys += 1;
+ } else if (result.updated()) {
+ oldKeys += 1;
+ } else {
+ newKeys += 1;
+ }
} catch (PgpGeneralException e) {
Log.e(Constants.TAG, "Encountered bad key on import!", e);
@@ -170,11 +168,31 @@ public class PgpImportExport {
updateProgress(position / entries.size() * 100, 100);
}
- returnData.putInt(KeychainIntentService.RESULT_IMPORT_ADDED, newKeys);
- returnData.putInt(KeychainIntentService.RESULT_IMPORT_UPDATED, oldKeys);
- returnData.putInt(KeychainIntentService.RESULT_IMPORT_BAD, badKeys);
+ OperationLog log = mProviderHelper.getLog();
+ int resultType = 0;
+ // special return case: no new keys at all
+ if (badKeys == 0 && newKeys == 0 && oldKeys == 0) {
+ resultType = ImportResult.RESULT_FAIL_NOTHING;
+ } else {
+ if (newKeys > 0) {
+ resultType |= ImportResult.RESULT_OK_NEWKEYS;
+ }
+ if (oldKeys > 0) {
+ resultType |= ImportResult.RESULT_OK_UPDATED;
+ }
+ if (badKeys > 0) {
+ resultType |= ImportResult.RESULT_WITH_ERRORS;
+ if (newKeys == 0 && oldKeys == 0) {
+ resultType |= ImportResult.RESULT_ERROR;
+ }
+ }
+ if (log.containsWarnings()) {
+ resultType |= ImportResult.RESULT_WITH_WARNINGS;
+ }
+ }
+
+ return new ImportResult(resultType, log, newKeys, oldKeys, badKeys);
- return returnData;
}
public Bundle exportKeyRings(ArrayList publicKeyRingMasterIds,
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java
index 02e5411ca..e309ed632 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java
@@ -2,14 +2,23 @@ package org.sufficientlysecure.keychain.pgp;
import org.spongycastle.bcpg.ArmoredOutputStream;
import org.spongycastle.bcpg.S2K;
+import org.spongycastle.bcpg.SignatureSubpacketTags;
+import org.spongycastle.bcpg.sig.KeyFlags;
+import org.spongycastle.openpgp.PGPKeyFlags;
import org.spongycastle.openpgp.PGPKeyRing;
import org.spongycastle.openpgp.PGPObjectFactory;
import org.spongycastle.openpgp.PGPPublicKey;
+import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing;
+import org.spongycastle.openpgp.PGPSignature;
+import org.spongycastle.openpgp.PGPSignatureList;
import org.spongycastle.openpgp.PGPUtil;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
+import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog;
+import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel;
+import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Log;
@@ -18,7 +27,8 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
@@ -149,13 +159,13 @@ public class UncachedKeyRing {
aos.close();
}
- public ArrayList getAvailableSubkeys() {
+ public HashSet getAvailableSubkeys() {
if(!isSecret()) {
throw new RuntimeException("Tried to find available subkeys from non-secret keys. " +
"This is a programming error and should never happen!");
}
- ArrayList result = new ArrayList();
+ HashSet result = new HashSet();
// then, mark exactly the keys we have available
for (PGPSecretKey sub : new IterableIterator(
((PGPSecretKeyRing) mRing).getSecretKeys())) {
@@ -168,4 +178,411 @@ public class UncachedKeyRing {
return result;
}
+ /** "Canonicalizes" a key, removing inconsistencies in the process. This operation can be
+ * applied to public keyrings only.
+ *
+ * More specifically:
+ * - Remove all non-verifying self-certificates
+ * - Remove all "future" self-certificates
+ * - Remove all certificates flagged as "local"
+ * - Remove all certificates which are superseded by a newer one on the same target
+ *
+ * After this cleaning, a number of checks are done: TODO implement
+ * - See if each subkey retains a valid self certificate
+ * - See if each user id retains a valid self certificate
+ *
+ * This operation writes an OperationLog which can be used as part of a OperationResultParcel.
+ *
+ * @return A canonicalized key
+ *
+ */
+ public UncachedKeyRing canonicalize(OperationLog log, int indent) {
+ if (isSecret()) {
+ throw new RuntimeException("Tried to canonicalize non-secret keyring. " +
+ "This is a programming error and should never happen!");
+ }
+
+ log.add(LogLevel.START, LogType.MSG_KC,
+ new String[]{PgpKeyHelper.convertKeyIdToHex(getMasterKeyId())}, indent);
+ indent += 1;
+
+ final Date now = new Date();
+
+ int removedCerts = 0;
+
+ PGPPublicKeyRing ring = (PGPPublicKeyRing) mRing;
+ PGPPublicKey masterKey = mRing.getPublicKey();
+ final long masterKeyId = masterKey.getKeyID();
+
+ {
+ log.add(LogLevel.DEBUG, LogType.MSG_KC_MASTER,
+ new String[]{PgpKeyHelper.convertKeyIdToHex(masterKey.getKeyID())}, indent);
+ indent += 1;
+
+ PGPPublicKey modified = masterKey;
+ PGPSignature revocation = null;
+ for (PGPSignature zert : new IterableIterator(masterKey.getSignatures())) {
+ int type = zert.getSignatureType();
+
+ // Disregard certifications on user ids, we will deal with those later
+ if (type == PGPSignature.NO_CERTIFICATION
+ || type == PGPSignature.DEFAULT_CERTIFICATION
+ || type == PGPSignature.CASUAL_CERTIFICATION
+ || type == PGPSignature.POSITIVE_CERTIFICATION
+ || type == PGPSignature.CERTIFICATION_REVOCATION) {
+ continue;
+ }
+ WrappedSignature cert = new WrappedSignature(zert);
+
+ if (type != PGPSignature.KEY_REVOCATION) {
+ // Unknown type, just remove
+ log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_TYPE, new String[]{
+ "0x" + Integer.toString(type, 16)
+ }, indent);
+ modified = PGPPublicKey.removeCertification(modified, zert);
+ removedCerts += 1;
+ continue;
+ }
+
+ if (cert.getCreationTime().after(now)) {
+ // Creation date in the future? No way!
+ log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_TIME, null, indent);
+ modified = PGPPublicKey.removeCertification(modified, zert);
+ removedCerts += 1;
+ continue;
+ }
+
+ if (cert.isLocal()) {
+ // Creation date in the future? No way!
+ log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_LOCAL, null, indent);
+ modified = PGPPublicKey.removeCertification(modified, zert);
+ removedCerts += 1;
+ continue;
+ }
+
+ try {
+ cert.init(masterKey);
+ if (!cert.verifySignature(masterKey)) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD, null, indent);
+ modified = PGPPublicKey.removeCertification(modified, zert);
+ removedCerts += 1;
+ continue;
+ }
+ } catch (PgpGeneralException e) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_ERR, null, indent);
+ modified = PGPPublicKey.removeCertification(modified, zert);
+ removedCerts += 1;
+ continue;
+ }
+
+ // first revocation? fine then.
+ if (revocation == null) {
+ revocation = zert;
+ // more revocations? at least one is superfluous, then.
+ } else if (revocation.getCreationTime().before(zert.getCreationTime())) {
+ modified = PGPPublicKey.removeCertification(modified, revocation);
+ removedCerts += 1;
+ log.add(LogLevel.INFO, LogType.MSG_KC_REVOKE_DUP, null, indent);
+ revocation = zert;
+ } else {
+ modified = PGPPublicKey.removeCertification(modified, zert);
+ removedCerts += 1;
+ log.add(LogLevel.INFO, LogType.MSG_KC_REVOKE_DUP, null, indent);
+ }
+ }
+
+ for (String userId : new IterableIterator(masterKey.getUserIDs())) {
+ PGPSignature selfCert = null;
+ revocation = null;
+
+ // look through signatures for this specific key
+ for (PGPSignature zert : new IterableIterator(
+ masterKey.getSignaturesForID(userId))) {
+ WrappedSignature cert = new WrappedSignature(zert);
+ long certId = cert.getKeyId();
+
+ int type = zert.getSignatureType();
+ if (type != PGPSignature.DEFAULT_CERTIFICATION
+ && type != PGPSignature.NO_CERTIFICATION
+ && type != PGPSignature.CASUAL_CERTIFICATION
+ && type != PGPSignature.POSITIVE_CERTIFICATION
+ && type != PGPSignature.CERTIFICATION_REVOCATION) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_UID_BAD_TYPE,
+ new String[] {
+ "0x" + Integer.toString(zert.getSignatureType(), 16)
+ }, indent);
+ modified = PGPPublicKey.removeCertification(modified, userId, zert);
+ removedCerts += 1;
+ }
+
+ if (cert.getCreationTime().after(now)) {
+ // Creation date in the future? No way!
+ log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_TIME, null, indent);
+ modified = PGPPublicKey.removeCertification(modified, zert);
+ removedCerts += 1;
+ continue;
+ }
+
+ if (cert.isLocal()) {
+ // Creation date in the future? No way!
+ log.add(LogLevel.WARN, LogType.MSG_KC_REVOKE_BAD_LOCAL, null, indent);
+ modified = PGPPublicKey.removeCertification(modified, zert);
+ removedCerts += 1;
+ continue;
+ }
+
+ // If this is a foreign signature, never mind any further
+ if (certId != masterKeyId) {
+ continue;
+ }
+
+ // Otherwise, first make sure it checks out
+ try {
+ cert.init(masterKey);
+ if (!cert.verifySignature(masterKey, userId)) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_UID_BAD,
+ new String[] { userId }, indent);
+ modified = PGPPublicKey.removeCertification(modified, userId, zert);
+ removedCerts += 1;
+ continue;
+ }
+ } catch (PgpGeneralException e) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_UID_BAD_ERR,
+ new String[] { userId }, indent);
+ modified = PGPPublicKey.removeCertification(modified, userId, zert);
+ removedCerts += 1;
+ continue;
+ }
+
+ switch (type) {
+ case PGPSignature.DEFAULT_CERTIFICATION:
+ case PGPSignature.NO_CERTIFICATION:
+ case PGPSignature.CASUAL_CERTIFICATION:
+ case PGPSignature.POSITIVE_CERTIFICATION:
+ if (selfCert == null) {
+ selfCert = zert;
+ } else if (selfCert.getCreationTime().before(cert.getCreationTime())) {
+ modified = PGPPublicKey.removeCertification(modified, userId, selfCert);
+ removedCerts += 1;
+ log.add(LogLevel.INFO, LogType.MSG_KC_UID_DUP,
+ new String[] { userId }, indent);
+ selfCert = zert;
+ } else {
+ modified = PGPPublicKey.removeCertification(modified, userId, zert);
+ removedCerts += 1;
+ log.add(LogLevel.INFO, LogType.MSG_KC_UID_DUP,
+ new String[] { userId }, indent);
+ }
+ // If there is a revocation certificate, and it's older than this, drop it
+ if (revocation != null
+ && revocation.getCreationTime().before(selfCert.getCreationTime())) {
+ modified = PGPPublicKey.removeCertification(modified, userId, revocation);
+ revocation = null;
+ removedCerts += 1;
+ log.add(LogLevel.INFO, LogType.MSG_KC_UID_REVOKE_OLD,
+ new String[] { userId }, indent);
+ }
+ break;
+
+ case PGPSignature.CERTIFICATION_REVOCATION:
+ // If this is older than the (latest) self cert, drop it
+ if (selfCert != null && selfCert.getCreationTime().after(zert.getCreationTime())) {
+ modified = PGPPublicKey.removeCertification(modified, userId, zert);
+ removedCerts += 1;
+ log.add(LogLevel.INFO, LogType.MSG_KC_UID_REVOKE_OLD,
+ new String[] { userId }, indent);
+ continue;
+ }
+ // first revocation? remember it.
+ if (revocation == null) {
+ revocation = zert;
+ // more revocations? at least one is superfluous, then.
+ } else if (revocation.getCreationTime().before(cert.getCreationTime())) {
+ modified = PGPPublicKey.removeCertification(modified, userId, revocation);
+ removedCerts += 1;
+ log.add(LogLevel.INFO, LogType.MSG_KC_UID_REVOKE_DUP,
+ new String[] { userId }, indent);
+ revocation = zert;
+ } else {
+ modified = PGPPublicKey.removeCertification(modified, userId, zert);
+ removedCerts += 1;
+ log.add(LogLevel.INFO, LogType.MSG_KC_UID_REVOKE_DUP,
+ new String[] { userId }, indent);
+ }
+ break;
+
+ }
+
+ }
+ }
+
+ // Replace modified key in the keyring
+ ring = PGPPublicKeyRing.insertPublicKey(ring, modified);
+
+ log.add(LogLevel.DEBUG, LogType.MSG_KC_MASTER_SUCCESS, null, indent);
+ indent -= 1;
+
+ }
+
+ // Process all keys
+ for (PGPPublicKey key : new IterableIterator(ring.getPublicKeys())) {
+ // Don't care about the master key here, that one gets special treatment above
+ if (key.isMasterKey()) {
+ continue;
+ }
+ log.add(LogLevel.DEBUG, LogType.MSG_KC_SUB,
+ new String[]{PgpKeyHelper.convertKeyIdToHex(key.getKeyID())}, indent);
+ indent += 1;
+ // A subkey needs exactly one subkey binding certificate, and optionally one revocation
+ // certificate.
+ PGPPublicKey modified = key;
+ PGPSignature selfCert = null, revocation = null;
+ uids: for (PGPSignature zig : new IterableIterator(key.getSignatures())) {
+ // remove from keyring (for now)
+ modified = PGPPublicKey.removeCertification(modified, zig);
+ // add this too, easier than adding it for every single "continue" case
+ removedCerts += 1;
+
+ WrappedSignature cert = new WrappedSignature(zig);
+ int type = cert.getSignatureType();
+
+ // filter out bad key types...
+ if (cert.getKeyId() != masterKey.getKeyID()) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_KEYID, null, indent);
+ continue;
+ }
+
+ if (type != PGPSignature.SUBKEY_BINDING && type != PGPSignature.SUBKEY_REVOCATION) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_TYPE, new String[]{
+ "0x" + Integer.toString(type, 16)
+ }, indent);
+ continue;
+ }
+
+ if (cert.getCreationTime().after(now)) {
+ // Creation date in the future? No way!
+ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_TIME, null, indent);
+ continue;
+ }
+
+ if (cert.isLocal()) {
+ // Creation date in the future? No way!
+ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_LOCAL, null, indent);
+ continue;
+ }
+
+ if (type == PGPSignature.SUBKEY_BINDING) {
+
+ // make sure the certificate checks out
+ try {
+ cert.init(masterKey);
+ if (!cert.verifySignature(masterKey, key)) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD, null, indent);
+ continue;
+ }
+ } catch (PgpGeneralException e) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_BAD_ERR, null, indent);
+ continue;
+ }
+
+ if (zig.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.KEY_FLAGS)) {
+ int flags = ((KeyFlags) zig.getHashedSubPackets()
+ .getSubpacket(SignatureSubpacketTags.KEY_FLAGS)).getFlags();
+ // If this subkey is allowed to sign data,
+ if ((flags & PGPKeyFlags.CAN_SIGN) == PGPKeyFlags.CAN_SIGN) {
+ try {
+ PGPSignatureList list = zig.getUnhashedSubPackets().getEmbeddedSignatures();
+ boolean ok = false;
+ for (int i = 0; i < list.size(); i++) {
+ WrappedSignature subsig = new WrappedSignature(list.get(i));
+ if (subsig.getSignatureType() == PGPSignature.PRIMARYKEY_BINDING) {
+ subsig.init(key);
+ if (subsig.verifySignature(masterKey, key)) {
+ ok = true;
+ } else {
+ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_PRIMARY_BAD, null, indent);
+ continue uids;
+ }
+ }
+ }
+ if (!ok) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_PRIMARY_NONE, null, indent);
+ continue;
+ }
+ } catch (Exception e) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_PRIMARY_BAD_ERR, null, indent);
+ continue;
+ }
+ }
+ }
+
+ // if we already have a cert, and this one is not newer: skip it
+ if (selfCert != null && selfCert.getCreationTime().before(cert.getCreationTime())) {
+ continue;
+ }
+
+ selfCert = zig;
+ // if this is newer than a possibly existing revocation, drop that one
+ if (revocation != null && selfCert.getCreationTime().after(revocation.getCreationTime())) {
+ revocation = null;
+ }
+
+ // it must be a revocation, then (we made sure above)
+ } else {
+
+ // make sure the certificate checks out
+ try {
+ cert.init(masterKey);
+ if (!cert.verifySignature(key)) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_REVOKE_BAD, null, indent);
+ continue;
+ }
+ } catch (PgpGeneralException e) {
+ log.add(LogLevel.WARN, LogType.MSG_KC_SUB_REVOKE_BAD_ERR, null, indent);
+ continue;
+ }
+
+ // if there is no binding (yet), or the revocation is newer than the binding: keep it
+ if (selfCert == null || selfCert.getCreationTime().before(cert.getCreationTime())) {
+ revocation = zig;
+ }
+ }
+ }
+
+ // it is not properly bound? error!
+ if (selfCert == null) {
+ ring = PGPPublicKeyRing.removePublicKey(ring, modified);
+
+ log.add(LogLevel.ERROR, LogType.MSG_KC_SUB_NO_CERT,
+ new String[]{PgpKeyHelper.convertKeyIdToHex(key.getKeyID())}, indent);
+ indent -= 1;
+ continue;
+ }
+
+ // re-add certification
+ modified = PGPPublicKey.addCertification(modified, selfCert);
+ removedCerts -= 1;
+ // add revocation, if any
+ if (revocation != null) {
+ modified = PGPPublicKey.addCertification(modified, revocation);
+ removedCerts -= 1;
+ }
+ // replace pubkey in keyring
+ ring = PGPPublicKeyRing.insertPublicKey(ring, modified);
+
+ log.add(LogLevel.DEBUG, LogType.MSG_KC_SUB_SUCCESS, null, indent);
+ indent -= 1;
+ }
+
+ if (removedCerts > 0) {
+ log.add(LogLevel.OK, LogType.MSG_KC_SUCCESS_REMOVED,
+ new String[] { Integer.toString(removedCerts) }, indent);
+ } else {
+ log.add(LogLevel.OK, LogType.MSG_KC_SUCCESS, null, indent);
+ }
+
+ return new UncachedKeyRing(ring);
+ }
+
+
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedPublicKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedPublicKey.java
index 108c8c8c3..33db7771b 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedPublicKey.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedPublicKey.java
@@ -2,6 +2,7 @@ package org.sufficientlysecure.keychain.pgp;
import org.spongycastle.bcpg.SignatureSubpacketTags;
import org.spongycastle.bcpg.sig.KeyFlags;
+import org.spongycastle.openpgp.PGPException;
import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.openpgp.PGPSignature;
import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
@@ -9,6 +10,7 @@ import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProv
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.util.IterableIterator;
+import java.security.SignatureException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -28,8 +30,13 @@ public class UncachedPublicKey {
}
/** The revocation signature is NOT checked here, so this may be false! */
- public boolean maybeRevoked() {
- return mPublicKey.isRevoked();
+ public boolean isRevoked() {
+ for (PGPSignature sig : new IterableIterator(
+ mPublicKey.getSignaturesOfType(isMasterKey() ? PGPSignature.KEY_REVOCATION
+ : PGPSignature.SUBKEY_REVOCATION))) {
+ return true;
+ }
+ return false;
}
public Date getCreationTime() {
@@ -193,4 +200,5 @@ public class UncachedPublicKey {
}
};
}
+
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java
index 1b7a5e8ba..be7f960a9 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java
@@ -35,7 +35,7 @@ public class WrappedSignature {
final PGPSignature mSig;
- protected WrappedSignature(PGPSignature sig) {
+ WrappedSignature(PGPSignature sig) {
mSig = sig;
}
@@ -88,7 +88,7 @@ public class WrappedSignature {
init(key.getPublicKey());
}
- protected void init(PGPPublicKey key) throws PgpGeneralException {
+ void init(PGPPublicKey key) throws PgpGeneralException {
try {
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
new JcaPGPContentVerifierBuilderProvider()
@@ -125,7 +125,27 @@ public class WrappedSignature {
}
}
- protected boolean verifySignature(PGPPublicKey key, String uid) throws PgpGeneralException {
+ boolean verifySignature(PGPPublicKey key) throws PgpGeneralException {
+ try {
+ return mSig.verifyCertification(key);
+ } catch (SignatureException e) {
+ throw new PgpGeneralException("Sign!", e);
+ } catch (PGPException e) {
+ throw new PgpGeneralException("Error!", e);
+ }
+ }
+
+ boolean verifySignature(PGPPublicKey masterKey, PGPPublicKey subKey) throws PgpGeneralException {
+ try {
+ return mSig.verifyCertification(masterKey, subKey);
+ } catch (SignatureException e) {
+ throw new PgpGeneralException("Sign!", e);
+ } catch (PGPException e) {
+ throw new PgpGeneralException("Error!", e);
+ }
+ }
+
+ boolean verifySignature(PGPPublicKey key, String uid) throws PgpGeneralException {
try {
return mSig.verifyCertification(uid, key);
} catch (SignatureException e) {
@@ -158,4 +178,11 @@ public class WrappedSignature {
return new WrappedSignature(signatures.get(0));
}
+ public boolean isLocal() {
+ if (!mSig.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.EXPORTABLE)) {
+ return false;
+ }
+ SignatureSubpacket p = mSig.getHashedSubPackets().getSubpacket(SignatureSubpacketTags.EXPORTABLE);
+ return p.getData()[0] == 0;
+ }
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java
index ca7e622bb..102c8e6d0 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java
@@ -29,6 +29,10 @@ import android.support.v4.util.LongSparseArray;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.KeyRing;
+import org.sufficientlysecure.keychain.pgp.WrappedPublicKey;
+import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType;
+import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel;
+import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog;
import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
@@ -45,6 +49,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
import org.sufficientlysecure.keychain.remote.AccountSettings;
import org.sufficientlysecure.keychain.remote.AppSettings;
+import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Log;
@@ -58,13 +63,43 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+/** This class contains high level methods for database access. Despite its
+ * name, it is not only a helper but actually the main interface for all
+ * synchronous database operations.
+ *
+ * Operations in this class write logs (TODO). These can be obtained from the
+ * OperationResultParcel return values directly, but are also accumulated over
+ * the lifetime of the executing ProviderHelper object unless the resetLog()
+ * method is called to start a new one specifically.
+ *
+ */
public class ProviderHelper {
- private Context mContext;
- private ContentResolver mContentResolver;
+ private final Context mContext;
+ private final ContentResolver mContentResolver;
+ private OperationLog mLog;
+ private int mIndent;
public ProviderHelper(Context context) {
- this.mContext = context;
- this.mContentResolver = context.getContentResolver();
+ this(context, new OperationLog(), 0);
+ }
+
+ public ProviderHelper(Context context, OperationLog log, int indent) {
+ mContext = context;
+ mContentResolver = context.getContentResolver();
+ mLog = log;
+ mIndent = indent;
+ }
+
+ public void resetLog() {
+ if(mLog != null) {
+ // Start a new log (leaving the old one intact)
+ mLog = new OperationLog();
+ mIndent = 0;
+ }
+ }
+
+ public OperationLog getLog() {
+ return mLog;
}
public static class NotFoundException extends Exception {
@@ -76,6 +111,17 @@ public class ProviderHelper {
}
}
+ public void log(LogLevel level, LogType type) {
+ if(mLog != null) {
+ mLog.add(level, type, null, mIndent);
+ }
+ }
+ public void log(LogLevel level, LogType type, String[] parameters) {
+ if(mLog != null) {
+ mLog.add(level, type, parameters, mIndent);
+ }
+ }
+
// If we ever switch to api level 11, we can ditch this whole mess!
public static final int FIELD_TYPE_NULL = 1;
// this is called integer to stay coherent with the constants in Cursor (api level 11)
@@ -126,36 +172,31 @@ public class ProviderHelper {
}
}
- public Object getUnifiedData(long masterKeyId, String column, int type)
- throws NotFoundException {
- return getUnifiedData(masterKeyId, new String[]{column}, new int[]{type}).get(column);
- }
-
public HashMap getUnifiedData(long masterKeyId, String[] proj, int[] types)
throws NotFoundException {
return getGenericData(KeyRings.buildUnifiedKeyRingUri(masterKeyId), proj, types);
}
- private LongSparseArray getUncachedMasterKeys(Uri queryUri) {
- Cursor cursor = mContentResolver.query(queryUri,
- new String[]{KeyRingData.MASTER_KEY_ID, KeyRingData.KEY_RING_DATA},
- null, null, null);
+ private LongSparseArray getTrustedMasterKeys() {
+ Cursor cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(), new String[] {
+ KeyRings.MASTER_KEY_ID,
+ // we pick from cache only information that is not easily available from keyrings
+ KeyRings.HAS_ANY_SECRET, KeyRings.VERIFIED,
+ // and of course, ring data
+ KeyRings.PUBKEY_DATA
+ }, KeyRings.HAS_ANY_SECRET + " = 1", null, null);
- LongSparseArray result =
- new LongSparseArray(cursor.getCount());
+ LongSparseArray result =
+ new LongSparseArray(cursor.getCount());
try {
if (cursor != null && cursor.moveToFirst()) do {
long masterKeyId = cursor.getLong(0);
- byte[] data = cursor.getBlob(1);
- if (data != null) {
- try {
- result.put(masterKeyId,
- UncachedKeyRing.decodeFromData(data).getPublicKey());
- } catch(PgpGeneralException e) {
- Log.e(Constants.TAG, "Error parsing keyring, skipping " + masterKeyId, e);
- } catch(IOException e) {
- Log.e(Constants.TAG, "IO error, skipping keyring" + masterKeyId, e);
- }
+ boolean hasAnySecret = cursor.getInt(1) > 0;
+ int verified = cursor.getInt(2);
+ byte[] blob = cursor.getBlob(3);
+ if (blob != null) {
+ result.put(masterKeyId,
+ new WrappedPublicKeyRing(blob, hasAnySecret, verified).getSubkey());
}
} while (cursor.moveToNext());
} finally {
@@ -206,7 +247,7 @@ public class ProviderHelper {
throw new NotFoundException("Secret key not available!");
}
return secret
- ? new WrappedSecretKeyRing(blob, hasAnySecret, verified)
+ ? new WrappedSecretKeyRing(blob, true, verified)
: new WrappedPublicKeyRing(blob, hasAnySecret, verified);
} else {
throw new NotFoundException("Key not found!");
@@ -222,134 +263,269 @@ public class ProviderHelper {
* Saves PGPPublicKeyRing with its keys and userIds in DB
*/
@SuppressWarnings("unchecked")
- public void savePublicKeyRing(UncachedKeyRing keyRing) throws IOException {
+ public SaveKeyringResult savePublicKeyRing(UncachedKeyRing keyRing) {
if (keyRing.isSecret()) {
- throw new RuntimeException("Tried to save secret keyring as public! " +
- "This is a bug, please file a bug report.");
+ log(LogLevel.ERROR, LogType.MSG_IP_BAD_TYPE_SECRET);
+ return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
}
+ // start with ok result
+ int result = SaveKeyringResult.SAVED_PUBLIC;
+
+ long masterKeyId = keyRing.getMasterKeyId();
+ log(LogLevel.START, LogType.MSG_IP,
+ new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) });
+ mIndent += 1;
+
+ // Canonicalize this key, to assert a number of assumptions made about it.
+ keyRing = keyRing.canonicalize(mLog, mIndent);
+
UncachedPublicKey masterKey = keyRing.getPublicKey();
- long masterKeyId = masterKey.getKeyId();
// IF there is a secret key, preserve it!
- UncachedKeyRing secretRing = null;
+ UncachedKeyRing secretRing;
try {
secretRing = getWrappedSecretKeyRing(masterKeyId).getUncached();
+ log(LogLevel.DEBUG, LogType.MSG_IP_PRESERVING_SECRET);
} catch (NotFoundException e) {
- Log.e(Constants.TAG, "key not found!");
+ secretRing = null;
}
- // delete old version of this keyRing, which also deletes all keys and userIds on cascade
+ ArrayList operations;
try {
- mContentResolver.delete(KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null);
- } catch (UnsupportedOperationException e) {
- Log.e(Constants.TAG, "Key could not be deleted! Maybe we are creating a new one!", e);
- }
- // insert new version of this keyRing
- ContentValues values = new ContentValues();
- values.put(KeyRingData.MASTER_KEY_ID, masterKeyId);
- values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded());
- Uri uri = KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId));
- mContentResolver.insert(uri, values);
+ log(LogLevel.DEBUG, LogType.MSG_IP_PREPARE);
+ mIndent += 1;
- // save all keys and userIds included in keyRing object in database
- ArrayList operations = new ArrayList();
+ // save all keys and userIds included in keyRing object in database
+ operations = new ArrayList();
- int rank = 0;
- for (UncachedPublicKey key : new IterableIterator(keyRing.getPublicKeys())) {
- operations.add(buildPublicKeyOperations(masterKeyId, key, rank));
- ++rank;
- }
-
- // get a list of owned secret keys, for verification filtering
- LongSparseArray allKeyRings =
- getUncachedMasterKeys(KeyRingData.buildSecretKeyRingUri());
- // special case: available secret keys verify themselves!
- if (secretRing != null) {
- allKeyRings.put(secretRing.getMasterKeyId(), secretRing.getPublicKey());
- }
-
- // classify and order user ids. primary are moved to the front, revoked to the back,
- // otherwise the order in the keyfile is preserved.
- List uids = new ArrayList();
-
- for (String userId : new IterableIterator(
- masterKey.getUnorderedUserIds().iterator())) {
- UserIdItem item = new UserIdItem();
- uids.add(item);
- item.userId = userId;
-
- // look through signatures for this specific key
- for (WrappedSignature cert : new IterableIterator(
- masterKey.getSignaturesForId(userId))) {
- long certId = cert.getKeyId();
+ log(LogLevel.INFO, LogType.MSG_IP_INSERT_KEYRING);
+ { // insert keyring
+ // insert new version of this keyRing
+ ContentValues values = new ContentValues();
+ values.put(KeyRingData.MASTER_KEY_ID, masterKeyId);
try {
- // self signature
- if (certId == masterKeyId) {
- cert.init(masterKey);
- if (!cert.verifySignature(masterKey, userId)) {
- // not verified?! dang! TODO notify user? this is kinda serious...
- Log.e(Constants.TAG, "Could not verify self signature for " + userId + "!");
- continue;
+ values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded());
+ } catch (IOException e) {
+ log(LogLevel.ERROR, LogType.MSG_IP_ENCODE_FAIL);
+ return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
+ }
+
+ Uri uri = KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId));
+ operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build());
+ }
+
+ log(LogLevel.INFO, LogType.MSG_IP_INSERT_SUBKEYS);
+ mIndent += 1;
+ { // insert subkeys
+ Uri uri = Keys.buildKeysUri(Long.toString(masterKeyId));
+ int rank = 0;
+ for (UncachedPublicKey key : new IterableIterator(keyRing.getPublicKeys())) {
+ log(LogLevel.DEBUG, LogType.MSG_IP_SUBKEY, new String[]{
+ PgpKeyHelper.convertKeyIdToHex(key.getKeyId())
+ });
+ mIndent += 1;
+
+ ContentValues values = new ContentValues();
+ values.put(Keys.MASTER_KEY_ID, masterKeyId);
+ values.put(Keys.RANK, rank);
+
+ values.put(Keys.KEY_ID, key.getKeyId());
+ values.put(Keys.KEY_SIZE, key.getBitStrength());
+ values.put(Keys.ALGORITHM, key.getAlgorithm());
+ values.put(Keys.FINGERPRINT, key.getFingerprint());
+
+ boolean c = key.canCertify(), e = key.canEncrypt(), s = key.canSign();
+ values.put(Keys.CAN_CERTIFY, c);
+ values.put(Keys.CAN_ENCRYPT, e);
+ values.put(Keys.CAN_SIGN, s);
+ values.put(Keys.IS_REVOKED, key.isRevoked());
+ if (c) {
+ if (e) {
+ log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_CES
+ : LogType.MSG_IP_SUBKEY_FLAGS_CEX, null);
+ } else {
+ log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_CXS
+ : LogType.MSG_IP_SUBKEY_FLAGS_CXX, null);
}
- // is this the first, or a more recent certificate?
- if (item.selfCert == null ||
- item.selfCert.getCreationTime().before(cert.getCreationTime())) {
- item.selfCert = cert;
- item.isPrimary = cert.isPrimaryUserId();
- item.isRevoked = cert.isRevocation();
+ } else {
+ if (e) {
+ log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_XES
+ : LogType.MSG_IP_SUBKEY_FLAGS_XEX, null);
+ } else {
+ log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_XXS
+ : LogType.MSG_IP_SUBKEY_FLAGS_XXX, null);
}
}
- // verify signatures from known private keys
- if (allKeyRings.indexOfKey(certId) >= 0) {
- cert.init(allKeyRings.get(certId));
- if (cert.verifySignature(masterKey, userId)) {
- item.trustedCerts.add(cert);
+
+ Date creation = key.getCreationTime();
+ values.put(Keys.CREATION, creation.getTime() / 1000);
+ Date expiryDate = key.getExpiryTime();
+ if (expiryDate != null) {
+ values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
+ if (key.isExpired()) {
+ log(LogLevel.DEBUG, LogType.MSG_IP_SUBKEY_EXPIRED, new String[]{
+ expiryDate.toString()
+ });
+ } else {
+ log(LogLevel.DEBUG, LogType.MSG_IP_SUBKEY_EXPIRES, new String[]{
+ expiryDate.toString()
+ });
}
}
- } catch (PgpGeneralException e) {
- Log.e(Constants.TAG, "Signature verification failed! "
- + PgpKeyHelper.convertKeyIdToHex(masterKey.getKeyId())
- + " from "
- + PgpKeyHelper.convertKeyIdToHex(cert.getKeyId()), e);
+
+ operations.add(ContentProviderOperation.newInsert(uri).withValues(values).build());
+ ++rank;
+ mIndent -= 1;
}
}
- }
+ mIndent -= 1;
+
+ // get a list of owned secret keys, for verification filtering
+ LongSparseArray trustedKeys = getTrustedMasterKeys();
+
+ // classify and order user ids. primary are moved to the front, revoked to the back,
+ // otherwise the order in the keyfile is preserved.
+ log(LogLevel.INFO, LogType.MSG_IP_UID_CLASSIFYING, new String[]{
+ Integer.toString(trustedKeys.size())
+ });
+ mIndent += 1;
+ List uids = new ArrayList();
+ for (String userId : new IterableIterator(
+ masterKey.getUnorderedUserIds().iterator())) {
+ UserIdItem item = new UserIdItem();
+ uids.add(item);
+ item.userId = userId;
+
+ int unknownCerts = 0;
+
+ log(LogLevel.INFO, LogType.MSG_IP_UID_PROCESSING, new String[]{ userId });
+ mIndent += 1;
+ // look through signatures for this specific key
+ for (WrappedSignature cert : new IterableIterator(
+ masterKey.getSignaturesForId(userId))) {
+ long certId = cert.getKeyId();
+ try {
+ // self signature
+ if (certId == masterKeyId) {
+
+ // NOTE self-certificates are already verified during canonicalization,
+ // AND we know there is at most one cert plus at most one revocation
+ if (!cert.isRevocation()) {
+ item.selfCert = cert;
+ item.isPrimary = cert.isPrimaryUserId();
+ log(LogLevel.DEBUG, LogType.MSG_IP_UID_SELF_GOOD);
+ } else {
+ item.isRevoked = true;
+ log(LogLevel.DEBUG, LogType.MSG_IP_UID_REVOKED);
+ }
+
+ }
+
+ // verify signatures from known private keys
+ if (trustedKeys.indexOfKey(certId) >= 0) {
+ WrappedPublicKey trustedKey = trustedKeys.get(certId);
+ cert.init(trustedKey);
+ if (cert.verifySignature(masterKey, userId)) {
+ item.trustedCerts.add(cert);
+ log(LogLevel.INFO, LogType.MSG_IP_UID_CERT_GOOD, new String[] {
+ PgpKeyHelper.convertKeyIdToHexShort(trustedKey.getKeyId()),
+ trustedKey.getPrimaryUserId()
+ });
+ } else {
+ log(LogLevel.WARN, LogType.MSG_IP_UID_CERT_BAD);
+ }
+ }
+
+ unknownCerts += 1;
+
+ } catch (PgpGeneralException e) {
+ log(LogLevel.WARN, LogType.MSG_IP_UID_CERT_ERROR, new String[]{
+ PgpKeyHelper.convertKeyIdToHex(cert.getKeyId())
+ });
+ }
+ }
+
+ if (unknownCerts > 0) {
+ log(LogLevel.DEBUG, LogType.MSG_IP_UID_CERTS_UNKNOWN, new String[]{
+ Integer.toString(unknownCerts)
+ });
+ }
+ mIndent -= 1;
- // primary before regular before revoked (see UserIdItem.compareTo)
- // this is a stable sort, so the order of keys is otherwise preserved.
- Collections.sort(uids);
- // iterate and put into db
- for (int userIdRank = 0; userIdRank < uids.size(); userIdRank++) {
- UserIdItem item = uids.get(userIdRank);
- operations.add(buildUserIdOperations(masterKeyId, item, userIdRank));
- // no self cert is bad, but allowed by the rfc...
- if (item.selfCert != null) {
- operations.add(buildCertOperations(
- masterKeyId, userIdRank, item.selfCert, Certs.VERIFIED_SELF));
}
- // don't bother with trusted certs if the uid is revoked, anyways
- if (item.isRevoked) {
- continue;
- }
- for (int i = 0; i < item.trustedCerts.size(); i++) {
- operations.add(buildCertOperations(
- masterKeyId, userIdRank, item.trustedCerts.get(i), Certs.VERIFIED_SECRET));
+ mIndent -= 1;
+
+ log(LogLevel.DEBUG, LogType.MSG_IP_UID_REORDER);
+ // primary before regular before revoked (see UserIdItem.compareTo)
+ // this is a stable sort, so the order of keys is otherwise preserved.
+ Collections.sort(uids);
+ // iterate and put into db
+ for (int userIdRank = 0; userIdRank < uids.size(); userIdRank++) {
+ UserIdItem item = uids.get(userIdRank);
+ operations.add(buildUserIdOperations(masterKeyId, item, userIdRank));
+ if (item.selfCert != null) {
+ operations.add(buildCertOperations(masterKeyId, userIdRank, item.selfCert,
+ secretRing != null ? Certs.VERIFIED_SECRET : Certs.VERIFIED_SELF));
+ }
+ // don't bother with trusted certs if the uid is revoked, anyways
+ if (item.isRevoked) {
+ continue;
+ }
+ for (int i = 0; i < item.trustedCerts.size(); i++) {
+ operations.add(buildCertOperations(
+ masterKeyId, userIdRank, item.trustedCerts.get(i), Certs.VERIFIED_SECRET));
+ }
}
+
+ log(LogLevel.DEBUG, LogType.MSG_IP_PREPARE_SUCCESS);
+ mIndent -= 1;
+
+ } catch (IOException e) {
+ log(LogLevel.ERROR, LogType.MSG_IP_FAIL_IO_EXC);
+ Log.e(Constants.TAG, "IOException during import", e);
+ mIndent -= 1;
+ return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
}
try {
- mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations);
- } catch (RemoteException e) {
- Log.e(Constants.TAG, "applyBatch failed!", e);
- } catch (OperationApplicationException e) {
- Log.e(Constants.TAG, "applyBatch failed!", e);
- }
+ // delete old version of this keyRing, which also deletes all keys and userIds on cascade
+ int deleted = mContentResolver.delete(
+ KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null);
+ if (deleted > 0) {
+ log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_OK);
+ result |= SaveKeyringResult.UPDATED;
+ } else {
+ log(LogLevel.DEBUG, LogType.MSG_IP_DELETE_OLD_FAIL);
+ }
- // Save the saved keyring (if any)
- if (secretRing != null) {
- saveSecretKeyRing(secretRing);
+ log(LogLevel.DEBUG, LogType.MSG_IP_APPLY_BATCH);
+ mContentResolver.applyBatch(KeychainContract.CONTENT_AUTHORITY, operations);
+
+ // Save the saved keyring (if any)
+ if (secretRing != null) {
+ log(LogLevel.DEBUG, LogType.MSG_IP_REINSERT_SECRET);
+ mIndent += 1;
+ saveSecretKeyRing(secretRing);
+ result |= SaveKeyringResult.SAVED_SECRET;
+ mIndent -= 1;
+ }
+
+ mIndent -= 1;
+ log(LogLevel.OK, LogType.MSG_IP_SUCCESS);
+ return new SaveKeyringResult(result, mLog);
+
+ } catch (RemoteException e) {
+ log(LogLevel.ERROR, LogType.MSG_IP_FAIL_REMOTE_EX);
+ Log.e(Constants.TAG, "RemoteException during import", e);
+ mIndent -= 1;
+ return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
+ } catch (OperationApplicationException e) {
+ log(LogLevel.ERROR, LogType.MSG_IP_FAIL_OP_EX);
+ Log.e(Constants.TAG, "OperationApplicationException during import", e);
+ mIndent -= 1;
+ return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
}
}
@@ -378,14 +554,37 @@ public class ProviderHelper {
/**
* Saves a PGPSecretKeyRing in the DB. This will only work if a corresponding public keyring
* is already in the database!
+ *
+ * TODO allow adding secret keys where no public key exists (ie, consolidate keys)
*/
- public void saveSecretKeyRing(UncachedKeyRing keyRing) throws IOException {
+ public SaveKeyringResult saveSecretKeyRing(UncachedKeyRing keyRing) {
+
if (!keyRing.isSecret()) {
- throw new RuntimeException("Tried to save publkc keyring as secret! " +
- "This is a bug, please file a bug report.");
+ log(LogLevel.ERROR, LogType.MSG_IS_BAD_TYPE_PUBLIC);
+ return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
}
long masterKeyId = keyRing.getMasterKeyId();
+ log(LogLevel.START, LogType.MSG_IS,
+ new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) });
+ mIndent += 1;
+
+ // IF this is successful, it's a secret key
+ int result = SaveKeyringResult.SAVED_SECRET;
+
+ // save secret keyring
+ try {
+ ContentValues values = new ContentValues();
+ values.put(KeyRingData.MASTER_KEY_ID, masterKeyId);
+ values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded());
+ // insert new version of this keyRing
+ Uri uri = KeyRingData.buildSecretKeyRingUri(Long.toString(masterKeyId));
+ mContentResolver.insert(uri, values);
+ } catch (IOException e) {
+ Log.e(Constants.TAG, "Failed to encode key!", e);
+ log(LogLevel.ERROR, LogType.MSG_IS_IO_EXCPTION);
+ return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog);
+ }
{
Uri uri = Keys.buildKeysUri(Long.toString(masterKeyId));
@@ -397,24 +596,38 @@ public class ProviderHelper {
values.put(Keys.HAS_SECRET, 1);
// then, mark exactly the keys we have available
- for (Long sub : new IterableIterator(keyRing.getAvailableSubkeys().iterator())) {
- mContentResolver.update(uri, values, Keys.KEY_ID + " = ?", new String[] {
- Long.toString(sub)
- });
+ log(LogLevel.INFO, LogType.MSG_IS_IMPORTING_SUBKEYS);
+ mIndent += 1;
+ Set available = keyRing.getAvailableSubkeys();
+ for (UncachedPublicKey sub :
+ new IterableIterator(keyRing.getPublicKeys())) {
+ long id = sub.getKeyId();
+ if(available.contains(id)) {
+ int upd = mContentResolver.update(uri, values, Keys.KEY_ID + " = ?",
+ new String[] { Long.toString(id) });
+ if (upd == 1) {
+ log(LogLevel.DEBUG, LogType.MSG_IS_SUBKEY_OK, new String[]{
+ PgpKeyHelper.convertKeyIdToHex(id)
+ });
+ } else {
+ log(LogLevel.WARN, LogType.MSG_IS_SUBKEY_NONEXISTENT, new String[]{
+ PgpKeyHelper.convertKeyIdToHex(id)
+ });
+ }
+ } else {
+ log(LogLevel.INFO, LogType.MSG_IS_SUBKEY_STRIPPED, new String[]{
+ PgpKeyHelper.convertKeyIdToHex(id)
+ });
+ }
}
+ mIndent -= 1;
+
// this implicitly leaves all keys which were not in the secret key ring
// with has_secret = 0
}
- // save secret keyring
- {
- ContentValues values = new ContentValues();
- values.put(KeyRingData.MASTER_KEY_ID, masterKeyId);
- values.put(KeyRingData.KEY_RING_DATA, keyRing.getEncoded());
- // insert new version of this keyRing
- Uri uri = KeyRingData.buildSecretKeyRingUri(Long.toString(masterKeyId));
- mContentResolver.insert(uri, values);
- }
+ log(LogLevel.OK, LogType.MSG_IS_SUCCESS);
+ return new SaveKeyringResult(result, mLog);
}
@@ -432,37 +645,6 @@ public class ProviderHelper {
saveSecretKeyRing(secRing);
}
- /**
- * Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing
- */
- private ContentProviderOperation
- buildPublicKeyOperations(long masterKeyId, UncachedPublicKey key, int rank) throws IOException {
-
- ContentValues values = new ContentValues();
- values.put(Keys.MASTER_KEY_ID, masterKeyId);
- values.put(Keys.RANK, rank);
-
- values.put(Keys.KEY_ID, key.getKeyId());
- values.put(Keys.KEY_SIZE, key.getBitStrength());
- values.put(Keys.ALGORITHM, key.getAlgorithm());
- values.put(Keys.FINGERPRINT, key.getFingerprint());
-
- values.put(Keys.CAN_CERTIFY, key.canCertify());
- values.put(Keys.CAN_SIGN, key.canSign());
- values.put(Keys.CAN_ENCRYPT, key.canEncrypt());
- values.put(Keys.IS_REVOKED, key.maybeRevoked());
-
- values.put(Keys.CREATION, key.getCreationTime().getTime() / 1000);
- Date expiryDate = key.getExpiryTime();
- if (expiryDate != null) {
- values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
- }
-
- Uri uri = Keys.buildKeysUri(Long.toString(masterKeyId));
-
- return ContentProviderOperation.newInsert(uri).withValues(values).build();
- }
-
/**
* Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing
*/
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java
new file mode 100644
index 000000000..8db9294df
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/ContactSyncAdapterService.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.sufficientlysecure.keychain.service;
+
+import android.accounts.Account;
+import android.app.Service;
+import android.content.AbstractThreadedSyncAdapter;
+import android.content.ContentProviderClient;
+import android.content.Intent;
+import android.content.SyncResult;
+import android.os.*;
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.KeychainApplication;
+import org.sufficientlysecure.keychain.helper.ContactHelper;
+import org.sufficientlysecure.keychain.helper.EmailKeyHelper;
+import org.sufficientlysecure.keychain.util.Log;
+
+public class ContactSyncAdapterService extends Service {
+
+ private class ContactSyncAdapter extends AbstractThreadedSyncAdapter {
+
+ public ContactSyncAdapter() {
+ super(ContactSyncAdapterService.this, true);
+ }
+
+ @Override
+ public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
+ final SyncResult syncResult) {
+ EmailKeyHelper.importContacts(getContext(), new Messenger(new Handler(Looper.getMainLooper(),
+ new Handler.Callback() {
+ @Override
+ public boolean handleMessage(Message msg) {
+ Bundle data = msg.getData();
+ switch (msg.arg1) {
+ case KeychainIntentServiceHandler.MESSAGE_OKAY:
+ return true;
+ case KeychainIntentServiceHandler.MESSAGE_UPDATE_PROGRESS:
+ if (data.containsKey(KeychainIntentServiceHandler.DATA_PROGRESS) &&
+ data.containsKey(KeychainIntentServiceHandler.DATA_PROGRESS_MAX)) {
+ Log.d(Constants.TAG, "Progress: " +
+ data.getInt(KeychainIntentServiceHandler.DATA_PROGRESS) + "/" +
+ data.getInt(KeychainIntentServiceHandler.DATA_PROGRESS_MAX));
+ return false;
+ }
+ default:
+ Log.d(Constants.TAG, "Syncing... " + msg.toString());
+ return false;
+ }
+ }
+ })));
+ KeychainApplication.setupAccountAsNeeded(ContactSyncAdapterService.this);
+ ContactHelper.writeKeysToContacts(ContactSyncAdapterService.this);
+ }
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return new ContactSyncAdapter().getSyncAdapterBinder();
+ }
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/DummyAccountService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/DummyAccountService.java
new file mode 100644
index 000000000..008502ce7
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/DummyAccountService.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2014 Dominik Schürmann
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.sufficientlysecure.keychain.service;
+
+import android.accounts.AbstractAccountAuthenticator;
+import android.accounts.Account;
+import android.accounts.AccountAuthenticatorResponse;
+import android.accounts.NetworkErrorException;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.widget.Toast;
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.util.Log;
+
+/**
+ * This service actually does nothing, it's sole task is to show a Toast if the use tries to create an account.
+ */
+public class DummyAccountService extends Service {
+
+ private class Toaster {
+ private static final String TOAST_MESSAGE = "toast_message";
+ private Context context;
+ private Handler handler = new Handler(new Handler.Callback() {
+ @Override
+ public boolean handleMessage(Message msg) {
+ Toast.makeText(context, msg.getData().getString(TOAST_MESSAGE), Toast.LENGTH_LONG).show();
+ return true;
+ }
+ });
+
+ private Toaster(Context context) {
+ this.context = context;
+ }
+
+ public void toast(int resourceId) {
+ toast(context.getString(resourceId));
+ }
+
+ public void toast(String message) {
+ Message msg = new Message();
+ Bundle bundle = new Bundle();
+ bundle.putString(TOAST_MESSAGE, message);
+ msg.setData(bundle);
+ handler.sendMessage(msg);
+ }
+ }
+
+ private class Authenticator extends AbstractAccountAuthenticator {
+
+ public Authenticator() {
+ super(DummyAccountService.this);
+ }
+
+ @Override
+ public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
+ Log.d(Constants.TAG, "DummyAccountService.editProperties");
+ return null;
+ }
+
+ @Override
+ public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType,
+ String[] requiredFeatures, Bundle options) throws NetworkErrorException {
+ response.onResult(new Bundle());
+ toaster.toast(R.string.info_no_manual_account_creation);
+ Log.d(Constants.TAG, "DummyAccountService.addAccount");
+ return null;
+ }
+
+ @Override
+ public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options)
+ throws NetworkErrorException {
+ Log.d(Constants.TAG, "DummyAccountService.confirmCredentials");
+ return null;
+ }
+
+ @Override
+ public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType,
+ Bundle options) throws NetworkErrorException {
+ Log.d(Constants.TAG, "DummyAccountService.getAuthToken");
+ return null;
+ }
+
+ @Override
+ public String getAuthTokenLabel(String authTokenType) {
+ Log.d(Constants.TAG, "DummyAccountService.getAuthTokenLabel");
+ return null;
+ }
+
+ @Override
+ public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType,
+ Bundle options) throws NetworkErrorException {
+ Log.d(Constants.TAG, "DummyAccountService.updateCredentials");
+ return null;
+ }
+
+ @Override
+ public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features)
+ throws NetworkErrorException {
+ Log.d(Constants.TAG, "DummyAccountService.hasFeatures");
+ return null;
+ }
+ }
+
+ private Toaster toaster;
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ toaster = new Toaster(this);
+ return new Authenticator().getIBinder();
+ }
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
index 498b963f2..3ddcdfcf4 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
@@ -32,6 +32,7 @@ import org.sufficientlysecure.keychain.helper.FileHelper;
import org.sufficientlysecure.keychain.helper.OtherHelper;
import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
+import org.sufficientlysecure.keychain.keyimport.Keyserver;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserver;
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
@@ -174,14 +175,11 @@ public class KeychainIntentService extends IntentService
public static final String RESULT_DECRYPTED_BYTES = "decrypted_data";
public static final String RESULT_DECRYPT_VERIFY_RESULT = "signature";
- // import
- public static final String RESULT_IMPORT_ADDED = "added";
- public static final String RESULT_IMPORT_UPDATED = "updated";
- public static final String RESULT_IMPORT_BAD = "bad";
-
// export
public static final String RESULT_EXPORT = "exported";
+ public static final String RESULT = "result";
+
Messenger mMessenger;
private boolean mIsCanceled;
@@ -648,7 +646,10 @@ public class KeychainIntentService extends IntentService
List entries = data.getParcelableArrayList(IMPORT_KEY_LIST);
PgpImportExport pgpImportExport = new PgpImportExport(this, this);
- Bundle resultData = pgpImportExport.importKeyRings(entries);
+ OperationResults.ImportResult result = pgpImportExport.importKeyRings(entries);
+
+ Bundle resultData = new Bundle();
+ resultData.putParcelable(RESULT, result);
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData);
} catch (Exception e) {
@@ -734,49 +735,30 @@ public class KeychainIntentService extends IntentService
} catch (Exception e) {
sendErrorToHandler(e);
}
- } else if (ACTION_IMPORT_KEYBASE_KEYS.equals(action)) {
- ArrayList entries = data.getParcelableArrayList(DOWNLOAD_KEY_LIST);
-
- try {
- KeybaseKeyserver server = new KeybaseKeyserver();
- ArrayList keyRings = new ArrayList(entries.size());
- for (ImportKeysListEntry entry : entries) {
- // the keybase handle is in userId(1)
- String keybaseId = entry.getExtraData();
- byte[] downloadedKeyBytes = server.get(keybaseId).getBytes();
-
- // save key bytes in entry object for doing the
- // actual import afterwards
- keyRings.add(new ParcelableKeyRing(downloadedKeyBytes));
- }
-
- Intent importIntent = new Intent(this, KeychainIntentService.class);
- importIntent.setAction(ACTION_IMPORT_KEYRING);
- Bundle importData = new Bundle();
- importData.putParcelableArrayList(IMPORT_KEY_LIST, keyRings);
- importIntent.putExtra(EXTRA_DATA, importData);
- importIntent.putExtra(EXTRA_MESSENGER, mMessenger);
-
- // now import it with this service
- onHandleIntent(importIntent);
-
- // result is handled in ACTION_IMPORT_KEYRING
- } catch (Exception e) {
- sendErrorToHandler(e);
- }
- } else if (ACTION_DOWNLOAD_AND_IMPORT_KEYS.equals(action)) {
+ } else if (ACTION_DOWNLOAD_AND_IMPORT_KEYS.equals(action) || ACTION_IMPORT_KEYBASE_KEYS.equals(action)) {
try {
ArrayList entries = data.getParcelableArrayList(DOWNLOAD_KEY_LIST);
// this downloads the keys and places them into the ImportKeysListEntry entries
String keyServer = data.getString(DOWNLOAD_KEY_SERVER);
- HkpKeyserver server = new HkpKeyserver(keyServer);
ArrayList keyRings = new ArrayList(entries.size());
for (ImportKeysListEntry entry : entries) {
+
+ Keyserver server;
+ if (entry.getOrigin() == null) {
+ server = new HkpKeyserver(keyServer);
+ } else if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) {
+ server = new KeybaseKeyserver();
+ } else {
+ server = new HkpKeyserver(entry.getOrigin());
+ }
+
// if available use complete fingerprint for get request
byte[] downloadedKeyBytes;
- if (entry.getFingerprintHex() != null) {
+ if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) {
+ downloadedKeyBytes = server.get(entry.getExtraData()).getBytes();
+ } else if (entry.getFingerprintHex() != null) {
downloadedKeyBytes = server.get("0x" + entry.getFingerprintHex()).getBytes();
} else {
downloadedKeyBytes = server.get(entry.getKeyIdHex()).getBytes();
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java
new file mode 100644
index 000000000..b5f01ce4d
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java
@@ -0,0 +1,250 @@
+package org.sufficientlysecure.keychain.service;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.util.IterableIterator;
+
+import java.util.ArrayList;
+
+/** Represent the result of an operation.
+ *
+ * This class holds a result and the log of an operation. It can be subclassed
+ * to include typed additional information specific to the operation. To keep
+ * the class structure (somewhat) simple, this class contains an exhaustive
+ * list (ie, enum) of all possible log types, which should in all cases be tied
+ * to string resource ids.
+ *
+ */
+public class OperationResultParcel implements Parcelable {
+ /** Holds the overall result, the number specifying varying degrees of success. The first bit
+ * is 0 on overall success, 1 on overall failure. All other bits may be used for more specific
+ * conditions. */
+ final int mResult;
+
+ public static final int RESULT_OK = 0;
+ public static final int RESULT_ERROR = 1;
+
+ /// A list of log entries tied to the operation result.
+ final OperationLog mLog;
+
+ public OperationResultParcel(int result, OperationLog log) {
+ mResult = result;
+ mLog = log;
+ }
+
+ public OperationResultParcel(Parcel source) {
+ mResult = source.readInt();
+ mLog = new OperationLog();
+ mLog.addAll(source.createTypedArrayList(LogEntryParcel.CREATOR));
+ }
+
+ public int getResult() {
+ return mResult;
+ }
+
+ public boolean success() {
+ return (mResult & 1) == 0;
+ }
+
+ public OperationLog getLog() {
+ return mLog;
+ }
+
+ /** One entry in the log. */
+ public static class LogEntryParcel implements Parcelable {
+ public final LogLevel mLevel;
+ public final LogType mType;
+ public final String[] mParameters;
+ public final int mIndent;
+
+ public LogEntryParcel(LogLevel level, LogType type, String[] parameters, int indent) {
+ mLevel = level;
+ mType = type;
+ mParameters = parameters;
+ mIndent = indent;
+ }
+ public LogEntryParcel(LogLevel level, LogType type, String[] parameters) {
+ this(level, type, parameters, 0);
+ }
+
+ public LogEntryParcel(Parcel source) {
+ mLevel = LogLevel.values()[source.readInt()];
+ mType = LogType.values()[source.readInt()];
+ mParameters = source.createStringArray();
+ mIndent = source.readInt();
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(mLevel.ordinal());
+ dest.writeInt(mType.ordinal());
+ dest.writeStringArray(mParameters);
+ dest.writeInt(mIndent);
+ }
+
+ public static final Creator CREATOR = new Creator() {
+ public LogEntryParcel createFromParcel(final Parcel source) {
+ return new LogEntryParcel(source);
+ }
+
+ public LogEntryParcel[] newArray(final int size) {
+ return new LogEntryParcel[size];
+ }
+ };
+
+ }
+
+ public static enum LogType {
+
+ // import public
+ MSG_IP(R.string.msg_ip),
+ MSG_IP_APPLY_BATCH (R.string.msg_ip_apply_batch),
+ MSG_IP_BAD_TYPE_SECRET (R.string.msg_ip_bad_type_secret),
+ MSG_IP_DELETE_OLD_FAIL (R.string.msg_ip_delete_old_fail),
+ MSG_IP_DELETE_OLD_OK (R.string.msg_ip_delete_old_ok),
+ MSG_IP_ENCODE_FAIL (R.string.msg_ip_encode_fail),
+ MSG_IP_FAIL_IO_EXC (R.string.msg_ip_fail_io_exc),
+ MSG_IP_FAIL_OP_EX (R.string.msg_ip_fail_op_ex),
+ MSG_IP_FAIL_REMOTE_EX (R.string.msg_ip_fail_remote_ex),
+ MSG_IP_INSERT_KEYRING (R.string.msg_ip_insert_keyring),
+ MSG_IP_INSERT_SUBKEYS (R.string.msg_ip_insert_subkeys),
+ MSG_IP_PREPARE (R.string.msg_ip_prepare),
+ MSG_IP_PREPARE_SUCCESS(R.string.msg_ip_prepare_success),
+ MSG_IP_PRESERVING_SECRET (R.string.msg_ip_preserving_secret),
+ MSG_IP_REINSERT_SECRET (R.string.msg_ip_reinsert_secret),
+ MSG_IP_SUBKEY (R.string.msg_ip_subkey),
+ MSG_IP_SUBKEY_EXPIRED (R.string.msg_ip_subkey_expired),
+ MSG_IP_SUBKEY_EXPIRES (R.string.msg_ip_subkey_expires),
+ MSG_IP_SUBKEY_FLAGS (R.string.msg_ip_subkey_flags),
+ MSG_IP_SUBKEY_FLAGS_CES (R.string.msg_ip_subkey_flags_ces),
+ MSG_IP_SUBKEY_FLAGS_CEX (R.string.msg_ip_subkey_flags_cex),
+ MSG_IP_SUBKEY_FLAGS_CXS (R.string.msg_ip_subkey_flags_cxs),
+ MSG_IP_SUBKEY_FLAGS_XES (R.string.msg_ip_subkey_flags_xes),
+ MSG_IP_SUBKEY_FLAGS_CXX (R.string.msg_ip_subkey_flags_cxx),
+ MSG_IP_SUBKEY_FLAGS_XEX (R.string.msg_ip_subkey_flags_xex),
+ MSG_IP_SUBKEY_FLAGS_XXS (R.string.msg_ip_subkey_flags_xxs),
+ MSG_IP_SUBKEY_FLAGS_XXX (R.string.msg_ip_subkey_flags_xxx),
+ MSG_IP_SUCCESS (R.string.msg_ip_success),
+ MSG_IP_UID_CERT_BAD (R.string.msg_ip_uid_cert_bad),
+ MSG_IP_UID_CERT_ERROR (R.string.msg_ip_uid_cert_error),
+ MSG_IP_UID_CERT_GOOD (R.string.msg_ip_uid_cert_good),
+ MSG_IP_UID_CERTS_UNKNOWN (R.string.msg_ip_uid_certs_unknown),
+ MSG_IP_UID_CLASSIFYING (R.string.msg_ip_uid_classifying),
+ MSG_IP_UID_REORDER(R.string.msg_ip_uid_reorder),
+ MSG_IP_UID_PROCESSING (R.string.msg_ip_uid_processing),
+ MSG_IP_UID_REVOKED (R.string.msg_ip_uid_revoked),
+ MSG_IP_UID_SELF_GOOD (R.string.msg_ip_uid_self_good),
+
+ // import secret
+ MSG_IS(R.string.msg_is),
+ MSG_IS_BAD_TYPE_PUBLIC (R.string.msg_is_bad_type_public),
+ MSG_IS_IMPORTING_SUBKEYS (R.string.msg_is_importing_subkeys),
+ MSG_IS_IO_EXCPTION (R.string.msg_is_io_excption),
+ MSG_IS_SUBKEY_NONEXISTENT (R.string.msg_is_subkey_nonexistent),
+ MSG_IS_SUBKEY_OK (R.string.msg_is_subkey_ok),
+ MSG_IS_SUBKEY_STRIPPED (R.string.msg_is_subkey_stripped),
+ MSG_IS_SUCCESS (R.string.msg_is_success),
+
+ // keyring canonicalization
+ MSG_KC (R.string.msg_kc),
+ MSG_KC_MASTER (R.string.msg_kc_master),
+ MSG_KC_MASTER_SUCCESS (R.string.msg_kc_master_success),
+ MSG_KC_REVOKE_BAD_ERR (R.string.msg_kc_revoke_bad_err),
+ MSG_KC_REVOKE_BAD_LOCAL (R.string.msg_kc_revoke_bad_local),
+ MSG_KC_REVOKE_BAD_TIME (R.string.msg_kc_revoke_bad_time),
+ MSG_KC_REVOKE_BAD_TYPE (R.string.msg_kc_revoke_bad_type),
+ MSG_KC_REVOKE_BAD (R.string.msg_kc_revoke_bad),
+ MSG_KC_REVOKE_DUP (R.string.msg_kc_revoke_dup),
+ MSG_KC_SUB (R.string.msg_kc_sub),
+ MSG_KC_SUB_BAD(R.string.msg_kc_sub_bad),
+ MSG_KC_SUB_BAD_ERR(R.string.msg_kc_sub_bad_err),
+ MSG_KC_SUB_BAD_LOCAL(R.string.msg_kc_sub_bad_local),
+ MSG_KC_SUB_BAD_KEYID(R.string.msg_kc_sub_bad_keyid),
+ MSG_KC_SUB_BAD_TIME(R.string.msg_kc_sub_bad_time),
+ MSG_KC_SUB_BAD_TYPE(R.string.msg_kc_sub_bad_type),
+ MSG_KC_SUB_PRIMARY_BAD(R.string.msg_kc_sub_primary_bad),
+ MSG_KC_SUB_PRIMARY_BAD_ERR(R.string.msg_kc_sub_primary_bad_err),
+ MSG_KC_SUB_PRIMARY_NONE(R.string.msg_kc_sub_primary_none),
+ MSG_KC_SUB_NO_CERT(R.string.msg_kc_sub_no_cert),
+ MSG_KC_SUB_REVOKE_BAD_ERR (R.string.msg_kc_sub_revoke_bad_err),
+ MSG_KC_SUB_REVOKE_BAD (R.string.msg_kc_sub_revoke_bad),
+ MSG_KC_SUB_REVOKE_DUP (R.string.msg_kc_sub_revoke_dup),
+ MSG_KC_SUB_SUCCESS (R.string.msg_kc_sub_success),
+ MSG_KC_SUCCESS_REMOVED (R.string.msg_kc_success_removed),
+ MSG_KC_SUCCESS (R.string.msg_kc_success),
+ MSG_KC_UID_BAD_ERR (R.string.msg_kc_uid_bad_err),
+ MSG_KC_UID_BAD_LOCAL (R.string.msg_kc_uid_bad_local),
+ MSG_KC_UID_BAD_TIME (R.string.msg_kc_uid_bad_time),
+ MSG_KC_UID_BAD_TYPE (R.string.msg_kc_uid_bad_type),
+ MSG_KC_UID_BAD (R.string.msg_kc_uid_bad),
+ MSG_KC_UID_DUP (R.string.msg_kc_uid_dup),
+ MSG_KC_UID_REVOKE_DUP (R.string.msg_kc_uid_revoke_dup),
+ MSG_KC_UID_REVOKE_OLD (R.string.msg_kc_uid_revoke_old),
+ ;
+
+ private final int mMsgId;
+ LogType(int msgId) {
+ mMsgId = msgId;
+ }
+ public int getMsgId() {
+ return mMsgId;
+ }
+ }
+
+ /** Enumeration of possible log levels. */
+ public static enum LogLevel {
+ DEBUG,
+ INFO,
+ WARN,
+ ERROR, // should occur once at the end of a failed operation
+ START, // should occur once at the start of each independent operation
+ OK, // should occur once at the end of a successful operation
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(mResult);
+ dest.writeTypedList(mLog);
+ }
+
+ public static final Creator CREATOR = new Creator() {
+ public OperationResultParcel createFromParcel(final Parcel source) {
+ return new OperationResultParcel(source);
+ }
+
+ public OperationResultParcel[] newArray(final int size) {
+ return new OperationResultParcel[size];
+ }
+ };
+
+ public static class OperationLog extends ArrayList {
+
+ /// Simple convenience method
+ public void add(LogLevel level, LogType type, String[] parameters, int indent) {
+ add(new OperationResultParcel.LogEntryParcel(level, type, parameters, indent));
+ }
+
+ public boolean containsWarnings() {
+ for(LogEntryParcel entry : new IterableIterator(iterator())) {
+ if (entry.mLevel == LogLevel.WARN || entry.mLevel == LogLevel.ERROR) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ }
+
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java
new file mode 100644
index 000000000..6c44b01f1
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java
@@ -0,0 +1,92 @@
+package org.sufficientlysecure.keychain.service;
+
+import android.os.Parcel;
+
+public abstract class OperationResults {
+
+ public static class ImportResult extends OperationResultParcel {
+
+ public final int mNewKeys, mUpdatedKeys, mBadKeys;
+
+ // At least one new key
+ public static final int RESULT_OK_NEWKEYS = 2;
+ // At least one updated key
+ public static final int RESULT_OK_UPDATED = 4;
+ // At least one key failed (might still be an overall success)
+ public static final int RESULT_WITH_ERRORS = 8;
+ // There are warnings in the log
+ public static final int RESULT_WITH_WARNINGS = 16;
+
+ // No keys to import...
+ public static final int RESULT_FAIL_NOTHING = 32 +1;
+
+ public boolean isOkBoth() {
+ return (mResult & (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED))
+ == (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED);
+ }
+ public boolean isOkNew() {
+ return (mResult & RESULT_OK_NEWKEYS) == RESULT_OK_NEWKEYS;
+ }
+ public boolean isOkUpdated() {
+ return (mResult & RESULT_OK_UPDATED) == RESULT_OK_UPDATED;
+ }
+ public boolean isFailNothing() {
+ return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING;
+ }
+
+ public ImportResult(Parcel source) {
+ super(source);
+ mNewKeys = source.readInt();
+ mUpdatedKeys = source.readInt();
+ mBadKeys = source.readInt();
+ }
+
+ public ImportResult(int result, OperationLog log,
+ int newKeys, int updatedKeys, int badKeys) {
+ super(result, log);
+ mNewKeys = newKeys;
+ mUpdatedKeys = updatedKeys;
+ mBadKeys = badKeys;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ super.writeToParcel(dest, flags);
+ dest.writeInt(mNewKeys);
+ dest.writeInt(mUpdatedKeys);
+ dest.writeInt(mBadKeys);
+ }
+
+ public static Creator CREATOR = new Creator() {
+ public ImportResult createFromParcel(final Parcel source) {
+ return new ImportResult(source);
+ }
+
+ public ImportResult[] newArray(final int size) {
+ return new ImportResult[size];
+ }
+ };
+
+ }
+
+ public static class SaveKeyringResult extends OperationResultParcel {
+
+ public SaveKeyringResult(int result, OperationLog log) {
+ super(result, log);
+ }
+
+ // Some old key was updated
+ public static final int UPDATED = 2;
+
+ // Public key was saved
+ public static final int SAVED_PUBLIC = 8;
+ // Secret key was saved (not exclusive with public!)
+ public static final int SAVED_SECRET = 16;
+
+ public boolean updated() {
+ return (mResult & UPDATED) == UPDATED;
+ }
+
+ }
+
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpActivity.java
index 9edaff19a..bbc1e4b1f 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpActivity.java
@@ -25,7 +25,7 @@ import android.support.v7.app.ActionBarActivity;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
-import org.sufficientlysecure.keychain.util.SlidingTabLayout;
+import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout;
public class HelpActivity extends ActionBarActivity {
public static final String EXTRA_SELECTED_TAB = "selected_tab";
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java
index 48602aaa1..f389726ff 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java
@@ -38,7 +38,10 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
-import com.devspark.appmsg.AppMsg;
+import com.github.johnpersano.supertoasts.SuperCardToast;
+import com.github.johnpersano.supertoasts.SuperToast;
+import com.github.johnpersano.supertoasts.util.OnClickWrapper;
+import com.github.johnpersano.supertoasts.util.Style;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
@@ -47,7 +50,7 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
-import org.sufficientlysecure.keychain.ui.dialog.BadImportKeyDialogFragment;
+import org.sufficientlysecure.keychain.service.OperationResults.ImportResult;
import org.sufficientlysecure.keychain.util.Log;
import java.util.ArrayList;
@@ -135,6 +138,7 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
}
handleActions(savedInstanceState, getIntent());
+
}
protected void handleActions(Bundle savedInstanceState, Intent intent) {
@@ -331,8 +335,11 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
public void loadFromFingerprint(Bundle savedInstanceState, String fingerprint) {
if (fingerprint == null || fingerprint.length() < 40) {
- AppMsg.makeText(this, R.string.import_qr_code_too_short_fingerprint,
- AppMsg.STYLE_ALERT).show();
+ SuperCardToast toast = SuperCardToast.create(this,
+ getString(R.string.import_qr_code_too_short_fingerprint),
+ SuperToast.Duration.LONG);
+ toast.setBackground(SuperToast.Background.RED);
+ toast.show();
return;
}
@@ -368,39 +375,93 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
// get returned data bundle
Bundle returnData = message.getData();
+ final ImportResult result =
+ returnData.getParcelable(KeychainIntentService.RESULT);
+
+ int resultType = result.getResult();
+
+ String str;
+ int duration, color;
+
+ // Not an overall failure
+ if ((resultType & ImportResult.RESULT_ERROR) == 0) {
+ String withWarnings;
+
+ // Any warnings?
+ if ((resultType & ImportResult.RESULT_WITH_WARNINGS) > 0) {
+ duration = 0;
+ color = Style.ORANGE;
+ withWarnings = getResources().getString(R.string.import_with_warnings);
+ } else {
+ duration = SuperToast.Duration.LONG;
+ color = Style.GREEN;
+ withWarnings = "";
+ }
+
+ // New and updated keys
+ if (result.isOkBoth()) {
+ str = getResources().getQuantityString(
+ R.plurals.import_keys_added_and_updated_1, result.mNewKeys, result.mNewKeys);
+ str += getResources().getQuantityString(
+ R.plurals.import_keys_added_and_updated_2, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings);
+ } else if (result.isOkUpdated()) {
+ str = getResources().getQuantityString(
+ R.plurals.import_keys_updated, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings);
+ } else if (result.isOkNew()) {
+ str = getResources().getQuantityString(
+ R.plurals.import_keys_added, result.mNewKeys, result.mNewKeys, withWarnings);
+ } else {
+ duration = 0;
+ color = Style.RED;
+ str = "internal error";
+ }
- int added = returnData.getInt(KeychainIntentService.RESULT_IMPORT_ADDED);
- int updated = returnData
- .getInt(KeychainIntentService.RESULT_IMPORT_UPDATED);
- int bad = returnData.getInt(KeychainIntentService.RESULT_IMPORT_BAD);
- String toastMessage;
- if (added > 0 && updated > 0) {
- String addedStr = getResources().getQuantityString(
- R.plurals.keys_added_and_updated_1, added, added);
- String updatedStr = getResources().getQuantityString(
- R.plurals.keys_added_and_updated_2, updated, updated);
- toastMessage = addedStr + updatedStr;
- } else if (added > 0) {
- toastMessage = getResources().getQuantityString(R.plurals.keys_added,
- added, added);
- } else if (updated > 0) {
- toastMessage = getResources().getQuantityString(R.plurals.keys_updated,
- updated, updated);
} else {
- toastMessage = getString(R.string.no_keys_added_or_updated);
+ duration = 0;
+ color = Style.RED;
+ if (result.isFailNothing()) {
+ str = getString(R.string.import_error_nothing);
+ } else {
+ str = getString(R.string.import_error);
+ }
}
- AppMsg.makeText(ImportKeysActivity.this, toastMessage, AppMsg.STYLE_INFO)
- .show();
+
+ SuperCardToast toast = new SuperCardToast(ImportKeysActivity.this,
+ SuperToast.Type.BUTTON, Style.getStyle(color, SuperToast.Animations.POPUP));
+ toast.setText(str);
+ toast.setDuration(duration);
+ toast.setIndeterminate(duration == 0);
+ toast.setSwipeToDismiss(true);
+ toast.setButtonIcon(R.drawable.ic_action_view_as_list,
+ getResources().getString(R.string.import_view_log));
+ toast.setButtonTextColor(getResources().getColor(R.color.black));
+ toast.setTextColor(getResources().getColor(R.color.black));
+ toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
+ new SuperToast.OnClickListener() {
+ @Override
+ public void onClick(View view, Parcelable token) {
+ Intent intent = new Intent(
+ ImportKeysActivity.this, LogDisplayActivity.class);
+ intent.putExtra(LogDisplayFragment.EXTRA_RESULT, result);
+ startActivity(intent);
+ }
+ }));
+ toast.show();
+
+ /*
if (bad > 0) {
BadImportKeyDialogFragment badImportKeyDialogFragment =
BadImportKeyDialogFragment.newInstance(bad);
badImportKeyDialogFragment.show(getSupportFragmentManager(), "badKeyDialog");
}
+ */
+ /*
if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN.equals(getIntent().getAction())) {
ImportKeysActivity.this.setResult(Activity.RESULT_OK, mPendingIntentData);
finish();
}
+ */
}
}
};
@@ -483,7 +544,11 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O
startService(intent);
} else {
- AppMsg.makeText(this, R.string.error_nothing_import, AppMsg.STYLE_ALERT).show();
+ SuperCardToast toast = SuperCardToast.create(this,
+ getString(R.string.error_nothing_import),
+ SuperToast.Duration.LONG);
+ toast.setBackground(SuperToast.Background.RED);
+ toast.show();
}
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
index 9cc0f4667..5eb8ecb8d 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
@@ -252,7 +252,7 @@ public class KeyListFragment extends LoaderFragment
static final int INDEX_HAS_ANY_SECRET = 6;
static final String ORDER =
- KeyRings.HAS_ANY_SECRET + " DESC, " + KeyRings.USER_ID + " ASC";
+ KeyRings.HAS_ANY_SECRET + " DESC, UPPER(" + KeyRings.USER_ID + ") ASC";
@Override
@@ -592,7 +592,7 @@ public class KeyListFragment extends LoaderFragment
String userId = mCursor.getString(KeyListFragment.INDEX_USER_ID);
String headerText = convertView.getResources().getString(R.string.user_id_no_name);
if (userId != null && userId.length() > 0) {
- headerText = "" + userId.subSequence(0, 1).charAt(0);
+ headerText = "" + userId.charAt(0);
}
holder.mText.setText(headerText);
holder.mCount.setVisibility(View.GONE);
@@ -621,7 +621,7 @@ public class KeyListFragment extends LoaderFragment
// otherwise, return the first character of the name as ID
String userId = mCursor.getString(KeyListFragment.INDEX_USER_ID);
if (userId != null && userId.length() > 0) {
- return userId.charAt(0);
+ return Character.toUpperCase(userId.charAt(0));
} else {
return Long.MAX_VALUE;
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayActivity.java
new file mode 100644
index 000000000..a0d449195
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayActivity.java
@@ -0,0 +1,21 @@
+package org.sufficientlysecure.keychain.ui;
+
+import android.os.Bundle;
+import android.support.v4.view.GestureDetectorCompat;
+import android.support.v7.app.ActionBarActivity;
+import android.view.GestureDetector;
+import android.view.GestureDetector.SimpleOnGestureListener;
+import android.view.MotionEvent;
+
+import org.sufficientlysecure.keychain.R;
+
+public class LogDisplayActivity extends ActionBarActivity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.log_display_activity);
+ }
+
+}
\ No newline at end of file
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java
new file mode 100644
index 000000000..496e98c18
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java
@@ -0,0 +1,175 @@
+package org.sufficientlysecure.keychain.ui;
+
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.support.v4.app.ListFragment;
+import android.util.TypedValue;
+import android.view.GestureDetector;
+import android.view.GestureDetector.SimpleOnGestureListener;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.View.OnTouchListener;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.service.OperationResultParcel;
+import org.sufficientlysecure.keychain.service.OperationResultParcel.LogEntryParcel;
+import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel;
+import org.sufficientlysecure.keychain.util.Log;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class LogDisplayFragment extends ListFragment implements OnTouchListener {
+
+ HashMap mAdapters = new HashMap();
+ LogAdapter mAdapter;
+ LogLevel mLevel = LogLevel.DEBUG;
+
+ OperationResultParcel mResult;
+
+ GestureDetector mDetector;
+
+ public static final String EXTRA_RESULT = "log";
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ Intent intent = getActivity().getIntent();
+ if (intent.getExtras() == null || !intent.getExtras().containsKey(EXTRA_RESULT)) {
+ getActivity().finish();
+ return;
+ }
+
+ mResult = intent.getParcelableExtra(EXTRA_RESULT);
+ if (mResult == null) {
+ getActivity().finish();
+ return;
+ }
+
+ mAdapter = new LogAdapter(getActivity(), mResult.getLog(), LogLevel.DEBUG);
+ mAdapters.put(LogLevel.DEBUG, mAdapter);
+ setListAdapter(mAdapter);
+
+ mDetector = new GestureDetector(getActivity(), new SimpleOnGestureListener() {
+ @Override
+ public boolean onFling(MotionEvent e1, MotionEvent e2, float vx, float vy) {
+ Log.d(Constants.TAG, "x: " + vx + ", y: " + vy);
+ if (vx < -2000) {
+ decreaseLogLevel();
+ } else if (vx > 2000) {
+ increaseLogLevel();
+ }
+ return true;
+ }
+ });
+
+ }
+
+ public void decreaseLogLevel() {
+ switch (mLevel) {
+ case DEBUG: mLevel = LogLevel.INFO; break;
+ case INFO: mLevel = LogLevel.WARN; break;
+ }
+ refreshLevel();
+ }
+
+ public void increaseLogLevel() {
+ switch (mLevel) {
+ case INFO: mLevel = LogLevel.DEBUG; break;
+ case WARN: mLevel = LogLevel.INFO; break;
+ }
+ refreshLevel();
+ }
+
+ private void refreshLevel() {
+ /* TODO not sure if this is a good idea
+ if (!mAdapters.containsKey(mLevel)) {
+ mAdapters.put(mLevel, new LogAdapter(getActivity(), mResult.getLog(), mLevel));
+ }
+ mAdapter = mAdapters.get(mLevel);
+ setListAdapter(mAdapter);
+ */
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ getListView().setDividerHeight(0);
+ getListView().setOnTouchListener(this);
+ }
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ mDetector.onTouchEvent(event);
+ return false;
+ }
+
+ private class LogAdapter extends ArrayAdapter {
+
+ private LayoutInflater mInflater;
+ private int dipFactor;
+
+ public LogAdapter(Context context, ArrayList log, LogLevel level) {
+ super(context, R.layout.log_display_item);
+ mInflater = LayoutInflater.from(getContext());
+ dipFactor = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
+ (float) 8, getResources().getDisplayMetrics());
+ // we can't use addAll for a LogLevel.DEBUG shortcut here, unfortunately :(
+ for (LogEntryParcel e : log) {
+ if (e.mLevel.ordinal() >= level.ordinal()) {
+ add(e);
+ }
+ }
+ notifyDataSetChanged();
+ }
+
+ private class ItemHolder {
+ final TextView mText;
+ final ImageView mImg;
+ public ItemHolder(TextView text, ImageView image) {
+ mText = text;
+ mImg = image;
+ }
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ LogEntryParcel entry = getItem(position);
+ ItemHolder ih;
+ if (convertView == null) {
+ convertView = mInflater.inflate(R.layout.log_display_item, parent, false);
+ ih = new ItemHolder(
+ (TextView) convertView.findViewById(R.id.log_text),
+ (ImageView) convertView.findViewById(R.id.log_img)
+ );
+ convertView.setTag(ih);
+ } else {
+ ih = (ItemHolder) convertView.getTag();
+ }
+
+ ih.mText.setText(getResources().getString(entry.mType.getMsgId(), (Object[]) entry.mParameters));
+ ih.mText.setTextColor(entry.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK);
+ convertView.setPadding((entry.mIndent) * dipFactor, 0, 0, 0);
+ switch (entry.mLevel) {
+ case DEBUG: ih.mImg.setBackgroundColor(Color.GRAY); break;
+ case INFO: ih.mImg.setBackgroundColor(Color.BLACK); break;
+ case WARN: ih.mImg.setBackgroundColor(Color.YELLOW); break;
+ case ERROR: ih.mImg.setBackgroundColor(Color.RED); break;
+ case START: ih.mImg.setBackgroundColor(Color.GREEN); break;
+ case OK: ih.mImg.setBackgroundColor(Color.GREEN); break;
+ }
+
+ return convertView;
+ }
+
+ }
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
index f27a4ad27..463c800d2 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java
@@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui;
import android.annotation.TargetApi;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
@@ -32,6 +33,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.provider.ContactsContract;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
@@ -47,6 +49,7 @@ import com.devspark.appmsg.AppMsg;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.helper.ContactHelper;
import org.sufficientlysecure.keychain.helper.ExportHelper;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
@@ -54,7 +57,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
import org.sufficientlysecure.keychain.util.Log;
-import org.sufficientlysecure.keychain.util.SlidingTabLayout;
+import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout;
import java.util.Date;
import java.util.HashMap;
@@ -92,6 +95,8 @@ public class ViewKeyActivity extends ActionBarActivity implements
private static final int LOADER_ID_UNIFIED = 0;
+ private boolean mShowAdvancedTabs;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -116,16 +121,13 @@ public class ViewKeyActivity extends ActionBarActivity implements
mViewPager = (ViewPager) findViewById(R.id.view_key_pager);
mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.view_key_sliding_tab_layout);
- mTabsAdapter = new PagerTabStripAdapter(this);
- mViewPager.setAdapter(mTabsAdapter);
-
int switchToTab = TAB_MAIN;
Intent intent = getIntent();
if (intent.getExtras() != null && intent.getExtras().containsKey(EXTRA_SELECTED_TAB)) {
switchToTab = intent.getExtras().getInt(EXTRA_SELECTED_TAB);
}
- Uri dataUri = getIntent().getData();
+ Uri dataUri = getDataUri();
if (dataUri == null) {
Log.e(Constants.TAG, "Data missing. Should be Uri of key!");
finish();
@@ -136,6 +138,18 @@ public class ViewKeyActivity extends ActionBarActivity implements
initNfc(dataUri);
+ mShowAdvancedTabs = false;
+
+ initTabs(dataUri);
+
+ // switch to tab selected by extra
+ mViewPager.setCurrentItem(switchToTab);
+ }
+
+ private void initTabs(Uri dataUri) {
+ mTabsAdapter = new PagerTabStripAdapter(this);
+ mViewPager.setAdapter(mTabsAdapter);
+
Bundle mainBundle = new Bundle();
mainBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, dataUri);
mTabsAdapter.addTab(ViewKeyMainFragment.class,
@@ -146,6 +160,11 @@ public class ViewKeyActivity extends ActionBarActivity implements
mTabsAdapter.addTab(ViewKeyShareFragment.class,
mainBundle, getString(R.string.key_view_tab_share));
+ // update layout after operations
+ mSlidingTabLayout.setViewPager(mViewPager);
+ }
+
+ private void addAdvancedTabs(Uri dataUri) {
Bundle keyDetailsBundle = new Bundle();
keyDetailsBundle.putParcelable(ViewKeyKeysFragment.ARG_DATA_URI, dataUri);
mTabsAdapter.addTab(ViewKeyKeysFragment.class,
@@ -156,11 +175,54 @@ public class ViewKeyActivity extends ActionBarActivity implements
mTabsAdapter.addTab(ViewKeyCertsFragment.class,
certBundle, getString(R.string.key_view_tab_certs));
- // NOTE: must be after adding the tabs!
+ // update layout after operations
mSlidingTabLayout.setViewPager(mViewPager);
+ }
- // switch to tab selected by extra
- mViewPager.setCurrentItem(switchToTab);
+ private void removeAdvancedTabs() {
+ // before removing, switch to the first tab if necessary
+ if (mViewPager.getCurrentItem() >= TAB_KEYS) {
+ // remove _after_ switching to the main tab
+ mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+ }
+
+ @Override
+ public void onPageSelected(int position) {
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int state) {
+ if (ViewPager.SCROLL_STATE_SETTLING == state) {
+ mTabsAdapter.removeTab(TAB_CERTS);
+ mTabsAdapter.removeTab(TAB_KEYS);
+
+ // update layout after operations
+ mSlidingTabLayout.setViewPager(mViewPager);
+
+ // remove this listener again
+// mViewPager.setOnPageChangeListener(null);
+ }
+ }
+ });
+
+ mViewPager.setCurrentItem(TAB_MAIN);
+ } else {
+ mTabsAdapter.removeTab(TAB_CERTS);
+ mTabsAdapter.removeTab(TAB_KEYS);
+ }
+
+ // update layout after operations
+ mSlidingTabLayout.setViewPager(mViewPager);
+ }
+
+ private Uri getDataUri() {
+ Uri dataUri = getIntent().getData();
+ if (dataUri != null && dataUri.getHost().equals(ContactsContract.AUTHORITY)) {
+ dataUri = ContactHelper.dataUriFromContactUri(this, dataUri);
+ }
+ return dataUri;
}
private void loadData(Uri dataUri) {
@@ -177,6 +239,9 @@ public class ViewKeyActivity extends ActionBarActivity implements
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.key_view, menu);
+
+ MenuItem showAdvancedInfoItem = menu.findItem(R.id.menu_key_view_advanced);
+ showAdvancedInfoItem.setChecked(mShowAdvancedTabs);
return true;
}
@@ -184,24 +249,37 @@ public class ViewKeyActivity extends ActionBarActivity implements
public boolean onOptionsItemSelected(MenuItem item) {
try {
switch (item.getItemId()) {
- case android.R.id.home:
+ case android.R.id.home: {
Intent homeIntent = new Intent(this, KeyListActivity.class);
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(homeIntent);
return true;
- case R.id.menu_key_view_update:
+ }
+ case R.id.menu_key_view_update: {
updateFromKeyserver(mDataUri, mProviderHelper);
return true;
- case R.id.menu_key_view_export_keyserver:
+ }
+ case R.id.menu_key_view_export_keyserver: {
uploadToKeyserver(mDataUri);
return true;
- case R.id.menu_key_view_export_file:
+ }
+ case R.id.menu_key_view_export_file: {
exportToFile(mDataUri, mExportHelper, mProviderHelper);
return true;
+ }
case R.id.menu_key_view_delete: {
deleteKey(mDataUri, mExportHelper);
return true;
}
+ case R.id.menu_key_view_advanced: {
+ mShowAdvancedTabs = !mShowAdvancedTabs;
+ item.setChecked(mShowAdvancedTabs);
+ if (mShowAdvancedTabs) {
+ addAdvancedTabs(mDataUri);
+ } else {
+ removeAdvancedTabs();
+ }
+ }
}
} catch (ProviderHelper.NotFoundException e) {
AppMsg.makeText(this, R.string.error_key_not_found, AppMsg.STYLE_ALERT).show();
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java
index 0684efe0f..233b1fca8 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java
@@ -33,7 +33,6 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
import org.sufficientlysecure.keychain.pgp.KeyRing;
-import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.util.Highlighter;
import java.util.ArrayList;
@@ -120,13 +119,13 @@ public class ImportKeysAdapter extends ArrayAdapter {
}
// main user id
- String userId = entry.userIds.get(0);
+ String userId = entry.getUserIds().get(0);
String[] userIdSplit = KeyRing.splitUserId(userId);
// name
if (userIdSplit[0] != null) {
// show red user id if it is a secret key
- if (entry.secretKey) {
+ if (entry.isSecretKey()) {
holder.mainUserId.setText(mActivity.getString(R.string.secret_key)
+ " " + userIdSplit[0]);
holder.mainUserId.setTextColor(Color.RED);
@@ -147,30 +146,26 @@ public class ImportKeysAdapter extends ArrayAdapter {
holder.mainUserIdRest.setVisibility(View.GONE);
}
- holder.keyId.setText(entry.keyIdHex);
+ holder.keyId.setText(entry.getKeyIdHex());
- if (entry.fingerprintHex != null) {
- holder.fingerprint.setVisibility(View.VISIBLE);
- holder.fingerprint.setText(PgpKeyHelper.colorizeFingerprint(entry.fingerprintHex));
- } else {
- holder.fingerprint.setVisibility(View.GONE);
- }
+ // don't show full fingerprint on key import
+ holder.fingerprint.setVisibility(View.GONE);
- if (entry.bitStrength != 0 && entry.algorithm != null) {
- holder.algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm);
+ if (entry.getBitStrength() != 0 && entry.getAlgorithm() != null) {
+ holder.algorithm.setText("" + entry.getBitStrength() + "/" + entry.getAlgorithm());
holder.algorithm.setVisibility(View.VISIBLE);
} else {
holder.algorithm.setVisibility(View.INVISIBLE);
}
- if (entry.revoked) {
+ if (entry.isRevoked()) {
holder.status.setVisibility(View.VISIBLE);
holder.status.setText(R.string.revoked);
} else {
holder.status.setVisibility(View.GONE);
}
- if (entry.userIds.size() == 1) {
+ if (entry.getUserIds().size() == 1) {
holder.userIdsList.setVisibility(View.GONE);
} else {
holder.userIdsList.setVisibility(View.VISIBLE);
@@ -178,7 +173,7 @@ public class ImportKeysAdapter extends ArrayAdapter {
// clear view from holder
holder.userIdsList.removeAllViews();
- Iterator it = entry.userIds.iterator();
+ Iterator it = entry.getUserIds().iterator();
// skip primary user id
it.next();
while (it.hasNext()) {
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/PagerTabStripAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/PagerTabStripAdapter.java
index 977740567..3e3098b10 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/PagerTabStripAdapter.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/PagerTabStripAdapter.java
@@ -20,8 +20,13 @@ package org.sufficientlysecure.keychain.ui.adapter;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
+import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
+import android.view.ViewGroup;
+
+import org.sufficientlysecure.keychain.Constants;
import java.util.ArrayList;
@@ -52,6 +57,11 @@ public class PagerTabStripAdapter extends FragmentPagerAdapter {
notifyDataSetChanged();
}
+ public void removeTab(int index) {
+ mTabs.remove(index);
+ notifyDataSetChanged();
+ }
+
@Override
public int getCount() {
return mTabs.size();
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/SlidingTabLayout.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SlidingTabLayout.java
similarity index 99%
rename from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/SlidingTabLayout.java
rename to OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SlidingTabLayout.java
index 065034be1..17471c86c 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/SlidingTabLayout.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SlidingTabLayout.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.sufficientlysecure.keychain.util;
+package org.sufficientlysecure.keychain.ui.widget;
import android.content.Context;
import android.graphics.Typeface;
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/SlidingTabStrip.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SlidingTabStrip.java
similarity index 99%
rename from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/SlidingTabStrip.java
rename to OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SlidingTabStrip.java
index 9ce6f943e..4c41e12c5 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/SlidingTabStrip.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/SlidingTabStrip.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.sufficientlysecure.keychain.util;
+package org.sufficientlysecure.keychain.ui.widget;
import android.R;
import android.content.Context;
diff --git a/OpenKeychain/src/main/res/drawable-hdpi/ic_action_view_as_list.png b/OpenKeychain/src/main/res/drawable-hdpi/ic_action_view_as_list.png
new file mode 100644
index 000000000..86da228e9
Binary files /dev/null and b/OpenKeychain/src/main/res/drawable-hdpi/ic_action_view_as_list.png differ
diff --git a/OpenKeychain/src/main/res/drawable-mdpi/ic_action_view_as_list.png b/OpenKeychain/src/main/res/drawable-mdpi/ic_action_view_as_list.png
new file mode 100644
index 000000000..ccb4c7d7b
Binary files /dev/null and b/OpenKeychain/src/main/res/drawable-mdpi/ic_action_view_as_list.png differ
diff --git a/OpenKeychain/src/main/res/drawable-xhdpi/ic_action_view_as_list.png b/OpenKeychain/src/main/res/drawable-xhdpi/ic_action_view_as_list.png
new file mode 100644
index 000000000..b9c93c8c2
Binary files /dev/null and b/OpenKeychain/src/main/res/drawable-xhdpi/ic_action_view_as_list.png differ
diff --git a/OpenKeychain/src/main/res/drawable-xxhdpi/ic_action_view_as_list.png b/OpenKeychain/src/main/res/drawable-xxhdpi/ic_action_view_as_list.png
new file mode 100644
index 000000000..460041640
Binary files /dev/null and b/OpenKeychain/src/main/res/drawable-xxhdpi/ic_action_view_as_list.png differ
diff --git a/OpenKeychain/src/main/res/layout/help_activity.xml b/OpenKeychain/src/main/res/layout/help_activity.xml
index 76ba183b7..3ad087da3 100644
--- a/OpenKeychain/src/main/res/layout/help_activity.xml
+++ b/OpenKeychain/src/main/res/layout/help_activity.xml
@@ -4,7 +4,7 @@
android:layout_height="match_parent"
android:orientation="vertical" >
-
diff --git a/OpenKeychain/src/main/res/layout/import_keys_activity.xml b/OpenKeychain/src/main/res/layout/import_keys_activity.xml
index 2a332823e..0486b6bd6 100644
--- a/OpenKeychain/src/main/res/layout/import_keys_activity.xml
+++ b/OpenKeychain/src/main/res/layout/import_keys_activity.xml
@@ -1,22 +1,37 @@
-
+ android:layout_height="fill_parent"
+ android:orientation="vertical">
+
+
+
+
@@ -43,16 +58,4 @@
style="@style/SelectableItem" />
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/OpenKeychain/src/main/res/layout/log_display_activity.xml b/OpenKeychain/src/main/res/layout/log_display_activity.xml
new file mode 100644
index 000000000..591e2650c
--- /dev/null
+++ b/OpenKeychain/src/main/res/layout/log_display_activity.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OpenKeychain/src/main/res/layout/log_display_fragment.xml b/OpenKeychain/src/main/res/layout/log_display_fragment.xml
new file mode 100644
index 000000000..442e72d09
--- /dev/null
+++ b/OpenKeychain/src/main/res/layout/log_display_fragment.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OpenKeychain/src/main/res/layout/log_display_item.xml b/OpenKeychain/src/main/res/layout/log_display_item.xml
new file mode 100644
index 000000000..35489afed
--- /dev/null
+++ b/OpenKeychain/src/main/res/layout/log_display_item.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OpenKeychain/src/main/res/layout/view_key_activity.xml b/OpenKeychain/src/main/res/layout/view_key_activity.xml
index f43aade25..5aa1cd167 100644
--- a/OpenKeychain/src/main/res/layout/view_key_activity.xml
+++ b/OpenKeychain/src/main/res/layout/view_key_activity.xml
@@ -35,7 +35,7 @@
android:visibility="gone"
android:id="@+id/status_divider" />
-
diff --git a/OpenKeychain/src/main/res/menu/key_view.xml b/OpenKeychain/src/main/res/menu/key_view.xml
index 864016801..64877d725 100644
--- a/OpenKeychain/src/main/res/menu/key_view.xml
+++ b/OpenKeychain/src/main/res/menu/key_view.xml
@@ -31,4 +31,10 @@
app:showAsAction="never"
android:title="@string/menu_delete_key" />
+
+
\ No newline at end of file
diff --git a/OpenKeychain/src/main/res/values-de/strings.xml b/OpenKeychain/src/main/res/values-de/strings.xml
index e2dfa196b..3485846ad 100644
--- a/OpenKeychain/src/main/res/values-de/strings.xml
+++ b/OpenKeychain/src/main/res/values-de/strings.xml
@@ -206,23 +206,23 @@
Es wurde eine leere Identität hinzugefügt. Wirklich fortfahren?
Soll der öffentliche Schlüssel \'%s\' wirklich gelöscht werden?\nDies kann nicht rückgängig gemacht werden!
Private Schlüssel auch exportieren
-
+
- %d Schlüssel erfolgreich hinzugefügt
- %d Schlüssel erfolgreich hinzugefügt
-
+
- und %d Schlüssel erfolgreich aktualisiert.
- und %d Schlüssel erfolgreich aktualisiert.
-
+
- %d Schlüssel erfolgreich hinzugefügt.
- %d Schlüssel erfolgreich hinzugefügt.
-
+
- %d Schlüssel erfolgreich aktualisiert.
- %d Schlüssel erfolgreich aktualisiert.
- Keine Schlüssel hinzugefügt oder aktualisiert.
+ Keine Schlüssel hinzugefügt oder aktualisiert.
1 Schlüssel erfolgreich exportiert.
%d Schlüssel erfolgreich exportiert.
Keine Schlüssel exportiert.
diff --git a/OpenKeychain/src/main/res/values-es/strings.xml b/OpenKeychain/src/main/res/values-es/strings.xml
index 45d3d565b..f1e4e347d 100644
--- a/OpenKeychain/src/main/res/values-es/strings.xml
+++ b/OpenKeychain/src/main/res/values-es/strings.xml
@@ -206,23 +206,23 @@
Ha añadido una identidad vacía, ¿está seguro de que quiere continuar?
¿De veras quiere borrar la clave pública \'%s\'?\n¡No puede deshacer esto!
¿Exportar también las claves secretas?
-
+
- %d clave añadida satisfactoriamente
- %d claves añadidas satisfactoriamente
-
+
- y actualizada %d clave.
- y actualizadas %d claves.
-
+
- %d clave añadida satisfactoriamente.
- %d claves añadidas satisfactoriamente.
-
+
- %d clave actualizada satisfactoriamente.
- %d claves actualizadas satisfactoriamente.
- No se han añadido o actualizado claves.
+ No se han añadido o actualizado claves.
Se ha exportado 1 clave satisfactoriamente.
%d claves exportadas satisfactoriamente.
No se han exportado claves.
diff --git a/OpenKeychain/src/main/res/values-fr/strings.xml b/OpenKeychain/src/main/res/values-fr/strings.xml
index f49127b6f..55a85fb9b 100644
--- a/OpenKeychain/src/main/res/values-fr/strings.xml
+++ b/OpenKeychain/src/main/res/values-fr/strings.xml
@@ -206,23 +206,23 @@
Vous avez ajouté une identité vide, êtes-vous certain de vouloir continuer ?
Voulez-vous vraiment supprimer la clef publique %s ?\nCeci est irréversible !
Exporter aussi les clefs secrètes ?
-
+
- %d clef ajoutée avec succès
- %d clefs ajoutées avec succès
-
+
- et %d clef mise à jour.
- et %d clefs mises à jour.
-
+
- %d clef ajoutée avec succès.
- %d clefs ajoutées avec succès.
-
+
- %d clef mise à jour avec succès.
- %d clefs mises à jour avec succès.
- Aucune clef ajoutée ou mise à jour.
+ Aucune clef ajoutée ou mise à jour.
1 clef exportée avec succès.
%d clefs exportées avec succès.
Aucune clef exportée.
diff --git a/OpenKeychain/src/main/res/values-it/strings.xml b/OpenKeychain/src/main/res/values-it/strings.xml
index eae4dd4af..300627fa7 100644
--- a/OpenKeychain/src/main/res/values-it/strings.xml
+++ b/OpenKeychain/src/main/res/values-it/strings.xml
@@ -206,23 +206,23 @@
Hai aggiunto una identità vuota, sei sicuro di voler continuare?
Vuoi veramente eliminare la chiave pubblica \'%s\'?\nNon potrai annullare!
Esportare anche le chiavi segrete?
-
+
- %d chiave aggiunta correttamente
- %d chiavi aggiunte correttamente
-
+
- e %d chiave aggiornata.
- e %d chiavi aggiornate.
-
+
- %d chiave aggiunta correttamente.
- %d chiavi aggiunte correttamente.
-
+
- %d chiave aggiornata correttamente.
- %d chiavi aggiornate correttamente.
- Nessuna chiave aggiunta o aggiornata.
+ Nessuna chiave aggiunta o aggiornata.
1 chiave esportata correttamente.
%d chiavi esportate correttamente.
Nessuna chiave esportata.
diff --git a/OpenKeychain/src/main/res/values-ja/strings.xml b/OpenKeychain/src/main/res/values-ja/strings.xml
index c40e9dbdc..63fef2af2 100644
--- a/OpenKeychain/src/main/res/values-ja/strings.xml
+++ b/OpenKeychain/src/main/res/values-ja/strings.xml
@@ -203,19 +203,19 @@
あなたは空のユーザIDを追加しました、このまま続けますか?
公開鍵\'%s\'を本当に削除してもよいですか?\nこれは元に戻せません!
秘密鍵もエクスポートしますか?
-
+
- %d の鍵を追加しました
-
+
- そして %d の鍵をアップロードしました。
-
+
- %d の鍵を追加しました。
-
+
- %d の鍵をアップロードしました。
- 鍵の追加もしくは更新はありませんでした。
+ 鍵の追加もしくは更新はありませんでした。
1つの鍵をエクスポートしました。
%d の鍵をエクスポートしました。
鍵をエクスポートしていません。
diff --git a/OpenKeychain/src/main/res/values-nl/strings.xml b/OpenKeychain/src/main/res/values-nl/strings.xml
index d35d83517..f75d7a166 100644
--- a/OpenKeychain/src/main/res/values-nl/strings.xml
+++ b/OpenKeychain/src/main/res/values-nl/strings.xml
@@ -206,23 +206,23 @@
U heeft een lege identiteit toegevoegd, weet u zeker dat u wilt doorgaan?
Wilt u echt de publieke sleutel \'%s\' verwijderen?\nDit kunt u niet ongedaan maken!
Ook geheime sleutels exporteren?
-
+
- Succesvol %d sleutel toegevoegd
- Succesvol %d sleutels toegevoegd
-
+
- en %d sleutel bijgewerkt.
- en %d sleutels bijgewerkt.
-
+
- Succesvol %d sleutel toegevoegd.
- Succesvol %d sleutels toegevoegd.
-
+
- Succesvol %d sleutel bijgewerkt.
- Succesvol %d sleutels bijgewerkt.
- Geen sleutels toegevoegd of bijgewerkt.
+ Geen sleutels toegevoegd of bijgewerkt.
1 sleutel succesvol geëxporteerd.
Succesvol %d sleutels geëxporteerd.
Geen sleutels geëxporteerd.
diff --git a/OpenKeychain/src/main/res/values-pl/strings.xml b/OpenKeychain/src/main/res/values-pl/strings.xml
index d1b7de393..851e77c3a 100644
--- a/OpenKeychain/src/main/res/values-pl/strings.xml
+++ b/OpenKeychain/src/main/res/values-pl/strings.xml
@@ -191,27 +191,27 @@
Zostały dokonane zmiany w pęku kluczy, czy chcesz je zachować?
Czy na pewno chcesz usunąć klucz publiczny \'%s\'?\nNie można cofnąć tej operacji!
Czy wyeksportować również klucze prywatne?
-
+
- Pomyślnie dodano %d klucz
- Pomyślnie dodano %d kluczy
- Pomyślnie dodano %d kluczy
-
+
- i zaktualizowano %d klucz.
- i zaktualizowano %d kluczy.
- i zaktualizowano %d kluczy.
-
+
- Pomyślnie dodano %d klucz.
- Pomyślnie dodano %d kluczy.
- Pomyślnie dodano %d kluczy.
-
+
- Pomyślnie zaktualizowano %d klucz.
- Pomyślnie zaktualizowano %d kluczy.
- Pomyślnie zaktualizowano %d kluczy.
- Nie dodano ani zaktualizowano żadnych kluczy.
+ Nie dodano ani zaktualizowano żadnych kluczy.
Pomyślnie wyeksportowano 1 klucz.
Pomyślnie wyeksportowano %d kluczy.
Nie wyeksportowano żadnych kluczy.
diff --git a/OpenKeychain/src/main/res/values-ru/strings.xml b/OpenKeychain/src/main/res/values-ru/strings.xml
index 0becea0bc..b108324d1 100644
--- a/OpenKeychain/src/main/res/values-ru/strings.xml
+++ b/OpenKeychain/src/main/res/values-ru/strings.xml
@@ -206,27 +206,27 @@
Вы добавили пустой идентификатор. Вы уверены, что хотите продолжить?
Вы правда хотите удалить публичный ключ \'%s\'?\nЭто действие нельзя отменить!
Экспортировать секретные ключи?
-
+
- Успешно добавлено %d ключ
- Успешно добавлено %d ключей
- Успешно добавлено %d ключей
-
+
- и обновлен %d ключ.
- и обновлено %d ключей.
- и обновлено %d ключей.
-
+
- Добавлен %d ключ
- Добавлено %d ключей
- Добавлено %d ключей
-
+
- Обновлен %d ключ.
- Обновлено %d ключей.
- Обновлено %d ключей.
- Нет обновленных или добавленных ключей
+ Нет обновленных или добавленных ключей
Успешный экспорт 1 ключа.
Экспортировано %d ключей.
Ключи не были экспортированы.
diff --git a/OpenKeychain/src/main/res/values-sl/strings.xml b/OpenKeychain/src/main/res/values-sl/strings.xml
index 8b12cdebe..0fe44725b 100644
--- a/OpenKeychain/src/main/res/values-sl/strings.xml
+++ b/OpenKeychain/src/main/res/values-sl/strings.xml
@@ -212,31 +212,31 @@
Dodali ste prazno identiteto, ali res želite nadaljevati?
Ali res želite izbrisati javni ključ \'%s\'?\nTega koraka ne boste mogli preklicati!
Želite izvoziti tudi zasebne ključe?
-
+
- Uspešno dodan %d ključ
- Uspešno dodana %d ključa
- Uspešno dodani %d ključi
- Uspešno dodanih %d ključev
-
+
- in posodbljen %d.
- in posodobljena %d.
- in posodobljeni %d.
- in posodobljenih %d.
-
+
- Uspešno dodan %d ključ.
- Uspešno dodana %d ključa.
- Uspešno dodani %d ključi.
- Uspešno dodanih %d ključev.
-
+
- Uspešno posodobljen %d ključ.
- Uspešno posodobljena %d ključa.
- Uspešno posodobljeni %d ključi.
- Uspešno posodobljenih %d ključev.
- Noben ključ ni bil dodan ali posodobljen.
+ Noben ključ ni bil dodan ali posodobljen.
Uspešno izvožen 1 ključ.
Uspešno izvoženih ključev: %d
Noben ključ ni bil izvožen.
diff --git a/OpenKeychain/src/main/res/values-uk/strings.xml b/OpenKeychain/src/main/res/values-uk/strings.xml
index b27b6ffd3..2951d13f8 100644
--- a/OpenKeychain/src/main/res/values-uk/strings.xml
+++ b/OpenKeychain/src/main/res/values-uk/strings.xml
@@ -209,27 +209,27 @@
Ви вже додали порожню сутність. Ви справді хочете продовжити?
Ви справді хочете вилучити відкритий ключ \'%s\'?\nВи не зможете це відмінити!
Також експортувати секретні ключі?
-
+
- Успішно додано %d ключ
- Успішно додано %d ключі
- Успішно додано %d ключів
-
+
- і оновлено %d ключ.
- і оновлено %d ключі.
- і оновлено %d ключів.
-
+
- Успішно додано %d ключ.
- Успішно додано %d ключі.
- Успішно додано %d ключів.
-
+
- Успішно оновлено %d ключ.
- Успішно оновлено %d ключі.
- Успішно оновлено %d ключів.
- Жодного ключа не додано та не оновлено.
+ Жодного ключа не додано та не оновлено.
Успішно експортовано 1 ключ.
Успішно експортовано %d ключів.
Жодного ключа не експортовано.
diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml
index eeb6b3742..5a2c38419 100644
--- a/OpenKeychain/src/main/res/values/strings.xml
+++ b/OpenKeychain/src/main/res/values/strings.xml
@@ -28,6 +28,7 @@
Certify Identities
Key Details
Help
+ Log
Identities
@@ -102,6 +103,7 @@
Select all
Add keys
Export all keys
+ Show advanced info
Sign
@@ -220,24 +222,6 @@
Do you really want to delete the public key \'%s\'?\nYou can\'t undo this!
Also export secret keys?
-
- - Successfully added %d key
- - Successfully added %d keys
-
-
- - and updated %d key.
- - and updated %d keys.
-
-
- - Successfully added %d key.
- - Successfully added %d keys.
-
-
- - Successfully updated %d key.
- - Successfully updated %d keys.
-
-
- No keys added or updated.
Successfully exported 1 key.
Successfully exported %d keys.
No keys exported.
@@ -406,6 +390,28 @@
Get key from clipboard
Get key from Keybase.io
+
+
+ - Successfully added %1$d key
+ - Successfully added %1$d keys
+
+
+ - and updated %1$d key%2$s.
+ - and updated %1$d keys%2$s.
+
+
+ - Successfully added %1$d key%2$s.
+ - Successfully added %1$d keys%2$s.
+
+
+ - Successfully updated %1$d key%2$s.
+ - Successfully updated %1$d keys%2$s.
+
+ View Log
+ Nothing to import.
+ Error importing keys!
+ , with warnings
+
Decrypt File with OpenKeychain
Import Key with OpenKeychain
@@ -499,6 +505,91 @@
error!
key unavailable
+
+ Applying insert batch operation.
+ Tried to import secret keyring as public. This is a bug, please file a report!
+ No old key deleted (creating a new one?)
+ Deleted old key from database
+ Operation failed due to encoding error
+ Operation failed due to i/o error
+ Operation failed due to database error
+ Operation failed due to internal error
+ Importing public keyring %s
+ Encoding keyring data
+ Evaluating subkeys
+ Preparing database operations
+ OK
+ Preserving available secret key
+ Processing subkey %s
+ Subkey expired on %s
+ Subkey expires on %s
+ Subkey flags: %s
+ Subkey flags: certify, encrypt, sign
+ Subkey flags: certify, encrypt
+ Subkey flags: certify, sign
+ Subkey flags: encrypt, sign
+ Subkey flags: certify
+ Subkey flags: encrypt
+ Subkey flags: sign
+ Subkey flags: none
+ Successfully imported public keyring
+ Re-inserting secret key
+ Encountered bad certificate!
+ Error processing certificate!
+ Found good certificate from %1$s (%2$s)
+ Ignoring %s certificates from unknown pubkeys
+ Classifying user ids, using %s trusted signatures
+ Re-ordering user ids
+ Processing user id %s
+ Found uid revocation certificate
+ Found good self certificate
+ Tried to import public keyring as secret. This is a bug, please file a report!
+
+
+ Importing secret key %s
+ Processing secret subkeys
+ Error encoding keyring
+ Subkey %s unavailable in public key
+ Marked %s as available
+ Marked %s as stripped
+ Successfully imported secret keyring
+
+
+ Canonicalizing keyring %s
+ Processing master key
+ OK
+ Removing bad keyring revocation certificate
+ Removing keyring revocation certificate with "local" flag
+ Removing keyring revocation certificate with future timestamp
+ Removing master key certificate of unknown type (%s)
+ Removing bad keyring revocation certificate
+ Removing redundant keyring revocation certificate
+ Processing subkey %s
+ Removing invalid subkey binding certificate
+ Removing bad subkey binding certificate
+ Removing subkey binding certificate with "local" flag
+ Subkey binding issuer id mismatch
+ Removing subkey binding certificate with future timestamp
+ Unknown subkey certificate type: %s
+ Removing subkey binding certificate due to invalid primary binding certificate
+ Removing subkey binding certificate due to bad primary binding certificate
+ Removing subkey binding certificate due to missing primary binding certificate
+ No valid certificate found for %s, removing from ring
+ Removing bad subkey revocation key
+ Removing bad subkey revocation key
+ Removing redundant keyring revocation key
+ Subkey binding OK
+ Keyring canonicalization successful
+ Keyring canonicalization successful, removed %s certificates
+ Removing bad self certificate for user id %s
+ Removing user id certificate with "local" flag
+ Removing user id with future timestamp
+ Removing user id certificate of unknown type (%s)
+ Removing bad self certificate for user id "%s"
+ Removing outdated self certificate for user id "%s"
+ Removing redundant revocation certificate for user id "%s"
+ Removing outdated revocation certificate for user id "%s"
+
Certifier
Certificate Details
@@ -519,5 +610,7 @@
cannot sign
Encoding error
No encryption subkey available!
+ Do not create OpenKeychain-Accounts manually.\nFor more information, see Help.
+ Show key (%s)
diff --git a/OpenKeychain/src/main/res/xml/account_desc.xml b/OpenKeychain/src/main/res/xml/account_desc.xml
new file mode 100644
index 000000000..94ffdf40b
--- /dev/null
+++ b/OpenKeychain/src/main/res/xml/account_desc.xml
@@ -0,0 +1,6 @@
+
+
+
diff --git a/OpenKeychain/src/main/res/xml/custom_pgp_contacts_structure.xml b/OpenKeychain/src/main/res/xml/custom_pgp_contacts_structure.xml
new file mode 100644
index 000000000..5f5f2be80
--- /dev/null
+++ b/OpenKeychain/src/main/res/xml/custom_pgp_contacts_structure.xml
@@ -0,0 +1,5 @@
+
+
+
+
\ No newline at end of file
diff --git a/OpenKeychain/src/main/res/xml/sync_adapter_desc.xml b/OpenKeychain/src/main/res/xml/sync_adapter_desc.xml
new file mode 100644
index 000000000..d8fe60e91
--- /dev/null
+++ b/OpenKeychain/src/main/res/xml/sync_adapter_desc.xml
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index d8327c66b..231dc7f16 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,7 @@ Development mailinglist at http://groups.google.com/d/forum/openpgp-keychain-dev
1. Get all external submodules with ``git submodule update --init --recursive``
2. Have Android SDK "tools", "platform-tools", and "build-tools" directories in your PATH (http://developer.android.com/sdk/index.html)
3. Open the Android SDK Manager (shell command: ``android``).
-Expand the Tools directory and select "Android SDK Build-tools (Version 19.0.3)".
+Expand the Tools directory and select "Android SDK Build-tools (Version 19.1)".
Expand the Extras directory and install "Android Support Repository"
Select everything for the newest SDK Platform (API-Level 19)
4. Export ANDROID_HOME pointing to your Android SDK
@@ -42,8 +42,8 @@ Select everything for the newest SDK Platform (API-Level 19)
### Build API Demo with Gradle
-1. Follow 1-3 from above
-2. Change to API Demo directory ``cd OpenKeychain-API``
+1. Follow 1-4 from above
+2. The example code is available at https://github.com/open-keychain/api-example
3. Execute ``./gradlew build``
### Development with Android Studio
diff --git a/build.gradle b/build.gradle
index 815a8ff9a..e3cafe3ce 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,8 +5,8 @@ buildscript {
dependencies {
// NOTE: Always use fixed version codes not dynamic ones, e.g. 0.7.3 instead of 0.7.+, see README for more information
- classpath 'com.android.tools.build:gradle:0.10.0'
- classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.0'
+ classpath 'com.android.tools.build:gradle:0.11.1'
+ //classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.0'
}
}
@@ -17,5 +17,5 @@ allprojects {
}
task wrapper(type: Wrapper) {
- gradleVersion = '1.10'
+ gradleVersion = '1.12'
}
diff --git a/extern/AndroidBootstrap b/extern/AndroidBootstrap
index bfa160c4e..02f02391e 160000
--- a/extern/AndroidBootstrap
+++ b/extern/AndroidBootstrap
@@ -1 +1 @@
-Subproject commit bfa160c4ef3a1a53aebd68aca9c05b8e546219e0
+Subproject commit 02f02391e3eee9331e07d7690d3b533a8b0f69e2
diff --git a/extern/AppMsg b/extern/AppMsg
index ca714df97..61e747419 160000
--- a/extern/AppMsg
+++ b/extern/AppMsg
@@ -1 +1 @@
-Subproject commit ca714df97bfce67a7a9a1efefd2c49645b6f22e4
+Subproject commit 61e74741909a712db2e0d31ddffa5b7cf37c21f2
diff --git a/extern/StickyListHeaders b/extern/StickyListHeaders
index efe46c211..706c0e447 160000
--- a/extern/StickyListHeaders
+++ b/extern/StickyListHeaders
@@ -1 +1 @@
-Subproject commit efe46c21143cc54a2394303a67822f14580d1d20
+Subproject commit 706c0e447229226b6edc82ab10630d39fd0f6c38
diff --git a/extern/SuperToasts b/extern/SuperToasts
new file mode 160000
index 000000000..8578cfe69
--- /dev/null
+++ b/extern/SuperToasts
@@ -0,0 +1 @@
+Subproject commit 8578cfe6917cf16a9f123c1964e4bbff2a15be59
diff --git a/extern/dnsjava b/extern/dnsjava
new file mode 160000
index 000000000..71c8a9e56
--- /dev/null
+++ b/extern/dnsjava
@@ -0,0 +1 @@
+Subproject commit 71c8a9e56b19b34907e7e2e810ca15b57e3edc2b
diff --git a/extern/html-textview b/extern/html-textview
index c31ef2aff..eedaa334e 160000
--- a/extern/html-textview
+++ b/extern/html-textview
@@ -1 +1 @@
-Subproject commit c31ef2aff4282ad00af98e879e3e0a6000885b55
+Subproject commit eedaa334e761273efbfc49ded2124df58c8a4d88
diff --git a/extern/openkeychain-api-lib b/extern/openkeychain-api-lib
index 26497acb2..175a3cb77 160000
--- a/extern/openkeychain-api-lib
+++ b/extern/openkeychain-api-lib
@@ -1 +1 @@
-Subproject commit 26497acb27e9f6349c0557b15cd24a5b0b735e74
+Subproject commit 175a3cb772c88c9b50985abc98f81c9ea69c3659
diff --git a/extern/openpgp-api-lib b/extern/openpgp-api-lib
index 650e1ebda..a77887d32 160000
--- a/extern/openpgp-api-lib
+++ b/extern/openpgp-api-lib
@@ -1 +1 @@
-Subproject commit 650e1ebda82596cd4fbfaae406e6eccf189f4f63
+Subproject commit a77887d32fae68171fcd0d2989bf537c0c11f0b9
diff --git a/extern/zxing-android-integration b/extern/zxing-android-integration
index 34029d4dc..1d7878456 160000
--- a/extern/zxing-android-integration
+++ b/extern/zxing-android-integration
@@ -1 +1 @@
-Subproject commit 34029d4dcac81ec06137a046a189dac608e76efe
+Subproject commit 1d787845663fd232f98f5e8e0923733c1a188f2a
diff --git a/extern/zxing-qr-code b/extern/zxing-qr-code
index 50193905f..9ef2f3b66 160000
--- a/extern/zxing-qr-code
+++ b/extern/zxing-qr-code
@@ -1 +1 @@
-Subproject commit 50193905fd8cef92140ea242f77b04bb31391c9e
+Subproject commit 9ef2f3b66ea7cc283e865ec39434d023a18d17f3
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index d8e0b5b29..cc3d5d9a3 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Thu Mar 06 22:23:44 CET 2014
+#Mon Jun 09 22:04:23 CEST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-bin.zip
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-bin.zip
diff --git a/settings.gradle b/settings.gradle
index b0162875a..282c8a234 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -11,3 +11,5 @@ include ':extern:spongycastle:pg'
include ':extern:spongycastle:pkix'
include ':extern:spongycastle:prov'
include ':extern:AppMsg:library'
+include ':extern:SuperToasts:supertoasts'
+include ':extern:dnsjava'