API changes
This commit is contained in:
@@ -22,36 +22,36 @@ import java.util.Arrays;
|
||||
|
||||
public class ApgData implements Serializable {
|
||||
private static final long serialVersionUID = 6314045536270848410L;
|
||||
protected long mEncryptionKeyIds[] = null;
|
||||
protected long mSignatureKeyId = 0;
|
||||
protected String mSignatureUserId = null;
|
||||
protected long mPublicKeyIds[] = null;
|
||||
protected long mSecretKeyId = 0;
|
||||
protected String mSecretKeyUserId = null;
|
||||
protected boolean mSignatureSuccess = false;
|
||||
protected boolean mSignatureUnknown = false;
|
||||
protected String mDecryptedData = null;
|
||||
protected String mEncryptedData = null;
|
||||
|
||||
public void setSignatureKeyId(long keyId) {
|
||||
mSignatureKeyId = keyId;
|
||||
public void setSecretKeyId(long keyId) {
|
||||
mSecretKeyId = keyId;
|
||||
}
|
||||
|
||||
public long getSignatureKeyId() {
|
||||
return mSignatureKeyId;
|
||||
public long getSecretKeyId() {
|
||||
return mSecretKeyId;
|
||||
}
|
||||
|
||||
public void setEncryptionKeys(long keyIds[]) {
|
||||
mEncryptionKeyIds = keyIds;
|
||||
public void setPublicKeys(long keyIds[]) {
|
||||
mPublicKeyIds = keyIds;
|
||||
}
|
||||
|
||||
public long[] getEncryptionKeys() {
|
||||
return mEncryptionKeyIds;
|
||||
public long[] getPublicKeys() {
|
||||
return mPublicKeyIds;
|
||||
}
|
||||
|
||||
public boolean hasSignatureKey() {
|
||||
return mSignatureKeyId != 0;
|
||||
public boolean hasSecretKey() {
|
||||
return mSecretKeyId != 0;
|
||||
}
|
||||
|
||||
public boolean hasEncryptionKeys() {
|
||||
return (mEncryptionKeyIds != null) && (mEncryptionKeyIds.length > 0);
|
||||
public boolean hasPublicKeys() {
|
||||
return (mPublicKeyIds != null) && (mPublicKeyIds.length > 0);
|
||||
}
|
||||
|
||||
public String getEncryptedData() {
|
||||
@@ -70,12 +70,12 @@ public class ApgData implements Serializable {
|
||||
mDecryptedData = data;
|
||||
}
|
||||
|
||||
public void setSignatureUserId(String userId) {
|
||||
mSignatureUserId = userId;
|
||||
public void setSecretKeyUserId(String userId) {
|
||||
mSecretKeyUserId = userId;
|
||||
}
|
||||
|
||||
public String getSignatureUserId() {
|
||||
return mSignatureUserId;
|
||||
public String getSecretKeyUserId() {
|
||||
return mSecretKeyUserId;
|
||||
}
|
||||
|
||||
public boolean getSignatureSuccess() {
|
||||
@@ -96,11 +96,11 @@ public class ApgData implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String output = "mEncryptionKeyIds: " + Arrays.toString(mEncryptionKeyIds)
|
||||
+ "\nmSignatureKeyId: " + mSignatureKeyId + "\nmSignatureUserId: "
|
||||
+ mSignatureUserId + "\nmSignatureSuccess: " + mSignatureSuccess
|
||||
+ "\nmSignatureUnknown: " + mSignatureUnknown + "\nmDecryptedData: "
|
||||
+ mDecryptedData + "\nmEncryptedData: " + mEncryptedData;
|
||||
String output = "mPublicKeyIds: " + Arrays.toString(mPublicKeyIds) + "\nmSecretKeyId: "
|
||||
+ mSecretKeyId + "\nmSecretKeyUserId: " + mSecretKeyUserId
|
||||
+ "\nmSignatureSuccess: " + mSignatureSuccess + "\nmSignatureUnknown: "
|
||||
+ mSignatureUnknown + "\nmDecryptedData: " + mDecryptedData + "\nmEncryptedData: "
|
||||
+ mEncryptedData;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -27,12 +27,32 @@ public class ApgIntentHelper {
|
||||
public static final String APG_INTENT_PREFIX = "org.thialfihar.android.apg.intent.";
|
||||
|
||||
// Intents
|
||||
public static final String ACTION_DECRYPT = APG_INTENT_PREFIX + "DECRYPT";
|
||||
/**
|
||||
* Encrypt
|
||||
*/
|
||||
// without permission
|
||||
public static final String ACTION_ENCRYPT = APG_INTENT_PREFIX + "ENCRYPT";
|
||||
public static final String ACTION_DECRYPT_FILE = APG_INTENT_PREFIX + "DECRYPT_FILE";
|
||||
public static final String ACTION_ENCRYPT_FILE = APG_INTENT_PREFIX + "ENCRYPT_FILE";
|
||||
public static final String ACTION_DECRYPT_AND_RETURN = APG_INTENT_PREFIX + "DECRYPT_AND_RETURN";
|
||||
|
||||
// with permission
|
||||
public static final String ACTION_ENCRYPT_AND_RETURN = APG_INTENT_PREFIX + "ENCRYPT_AND_RETURN";
|
||||
public static final String ACTION_GENERATE_SIGNATURE_AND_RETURN = APG_INTENT_PREFIX
|
||||
+ "GENERATE_SIGNATURE_AND_RETURN";
|
||||
public static final String ACTION_ENCRYPT_STREAM_AND_RETURN = APG_INTENT_PREFIX
|
||||
+ "ENCRYPT_STREAM_AND_RETURN";
|
||||
|
||||
/**
|
||||
* Decrypt
|
||||
*/
|
||||
// without permission
|
||||
public static final String ACTION_DECRYPT = APG_INTENT_PREFIX + "DECRYPT";
|
||||
public static final String ACTION_DECRYPT_FILE = APG_INTENT_PREFIX + "DECRYPT_FILE";
|
||||
|
||||
// with permission
|
||||
public static final String ACTION_DECRYPT_AND_RETURN = APG_INTENT_PREFIX + "DECRYPT_AND_RETURN";
|
||||
public static final String ACTION_DECRYPT_STREAM_AND_RETURN = APG_INTENT_PREFIX
|
||||
+ "DECRYPT_STREAM_AND_RETURN";
|
||||
|
||||
public static final String ACTION_SELECT_PUBLIC_KEYS = APG_INTENT_PREFIX + "SELECT_PUBLIC_KEYS";
|
||||
public static final String ACTION_SELECT_SECRET_KEY = APG_INTENT_PREFIX + "SELECT_SECRET_KEY";
|
||||
public static final String ACTION_CREATE_KEY = APG_INTENT_PREFIX + "CREATE_KEY";
|
||||
@@ -60,15 +80,19 @@ public class ApgIntentHelper {
|
||||
|
||||
public static final String RESULT_EXTRA_MASTER_KEY_IDS = "masterKeyIds";
|
||||
public static final String RESULT_EXTRA_USER_IDS = "userIds";
|
||||
|
||||
// result from EditKey
|
||||
public static final String RESULT_EXTRA_MASTER_KEY_ID = "masterKeyId";
|
||||
public static final String RESULT_EXTRA_USER_ID = "userId";
|
||||
|
||||
public static final String INTENT_VERSION = "1";
|
||||
|
||||
public static final int DECRYPT_MESSAGE = 0x21070001;
|
||||
public static final int ENCRYPT_MESSAGE = 0x21070002;
|
||||
public static final int SELECT_PUBLIC_KEYS = 0x21070003;
|
||||
public static final int SELECT_SECRET_KEY = 0x21070004;
|
||||
public static final int CREATE_KEY = 0x21070005;
|
||||
public static final int EDIT_KEY = 0x21070006;
|
||||
public static final int DECRYPT_MESSAGE = 0x00007121;
|
||||
public static final int ENCRYPT_MESSAGE = 0x00007122;
|
||||
public static final int SELECT_PUBLIC_KEYS = 0x00007123;
|
||||
public static final int SELECT_SECRET_KEY = 0x00007124;
|
||||
public static final int CREATE_KEY = 0x00007125;
|
||||
public static final int EDIT_KEY = 0x00007126;
|
||||
|
||||
private Activity activity;
|
||||
|
||||
@@ -221,44 +245,53 @@ public class ApgIntentHelper {
|
||||
public boolean onActivityResult(int requestCode, int resultCode, Intent data, ApgData apgData) {
|
||||
|
||||
switch (requestCode) {
|
||||
case CREATE_KEY:
|
||||
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||
// user canceled!
|
||||
break;
|
||||
}
|
||||
apgData.setSecretKeyId(data.getLongExtra(RESULT_EXTRA_MASTER_KEY_ID, 0));
|
||||
apgData.setSecretKeyUserId(data.getStringExtra(RESULT_EXTRA_USER_ID));
|
||||
|
||||
break;
|
||||
case SELECT_SECRET_KEY:
|
||||
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||
// user canceled!
|
||||
break;
|
||||
}
|
||||
apgData.setSignatureKeyId(data.getLongExtra(EXTRA_KEY_ID, 0));
|
||||
apgData.setSignatureUserId(data.getStringExtra(EXTRA_USER_ID));
|
||||
break;
|
||||
apgData.setSecretKeyId(data.getLongExtra(EXTRA_KEY_ID, 0));
|
||||
apgData.setSecretKeyUserId(data.getStringExtra(EXTRA_USER_ID));
|
||||
|
||||
break;
|
||||
case SELECT_PUBLIC_KEYS:
|
||||
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||
apgData.setEncryptionKeys(null);
|
||||
apgData.setPublicKeys(null);
|
||||
break;
|
||||
}
|
||||
apgData.setEncryptionKeys(data.getLongArrayExtra(RESULT_EXTRA_MASTER_KEY_IDS));
|
||||
break;
|
||||
apgData.setPublicKeys(data.getLongArrayExtra(RESULT_EXTRA_MASTER_KEY_IDS));
|
||||
|
||||
break;
|
||||
case ENCRYPT_MESSAGE:
|
||||
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||
apgData.setEncryptionKeys(null);
|
||||
apgData.setPublicKeys(null);
|
||||
break;
|
||||
}
|
||||
apgData.setEncryptedData(data.getStringExtra(EXTRA_ENCRYPTED_MESSAGE));
|
||||
break;
|
||||
|
||||
break;
|
||||
case DECRYPT_MESSAGE:
|
||||
if (resultCode != Activity.RESULT_OK || data == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
apgData.setSignatureUserId(data.getStringExtra(EXTRA_SIGNATURE_USER_ID));
|
||||
apgData.setSignatureKeyId(data.getLongExtra(EXTRA_SIGNATURE_KEY_ID, 0));
|
||||
apgData.setSecretKeyUserId(data.getStringExtra(EXTRA_SIGNATURE_USER_ID));
|
||||
apgData.setSecretKeyId(data.getLongExtra(EXTRA_SIGNATURE_KEY_ID, 0));
|
||||
apgData.setSignatureSuccess(data.getBooleanExtra(EXTRA_SIGNATURE_SUCCESS, false));
|
||||
apgData.setSignatureUnknown(data.getBooleanExtra(EXTRA_SIGNATURE_UNKNOWN, false));
|
||||
|
||||
apgData.setDecryptedData(data.getStringExtra(EXTRA_DECRYPTED_MESSAGE));
|
||||
break;
|
||||
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -273,8 +306,8 @@ public class ApgIntentHelper {
|
||||
* The emails that should be used for preselection.
|
||||
* @return true when activity was found and executed successfully
|
||||
*/
|
||||
public boolean selectEncryptionKeys(String emails) {
|
||||
return selectEncryptionKeys(emails, null);
|
||||
public boolean selectPublicKeys(String emails) {
|
||||
return selectPublicKeys(emails, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,19 +319,17 @@ public class ApgIntentHelper {
|
||||
* ApgData with encryption keys and signature keys preselected
|
||||
* @return true when activity was found and executed successfully
|
||||
*/
|
||||
public boolean selectEncryptionKeys(String emails, ApgData apgData) {
|
||||
public boolean selectPublicKeys(String emails, ApgData apgData) {
|
||||
Intent intent = new Intent(ACTION_SELECT_PUBLIC_KEYS);
|
||||
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
|
||||
|
||||
long[] initialKeyIds = null;
|
||||
if (apgData == null || !apgData.hasEncryptionKeys()) {
|
||||
|
||||
if (apgData == null || !apgData.hasPublicKeys()) {
|
||||
ApgContentProviderHelper cPHelper = new ApgContentProviderHelper(activity);
|
||||
|
||||
initialKeyIds = cPHelper.getPublicKeyIdsFromEmail(emails);
|
||||
|
||||
} else {
|
||||
initialKeyIds = apgData.getEncryptionKeys();
|
||||
initialKeyIds = apgData.getPublicKeys();
|
||||
}
|
||||
intent.putExtra(EXTRA_SELECTION, initialKeyIds);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||
|
||||
import android.widget.Toast;
|
||||
|
||||
public class Util {
|
||||
public class ApgUtil {
|
||||
|
||||
/**
|
||||
* Check whether APG is installed and at a high enough version.
|
||||
@@ -48,4 +48,25 @@ public class Util {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits userId string into naming part and email part
|
||||
*
|
||||
* @param userId
|
||||
* @return array with naming (0) and email (1)
|
||||
*/
|
||||
public static String[] splitUserId(String userId) {
|
||||
String[] output = new String[2];
|
||||
|
||||
String chunks[] = userId.split(" <", 2);
|
||||
userId = chunks[0];
|
||||
if (chunks.length > 1) {
|
||||
output[1] = "<" + chunks[1];
|
||||
output[1] = output[1].replaceAll("<", "");
|
||||
output[1] = output[1].replaceAll(">", "");
|
||||
}
|
||||
output[0] = userId;
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user