From 710a0d8fe8d89cb9a1f247007000a7f49a29c527 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 10 Mar 2016 18:31:30 +0100 Subject: add extra for opportunistic encryption and according return status --- openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpError.java | 2 ++ openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java | 1 + 2 files changed, 3 insertions(+) diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpError.java b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpError.java index 69c39fd..67b10aa 100644 --- a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpError.java +++ b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpError.java @@ -33,6 +33,8 @@ public class OpenPgpError implements Parcelable { public static final int INCOMPATIBLE_API_VERSIONS = 1; public static final int NO_OR_WRONG_PASSPHRASE = 2; public static final int NO_USER_IDS = 3; + public static final int OPPORTUNISTIC_MISSING_KEYS = 4; + int errorId; String message; diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java index 658823a..fe019ab 100644 --- a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java +++ b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java @@ -236,6 +236,7 @@ public class OpenPgpApi { public static final String EXTRA_PASSPHRASE = "passphrase"; public static final String EXTRA_ORIGINAL_FILENAME = "original_filename"; public static final String EXTRA_ENABLE_COMPRESSION = "enable_compression"; + public static final String EXTRA_OPPORTUNISTIC_ENCRYPTION = "opportunistic"; // GET_SIGN_KEY_ID public static final String EXTRA_USER_ID = "user_id"; -- cgit v1.2.3 From f027645214ff41a54e15cc46058ce9f1867cad5f Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 29 Apr 2016 15:46:03 +0200 Subject: add optional cached sessionKey to OpenPgpDecryptionResult --- .../openpgp/OpenPgpDecryptionResult.java | 39 ++++++++++++++++------ .../org/openintents/openpgp/util/OpenPgpApi.java | 2 ++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpDecryptionResult.java b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpDecryptionResult.java index 2090b55..513b502 100644 --- a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpDecryptionResult.java +++ b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpDecryptionResult.java @@ -25,7 +25,7 @@ public class OpenPgpDecryptionResult implements Parcelable { * old versions of the protocol (and thus old versions of this class), we need a versioning * system for the parcels sent between the clients and the providers. */ - public static final int PARCELABLE_VERSION = 1; + public static final int PARCELABLE_VERSION = 2; // content not encrypted public static final int RESULT_NOT_ENCRYPTED = -1; @@ -34,26 +34,37 @@ public class OpenPgpDecryptionResult implements Parcelable { // encrypted public static final int RESULT_ENCRYPTED = 1; - int result; + public final int result; + public final byte[] sessionKey; + public final byte[] decryptedSessionKey; public int getResult() { return result; } - public void setResult(int result) { + public OpenPgpDecryptionResult(int result) { this.result = result; + this.sessionKey = null; + this.decryptedSessionKey = null; } - public OpenPgpDecryptionResult() { - - } - - public OpenPgpDecryptionResult(int result) { + public OpenPgpDecryptionResult(int result, byte[] sessionKey, byte[] decryptedSessionKey) { this.result = result; + if ((sessionKey == null) != (decryptedSessionKey == null)) { + throw new AssertionError("sessionkey must be null iff decryptedSessionKey is null"); + } + this.sessionKey = sessionKey; + this.decryptedSessionKey = decryptedSessionKey; } public OpenPgpDecryptionResult(OpenPgpDecryptionResult b) { this.result = b.result; + this.sessionKey = b.sessionKey; + this.decryptedSessionKey = b.decryptedSessionKey; + } + + public boolean hasDecryptedSessionKey() { + return sessionKey != null; } public int describeContents() { @@ -73,6 +84,9 @@ public class OpenPgpDecryptionResult implements Parcelable { int startPosition = dest.dataPosition(); // version 1 dest.writeInt(result); + // version 2 + dest.writeByteArray(sessionKey); + dest.writeByteArray(decryptedSessionKey); // Go back and write the size int parcelableSize = dest.dataPosition() - startPosition; dest.setDataPosition(sizePosition); @@ -82,12 +96,15 @@ public class OpenPgpDecryptionResult implements Parcelable { public static final Creator CREATOR = new Creator() { public OpenPgpDecryptionResult createFromParcel(final Parcel source) { - source.readInt(); // parcelableVersion + int version = source.readInt(); // parcelableVersion int parcelableSize = source.readInt(); int startPosition = source.dataPosition(); - OpenPgpDecryptionResult vr = new OpenPgpDecryptionResult(); - vr.result = source.readInt(); + int result = source.readInt(); + byte[] sessionKey = version > 1 ? source.createByteArray() : null; + byte[] decryptedSessionKey = version > 1 ? source.createByteArray() : null; + + OpenPgpDecryptionResult vr = new OpenPgpDecryptionResult(result, sessionKey, decryptedSessionKey); // skip over all fields added in future versions of this parcel source.setDataPosition(startPosition + parcelableSize); diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java index fe019ab..5fb2382 100644 --- a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java +++ b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java @@ -261,6 +261,8 @@ public class OpenPgpApi { // DECRYPT_VERIFY public static final String EXTRA_DETACHED_SIGNATURE = "detached_signature"; + public static final String EXTRA_DECRYPTION_RESULT_WRAPPER = "decryption_result_wrapper"; + public static final String EXTRA_DECRYPTION_RESULT = "decryption_result"; public static final String RESULT_SIGNATURE = "signature"; public static final String RESULT_DECRYPTION = "decryption"; public static final String RESULT_METADATA = "metadata"; -- cgit v1.2.3 From e0bf61df93c07bdc52d83c2f9f192d738b695ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 15 Feb 2016 23:49:22 +0100 Subject: Add BACKUP, RESTORE, IMPORT_KEY actions Conflicts: openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java --- .../org/openintents/openpgp/util/OpenPgpApi.java | 39 ++++++++++++++++------ 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java index 5fb2382..c88732c 100644 --- a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java +++ b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java @@ -65,14 +65,7 @@ public class OpenPgpApi { */ public static final String ACTION_CHECK_PERMISSION = "org.openintents.openpgp.action.CHECK_PERMISSION"; - /** - * DEPRECATED - * Same as ACTION_CLEARTEXT_SIGN - *

- * optional extras: - * boolean EXTRA_REQUEST_ASCII_ARMOR (DEPRECATED: this makes no sense here) - * char[] EXTRA_PASSPHRASE (key passphrase) - */ + @Deprecated public static final String ACTION_SIGN = "org.openintents.openpgp.action.SIGN"; /** @@ -212,11 +205,34 @@ public class OpenPgpApi { */ public static final String ACTION_GET_KEY = "org.openintents.openpgp.action.GET_KEY"; + /** + * Backup keys + *

+ * required extras: + * long[] EXTRA_KEY_IDS + * boolean EXTRA_BACKUP_SECRET + * + */ + public static final String ACTION_BACKUP = "org.openintents.openpgp.action.BACKUP"; + + /** + * Restore keys + * + */ + public static final String ACTION_RESTORE = "org.openintents.openpgp.action.RESTORE"; + + /** + * Import keys from input stream. Will return RESULT_CODE_USER_INTERACTION_REQUIRED to let the + * user acknowledge the import. + * + */ + public static final String ACTION_IMPORT_KEY = "org.openintents.openpgp.action.IMPORT_KEYS"; + /* Intent extras */ public static final String EXTRA_API_VERSION = "api_version"; - // DEPRECATED!!! + @Deprecated public static final String EXTRA_ACCOUNT_NAME = "account_name"; // ACTION_DETACHED_SIGN, ENCRYPT, SIGN_AND_ENCRYPT, DECRYPT_VERIFY @@ -245,6 +261,9 @@ public class OpenPgpApi { public static final String EXTRA_KEY_ID = "key_id"; public static final String RESULT_KEY_IDS = "key_ids"; + // BACKUP + public static final String EXTRA_BACKUP_SECRET = "backup_secret"; + /* Service Intent returns */ public static final String RESULT_CODE = "result_code"; @@ -269,7 +288,7 @@ public class OpenPgpApi { // This will be the charset which was specified in the headers of ascii armored input, if any public static final String RESULT_CHARSET = "charset"; - // INTERNAL, should not be used + // INTERNAL, must not be used public static final String EXTRA_CALL_UUID1 = "call_uuid1"; public static final String EXTRA_CALL_UUID2 = "call_uuid2"; -- cgit v1.2.3 From e7d72da343c6a42da6d1beb98ac8014da7cbce30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 22 Feb 2016 20:41:04 +0100 Subject: Improve documentation Conflicts: openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java --- .../openpgp/OpenPgpSignatureResult.java | 11 ++++------- .../org/openintents/openpgp/util/OpenPgpApi.java | 23 ++++++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java index f188968..ad3bb29 100644 --- a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java +++ b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java @@ -49,10 +49,11 @@ public class OpenPgpSignatureResult implements Parcelable { public static final int RESULT_INVALID_INSECURE = 6; int result; - boolean signatureOnly; String primaryUserId; ArrayList userIds; long keyId; + @Deprecated + boolean signatureOnly; public int getResult() { return result; @@ -62,16 +63,12 @@ public class OpenPgpSignatureResult implements Parcelable { this.result = result; } - /** - * @deprecated - */ + @Deprecated public boolean isSignatureOnly() { return signatureOnly; } - /** - * @deprecated - */ + @Deprecated public void setSignatureOnly(boolean signatureOnly) { this.signatureOnly = signatureOnly; } diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java index c88732c..5417f6b 100644 --- a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java +++ b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java @@ -201,32 +201,35 @@ public class OpenPgpApi { *

* optional extras: * String EXTRA_REQUEST_ASCII_ARMOR (request that the returned key is encoded in ASCII Armor) - * */ public static final String ACTION_GET_KEY = "org.openintents.openpgp.action.GET_KEY"; /** - * Backup keys + * Backup all keys given by EXTRA_KEY_IDS and if requested their secret parts. + * The encrypted backup will be written to the OutputStream. + * The client app has no access to the backup code used to encrypt the backup! + * This operation always requires user interaction with RESULT_CODE_USER_INTERACTION_REQUIRED! *

* required extras: - * long[] EXTRA_KEY_IDS - * boolean EXTRA_BACKUP_SECRET - * + * long[] EXTRA_KEY_IDS (keys that should be included in the backup) + * boolean EXTRA_BACKUP_SECRET (also backup secret keys) */ public static final String ACTION_BACKUP = "org.openintents.openpgp.action.BACKUP"; /** - * Restore keys + * Restore keys given a backup as InputStream. + * This operation always requires user interaction with RESULT_CODE_USER_INTERACTION_REQUIRED! * + * NOT IMPLEMENTED RIGHT NOW! */ - public static final String ACTION_RESTORE = "org.openintents.openpgp.action.RESTORE"; + private static final String ACTION_RESTORE = "org.openintents.openpgp.action.RESTORE"; /** - * Import keys from input stream. Will return RESULT_CODE_USER_INTERACTION_REQUIRED to let the - * user acknowledge the import. + * Import keys from InputStream. Only public keys will be imported! * + * NOT IMPLEMENTED RIGHT NOW! */ - public static final String ACTION_IMPORT_KEY = "org.openintents.openpgp.action.IMPORT_KEYS"; + private static final String ACTION_IMPORT_KEY = "org.openintents.openpgp.action.IMPORT_KEYS"; /* Intent extras */ -- cgit v1.2.3 From 169e004ba52b6dc15132d286bdc8aa216f0ca1f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 24 Feb 2016 15:39:23 +0100 Subject: Fix ACTION_GET_KEY_IDS example --- .../java/org/openintents/openpgp/example/OpenPgpApiActivity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java b/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java index 823c202..3ebe9b4 100644 --- a/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java +++ b/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java @@ -49,6 +49,7 @@ public class OpenPgpApiActivity extends Activity { private EditText mDetachedSignature; private EditText mEncryptUserIds; private EditText mGetKeyEdit; + private EditText mGetKeyIdsEdit; private OpenPgpServiceConnection mServiceConnection; @@ -79,7 +80,7 @@ public class OpenPgpApiActivity extends Activity { Button decryptAndVerify = (Button) findViewById(R.id.crypto_provider_demo_decrypt_and_verify); Button verifyDetachedSignature = (Button) findViewById(R.id.crypto_provider_demo_verify_detached_signature); mGetKeyEdit = (EditText) findViewById(R.id.crypto_provider_demo_get_key_edit); - EditText getKeyIdsEdit = (EditText) findViewById(R.id.crypto_provider_demo_get_key_ids_edit); + mGetKeyIdsEdit = (EditText) findViewById(R.id.crypto_provider_demo_get_key_ids_edit); Button getKey = (Button) findViewById(R.id.crypto_provider_demo_get_key); Button getKeyIds = (Button) findViewById(R.id.crypto_provider_demo_get_key_ids); @@ -387,6 +388,7 @@ public class OpenPgpApiActivity extends Activity { public void getKeyIds(Intent data) { data.setAction(OpenPgpApi.ACTION_GET_KEY_IDS); + data.putExtra(OpenPgpApi.EXTRA_USER_IDS, mGetKeyIdsEdit.getText().toString().split(",")); OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService()); api.executeApiAsync(data, null, null, new MyCallback(false, null, REQUEST_CODE_GET_KEY_IDS)); @@ -394,7 +396,6 @@ public class OpenPgpApiActivity extends Activity { public void getAnyKeyIds(Intent data) { data.setAction(OpenPgpApi.ACTION_GET_KEY_IDS); -// data.putExtra(OpenPgpApi.EXTRA_USER_IDS, mGetKeyIdsEdit.getText().toString().split(",")); OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService()); api.executeApiAsync(data, null, null, new MyCallback(false, null, REQUEST_CODE_GET_KEY_IDS)); -- cgit v1.2.3 From 39fa41f8815f2ead9a71140af0b4e5e7d4924977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Tue, 1 Mar 2016 00:04:22 +0100 Subject: Backup example --- .../openpgp/example/OpenPgpApiActivity.java | 23 ++++++++++++++++++++++ example/src/main/res/layout/openpgp_provider.xml | 8 +++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java b/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java index 3ebe9b4..992f8be 100644 --- a/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java +++ b/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java @@ -63,6 +63,7 @@ public class OpenPgpApiActivity extends Activity { public static final int REQUEST_CODE_GET_KEY_IDS = 9915; public static final int REQUEST_CODE_DETACHED_SIGN = 9916; public static final int REQUEST_CODE_DECRYPT_AND_VERIFY_DETACHED = 9917; + public static final int REQUEST_CODE_BACKUP = 9918; @Override public void onCreate(Bundle savedInstanceState) { @@ -83,6 +84,7 @@ public class OpenPgpApiActivity extends Activity { mGetKeyIdsEdit = (EditText) findViewById(R.id.crypto_provider_demo_get_key_ids_edit); Button getKey = (Button) findViewById(R.id.crypto_provider_demo_get_key); Button getKeyIds = (Button) findViewById(R.id.crypto_provider_demo_get_key_ids); + Button backup = (Button) findViewById(R.id.crypto_provider_demo_backup); cleartextSign.setOnClickListener(new View.OnClickListener() { @Override @@ -132,6 +134,12 @@ public class OpenPgpApiActivity extends Activity { getKeyIds(new Intent()); } }); + backup.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + backup(new Intent()); + } + }); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); String providerPackageName = settings.getString("openpgp_provider_list", ""); @@ -401,6 +409,17 @@ public class OpenPgpApiActivity extends Activity { api.executeApiAsync(data, null, null, new MyCallback(false, null, REQUEST_CODE_GET_KEY_IDS)); } + public void backup(Intent data) { + data.setAction(OpenPgpApi.ACTION_BACKUP); + data.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[]{Long.decode(mGetKeyEdit.getText().toString())}); + data.putExtra(OpenPgpApi.EXTRA_BACKUP_SECRET, true); + + ByteArrayOutputStream os = new ByteArrayOutputStream(); + + OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService()); + api.executeApiAsync(data, null, os, new MyCallback(true, os, REQUEST_CODE_BACKUP)); + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); @@ -447,6 +466,10 @@ public class OpenPgpApiActivity extends Activity { getKeyIds(data); break; } + case REQUEST_CODE_BACKUP: { + backup(data); + break; + } } } } diff --git a/example/src/main/res/layout/openpgp_provider.xml b/example/src/main/res/layout/openpgp_provider.xml index 13096b4..d2b4572 100644 --- a/example/src/main/res/layout/openpgp_provider.xml +++ b/example/src/main/res/layout/openpgp_provider.xml @@ -153,7 +153,7 @@ +