aboutsummaryrefslogtreecommitdiffstats
path: root/org_apg
diff options
context:
space:
mode:
Diffstat (limited to 'org_apg')
-rw-r--r--org_apg/AndroidManifest.xml65
-rw-r--r--org_apg/src/org/thialfihar/android/apg/Constants.java8
-rw-r--r--org_apg/src/org/thialfihar/android/apg/helper/PGPHelper.java8
-rw-r--r--org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java244
-rw-r--r--org_apg/src/org/thialfihar/android/apg/provider/ApgProvider.java26
-rw-r--r--org_apg/src/org/thialfihar/android/apg/provider/ProviderHelper.java93
-rw-r--r--org_apg/src/org/thialfihar/android/apg/service/ApgIntentService.java881
-rw-r--r--org_apg/src/org/thialfihar/android/apg/service/ApgIntentServiceHandler.java (renamed from org_apg/src/org/thialfihar/android/apg/service/ApgServiceHandler.java)8
-rw-r--r--org_apg/src/org/thialfihar/android/apg/service/ApgRemoteService.java5
-rw-r--r--org_apg/src/org/thialfihar/android/apg/service/ApgService.java997
-rw-r--r--org_apg/src/org/thialfihar/android/apg/service/IApgEncryptDecryptHandler.aidl16
-rw-r--r--org_apg/src/org/thialfihar/android/apg/service/IApgHelperHandler.aidl9
-rw-r--r--org_apg/src/org/thialfihar/android/apg/service/IApgService.aidl130
-rw-r--r--org_apg/src/org/thialfihar/android/apg/service/IApgSignVerifyHandler.aidl11
-rw-r--r--org_apg/src/org/thialfihar/android/apg/service/PassphraseCacheService.java14
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java107
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/EditKeyActivity.java48
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java61
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/ImportFromQRCodeActivity.java28
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java54
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java4
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/KeyServerQueryActivity.java28
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/KeyServerUploadActivity.java20
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/SignKeyActivity.java36
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/dialog/DeleteFileDialogFragment.java18
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/dialog/DeleteKeyDialogFragment.java4
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/dialog/PassphraseDialogFragment.java3
-rw-r--r--org_apg/src/org/thialfihar/android/apg/ui/widget/SectionView.java26
28 files changed, 1711 insertions, 1241 deletions
diff --git a/org_apg/AndroidManifest.xml b/org_apg/AndroidManifest.xml
index 6194e39ca..27045c738 100644
--- a/org_apg/AndroidManifest.xml
+++ b/org_apg/AndroidManifest.xml
@@ -336,7 +336,21 @@
android:label="@string/title_help" />
<service android:name=".service.PassphraseCacheService" />
- <service android:name=".service.ApgService" />
+ <service android:name=".service.ApgIntentService" />
+ <service
+ android:name=".service.ApgService"
+ android:enabled="true"
+ android:exported="true"
+ android:permission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS"
+ android:process=":remote" >
+ <intent-filter>
+ <action android:name="org.thialfihar.android.apg.service.IApgService" />
+ </intent-filter>
+
+ <meta-data
+ android:name="api_version"
+ android:value="3" />
+ </service>
<provider
android:name=".provider.ApgProvider"
@@ -344,31 +358,34 @@
android:readPermission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS" />
<!-- DEPRECATED: -->
-<!-- <provider -->
-<!-- android:name=".deprecated.DataProvider" -->
-<!-- android:authorities="org.thialfihar.android.apg.provider" -->
-<!-- android:readPermission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS" /> -->
+ <!-- <provider -->
+ <!-- android:name=".deprecated.DataProvider" -->
+ <!-- android:authorities="org.thialfihar.android.apg.provider" -->
+ <!-- android:readPermission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS" /> -->
+
<!-- TODO: need to be moved into new service model -->
-<!-- <service -->
-<!-- android:name=".deprecated.ApgService2" -->
-<!-- android:enabled="true" -->
-<!-- android:exported="true" -->
-<!-- android:permission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS" -->
-<!-- android:process=":remote" > -->
-<!-- <intent-filter> -->
-<!-- <action android:name="org.thialfihar.android.apg.service.IApgService2" /> -->
-<!-- </intent-filter> -->
-
-<!-- <meta-data -->
-<!-- android:name="api_version" -->
-<!-- android:value="2" /> -->
-<!-- </service> -->
-
-<!-- <provider -->
-<!-- android:name=".deprecated.ApgServiceBlobProvider" -->
-<!-- android:authorities="org.thialfihar.android.apg.provider.apgserviceblobprovider" -->
-<!-- android:permission="org.thialfihar.android.apg.permission.STORE_BLOBS" /> -->
+ <!-- <service -->
+ <!-- android:name=".deprecated.ApgService2" -->
+ <!-- android:enabled="true" -->
+ <!-- android:exported="true" -->
+ <!-- android:permission="org.thialfihar.android.apg.permission.READ_KEY_DETAILS" -->
+ <!-- android:process=":remote" > -->
+ <!-- <intent-filter> -->
+ <!-- <action android:name="org.thialfihar.android.apg.service.IApgService2" /> -->
+ <!-- </intent-filter> -->
+
+
+ <!-- <meta-data -->
+ <!-- android:name="api_version" -->
+ <!-- android:value="2" /> -->
+ <!-- </service> -->
+
+
+ <!-- <provider -->
+ <!-- android:name=".deprecated.ApgServiceBlobProvider" -->
+ <!-- android:authorities="org.thialfihar.android.apg.provider.apgserviceblobprovider" -->
+ <!-- android:permission="org.thialfihar.android.apg.permission.STORE_BLOBS" /> -->
</application>
</manifest> \ No newline at end of file
diff --git a/org_apg/src/org/thialfihar/android/apg/Constants.java b/org_apg/src/org/thialfihar/android/apg/Constants.java
index c0ae2794e..97e70bbea 100644
--- a/org_apg/src/org/thialfihar/android/apg/Constants.java
+++ b/org_apg/src/org/thialfihar/android/apg/Constants.java
@@ -59,12 +59,4 @@ public final class Constants {
public static final String KEY_SERVERS = "pool.sks-keyservers.net, subkeys.pgp.net, pgp.mit.edu";
}
- // TODO: rework!
- public static final class extras {
- public static final String PROGRESS = "progress";
- public static final String PROGRESS_MAX = "max";
- public static final String STATUS = "status";
- public static final String MESSAGE = "message";
- public static final String KEY_ID = "keyId";
- }
}
diff --git a/org_apg/src/org/thialfihar/android/apg/helper/PGPHelper.java b/org_apg/src/org/thialfihar/android/apg/helper/PGPHelper.java
index a5d5ced5e..91b0bfbc0 100644
--- a/org_apg/src/org/thialfihar/android/apg/helper/PGPHelper.java
+++ b/org_apg/src/org/thialfihar/android/apg/helper/PGPHelper.java
@@ -384,10 +384,10 @@ public class PGPHelper {
}
public static String getPubkeyAsArmoredString(Context context, long keyId) {
- PGPPublicKey key = ProviderHelper.getPGPPublicKey(context, keyId);
+ PGPPublicKey key = ProviderHelper.getPGPPublicKeyByKeyId(context, keyId);
// if it is no public key get it from your own keys...
if (key == null) {
- PGPSecretKey secretKey = ProviderHelper.getPGPSecretKey(context, keyId);
+ PGPSecretKey secretKey = ProviderHelper.getPGPSecretKeyByKeyId(context, keyId);
if (secretKey == null) {
Log.e(Constants.TAG, "Key could not be found!");
return null;
@@ -415,10 +415,10 @@ public class PGPHelper {
}
public static String getFingerPrint(Context context, long keyId) {
- PGPPublicKey key = ProviderHelper.getPGPPublicKey(context, keyId);
+ PGPPublicKey key = ProviderHelper.getPGPPublicKeyByKeyId(context, keyId);
// if it is no public key get it from your own keys...
if (key == null) {
- PGPSecretKey secretKey = ProviderHelper.getPGPSecretKey(context, keyId);
+ PGPSecretKey secretKey = ProviderHelper.getPGPSecretKeyByKeyId(context, keyId);
if (secretKey == null) {
Log.e(Constants.TAG, "Key could not be found!");
return null;
diff --git a/org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java b/org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java
index 902c996b8..adccaf038 100644
--- a/org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java
+++ b/org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java
@@ -73,7 +73,7 @@ import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
import org.thialfihar.android.apg.provider.ProviderHelper;
-import org.thialfihar.android.apg.service.ApgService;
+import org.thialfihar.android.apg.service.ApgIntentService;
import org.thialfihar.android.apg.util.HkpKeyServer;
import org.thialfihar.android.apg.util.InputData;
import org.thialfihar.android.apg.util.PositionAwareInputStream;
@@ -599,9 +599,9 @@ public class PGPMain {
// nothing to do, we are done
}
- returnData.putInt(ApgService.RESULT_IMPORT_ADDED, newKeys);
- returnData.putInt(ApgService.RESULT_IMPORT_UPDATED, oldKeys);
- returnData.putInt(ApgService.RESULT_IMPORT_BAD, badKeys);
+ returnData.putInt(ApgIntentService.RESULT_IMPORT_ADDED, newKeys);
+ returnData.putInt(ApgIntentService.RESULT_IMPORT_UPDATED, oldKeys);
+ returnData.putInt(ApgIntentService.RESULT_IMPORT_BAD, badKeys);
updateProgress(progress, R.string.progress_done, 100, 100);
@@ -646,83 +646,42 @@ public class PGPMain {
++numKeys;
}
out.close();
- returnData.putInt(ApgService.RESULT_EXPORT, numKeys);
+ returnData.putInt(ApgIntentService.RESULT_EXPORT, numKeys);
updateProgress(progress, R.string.progress_done, 100, 100);
return returnData;
}
- // public static PGPKeyRing getKeyRing(int keyRingId) {
- // return (PGPKeyRing) mDatabase.getKeyRing(keyRingId);
- // }
-
- // public static PGPSecretKeyRing getSecretKeyRing(long keyId) {
- // byte[] data = mDatabase.getKeyRingDataFromKeyId(Id.database.type_secret, keyId);
- // if (data == null) {
- // return null;
- // }
- // return PGPConversionHelper.BytesToPGPSecretKeyRing(data);
- // }
- //
- // public static PGPPublicKeyRing getPublicKeyRing(long keyId) {
- // byte[] data = mDatabase.getKeyRingDataFromKeyId(Id.database.type_public, keyId);
- // if (data == null) {
- // return null;
- // }
- // return PGPConversionHelper.BytesToPGPPublicKeyRing(data);
- // }
-
- // public static Vector<Integer> getKeyRingIds(int type) {
- // SQLiteDatabase db = mDatabase.db();
- // Vector<Integer> keyIds = new Vector<Integer>();
- // Cursor c = db.query(KeyRings.TABLE_NAME, new String[] { KeyRings._ID }, KeyRings.TYPE
- // + " = ?", new String[] { "" + type }, null, null, null);
- // if (c != null && c.moveToFirst()) {
- // do {
- // keyIds.add(c.getInt(0));
- // } while (c.moveToNext());
- // }
- //
- // if (c != null) {
- // c.close();
- // }
- //
- // return keyIds;
- // }
-
- // public static String getMainUserId(long keyId, int type) {
- // SQLiteDatabase db = mDatabase.db();
- // Cursor c = db.query(Keys.TABLE_NAME + " INNER JOIN " + KeyRings.TABLE_NAME + " ON ("
- // + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + Keys.TABLE_NAME + "."
- // + Keys.KEY_RING_ID + ") " + " INNER JOIN " + Keys.TABLE_NAME + " AS masterKey ON ("
- // + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + "masterKey."
- // + Keys.KEY_RING_ID + " AND " + "masterKey." + Keys.IS_MASTER_KEY + " = '1') "
- // + " INNER JOIN " + UserIds.TABLE_NAME + " ON (" + UserIds.TABLE_NAME + "."
- // + UserIds.KEY_ID + " = " + "masterKey." + Keys._ID + " AND " + UserIds.TABLE_NAME
- // + "." + UserIds.RANK + " = '0')", new String[] { UserIds.USER_ID }, Keys.TABLE_NAME
- // + "." + Keys.KEY_ID + " = ? AND " + KeyRings.TABLE_NAME + "." + KeyRings.TYPE
- // + " = ?", new String[] { "" + keyId, "" + type, }, null, null, null);
- // String userId = "";
- // if (c != null && c.moveToFirst()) {
- // do {
- // userId = c.getString(0);
- // } while (c.moveToNext());
- // }
- //
- // if (c != null) {
- // c.close();
- // }
- //
- // return userId;
- // }
-
- public static void encrypt(Context context, InputData data, OutputStream outStream,
- boolean armored, long encryptionKeyIds[], long signatureKeyId,
- String signaturePassPhrase, ProgressDialogUpdater progress, int symmetricAlgorithm,
- int hashAlgorithm, int compression, boolean forceV3Signature, String passPhrase)
- throws IOException, ApgGeneralException, PGPException, NoSuchProviderException,
- NoSuchAlgorithmException, SignatureException {
+ /**
+ * Encrypt and Sign data
+ *
+ * @param context
+ * @param progress
+ * @param data
+ * @param outStream
+ * @param useAsciiArmor
+ * @param compression
+ * @param encryptionKeyIds
+ * @param symmetricEncryptionAlgorithm
+ * @param encryptionPassphrase
+ * @param signatureKeyId
+ * @param signatureHashAlgorithm
+ * @param signatureForceV3
+ * @param signaturePassphrase
+ * @throws IOException
+ * @throws ApgGeneralException
+ * @throws PGPException
+ * @throws NoSuchProviderException
+ * @throws NoSuchAlgorithmException
+ * @throws SignatureException
+ */
+ public static void encryptAndSign(Context context, ProgressDialogUpdater progress,
+ InputData data, OutputStream outStream, boolean useAsciiArmor, int compression,
+ long encryptionKeyIds[], String encryptionPassphrase, int symmetricEncryptionAlgorithm,
+ long signatureKeyId, int signatureHashAlgorithm, boolean signatureForceV3,
+ String signaturePassphrase) throws IOException, ApgGeneralException, PGPException,
+ NoSuchProviderException, NoSuchAlgorithmException, SignatureException {
if (encryptionKeyIds == null) {
encryptionKeyIds = new long[0];
@@ -731,7 +690,7 @@ public class PGPMain {
ArmoredOutputStream armorOut = null;
OutputStream out = null;
OutputStream encryptOut = null;
- if (armored) {
+ if (useAsciiArmor) {
armorOut = new ArmoredOutputStream(outStream);
armorOut.setHeader("Version", getFullVersion(context));
out = armorOut;
@@ -742,27 +701,27 @@ public class PGPMain {
PGPSecretKeyRing signingKeyRing = null;
PGPPrivateKey signaturePrivateKey = null;
- if (encryptionKeyIds.length == 0 && passPhrase == null) {
+ if (encryptionKeyIds.length == 0 && encryptionPassphrase == null) {
throw new ApgGeneralException(
context.getString(R.string.error_noEncryptionKeysOrPassPhrase));
}
if (signatureKeyId != Id.key.none) {
- signingKeyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(context,
+ signingKeyRing = ProviderHelper.getPGPSecretKeyRingByKeyId(context,
signatureKeyId);
signingKey = PGPHelper.getSigningKey(context, signatureKeyId);
if (signingKey == null) {
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
}
- if (signaturePassPhrase == null) {
+ if (signaturePassphrase == null) {
throw new ApgGeneralException(
context.getString(R.string.error_noSignaturePassPhrase));
}
if (progress != null)
progress.setProgress(R.string.progress_extractingSignatureKey, 0, 100);
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
- BOUNCY_CASTLE_PROVIDER_NAME).build(signaturePassPhrase.toCharArray());
+ BOUNCY_CASTLE_PROVIDER_NAME).build(signaturePassphrase.toCharArray());
signaturePrivateKey = signingKey.extractPrivateKey(keyDecryptor);
if (signaturePrivateKey == null) {
throw new ApgGeneralException(
@@ -773,26 +732,28 @@ public class PGPMain {
// encrypt and compress input file content
JcePGPDataEncryptorBuilder encryptorBuilder = new JcePGPDataEncryptorBuilder(
- symmetricAlgorithm).setProvider(BOUNCY_CASTLE_PROVIDER_NAME)
+ symmetricEncryptionAlgorithm).setProvider(BOUNCY_CASTLE_PROVIDER_NAME)
.setWithIntegrityPacket(true);
PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(encryptorBuilder);
if (encryptionKeyIds.length == 0) {
- // symmetric encryption
+ // Symmetric encryption
Log.d(Constants.TAG, "encryptionKeyIds length is 0 -> symmetric encryption");
JcePBEKeyEncryptionMethodGenerator symmetricEncryptionGenerator = new JcePBEKeyEncryptionMethodGenerator(
- passPhrase.toCharArray());
+ encryptionPassphrase.toCharArray());
cPk.addMethod(symmetricEncryptionGenerator);
- }
- for (int i = 0; i < encryptionKeyIds.length; ++i) {
- PGPPublicKey key = PGPHelper.getEncryptPublicKey(context, encryptionKeyIds[i]);
- if (key != null) {
-
- JcePublicKeyKeyEncryptionMethodGenerator pubKeyEncryptionGenerator = new JcePublicKeyKeyEncryptionMethodGenerator(
- key);
- cPk.addMethod(pubKeyEncryptionGenerator);
+ } else {
+ // Asymmetric encryption
+ for (int i = 0; i < encryptionKeyIds.length; ++i) {
+ PGPPublicKey key = PGPHelper.getEncryptPublicKey(context, encryptionKeyIds[i]);
+ if (key != null) {
+
+ JcePublicKeyKeyEncryptionMethodGenerator pubKeyEncryptionGenerator = new JcePublicKeyKeyEncryptionMethodGenerator(
+ key);
+ cPk.addMethod(pubKeyEncryptionGenerator);
+ }
}
}
encryptOut = cPk.open(out, new byte[1 << 16]);
@@ -806,10 +767,10 @@ public class PGPMain {
// content signer based on signing key algorithm and choosen hash algorithm
JcaPGPContentSignerBuilder contentSignerBuilder = new JcaPGPContentSignerBuilder(
- signingKey.getPublicKey().getAlgorithm(), hashAlgorithm)
+ signingKey.getPublicKey().getAlgorithm(), signatureHashAlgorithm)
.setProvider(BOUNCY_CASTLE_PROVIDER_NAME);
- if (forceV3Signature) {
+ if (signatureForceV3) {
signatureV3Generator = new PGPV3SignatureGenerator(contentSignerBuilder);
signatureV3Generator.init(PGPSignature.BINARY_DOCUMENT, signaturePrivateKey);
} else {
@@ -832,7 +793,7 @@ public class PGPMain {
bcpgOut = new BCPGOutputStream(compressGen.open(encryptOut));
}
if (signatureKeyId != Id.key.none) {
- if (forceV3Signature) {
+ if (signatureForceV3) {
signatureV3Generator.generateOnePassVersion(false).encode(bcpgOut);
} else {
signatureGenerator.generateOnePassVersion(false).encode(bcpgOut);
@@ -852,7 +813,7 @@ public class PGPMain {
while ((n = in.read(buffer)) > 0) {
pOut.write(buffer, 0, n);
if (signatureKeyId != Id.key.none) {
- if (forceV3Signature) {
+ if (signatureForceV3) {
signatureV3Generator.update(buffer, 0, n);
} else {
signatureGenerator.update(buffer, 0, n);
@@ -868,7 +829,7 @@ public class PGPMain {
if (signatureKeyId != Id.key.none) {
updateProgress(progress, R.string.progress_generatingSignature, 95, 100);
- if (forceV3Signature) {
+ if (signatureForceV3) {
signatureV3Generator.generate().encode(pOut);
} else {
signatureGenerator.generate().encode(pOut);
@@ -878,16 +839,16 @@ public class PGPMain {
compressGen.close();
}
encryptOut.close();
- if (armored) {
+ if (useAsciiArmor) {
armorOut.close();
}
updateProgress(progress, R.string.progress_done, 100, 100);
}
- public static void signText(Context context, InputData data, OutputStream outStream,
- long signatureKeyId, String signaturePassPhrase, int hashAlgorithm,
- boolean forceV3Signature, ProgressDialogUpdater progress) throws ApgGeneralException,
+ public static void signText(Context context, ProgressDialogUpdater progress, InputData data,
+ OutputStream outStream, long signatureKeyId, String signaturePassphrase,
+ int signatureHashAlgorithm, boolean forceV3Signature) throws ApgGeneralException,
PGPException, IOException, NoSuchAlgorithmException, SignatureException {
ArmoredOutputStream armorOut = new ArmoredOutputStream(outStream);
@@ -902,19 +863,19 @@ public class PGPMain {
throw new ApgGeneralException(context.getString(R.string.error_noSignatureKey));
}
- signingKeyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(context, signatureKeyId);
+ signingKeyRing = ProviderHelper.getPGPSecretKeyRingByKeyId(context, signatureKeyId);
signingKey = PGPHelper.getSigningKey(context, signatureKeyId);
if (signingKey == null) {
armorOut.close();
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
}
- if (signaturePassPhrase == null) {
+ if (signaturePassphrase == null) {
armorOut.close();
throw new ApgGeneralException(context.getString(R.string.error_noSignaturePassPhrase));
}
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
- BOUNCY_CASTLE_PROVIDER_NAME).build(signaturePassPhrase.toCharArray());
+ BOUNCY_CASTLE_PROVIDER_NAME).build(signaturePassphrase.toCharArray());
signaturePrivateKey = signingKey.extractPrivateKey(keyDecryptor);
if (signaturePrivateKey == null) {
armorOut.close();
@@ -930,7 +891,7 @@ public class PGPMain {
// content signer based on signing key algorithm and choosen hash algorithm
JcaPGPContentSignerBuilder contentSignerBuilder = new JcaPGPContentSignerBuilder(signingKey
- .getPublicKey().getAlgorithm(), hashAlgorithm)
+ .getPublicKey().getAlgorithm(), signatureHashAlgorithm)
.setProvider(BOUNCY_CASTLE_PROVIDER_NAME);
if (forceV3Signature) {
@@ -948,7 +909,7 @@ public class PGPMain {
updateProgress(progress, R.string.progress_signing, 40, 100);
- armorOut.beginClearText(hashAlgorithm);
+ armorOut.beginClearText(signatureHashAlgorithm);
InputStream inStream = data.getInputStream();
final BufferedReader reader = new BufferedReader(new InputStreamReader(inStream));
@@ -992,11 +953,11 @@ public class PGPMain {
updateProgress(progress, R.string.progress_done, 100, 100);
}
- public static void generateSignature(Context context, InputData data, OutputStream outStream,
- boolean armored, boolean binary, long signatureKeyId, String signaturePassPhrase,
- int hashAlgorithm, boolean forceV3Signature, ProgressDialogUpdater progress)
- throws ApgGeneralException, PGPException, IOException, NoSuchAlgorithmException,
- SignatureException {
+ public static void generateSignature(Context context, ProgressDialogUpdater progress,
+ InputData data, OutputStream outStream, boolean armored, boolean binary,
+ long signatureKeyId, String signaturePassPhrase, int hashAlgorithm,
+ boolean forceV3Signature) throws ApgGeneralException, PGPException, IOException,
+ NoSuchAlgorithmException, SignatureException {
OutputStream out = null;
@@ -1018,7 +979,7 @@ public class PGPMain {
throw new ApgGeneralException(context.getString(R.string.error_noSignatureKey));
}
- signingKeyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(context, signatureKeyId);
+ signingKeyRing = ProviderHelper.getPGPSecretKeyRingByKeyId(context, signatureKeyId);
signingKey = PGPHelper.getSigningKey(context, signatureKeyId);
if (signingKey == null) {
throw new ApgGeneralException(context.getString(R.string.error_signatureFailed));
@@ -1118,7 +1079,7 @@ public class PGPMain {
if (passphrase == null || passphrase.length() <= 0) {
throw new ApgGeneralException("Unable to obtain passphrase");
} else {
- PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(context,
+ PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRingByKeyId(context,
pubKeyId);
PGPSecretKey signingKey = PGPHelper.getSigningKey(context, masterKeyId);
@@ -1185,7 +1146,7 @@ public class PGPMain {
if (obj instanceof PGPPublicKeyEncryptedData) {
gotAsymmetricEncryption = true;
PGPPublicKeyEncryptedData pbe = (PGPPublicKeyEncryptedData) obj;
- secretKey = ProviderHelper.getPGPSecretKey(context, pbe.getKeyID());
+ secretKey = ProviderHelper.getPGPSecretKeyByKeyId(context, pbe.getKeyID());
if (secretKey != null) {
break;
}
@@ -1232,12 +1193,13 @@ public class PGPMain {
return false;
}
- public static Bundle decrypt(Context context, InputData data, OutputStream outStream,
- String passPhrase, ProgressDialogUpdater progress, boolean assumeSymmetric)
+ public static Bundle decryptAndVerify(Context context, ProgressDialogUpdater progress,
+ InputData data, OutputStream outStream, String passphrase, boolean assumeSymmetric)
throws IOException, ApgGeneralException, PGPException, SignatureException {
- if (passPhrase == null) {
- passPhrase = "";
+ if (passphrase == null) {
+ passphrase = "";
}
+
Bundle returnData = new Bundle();
InputStream in = PGPUtil.getDecoderStream(data.getInputStream());
PGPObjectFactory pgpF = new PGPObjectFactory(in);
@@ -1289,7 +1251,7 @@ public class PGPMain {
.setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build();
PBEDataDecryptorFactory decryptorFactory = new JcePBEDataDecryptorFactoryBuilder(
digestCalcProvider).setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(
- passPhrase.toCharArray());
+ passphrase.toCharArray());
clear = pbe.getDataStream(decryptorFactory);
@@ -1306,7 +1268,7 @@ public class PGPMain {
Object obj = it.next();
if (obj instanceof PGPPublicKeyEncryptedData) {
PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) obj;
- secretKey = ProviderHelper.getPGPSecretKey(context, encData.getKeyID());
+ secretKey = ProviderHelper.getPGPSecretKeyByKeyId(context, encData.getKeyID());
if (secretKey != null) {
pbe = encData;
break;
@@ -1323,7 +1285,7 @@ public class PGPMain {
PGPPrivateKey privateKey = null;
try {
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder()
- .setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
+ .setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(passphrase.toCharArray());
privateKey = secretKey.extractPrivateKey(keyDecryptor);
} catch (PGPException e) {
throw new PGPException(context.getString(R.string.error_wrongPassPhrase));
@@ -1363,11 +1325,11 @@ public class PGPMain {
if (dataChunk instanceof PGPOnePassSignatureList) {
if (progress != null)
progress.setProgress(R.string.progress_processingSignature, currentProgress, 100);
- returnData.putBoolean(ApgService.RESULT_SIGNATURE, true);
+ returnData.putBoolean(ApgIntentService.RESULT_SIGNATURE, true);
PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk;
for (int i = 0; i < sigList.size(); ++i) {
signature = sigList.get(i);
- signatureKey = ProviderHelper.getPGPPublicKey(context, signature.getKeyID());
+ signatureKey = ProviderHelper.getPGPPublicKeyByKeyId(context, signature.getKeyID());
if (signatureKeyId == 0) {
signatureKeyId = signature.getKeyID();
}
@@ -1377,17 +1339,17 @@ public class PGPMain {
signatureIndex = i;
signatureKeyId = signature.getKeyID();
String userId = null;
- PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(
+ PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingByKeyId(
context, signatureKeyId);
if (signKeyRing != null) {
userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(signKeyRing));
}
- returnData.putString(ApgService.RESULT_SIGNATURE_USER_ID, userId);
+ returnData.putString(ApgIntentService.RESULT_SIGNATURE_USER_ID, userId);
break;
}
}
- returnData.putLong(ApgService.RESULT_SIGNATURE_KEY_ID, signatureKeyId);
+ returnData.putLong(ApgIntentService.RESULT_SIGNATURE_KEY_ID, signatureKeyId);
if (signature != null) {
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider = new JcaPGPContentVerifierBuilderProvider()
@@ -1395,7 +1357,7 @@ public class PGPMain {
signature.init(contentVerifierBuilderProvider, signatureKey);
} else {
- returnData.putBoolean(ApgService.RESULT_SIGNATURE_UNKNOWN, true);
+ returnData.putBoolean(ApgIntentService.RESULT_SIGNATURE_UNKNOWN, true);
}
dataChunk = plainFact.nextObject();
@@ -1432,7 +1394,7 @@ public class PGPMain {
try {
signature.update(buffer, 0, n);
} catch (SignatureException e) {
- returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS, false);
+ returnData.putBoolean(ApgIntentService.RESULT_SIGNATURE_SUCCESS, false);
signature = null;
}
}
@@ -1454,9 +1416,9 @@ public class PGPMain {
PGPSignatureList signatureList = (PGPSignatureList) plainFact.nextObject();
PGPSignature messageSignature = signatureList.get(signatureIndex);
if (signature.verify(messageSignature)) {
- returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS, true);
+ returnData.putBoolean(ApgIntentService.RESULT_SIGNATURE_SUCCESS, true);
} else {
- returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS, false);
+ returnData.putBoolean(ApgIntentService.RESULT_SIGNATURE_SUCCESS, false);
}
}
}
@@ -1478,8 +1440,8 @@ public class PGPMain {
return returnData;
}
- public static Bundle verifyText(Context context, InputData data, OutputStream outStream,
- boolean lookupUnknownKey, ProgressDialogUpdater progress) throws IOException,
+ public static Bundle verifyText(Context context, ProgressDialogUpdater progress,
+ InputData data, OutputStream outStream, boolean lookupUnknownKey) throws IOException,
ApgGeneralException, PGPException, SignatureException {
Bundle returnData = new Bundle();
@@ -1509,7 +1471,7 @@ public class PGPMain {
byte[] clearText = out.toByteArray();
outStream.write(clearText);
- returnData.putBoolean(ApgService.RESULT_SIGNATURE, true);
+ returnData.putBoolean(ApgIntentService.RESULT_SIGNATURE, true);
updateProgress(progress, R.string.progress_processingSignature, 60, 100);
PGPObjectFactory pgpFact = new PGPObjectFactory(aIn);
@@ -1523,7 +1485,7 @@ public class PGPMain {
PGPPublicKey signatureKey = null;
for (int i = 0; i < sigList.size(); ++i) {
signature = sigList.get(i);
- signatureKey = ProviderHelper.getPGPPublicKey(context, signature.getKeyID());
+ signatureKey = ProviderHelper.getPGPPublicKeyByKeyId(context, signature.getKeyID());
if (signatureKeyId == 0) {
signatureKeyId = signature.getKeyID();
}
@@ -1531,8 +1493,8 @@ public class PGPMain {
if (signatureKey == null && lookupUnknownKey) {
returnData = new Bundle();
- returnData.putLong(ApgService.RESULT_SIGNATURE_KEY_ID, signatureKeyId);
- returnData.putBoolean(ApgService.RESULT_SIGNATURE_LOOKUP_KEY, true);
+ returnData.putLong(ApgIntentService.RESULT_SIGNATURE_KEY_ID, signatureKeyId);
+ returnData.putBoolean(ApgIntentService.RESULT_SIGNATURE_LOOKUP_KEY, true);
// return directly now, decrypt will be done again after importing unknown key
return returnData;
@@ -1543,20 +1505,20 @@ public class PGPMain {
} else {
signatureKeyId = signature.getKeyID();
String userId = null;
- PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(
+ PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingByKeyId(
context, signatureKeyId);
if (signKeyRing != null) {
userId = PGPHelper.getMainUserId(PGPHelper.getMasterKey(signKeyRing));
}
- returnData.putString(ApgService.RESULT_SIGNATURE_USER_ID, userId);
+ returnData.putString(ApgIntentService.RESULT_SIGNATURE_USER_ID, userId);
break;
}
}
- returnData.putLong(ApgService.RESULT_SIGNATURE_KEY_ID, signatureKeyId);
+ returnData.putLong(ApgIntentService.RESULT_SIGNATURE_KEY_ID, signatureKeyId);
if (signature == null) {
- returnData.putBoolean(ApgService.RESULT_SIGNATURE_UNKNOWN, true);
+ returnData.putBoolean(ApgIntentService.RESULT_SIGNATURE_UNKNOWN, true);
if (progress != null)
progress.setProgress(R.string.progress_done, 100, 100);
return returnData;
@@ -1584,7 +1546,7 @@ public class PGPMain {
} while (lookAhead != -1);
}
- returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS, signature.verify());
+ returnData.putBoolean(ApgIntentService.RESULT_SIGNATURE_SUCCESS, signature.verify());
updateProgress(progress, R.string.progress_done, 100, 100);
return returnData;
@@ -1822,7 +1784,7 @@ public class PGPMain {
return size;
}
- public static void deleteFileSecurely(Context context, File file, ProgressDialogUpdater progress)
+ public static void deleteFileSecurely(Context context, ProgressDialogUpdater progress, File file)
throws FileNotFoundException, IOException {
long length = file.length();
SecureRandom random = new SecureRandom();
diff --git a/org_apg/src/org/thialfihar/android/apg/provider/ApgProvider.java b/org_apg/src/org/thialfihar/android/apg/provider/ApgProvider.java
index 5d2ef6506..ad0bd4a41 100644
--- a/org_apg/src/org/thialfihar/android/apg/provider/ApgProvider.java
+++ b/org_apg/src/org/thialfihar/android/apg/provider/ApgProvider.java
@@ -286,17 +286,21 @@ public class ApgProvider extends ContentProvider {
}
private SQLiteQueryBuilder buildKeyRingQuery(SQLiteQueryBuilder qb,
- HashMap<String, String> projectionMap, int match, String sortOrder) {
+ HashMap<String, String> projectionMap, int match, boolean isMasterKey, String sortOrder) {
qb.appendWhere(Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " = ");
qb.appendWhereEscapeString(Integer.toString(getKeyType(match)));
+ String isMasterKeyQuery = "";
+ if (isMasterKey) {
+ isMasterKeyQuery = " AND " + Tables.KEYS + "." + KeysColumns.IS_MASTER_KEY + " = '1'";
+ }
+
qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "("
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
- + KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "."
- + KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN " + Tables.USER_IDS
- + " ON " + "(" + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.USER_IDS
- + "." + UserIdsColumns.KEY_RING_ROW_ID + " AND " + Tables.USER_IDS + "."
- + UserIdsColumns.RANK + " = '0')");
+ + KeysColumns.KEY_RING_ROW_ID + isMasterKeyQuery + ") " + " INNER JOIN "
+ + Tables.USER_IDS + " ON " + "(" + Tables.KEY_RINGS + "." + BaseColumns._ID + " = "
+ + Tables.USER_IDS + "." + UserIdsColumns.KEY_RING_ROW_ID + " AND "
+ + Tables.USER_IDS + "." + UserIdsColumns.RANK + " = '0')");
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
@@ -326,7 +330,7 @@ public class ApgProvider extends ContentProvider {
switch (match) {
case PUBLIC_KEY_RING:
case SECRET_KEY_RING:
- qb = buildKeyRingQuery(qb, projectionMap, match, sortOrder);
+ qb = buildKeyRingQuery(qb, projectionMap, match, true, sortOrder);
if (TextUtils.isEmpty(sortOrder)) {
sortOrder = Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC";
@@ -336,7 +340,7 @@ public class ApgProvider extends ContentProvider {
case PUBLIC_KEY_RING_BY_ROW_ID:
case SECRET_KEY_RING_BY_ROW_ID:
- qb = buildKeyRingQuery(qb, projectionMap, match, sortOrder);
+ qb = buildKeyRingQuery(qb, projectionMap, match, true, sortOrder);
qb.appendWhere(" AND " + Tables.KEY_RINGS + "." + BaseColumns._ID + " = ");
qb.appendWhereEscapeString(uri.getLastPathSegment());
@@ -349,7 +353,7 @@ public class ApgProvider extends ContentProvider {
case PUBLIC_KEY_RING_BY_MASTER_KEY_ID:
case SECRET_KEY_RING_BY_MASTER_KEY_ID:
- qb = buildKeyRingQuery(qb, projectionMap, match, sortOrder);
+ qb = buildKeyRingQuery(qb, projectionMap, match, true, sortOrder);
qb.appendWhere(" AND " + Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID + " = ");
qb.appendWhereEscapeString(uri.getLastPathSegment());
@@ -362,9 +366,9 @@ public class ApgProvider extends ContentProvider {
case SECRET_KEY_RING_BY_KEY_ID:
case PUBLIC_KEY_RING_BY_KEY_ID:
- qb = buildKeyRingQuery(qb, projectionMap, match, sortOrder);
+ qb = buildKeyRingQuery(qb, projectionMap, match, false, sortOrder);
- qb.appendWhere(" AND " + Tables.KEYS + KeysColumns.KEY_ID + " = ");
+ qb.appendWhere(" AND " + Tables.KEYS + "." + KeysColumns.KEY_ID + " = ");
qb.appendWhereEscapeString(uri.getLastPathSegment());
if (TextUtils.isEmpty(sortOrder)) {
diff --git a/org_apg/src/org/thialfihar/android/apg/provider/ProviderHelper.java b/org_apg/src/org/thialfihar/android/apg/provider/ProviderHelper.java
index 1b4ddad8a..ae4b1520c 100644
--- a/org_apg/src/org/thialfihar/android/apg/provider/ProviderHelper.java
+++ b/org_apg/src/org/thialfihar/android/apg/provider/ProviderHelper.java
@@ -59,8 +59,19 @@ public class ProviderHelper {
}
/**
- * Retrieves the actual PGPPublicKeyRing object from the database blob associated with the
- * maserKeyId
+ * Retrieves the actual PGPPublicKeyRing object from the database blob based on the rowId
+ *
+ * @param context
+ * @param rowId
+ * @return
+ */
+ public static PGPPublicKeyRing getPGPPublicKeyRingByRowId(Context context, long rowId) {
+ Uri queryUri = KeyRings.buildPublicKeyRingsUri(Long.toString(rowId));
+ return (PGPPublicKeyRing) getPGPKeyRing(context, queryUri);
+ }
+
+ /**
+ * Retrieves the actual PGPPublicKeyRing object from the database blob based on the maserKeyId
*
* @param context
* @param masterKeyId
@@ -72,14 +83,50 @@ public class ProviderHelper {
return (PGPPublicKeyRing) getPGPKeyRing(context, queryUri);
}
- public static PGPPublicKeyRing getPGPPublicKeyRing(Context context, long rowId) {
- Uri queryUri = KeyRings.buildPublicKeyRingsUri(Long.toString(rowId));
+ /**
+ * Retrieves the actual PGPPublicKeyRing object from the database blob associated with a key
+ * with this keyId
+ *
+ * @param context
+ * @param keyId
+ * @return
+ */
+ public static PGPPublicKeyRing getPGPPublicKeyRingByKeyId(Context context, long keyId) {
+ Uri queryUri = KeyRings.buildPublicKeyRingsByKeyIdUri(Long.toString(keyId));
return (PGPPublicKeyRing) getPGPKeyRing(context, queryUri);
}
/**
- * Retrieves the actual PGPSecretKeyRing object from the database blob associated with the
- * maserKeyId
+ * Retrieves the actual PGPPublicKey object from the database blob associated with a key with
+ * this keyId
+ *
+ * @param context
+ * @param keyId
+ * @return
+ */
+ public static PGPPublicKey getPGPPublicKeyByKeyId(Context context, long keyId) {
+ PGPPublicKeyRing keyRing = getPGPPublicKeyRingByKeyId(context, keyId);
+ if (keyRing == null) {
+ return null;
+ }
+
+ return keyRing.getPublicKey(keyId);
+ }
+
+ /**
+ * Retrieves the actual PGPSecretKeyRing object from the database blob based on the rowId
+ *
+ * @param context
+ * @param rowId
+ * @return
+ */
+ public static PGPSecretKeyRing getPGPSecretKeyRingByRowId(Context context, long rowId) {
+ Uri queryUri = KeyRings.buildSecretKeyRingsUri(Long.toString(rowId));
+ return (PGPSecretKeyRing) getPGPKeyRing(context, queryUri);
+ }
+
+ /**
+ * Retrieves the actual PGPSecretKeyRing object from the database blob based on the maserKeyId
*
* @param context
* @param masterKeyId
@@ -91,26 +138,34 @@ public class ProviderHelper {
return (PGPSecretKeyRing) getPGPKeyRing(context, queryUri);
}
- public static PGPSecretKeyRing getPGPSecretKeyRing(Context context, long rowId) {
- Uri queryUri = KeyRings.buildSecretKeyRingsUri(Long.toString(rowId));
+ /**
+ * Retrieves the actual PGPSecretKeyRing object from the database blob associated with a key
+ * with this keyId
+ *
+ * @param context
+ * @param keyId
+ * @return
+ */
+ public static PGPSecretKeyRing getPGPSecretKeyRingByKeyId(Context context, long keyId) {
+ Uri queryUri = KeyRings.buildSecretKeyRingsByKeyIdUri(Long.toString(keyId));
return (PGPSecretKeyRing) getPGPKeyRing(context, queryUri);
}
- public static PGPSecretKey getPGPSecretKey(Context context, long keyId) {
- PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(context, keyId);
- if (keyRing == null) {
- return null;
- }
- return keyRing.getSecretKey(keyId);
- }
-
- public static PGPPublicKey getPGPPublicKey(Context context, long keyId) {
- PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(context, keyId);
+ /**
+ * Retrieves the actual PGPSecretKey object from the database blob associated with a key with
+ * this keyId
+ *
+ * @param context
+ * @param keyId
+ * @return
+ */
+ public static PGPSecretKey getPGPSecretKeyByKeyId(Context context, long keyId) {
+ PGPSecretKeyRing keyRing = getPGPSecretKeyRingByKeyId(context, keyId);
if (keyRing == null) {
return null;
}
- return keyRing.getPublicKey(keyId);
+ return keyRing.getSecretKey(keyId);
}
/**
diff --git a/org_apg/src/org/thialfihar/android/apg/service/ApgIntentService.java b/org_apg/src/org/thialfihar/android/apg/service/ApgIntentService.java
new file mode 100644
index 000000000..e3290ae65
--- /dev/null
+++ b/org_apg/src/org/thialfihar/android/apg/service/ApgIntentService.java
@@ -0,0 +1,881 @@
+/*
+ * Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.thialfihar.android.apg.service;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Vector;
+
+import org.spongycastle.openpgp.PGPPublicKeyRing;
+import org.spongycastle.openpgp.PGPSecretKey;
+import org.spongycastle.openpgp.PGPSecretKeyRing;
+import org.thialfihar.android.apg.Constants;
+import org.thialfihar.android.apg.Id;
+import org.thialfihar.android.apg.R;
+import org.thialfihar.android.apg.helper.FileHelper;
+import org.thialfihar.android.apg.helper.OtherHelper;
+import org.thialfihar.android.apg.helper.PGPMain;
+import org.thialfihar.android.apg.helper.Preferences;
+import org.thialfihar.android.apg.helper.PGPMain.ApgGeneralException;
+import org.thialfihar.android.apg.helper.PGPConversionHelper;
+import org.thialfihar.android.apg.provider.ApgContract.DataStream;
+import org.thialfihar.android.apg.provider.ProviderHelper;
+import org.thialfihar.android.apg.util.HkpKeyServer;
+import org.thialfihar.android.apg.util.InputData;
+import org.thialfihar.android.apg.util.KeyServer.KeyInfo;
+import org.thialfihar.android.apg.util.ProgressDialogUpdater;
+
+import android.app.IntentService;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.RemoteException;
+
+import org.thialfihar.android.apg.util.Log;
+
+/**
+ * This Service contains all important long lasting operations for APG. It receives Intents with
+ * data from the activities or other apps, queues these intents, executes them, and stops itself
+ * after doing them.
+ */
+public class ApgIntentService extends IntentService implements ProgressDialogUpdater {
+
+ /* extras that can be given by intent */
+ public static final String EXTRA_MESSENGER = "messenger";
+ public static final String EXTRA_ACTION = "action";
+ public static final String EXTRA_DATA = "data";
+
+ /* possible EXTRA_ACTIONs */
+ public static final int ACTION_ENCRYPT_SIGN = 10;
+
+ public static final int ACTION_DECRYPT_VERIFY = 20;
+
+ public static final int ACTION_SAVE_KEYRING = 30;
+ public static final int ACTION_GENERATE_KEY = 31;
+ public static final int ACTION_GENERATE_DEFAULT_RSA_KEYS = 32;
+
+ public static final int ACTION_DELETE_FILE_SECURELY = 40;
+
+ public static final int ACTION_IMPORT_KEY = 50;
+ public static final int ACTION_EXPORT_KEY = 51;
+
+ public static final int ACTION_UPLOAD_KEY = 60;
+ public static final int ACTION_QUERY_KEY = 61;
+
+ public static final int ACTION_SIGN_KEY = 70;
+
+ /* keys for data bundle */
+
+ // encrypt, decrypt, import export
+ public static final String TARGET = "target";
+ // possible targets:
+ public static final int TARGET_BYTES = 1;
+ public static final int TARGET_FILE = 2;
+ public static final int TARGET_STREAM = 3;
+
+ // encrypt
+ public static final String SECRET_KEY_ID = "secretKeyId";
+ public static final String USE_ASCII_AMOR = "useAsciiAmor";
+ public static final String ENCRYPTION_KEYS_IDS = "encryptionKeysIds";
+ public static final String COMPRESSION_ID = "compressionId";
+ public static final String GENERATE_SIGNATURE = "generateSignature";
+ public static final String SIGN_ONLY = "signOnly";
+ public static final String MESSAGE_BYTES = "messageBytes";
+ public static final String INPUT_FILE = "inputFile";
+ public static final String OUTPUT_FILE = "outputFile";
+ public static final String PROVIDER_URI = "providerUri";
+
+ // decrypt/verify
+ public static final String SIGNED_ONLY = "signedOnly";
+ public static final String RETURN_BYTES = "returnBinary";
+ public static final String CIPHERTEXT_BYTES = "ciphertextBytes";
+ public static final String ASSUME_SYMMETRIC = "assumeSymmetric";
+ public static final String LOOKUP_UNKNOWN_KEY = "lookupUnknownKey";
+
+ // edit keys
+ public static final String NEW_PASSPHRASE = "newPassphrase";
+ public static final String CURRENT_PASSPHRASE = "currentPassphrase";
+ public static final String USER_IDS = "userIds";
+ public static final String KEYS = "keys";
+ public static final String KEYS_USAGES = "keysUsages";
+ public static final String MASTER_KEY_ID = "masterKeyId";
+
+ // generate key
+ public static final String ALGORITHM = "algorithm";
+ public static final String KEY_SIZE = "keySize";
+ public static final String SYMMETRIC_PASSPHRASE = "passphrase";
+ public static final String MASTER_KEY = "masterKey";
+
+ // delete file securely
+ public static final String DELETE_FILE = "deleteFile";
+
+ // import key
+ public static final String IMPORT_INPUT_STREAM = "importInputStream";
+ public static final String IMPORT_FILENAME = "importFilename";
+ public static final String IMPORT_BYTES = "importBytes";
+ public static final String IMPORT_KEY_TYPE = "importKeyType";
+
+ // export key
+ public static final String EXPORT_OUTPUT_STREAM = "exportOutputStream";
+ public static final String EXPORT_FILENAME = "exportFilename";
+ public static final String EXPORT_KEY_TYPE = "exportKeyType";
+ public static final String EXPORT_ALL = "exportAll";
+ public static final String EXPORT_KEY_RING_ID = "exportKeyRingId";
+
+ // upload key
+ public static final String UPLOAD_KEY_SERVER = "uploadKeyServer";
+ public static final String UPLOAD_KEY_KEYRING_ROW_ID = "uploadKeyRingId";
+
+ // query key
+ public static final String QUERY_KEY_SERVER = "queryKeyServer";
+ public static final String QUERY_KEY_TYPE = "queryKeyType";
+ public static final String QUERY_KEY_STRING = "queryKeyString";
+ public static final String QUERY_KEY_ID = "queryKeyId";
+
+ // sign key
+ public static final String SIGN_KEY_MASTER_KEY_ID = "signKeyMasterKeyId";
+ public static final String SIGN_KEY_PUB_KEY_ID = "signKeyPubKeyId";
+
+ /*
+ * possible data keys as result send over messenger
+ */
+ // keys
+ public static final String RESULT_NEW_KEY = "newKey";
+ public static final String RESULT_NEW_KEY2 = "newKey2";
+
+ // encrypt
+ public static final String RESULT_SIGNATURE_BYTES = "signatureData";
+ public static final String RESULT_SIGNATURE_STRING = "signatureText";
+ public static final String RESULT_ENCRYPTED_STRING = "encryptedMessage";
+ public static final String RESULT_ENCRYPTED_BYTES = "encryptedData";
+ public static final String RESULT_URI = "resultUri";
+
+ // decrypt/verify
+ public static final String RESULT_DECRYPTED_STRING = "decryptedMessage";
+ public static final String RESULT_DECRYPTED_BYTES = "decryptedData";
+ public static final String RESULT_SIGNATURE = "signature";
+ public static final String RESULT_SIGNATURE_KEY_ID = "signatureKeyId";
+ public static final String RESULT_SIGNATURE_USER_ID = "signatureUserId";
+
+ public static final String RESULT_SIGNATURE_SUCCESS = "signatureSuccess";
+ public static final String RESULT_SIGNATURE_UNKNOWN = "signatureUnknown";
+ public static final String RESULT_SIGNATURE_LOOKUP_KEY = "lookupKey";
+
+ // 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";
+
+ // query
+ public static final String RESULT_QUERY_KEY_KEY_DATA = "queryKeyKeyData";
+ public static final String RESULT_QUERY_KEY_SEARCH_RESULT = "queryKeySearchResult";
+
+ Messenger mMessenger;
+
+ public ApgIntentService() {
+ super("ApgService");
+ }
+
+ /**
+ * The IntentService calls this method from the default worker thread with the intent that
+ * started the service. When this method returns, IntentService stops the service, as
+ * appropriate.
+ */
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ Bundle extras = intent.getExtras();
+ if (extras == null) {
+ Log.e(Constants.TAG, "Extras bundle is null!");
+ return;
+ }
+
+ if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) || extras
+ .containsKey(EXTRA_ACTION))) {
+ Log.e(Constants.TAG,
+ "Extra bundle must contain a messenger, a data bundle, and an action!");
+ return;
+ }
+
+ mMessenger = (Messenger) extras.get(EXTRA_MESSENGER);
+ Bundle data = extras.getBundle(EXTRA_DATA);
+
+ OtherHelper.logDebugBundle(data, "EXTRA_DATA");
+
+ int action = extras.getInt(EXTRA_ACTION);
+
+ // execute action from extra bundle
+ switch (action) {
+ case ACTION_ENCRYPT_SIGN:
+
+ try {
+ /* Input */
+ int target = data.getInt(TARGET);
+
+ long secretKeyId = data.getLong(SECRET_KEY_ID);
+ String encryptionPassphrase = data.getString(SYMMETRIC_PASSPHRASE);
+
+ boolean useAsciiArmor = data.getBoolean(USE_ASCII_AMOR);
+ long encryptionKeyIds[] = data.getLongArray(ENCRYPTION_KEYS_IDS);
+ int compressionId = data.getInt(COMPRESSION_ID);
+ boolean generateSignature = data.getBoolean(GENERATE_SIGNATURE);
+ boolean signOnly = data.getBoolean(SIGN_ONLY);
+
+ InputStream inStream = null;
+ long inLength = -1;
+ InputData inputData = null;
+ OutputStream outStream = null;
+ String streamFilename = null;
+ switch (target) {
+ case TARGET_BYTES: /* encrypting bytes directly */
+ byte[] bytes = data.getByteArray(MESSAGE_BYTES);
+
+ inStream = new ByteArrayInputStream(bytes);
+ inLength = bytes.length;
+
+ inputData = new InputData(inStream, inLength);
+ outStream = new ByteArrayOutputStream();
+
+ break;
+ case TARGET_FILE: /* encrypting file */
+ String inputFile = data.getString(INPUT_FILE);
+ String outputFile = data.getString(OUTPUT_FILE);
+
+ // check if storage is ready
+ if (!FileHelper.isStorageMounted(inputFile)
+ || !FileHelper.isStorageMounted(outputFile)) {
+ throw new ApgGeneralException(
+ getString(R.string.error_externalStorageNotReady));
+ }
+
+ inStream = new FileInputStream(inputFile);
+ File file = new File(inputFile);
+ inLength = file.length();
+ inputData = new InputData(inStream, inLength);
+
+ outStream = new FileOutputStream(outputFile);
+
+ break;
+
+ case TARGET_STREAM: /* Encrypting stream from content uri */
+ Uri providerUri = (Uri) data.getParcelable(PROVIDER_URI);
+
+ // InputStream
+ InputStream in = getContentResolver().openInputStream(providerUri);
+ inLength = PGPMain.getLengthOfStream(in);
+ inputData = new InputData(in, inLength);
+
+ // OutputStream
+ try {
+ while (true) {
+ streamFilename = PGPMain.generateRandomString(32);
+ if (streamFilename == null) {
+ throw new PGPMain.ApgGeneralException(
+ "couldn't generate random file name");
+ }
+ openFileInput(streamFilename).close();
+ }
+ } catch (FileNotFoundException e) {
+ // found a name that isn't used yet
+ }
+ outStream = openFileOutput(streamFilename, Context.MODE_PRIVATE);
+
+ break;
+
+ default:
+ throw new PGPMain.ApgGeneralException("No target choosen!");
+
+ }
+
+ /* Operation */
+
+ if (generateSignature) {
+ Log.d(Constants.TAG, "generating signature...");
+ PGPMain.generateSignature(this, this, inputData, outStream, useAsciiArmor,
+ false, secretKeyId, PassphraseCacheService.getCachedPassphrase(this,
+ secretKeyId), Preferences.getPreferences(this)
+ .getDefaultHashAlgorithm(), Preferences.getPreferences(this)
+ .getForceV3Signatures());
+ } else if (signOnly) {
+ Log.d(Constants.TAG, "sign only...");
+ PGPMain.signText(this, this, inputData, outStream, secretKeyId,
+ PassphraseCacheService.getCachedPassphrase(this, secretKeyId),
+ Preferences.getPreferences(this).getDefaultHashAlgorithm(), Preferences
+ .getPreferences(this).getForceV3Signatures());
+ } else {
+ Log.d(Constants.TAG, "encrypt...");
+ PGPMain.encryptAndSign(this, this, inputData, outStream, useAsciiArmor,
+ compressionId, encryptionKeyIds, encryptionPassphrase, Preferences
+ .getPreferences(this).getDefaultEncryptionAlgorithm(),
+ secretKeyId,
+ Preferences.getPreferences(this).getDefaultHashAlgorithm(), Preferences
+ .getPreferences(this).getForceV3Signatures(),
+ PassphraseCacheService.getCachedPassphrase(this, secretKeyId));
+ }
+
+ outStream.close();
+
+ /* Output */
+
+ Bundle resultData = new Bundle();
+
+ switch (target) {
+ case TARGET_BYTES:
+ if (useAsciiArmor) {
+ String output = new String(
+ ((ByteArrayOutputStream) outStream).toByteArray());
+ if (generateSignature) {
+ resultData.putString(RESULT_SIGNATURE_STRING, output);
+ } else {
+ resultData.putString(RESULT_ENCRYPTED_STRING, output);
+ }
+ } else {
+ byte output[] = ((ByteArrayOutputStream) outStream).toByteArray();
+ if (generateSignature) {
+ resultData.putByteArray(RESULT_SIGNATURE_BYTES, output);
+ } else {
+ resultData.putByteArray(RESULT_ENCRYPTED_BYTES, output);
+ }
+ }
+
+ break;
+ case TARGET_FILE:
+ // nothing, file was written, just send okay
+
+ break;
+ case TARGET_STREAM:
+ String uri = DataStream.buildDataStreamUri(streamFilename).toString();
+ resultData.putString(RESULT_URI, uri);
+
+ break;
+ }
+
+ OtherHelper.logDebugBundle(resultData, "resultData");
+
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY, resultData);
+ } catch (Exception e) {
+ sendErrorToHandler(e);
+ }
+
+ break;
+
+ case ACTION_DECRYPT_VERIFY:
+ try {
+ /* Input */
+ int target = data.getInt(TARGET);
+
+ long secretKeyId = data.getLong(SECRET_KEY_ID);
+ byte[] bytes = data.getByteArray(CIPHERTEXT_BYTES);
+ boolean signedOnly = data.getBoolean(SIGNED_ONLY);
+ boolean returnBytes = data.getBoolean(RETURN_BYTES);
+ boolean assumeSymmetricEncryption = data.getBoolean(ASSUME_SYMMETRIC);
+
+ boolean lookupUnknownKey = data.getBoolean(LOOKUP_UNKNOWN_KEY);
+
+ InputStream inStream = null;
+ long inLength = -1;
+ InputData inputData = null;
+ OutputStream outStream = null;
+ String streamFilename = null;
+ switch (target) {
+ case TARGET_BYTES: /* decrypting bytes directly */
+ inStream = new ByteArrayInputStream(bytes);
+ inLength = bytes.length;
+
+ inputData = new InputData(inStream, inLength);
+ outStream = new ByteArrayOutputStream();
+
+ break;
+
+ case TARGET_FILE: /* decrypting file */
+ String inputFile = data.getString(INPUT_FILE);
+ String outputFile = data.getString(OUTPUT_FILE);
+
+ // check if storage is ready
+ if (!FileHelper.isStorageMounted(inputFile)
+ || !FileHelper.isStorageMounted(outputFile)) {
+ throw new ApgGeneralException(
+ getString(R.string.error_externalStorageNotReady));
+ }
+
+ // InputStream
+ inLength = -1;
+ inStream = new FileInputStream(inputFile);
+ File file = new File(inputFile);
+ inLength = file.length();
+ inputData = new InputData(inStream, inLength);
+
+ // OutputStream
+ outStream = new FileOutputStream(outputFile);
+
+ break;
+
+ case TARGET_STREAM: /* decrypting stream from content uri */
+ Uri providerUri = (Uri) data.getParcelable(PROVIDER_URI);
+
+ // InputStream
+ InputStream in = getContentResolver().openInputStream(providerUri);
+ inLength = PGPMain.getLengthOfStream(in);
+ inputData = new InputData(in, inLength);
+
+ // OutputStream
+ try {
+ while (true) {
+ streamFilename = PGPMain.generateRandomString(32);
+ if (streamFilename == null) {
+ throw new PGPMain.ApgGeneralException(
+ "couldn't generate random file name");
+ }
+ openFileInput(streamFilename).close();
+ }
+ } catch (FileNotFoundException e) {
+ // found a name that isn't used yet
+ }
+ outStream = openFileOutput(streamFilename, Context.MODE_PRIVATE);
+
+ break;
+
+ default:
+ throw new PGPMain.ApgGeneralException("No target choosen!");
+
+ }
+
+ /* Operation */
+
+ Bundle resultData = new Bundle();
+
+ // verifyText and decrypt returning additional resultData values for the
+ // verification of signatures
+ if (signedOnly) {
+ resultData = PGPMain.verifyText(this, this, inputData, outStream,
+ lookupUnknownKey);
+ } else {
+ resultData = PGPMain.decryptAndVerify(this, this, inputData, outStream,
+ PassphraseCacheService.getCachedPassphrase(this, secretKeyId),
+ assumeSymmetricEncryption);
+ }
+
+ outStream.close();
+
+ /* Output */
+
+ switch (target) {
+ case TARGET_BYTES:
+ if (returnBytes) {
+ byte output[] = ((ByteArrayOutputStream) outStream).toByteArray();
+ resultData.putByteArray(RESULT_DECRYPTED_BYTES, output);
+ } else {
+ String output = new String(
+ ((ByteArrayOutputStream) outStream).toByteArray());
+ resultData.putString(RESULT_DECRYPTED_STRING, output);
+ }
+
+ break;
+ case TARGET_FILE:
+ // nothing, file was written, just send okay and verification bundle
+
+ break;
+ case TARGET_STREAM:
+ String uri = DataStream.buildDataStreamUri(streamFilename).toString();
+ resultData.putString(RESULT_URI, uri);
+
+ break;
+ }
+
+ OtherHelper.logDebugBundle(resultData, "resultData");
+
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY, resultData);
+ } catch (Exception e) {
+ sendErrorToHandler(e);
+ }
+
+ break;
+
+ case ACTION_SAVE_KEYRING:
+
+ try {
+ /* Input */
+ String oldPassPhrase = data.getString(CURRENT_PASSPHRASE);
+ String newPassPhrase = data.getString(NEW_PASSPHRASE);
+ if (newPassPhrase == null) {
+ newPassPhrase = oldPassPhrase;
+ }
+ ArrayList<String> userIds = data.getStringArrayList(USER_IDS);
+ ArrayList<PGPSecretKey> keys = PGPConversionHelper.BytesToPGPSecretKeyList(data
+ .getByteArray(KEYS));
+ ArrayList<Integer> keysUsages = data.getIntegerArrayList(KEYS_USAGES);
+ long masterKeyId = data.getLong(MASTER_KEY_ID);
+
+ /* Operation */
+ PGPMain.buildSecretKey(this, userIds, keys, keysUsages, masterKeyId, oldPassPhrase,
+ newPassPhrase, this);
+ PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase);
+
+ /* Output */
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY);
+ } catch (Exception e) {
+ sendErrorToHandler(e);
+ }
+
+ break;
+
+ case ACTION_GENERATE_KEY:
+
+ try {
+ /* Input */
+ int algorithm = data.getInt(ALGORITHM);
+ String passphrase = data.getString(SYMMETRIC_PASSPHRASE);
+ int keysize = data.getInt(KEY_SIZE);
+ PGPSecretKey masterKey = null;
+ if (data.containsKey(MASTER_KEY)) {
+ masterKey = PGPConversionHelper.BytesToPGPSecretKey(data
+ .getByteArray(MASTER_KEY));
+ }
+
+ /* Operation */
+ PGPSecretKeyRing newKeyRing = PGPMain.createKey(this, algorithm, keysize,
+ passphrase, masterKey);
+
+ /* Output */
+ Bundle resultData = new Bundle();
+ resultData.putByteArray(RESULT_NEW_KEY,
+ PGPConversionHelper.PGPSecretKeyRingToBytes(newKeyRing));
+
+ OtherHelper.logDebugBundle(resultData, "resultData");
+
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY, resultData);
+ } catch (Exception e) {
+ sendErrorToHandler(e);
+ }
+
+ break;
+
+ case ACTION_GENERATE_DEFAULT_RSA_KEYS:
+ // generate one RSA 2048 key for signing and one subkey for encrypting!
+ try {
+ /* Input */
+ String passphrase = data.getString(SYMMETRIC_PASSPHRASE);
+
+ /* Operation */
+ PGPSecretKeyRing masterKeyRing = PGPMain.createKey(this, Id.choice.algorithm.rsa,
+ 2048, passphrase, null);
+
+ PGPSecretKeyRing subKeyRing = PGPMain.createKey(this, Id.choice.algorithm.rsa,
+ 2048, passphrase, masterKeyRing.getSecretKey());
+
+ /* Output */
+ Bundle resultData = new Bundle();
+ resultData.putByteArray(RESULT_NEW_KEY,
+ PGPConversionHelper.PGPSecretKeyRingToBytes(masterKeyRing));
+ resultData.putByteArray(RESULT_NEW_KEY2,
+ PGPConversionHelper.PGPSecretKeyRingToBytes(subKeyRing));
+
+ OtherHelper.logDebugBundle(resultData, "resultData");
+
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY, resultData);
+ } catch (Exception e) {
+ sendErrorToHandler(e);
+ }
+
+ break;
+
+ case ACTION_DELETE_FILE_SECURELY:
+ try {
+ /* Input */
+ String deleteFile = data.getString(DELETE_FILE);
+
+ /* Operation */
+ try {
+ PGPMain.deleteFileSecurely(this, this, new File(deleteFile));
+ } catch (FileNotFoundException e) {
+ throw new PGPMain.ApgGeneralException(getString(R.string.error_fileNotFound,
+ deleteFile));
+ } catch (IOException e) {
+ throw new PGPMain.ApgGeneralException(getString(
+ R.string.error_fileDeleteFailed, deleteFile));
+ }
+
+ /* Output */
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY);
+ } catch (Exception e) {
+ sendErrorToHandler(e);
+ }
+
+ break;
+
+ case ACTION_IMPORT_KEY:
+ try {
+
+ /* Input */
+ int target = data.getInt(TARGET);
+
+ int keyType = Id.type.public_key;
+ if (data.containsKey(IMPORT_KEY_TYPE)) {
+ keyType = data.getInt(IMPORT_KEY_TYPE);
+ }
+
+ /* Operation */
+ InputStream inStream = null;
+ long inLength = -1;
+ InputData inputData = null;
+ switch (target) {
+ case TARGET_BYTES: /* import key from bytes directly */
+ byte[] bytes = data.getByteArray(IMPORT_BYTES);
+
+ inStream = new ByteArrayInputStream(bytes);
+ inLength = bytes.length;
+
+ inputData = new InputData(inStream, inLength);
+
+ break;
+ case TARGET_FILE: /* import key from file */
+ String inputFile = data.getString(IMPORT_FILENAME);
+
+ inStream = new FileInputStream(inputFile);
+ File file = new File(inputFile);
+ inLength = file.length();
+ inputData = new InputData(inStream, inLength);
+
+ break;
+
+ case TARGET_STREAM:
+ // TODO: not implemented
+ break;
+ }
+
+ Bundle resultData = new Bundle();
+ resultData = PGPMain.importKeyRings(this, keyType, inputData, this);
+
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY, resultData);
+ } catch (Exception e) {
+ sendErrorToHandler(e);
+ }
+
+ break;
+
+ case ACTION_EXPORT_KEY:
+ try {
+
+ /* Input */
+ int keyType = Id.type.public_key;
+ if (data.containsKey(EXPORT_KEY_TYPE)) {
+ keyType = data.getInt(EXPORT_KEY_TYPE);
+ }
+
+ String outputFile = data.getString(EXPORT_FILENAME);
+
+ boolean exportAll = data.getBoolean(EXPORT_ALL);
+ int keyRingId = -1;
+ if (!exportAll) {
+ keyRingId = data.getInt(EXPORT_KEY_RING_ID);
+ }
+
+ /* Operation */
+
+ // check if storage is ready
+ if (!FileHelper.isStorageMounted(outputFile)) {
+ throw new ApgGeneralException(getString(R.string.error_externalStorageNotReady));
+ }
+
+ // OutputStream
+ FileOutputStream outStream = new FileOutputStream(outputFile);
+
+ Vector<Integer> keyRingIds = new Vector<Integer>();
+ if (exportAll) {
+ if (keyType == Id.type.public_key) {
+ keyRingIds = ProviderHelper.getPublicKeyRingsRowIds(this);
+ } else {
+ keyRingIds = ProviderHelper.getSecretKeyRingsRowIds(this);
+ }
+ } else {
+ keyRingIds.add(keyRingId);
+ }
+
+ Bundle resultData = new Bundle();
+ resultData = PGPMain.exportKeyRings(this, keyRingIds, outStream, this);
+
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY, resultData);
+ } catch (Exception e) {
+ sendErrorToHandler(e);
+ }
+
+ break;
+
+ case ACTION_UPLOAD_KEY:
+ try {
+
+ /* Input */
+ int keyRingRowId = data.getInt(UPLOAD_KEY_KEYRING_ROW_ID);
+ String keyServer = data.getString(UPLOAD_KEY_SERVER);
+
+ /* Operation */
+ HkpKeyServer server = new HkpKeyServer(keyServer);
+
+ PGPPublicKeyRing keyring = ProviderHelper.getPGPPublicKeyRingByRowId(this, keyRingRowId);
+ if (keyring != null) {
+ boolean uploaded = PGPMain.uploadKeyRingToServer(server,
+ (PGPPublicKeyRing) keyring);
+ if (!uploaded) {
+ throw new ApgGeneralException("Unable to export key to selected server");
+ }
+ }
+
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY);
+ } catch (Exception e) {
+ sendErrorToHandler(e);
+ }
+
+ break;
+
+ case ACTION_QUERY_KEY:
+ try {
+
+ /* Input */
+ int queryType = data.getInt(QUERY_KEY_TYPE);
+ String keyServer = data.getString(QUERY_KEY_SERVER);
+
+ String queryString = data.getString(QUERY_KEY_STRING);
+ long keyId = data.getLong(QUERY_KEY_ID);
+
+ /* Operation */
+ Bundle resultData = new Bundle();
+
+ HkpKeyServer server = new HkpKeyServer(keyServer);
+ if (queryType == Id.keyserver.search) {
+ ArrayList<KeyInfo> searchResult = server.search(queryString);
+
+ resultData.putParcelableArrayList(RESULT_QUERY_KEY_SEARCH_RESULT, searchResult);
+ } else if (queryType == Id.keyserver.get) {
+ String keyData = server.get(keyId);
+
+ resultData.putString(RESULT_QUERY_KEY_KEY_DATA, keyData);
+ }
+
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY, resultData);
+ } catch (Exception e) {
+ sendErrorToHandler(e);
+ }
+
+ break;
+
+ case ACTION_SIGN_KEY:
+ try {
+
+ /* Input */
+ long masterKeyId = data.getLong(SIGN_KEY_MASTER_KEY_ID);
+ long pubKeyId = data.getLong(SIGN_KEY_PUB_KEY_ID);
+
+ /* Operation */
+ String signaturePassPhrase = PassphraseCacheService.getCachedPassphrase(this,
+ masterKeyId);
+
+ PGPPublicKeyRing signedPubKeyRing = PGPMain.signKey(this, masterKeyId, pubKeyId,
+ signaturePassPhrase);
+
+ // store the signed key in our local cache
+ int retval = PGPMain.storeKeyRingInCache(this, signedPubKeyRing);
+ if (retval != Id.return_value.ok && retval != Id.return_value.updated) {
+ throw new ApgGeneralException("Failed to store signed key in local cache");
+ }
+
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_OKAY);
+ } catch (Exception e) {
+ sendErrorToHandler(e);
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ }
+
+ private void sendErrorToHandler(Exception e) {
+ Log.e(Constants.TAG, "ApgService Exception: ", e);
+ e.printStackTrace();
+
+ Bundle data = new Bundle();
+ data.putString(ApgIntentServiceHandler.DATA_ERROR, e.getMessage());
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_EXCEPTION, null, data);
+ }
+
+ private void sendMessageToHandler(Integer arg1, Integer arg2, Bundle data) {
+ Message msg = Message.obtain();
+ msg.arg1 = arg1;
+ if (arg2 != null) {
+ msg.arg2 = arg2;
+ }
+ if (data != null) {
+ msg.setData(data);
+ }
+
+ try {
+ mMessenger.send(msg);
+ } catch (RemoteException e) {
+ Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
+ } catch (NullPointerException e) {
+ Log.w(Constants.TAG, "Messenger is null!", e);
+ }
+ }
+
+ private void sendMessageToHandler(Integer arg1, Bundle data) {
+ sendMessageToHandler(arg1, null, data);
+ }
+
+ private void sendMessageToHandler(Integer arg1) {
+ sendMessageToHandler(arg1, null, null);
+ }
+
+ /**
+ * Set progress of ProgressDialog by sending message to handler on UI thread
+ */
+ public void setProgress(String message, int progress, int max) {
+ Log.d(Constants.TAG, "Send message by setProgress with progress=" + progress + ", max="
+ + max);
+
+ Bundle data = new Bundle();
+ if (message != null) {
+ data.putString(ApgIntentServiceHandler.DATA_MESSAGE, message);
+ }
+ data.putInt(ApgIntentServiceHandler.DATA_PROGRESS, progress);
+ data.putInt(ApgIntentServiceHandler.DATA_PROGRESS_MAX, max);
+
+ sendMessageToHandler(ApgIntentServiceHandler.MESSAGE_UPDATE_PROGRESS, null, data);
+ }
+
+ public void setProgress(int resourceId, int progress, int max) {
+ setProgress(getString(resourceId), progress, max);
+ }
+
+ public void setProgress(int progress, int max) {
+ setProgress(null, progress, max);
+ }
+}
diff --git a/org_apg/src/org/thialfihar/android/apg/service/ApgServiceHandler.java b/org_apg/src/org/thialfihar/android/apg/service/ApgIntentServiceHandler.java
index 91b7d4451..8494cf035 100644
--- a/org_apg/src/org/thialfihar/android/apg/service/ApgServiceHandler.java
+++ b/org_apg/src/org/thialfihar/android/apg/service/ApgIntentServiceHandler.java
@@ -26,7 +26,7 @@ import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
-public class ApgServiceHandler extends Handler {
+public class ApgIntentServiceHandler extends Handler {
// possible messages send from this service to handler on ui
public static final int MESSAGE_OKAY = 1;
@@ -43,16 +43,16 @@ public class ApgServiceHandler extends Handler {
Activity mActivity;
ProgressDialogFragment mProgressDialogFragment;
- public ApgServiceHandler(Activity activity) {
+ public ApgIntentServiceHandler(Activity activity) {
this.mActivity = activity;
}
- public ApgServiceHandler(Activity activity, ProgressDialogFragment progressDialogFragment) {
+ public ApgIntentServiceHandler(Activity activity, ProgressDialogFragment progressDialogFragment) {
this.mActivity = activity;
this.mProgressDialogFragment = progressDialogFragment;
}
- public ApgServiceHandler(Activity activity, int progressDialogMessageId, int progressDialogStyle) {
+ public ApgIntentServiceHandler(Activity activity, int progressDialogMessageId, int progressDialogStyle) {
this.mActivity = activity;
this.mProgressDialogFragment = ProgressDialogFragment.newInstance(progressDialogMessageId,
progressDialogStyle);
diff --git a/org_apg/src/org/thialfihar/android/apg/service/ApgRemoteService.java b/org_apg/src/org/thialfihar/android/apg/service/ApgRemoteService.java
deleted file mode 100644
index 1cfdf4864..000000000
--- a/org_apg/src/org/thialfihar/android/apg/service/ApgRemoteService.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.thialfihar.android.apg.service;
-
-public class ApgRemoteService {
-
-}
diff --git a/org_apg/src/org/thialfihar/android/apg/service/ApgService.java b/org_apg/src/org/thialfihar/android/apg/service/ApgService.java
index 547e1ee6a..1404e441d 100644
--- a/org_apg/src/org/thialfihar/android/apg/service/ApgService.java
+++ b/org_apg/src/org/thialfihar/android/apg/service/ApgService.java
@@ -1,887 +1,296 @@
-/*
- * Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
package org.thialfihar.android.apg.service;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Vector;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SignatureException;
-import org.spongycastle.openpgp.PGPPublicKeyRing;
-import org.spongycastle.openpgp.PGPSecretKey;
-import org.spongycastle.openpgp.PGPSecretKeyRing;
+import org.spongycastle.openpgp.PGPException;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.R;
-import org.thialfihar.android.apg.helper.FileHelper;
-import org.thialfihar.android.apg.helper.OtherHelper;
import org.thialfihar.android.apg.helper.PGPMain;
-import org.thialfihar.android.apg.helper.Preferences;
import org.thialfihar.android.apg.helper.PGPMain.ApgGeneralException;
-import org.thialfihar.android.apg.helper.PGPConversionHelper;
-import org.thialfihar.android.apg.provider.ApgContract.DataStream;
-import org.thialfihar.android.apg.provider.ProviderHelper;
-import org.thialfihar.android.apg.util.HkpKeyServer;
import org.thialfihar.android.apg.util.InputData;
-import org.thialfihar.android.apg.util.KeyServer.KeyInfo;
+import org.thialfihar.android.apg.util.Log;
import org.thialfihar.android.apg.util.ProgressDialogUpdater;
-import android.app.IntentService;
+import android.app.Service;
import android.content.Context;
import android.content.Intent;
-import android.net.Uri;
import android.os.Bundle;
-import android.os.Message;
-import android.os.Messenger;
+import android.os.IBinder;
import android.os.RemoteException;
-import org.thialfihar.android.apg.util.Log;
-
/**
- * This Service contains all important long lasting operations for APG. It receives Intents with
- * data from the activities or other apps, queues these intents, executes them, and stops itself
- * after doing them.
+ * TODO:
+ *
+ * - is this service thread safe? Probably not!
+ *
*/
-public class ApgService extends IntentService implements ProgressDialogUpdater {
-
- /* extras that can be given by intent */
- public static final String EXTRA_MESSENGER = "messenger";
- public static final String EXTRA_ACTION = "action";
- public static final String EXTRA_DATA = "data";
-
- /* possible EXTRA_ACTIONs */
- public static final int ACTION_ENCRYPT_SIGN = 10;
-
- public static final int ACTION_DECRYPT_VERIFY = 20;
-
- public static final int ACTION_SAVE_KEYRING = 30;
- public static final int ACTION_GENERATE_KEY = 31;
- public static final int ACTION_GENERATE_DEFAULT_RSA_KEYS = 32;
-
- public static final int ACTION_DELETE_FILE_SECURELY = 40;
-
- public static final int ACTION_IMPORT_KEY = 50;
- public static final int ACTION_EXPORT_KEY = 51;
-
- public static final int ACTION_UPLOAD_KEY = 60;
- public static final int ACTION_QUERY_KEY = 61;
-
- public static final int ACTION_SIGN_KEY = 70;
-
- /* keys for data bundle */
-
- // encrypt, decrypt, import export
- public static final String TARGET = "target";
- // possible targets:
- public static final int TARGET_BYTES = 1;
- public static final int TARGET_FILE = 2;
- public static final int TARGET_STREAM = 3;
-
- // encrypt
- public static final String SECRET_KEY_ID = "secretKeyId";
- public static final String USE_ASCII_AMOR = "useAsciiAmor";
- public static final String ENCRYPTION_KEYS_IDS = "encryptionKeysIds";
- public static final String SIGNATURE_KEY_ID = "signatureKeyId";
- public static final String COMPRESSION_ID = "compressionId";
- public static final String GENERATE_SIGNATURE = "generateSignature";
- public static final String SIGN_ONLY = "signOnly";
- public static final String MESSAGE_BYTES = "messageBytes";
- public static final String INPUT_FILE = "inputFile";
- public static final String OUTPUT_FILE = "outputFile";
- public static final String PROVIDER_URI = "providerUri";
-
- // decrypt/verify
- public static final String SIGNED_ONLY = "signedOnly";
- public static final String RETURN_BYTES = "returnBinary";
- public static final String CIPHERTEXT_BYTES = "ciphertextBytes";
- public static final String ASSUME_SYMMETRIC = "assumeSymmetric";
- public static final String LOOKUP_UNKNOWN_KEY = "lookupUnknownKey";
-
- // edit keys
- public static final String NEW_PASSPHRASE = "newPassphrase";
- public static final String CURRENT_PASSPHRASE = "currentPassphrase";
- public static final String USER_IDS = "userIds";
- public static final String KEYS = "keys";
- public static final String KEYS_USAGES = "keysUsages";
- public static final String MASTER_KEY_ID = "masterKeyId";
-
- // generate key
- public static final String ALGORITHM = "algorithm";
- public static final String KEY_SIZE = "keySize";
- public static final String SYMMETRIC_PASSPHRASE = "passphrase";
- public static final String MASTER_KEY = "masterKey";
-
- // delete file securely
- public static final String DELETE_FILE = "deleteFile";
-
- // import key
- public static final String IMPORT_INPUT_STREAM = "importInputStream";
- public static final String IMPORT_FILENAME = "importFilename";
- public static final String IMPORT_BYTES = "importBytes";
- public static final String IMPORT_KEY_TYPE = "importKeyType";
-
- // export key
- public static final String EXPORT_OUTPUT_STREAM = "exportOutputStream";
- public static final String EXPORT_FILENAME = "exportFilename";
- public static final String EXPORT_KEY_TYPE = "exportKeyType";
- public static final String EXPORT_ALL = "exportAll";
- public static final String EXPORT_KEY_RING_ID = "exportKeyRingId";
-
- // upload key
- public static final String UPLOAD_KEY_SERVER = "uploadKeyServer";
- public static final String UPLOAD_KEY_KEYRING_ROW_ID = "uploadKeyRingId";
-
- // query key
- public static final String QUERY_KEY_SERVER = "queryKeyServer";
- public static final String QUERY_KEY_TYPE = "queryKeyType";
- public static final String QUERY_KEY_STRING = "queryKeyString";
- public static final String QUERY_KEY_ID = "queryKeyId";
-
- // sign key
- public static final String SIGN_KEY_MASTER_KEY_ID = "signKeyMasterKeyId";
- public static final String SIGN_KEY_PUB_KEY_ID = "signKeyPubKeyId";
-
- /* possible data keys as result send over messenger */
- // keys
- public static final String RESULT_NEW_KEY = "newKey";
- public static final String RESULT_NEW_KEY2 = "newKey2";
-
- // encrypt
- public static final String RESULT_SIGNATURE_DATA = "signatureData";
- public static final String RESULT_SIGNATURE_TEXT = "signatureText";
- public static final String RESULT_ENCRYPTED_MESSAGE = "encryptedMessage";
- public static final String RESULT_ENCRYPTED_DATA = "encryptedData";
- public static final String RESULT_URI = "resultUri";
-
- // decrypt/verify
- public static final String RESULT_DECRYPTED_MESSAGE = "decryptedMessage";
- public static final String RESULT_DECRYPTED_DATA = "decryptedData";
- public static final String RESULT_SIGNATURE = "signature";
- public static final String RESULT_SIGNATURE_KEY_ID = "signatureKeyId";
- public static final String RESULT_SIGNATURE_USER_ID = "signatureUserId";
-
- public static final String RESULT_SIGNATURE_SUCCESS = "signatureSuccess";
- public static final String RESULT_SIGNATURE_UNKNOWN = "signatureUnknown";
- public static final String RESULT_SIGNATURE_LOOKUP_KEY = "lookupKey";
-
- // 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";
-
- // query
- public static final String RESULT_QUERY_KEY_KEY_DATA = "queryKeyKeyData";
- public static final String RESULT_QUERY_KEY_SEARCH_RESULT = "queryKeySearchResult";
-
- Messenger mMessenger;
-
- public ApgService() {
- super("ApgService");
- }
+public class ApgService extends Service implements ProgressDialogUpdater {
+ Context mContext;
- /**
- * The IntentService calls this method from the default worker thread with the intent that
- * started the service. When this method returns, IntentService stops the service, as
- * appropriate.
- */
@Override
- protected void onHandleIntent(Intent intent) {
- Bundle extras = intent.getExtras();
- if (extras == null) {
- Log.e(Constants.TAG, "Extras bundle is null!");
- return;
- }
-
- if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) || extras
- .containsKey(EXTRA_ACTION))) {
- Log.e(Constants.TAG,
- "Extra bundle must contain a messenger, a data bundle, and an action!");
- return;
- }
-
- mMessenger = (Messenger) extras.get(EXTRA_MESSENGER);
- Bundle data = extras.getBundle(EXTRA_DATA);
-
- OtherHelper.logDebugBundle(data, "EXTRA_DATA");
-
- int action = extras.getInt(EXTRA_ACTION);
-
- // execute action from extra bundle
- switch (action) {
- case ACTION_ENCRYPT_SIGN:
-
- try {
- /* Input */
- int target = data.getInt(TARGET);
-
- long secretKeyId = data.getLong(SECRET_KEY_ID);
- String passphrase = data.getString(SYMMETRIC_PASSPHRASE);
-
- boolean useAsciiArmour = data.getBoolean(USE_ASCII_AMOR);
- long encryptionKeyIds[] = data.getLongArray(ENCRYPTION_KEYS_IDS);
- long signatureKeyId = data.getLong(SIGNATURE_KEY_ID);
- int compressionId = data.getInt(COMPRESSION_ID);
- boolean generateSignature = data.getBoolean(GENERATE_SIGNATURE);
- boolean signOnly = data.getBoolean(SIGN_ONLY);
-
- InputStream inStream = null;
- long inLength = -1;
- InputData inputData = null;
- OutputStream outStream = null;
- String streamFilename = null;
- switch (target) {
- case TARGET_BYTES: /* encrypting bytes directly */
- byte[] bytes = data.getByteArray(MESSAGE_BYTES);
-
- inStream = new ByteArrayInputStream(bytes);
- inLength = bytes.length;
-
- inputData = new InputData(inStream, inLength);
- outStream = new ByteArrayOutputStream();
-
- break;
- case TARGET_FILE: /* encrypting file */
- String inputFile = data.getString(INPUT_FILE);
- String outputFile = data.getString(OUTPUT_FILE);
-
- // check if storage is ready
- if (!FileHelper.isStorageMounted(inputFile)
- || !FileHelper.isStorageMounted(outputFile)) {
- sendErrorToHandler(new ApgGeneralException(
- getString(R.string.error_externalStorageNotReady)));
- return;
- }
-
- inStream = new FileInputStream(inputFile);
- File file = new File(inputFile);
- inLength = file.length();
- inputData = new InputData(inStream, inLength);
-
- outStream = new FileOutputStream(outputFile);
-
- break;
-
- case TARGET_STREAM: /* Encrypting stream from content uri */
- Uri providerUri = (Uri) data.getParcelable(PROVIDER_URI);
-
- // InputStream
- InputStream in = getContentResolver().openInputStream(providerUri);
- inLength = PGPMain.getLengthOfStream(in);
- inputData = new InputData(in, inLength);
-
- // OutputStream
- try {
- while (true) {
- streamFilename = PGPMain.generateRandomString(32);
- if (streamFilename == null) {
- throw new PGPMain.ApgGeneralException(
- "couldn't generate random file name");
- }
- openFileInput(streamFilename).close();
- }
- } catch (FileNotFoundException e) {
- // found a name that isn't used yet
- }
- outStream = openFileOutput(streamFilename, Context.MODE_PRIVATE);
-
- break;
-
- default:
- throw new PGPMain.ApgGeneralException("No target choosen!");
-
- }
-
- /* Operation */
-
- if (generateSignature) {
- Log.d(Constants.TAG, "generating signature...");
- PGPMain.generateSignature(this, inputData, outStream, useAsciiArmour, false,
- secretKeyId, PassphraseCacheService.getCachedPassphrase(this,
- secretKeyId), Preferences.getPreferences(this)
- .getDefaultHashAlgorithm(), Preferences.getPreferences(this)
- .getForceV3Signatures(), this);
- } else if (signOnly) {
- Log.d(Constants.TAG, "sign only...");
- PGPMain.signText(this, inputData, outStream, secretKeyId,
- PassphraseCacheService.getCachedPassphrase(this, secretKeyId),
- Preferences.getPreferences(this).getDefaultHashAlgorithm(), Preferences
- .getPreferences(this).getForceV3Signatures(), this);
- } else {
- Log.d(Constants.TAG, "encrypt...");
- PGPMain.encrypt(this, inputData, outStream, useAsciiArmour, encryptionKeyIds,
- signatureKeyId,
- PassphraseCacheService.getCachedPassphrase(this, signatureKeyId), this,
- Preferences.getPreferences(this).getDefaultEncryptionAlgorithm(),
- Preferences.getPreferences(this).getDefaultHashAlgorithm(),
- compressionId, Preferences.getPreferences(this).getForceV3Signatures(),
- passphrase);
- }
-
- outStream.close();
-
- /* Output */
-
- Bundle resultData = new Bundle();
-
- switch (target) {
- case TARGET_BYTES:
- if (useAsciiArmour) {
- String output = new String(
- ((ByteArrayOutputStream) outStream).toByteArray());
- if (generateSignature) {
- resultData.putString(RESULT_SIGNATURE_TEXT, output);
- } else {
- resultData.putString(RESULT_ENCRYPTED_MESSAGE, output);
- }
- } else {
- byte output[] = ((ByteArrayOutputStream) outStream).toByteArray();
- if (generateSignature) {
- resultData.putByteArray(RESULT_SIGNATURE_DATA, output);
- } else {
- resultData.putByteArray(RESULT_ENCRYPTED_DATA, output);
- }
- }
-
- break;
- case TARGET_FILE:
- // nothing, file was written, just send okay
-
- break;
- case TARGET_STREAM:
- String uri = DataStream.buildDataStreamUri(streamFilename).toString();
- resultData.putString(RESULT_URI, uri);
-
- break;
- }
-
- OtherHelper.logDebugBundle(resultData, "resultData");
-
- sendMessageToHandler(ApgServiceHandler.MESSAGE_OKAY, resultData);
- } catch (Exception e) {
- sendErrorToHandler(e);
- }
-
- break;
-
- case ACTION_DECRYPT_VERIFY:
- try {
- /* Input */
- int target = data.getInt(TARGET);
-
- long secretKeyId = data.getLong(SECRET_KEY_ID);
- byte[] bytes = data.getByteArray(CIPHERTEXT_BYTES);
- boolean signedOnly = data.getBoolean(SIGNED_ONLY);
- boolean returnBytes = data.getBoolean(RETURN_BYTES);
- boolean assumeSymmetricEncryption = data.getBoolean(ASSUME_SYMMETRIC);
-
- boolean lookupUnknownKey = data.getBoolean(LOOKUP_UNKNOWN_KEY);
-
- InputStream inStream = null;
- long inLength = -1;
- InputData inputData = null;
- OutputStream outStream = null;
- String streamFilename = null;
- switch (target) {
- case TARGET_BYTES: /* decrypting bytes directly */
- inStream = new ByteArrayInputStream(bytes);
- inLength = bytes.length;
-
- inputData = new InputData(inStream, inLength);
- outStream = new ByteArrayOutputStream();
-
- break;
-
- case TARGET_FILE: /* decrypting file */
- String inputFile = data.getString(INPUT_FILE);
- String outputFile = data.getString(OUTPUT_FILE);
-
- // check if storage is ready
- if (!FileHelper.isStorageMounted(inputFile)
- || !FileHelper.isStorageMounted(outputFile)) {
- sendErrorToHandler(new ApgGeneralException(
- getString(R.string.error_externalStorageNotReady)));
- return;
- }
-
- // InputStream
- inLength = -1;
- inStream = new FileInputStream(inputFile);
- File file = new File(inputFile);
- inLength = file.length();
- inputData = new InputData(inStream, inLength);
-
- // OutputStream
- outStream = new FileOutputStream(outputFile);
-
- break;
-
- case TARGET_STREAM: /* decrypting stream from content uri */
- Uri providerUri = (Uri) data.getParcelable(PROVIDER_URI);
-
- // InputStream
- InputStream in = getContentResolver().openInputStream(providerUri);
- inLength = PGPMain.getLengthOfStream(in);
- inputData = new InputData(in, inLength);
-
- // OutputStream
- try {
- while (true) {
- streamFilename = PGPMain.generateRandomString(32);
- if (streamFilename == null) {
- throw new PGPMain.ApgGeneralException(
- "couldn't generate random file name");
- }
- openFileInput(streamFilename).close();
- }
- } catch (FileNotFoundException e) {
- // found a name that isn't used yet
- }
- outStream = openFileOutput(streamFilename, Context.MODE_PRIVATE);
-
- break;
-
- default:
- throw new PGPMain.ApgGeneralException("No target choosen!");
-
- }
-
- /* Operation */
-
- Bundle resultData = new Bundle();
-
- // verifyText and decrypt returning additional resultData values for the
- // verification of signatures
- if (signedOnly) {
- resultData = PGPMain.verifyText(this, inputData, outStream, lookupUnknownKey,
- this);
- } else {
- resultData = PGPMain.decrypt(this, inputData, outStream,
- PassphraseCacheService.getCachedPassphrase(this, secretKeyId), this,
- assumeSymmetricEncryption);
- }
+ public void onCreate() {
+ super.onCreate();
+ mContext = this;
+ Log.d(Constants.TAG, "ApgService, onCreate()");
+ }
- outStream.close();
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ Log.d(Constants.TAG, "ApgService, onDestroy()");
+ }
- /* Output */
+ @Override
+ public IBinder onBind(Intent intent) {
+ return mBinder;
+ }
- switch (target) {
- case TARGET_BYTES:
- if (returnBytes) {
- byte output[] = ((ByteArrayOutputStream) outStream).toByteArray();
- resultData.putByteArray(RESULT_DECRYPTED_DATA, output);
- } else {
- String output = new String(
- ((ByteArrayOutputStream) outStream).toByteArray());
- resultData.putString(RESULT_DECRYPTED_MESSAGE, output);
- }
+ void encryptAndSignImplementation(byte[] inputBytes, String inputUri, boolean useAsciiArmor,
+ int compression, long[] encryptionKeyIds, String encryptionPassphrase,
+ int symmetricEncryptionAlgorithm, long signatureKeyId, int signatureHashAlgorithm,
+ boolean signatureForceV3, String signaturePassphrase, IApgEncryptDecryptHandler handler)
+ throws RemoteException {
- break;
- case TARGET_FILE:
- // nothing, file was written, just send okay and verification bundle
+ try {
+ // TODO use inputUri
- break;
- case TARGET_STREAM:
- String uri = DataStream.buildDataStreamUri(streamFilename).toString();
- resultData.putString(RESULT_URI, uri);
+ // build InputData and write into OutputStream
+ InputStream inputStream = new ByteArrayInputStream(inputBytes);
+ long inputLength = inputBytes.length;
+ InputData input = new InputData(inputStream, inputLength);
- break;
- }
+ OutputStream output = new ByteArrayOutputStream();
- OtherHelper.logDebugBundle(resultData, "resultData");
+ PGPMain.encryptAndSign(mContext, ApgService.this, input, output, useAsciiArmor,
+ compression, encryptionKeyIds, encryptionPassphrase,
+ symmetricEncryptionAlgorithm, signatureKeyId, signatureHashAlgorithm,
+ signatureForceV3, signaturePassphrase);
- sendMessageToHandler(ApgServiceHandler.MESSAGE_OKAY, resultData);
- } catch (Exception e) {
- sendErrorToHandler(e);
- }
+ output.close();
- break;
+ byte[] outputBytes = ((ByteArrayOutputStream) output).toByteArray();
- case ACTION_SAVE_KEYRING:
+ // return over handler on client side
+ handler.onSuccessEncrypt(outputBytes, null);
+ } catch (Exception e) {
+ Log.e(Constants.TAG, "ApgService, Exception!", e);
try {
- /* Input */
- String oldPassPhrase = data.getString(CURRENT_PASSPHRASE);
- String newPassPhrase = data.getString(NEW_PASSPHRASE);
- if (newPassPhrase == null) {
- newPassPhrase = oldPassPhrase;
- }
- ArrayList<String> userIds = data.getStringArrayList(USER_IDS);
- ArrayList<PGPSecretKey> keys = PGPConversionHelper.BytesToPGPSecretKeyList(data
- .getByteArray(KEYS));
- ArrayList<Integer> keysUsages = data.getIntegerArrayList(KEYS_USAGES);
- long masterKeyId = data.getLong(MASTER_KEY_ID);
-
- /* Operation */
- PGPMain.buildSecretKey(this, userIds, keys, keysUsages, masterKeyId, oldPassPhrase,
- newPassPhrase, this);
- PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase);
-
- /* Output */
- sendMessageToHandler(ApgServiceHandler.MESSAGE_OKAY);
- } catch (Exception e) {
- sendErrorToHandler(e);
+ handler.onException(getExceptionId(e), e.getMessage());
+ } catch (Exception t) {
+ Log.e(Constants.TAG, "Error returning exception to client", t);
}
+ }
+ }
- break;
+ public void decryptAndVerifyImplementation(byte[] inputBytes, String inputUri,
+ String passphrase, boolean assumeSymmetric, IApgEncryptDecryptHandler handler)
+ throws RemoteException {
- case ACTION_GENERATE_KEY:
+ try {
+ // build InputData and write into OutputStream
+ InputStream inputStream = new ByteArrayInputStream(inputBytes);
+ long inputLength = inputBytes.length;
+ InputData inputData = new InputData(inputStream, inputLength);
- try {
- /* Input */
- int algorithm = data.getInt(ALGORITHM);
- String passphrase = data.getString(SYMMETRIC_PASSPHRASE);
- int keysize = data.getInt(KEY_SIZE);
- PGPSecretKey masterKey = null;
- if (data.containsKey(MASTER_KEY)) {
- masterKey = PGPConversionHelper.BytesToPGPSecretKey(data
- .getByteArray(MASTER_KEY));
- }
+ OutputStream outputStream = new ByteArrayOutputStream();
- /* Operation */
- PGPSecretKeyRing newKeyRing = PGPMain.createKey(this, algorithm, keysize,
- passphrase, masterKey);
+ Bundle outputBundle = PGPMain.decryptAndVerify(mContext, ApgService.this, inputData,
+ outputStream, passphrase, assumeSymmetric);
- /* Output */
- Bundle resultData = new Bundle();
- resultData.putByteArray(RESULT_NEW_KEY,
- PGPConversionHelper.PGPSecretKeyRingToBytes(newKeyRing));
+ outputStream.close();
- OtherHelper.logDebugBundle(resultData, "resultData");
+ byte[] outputBytes = ((ByteArrayOutputStream) outputStream).toByteArray();
- sendMessageToHandler(ApgServiceHandler.MESSAGE_OKAY, resultData);
- } catch (Exception e) {
- sendErrorToHandler(e);
- }
+ // get signature informations from bundle
+ boolean signature = outputBundle.getBoolean(ApgIntentService.RESULT_SIGNATURE);
+ long signatureKeyId = outputBundle.getLong(ApgIntentService.RESULT_SIGNATURE_KEY_ID);
+ String signatureUserId = outputBundle
+ .getString(ApgIntentService.RESULT_SIGNATURE_USER_ID);
+ boolean signatureSuccess = outputBundle
+ .getBoolean(ApgIntentService.RESULT_SIGNATURE_SUCCESS);
+ boolean signatureUnknown = outputBundle
+ .getBoolean(ApgIntentService.RESULT_SIGNATURE_UNKNOWN);
- break;
+ // return over handler on client side
+ handler.onSuccessDecrypt(outputBytes, null, signature, signatureKeyId, signatureUserId,
+ signatureSuccess, signatureUnknown);
+ } catch (Exception e) {
+ Log.e(Constants.TAG, "ApgService, Exception!", e);
- case ACTION_GENERATE_DEFAULT_RSA_KEYS:
- // generate one RSA 2048 key for signing and one subkey for encrypting!
try {
- /* Input */
- String passphrase = data.getString(SYMMETRIC_PASSPHRASE);
-
- /* Operation */
- PGPSecretKeyRing masterKeyRing = PGPMain.createKey(this, Id.choice.algorithm.rsa,
- 2048, passphrase, null);
-
- PGPSecretKeyRing subKeyRing = PGPMain.createKey(this, Id.choice.algorithm.rsa,
- 2048, passphrase, masterKeyRing.getSecretKey());
-
- /* Output */
- Bundle resultData = new Bundle();
- resultData.putByteArray(RESULT_NEW_KEY,
- PGPConversionHelper.PGPSecretKeyRingToBytes(masterKeyRing));
- resultData.putByteArray(RESULT_NEW_KEY2,
- PGPConversionHelper.PGPSecretKeyRingToBytes(subKeyRing));
-
- OtherHelper.logDebugBundle(resultData, "resultData");
-
- sendMessageToHandler(ApgServiceHandler.MESSAGE_OKAY, resultData);
- } catch (Exception e) {
- sendErrorToHandler(e);
+ handler.onException(getExceptionId(e), e.getMessage());
+ } catch (Exception t) {
+ Log.e(Constants.TAG, "Error returning exception to client", t);
}
+ }
+ }
- break;
+ private void getDecryptionKeyImplementation(byte[] inputBytes, String inputUri,
+ IApgHelperHandler handler) {
- case ACTION_DELETE_FILE_SECURELY:
- try {
- /* Input */
- String deleteFile = data.getString(DELETE_FILE);
-
- /* Operation */
- try {
- PGPMain.deleteFileSecurely(this, new File(deleteFile), this);
- } catch (FileNotFoundException e) {
- throw new PGPMain.ApgGeneralException(getString(R.string.error_fileNotFound,
- deleteFile));
- } catch (IOException e) {
- throw new PGPMain.ApgGeneralException(getString(
- R.string.error_fileDeleteFailed, deleteFile));
- }
+ // TODO: implement inputUri
- /* Output */
- sendMessageToHandler(ApgServiceHandler.MESSAGE_OKAY);
- } catch (Exception e) {
- sendErrorToHandler(e);
- }
+ try {
+ InputStream inputStream = new ByteArrayInputStream(inputBytes);
- break;
+ long secretKeyId = Id.key.none;
+ boolean symmetric;
- case ACTION_IMPORT_KEY:
try {
-
- /* Input */
- int target = data.getInt(TARGET);
-
- int keyType = Id.type.public_key;
- if (data.containsKey(IMPORT_KEY_TYPE)) {
- keyType = data.getInt(IMPORT_KEY_TYPE);
+ secretKeyId = PGPMain.getDecryptionKeyId(ApgService.this, inputStream);
+ if (secretKeyId == Id.key.none) {
+ throw new PGPMain.ApgGeneralException(
+ getString(R.string.error_noSecretKeyFound));
}
-
- /* Operation */
- InputStream inStream = null;
- long inLength = -1;
- InputData inputData = null;
- switch (target) {
- case TARGET_BYTES: /* import key from bytes directly */
- byte[] bytes = data.getByteArray(IMPORT_BYTES);
-
- inStream = new ByteArrayInputStream(bytes);
- inLength = bytes.length;
-
- inputData = new InputData(inStream, inLength);
-
- break;
- case TARGET_FILE: /* import key from file */
- String inputFile = data.getString(IMPORT_FILENAME);
-
- inStream = new FileInputStream(inputFile);
- File file = new File(inputFile);
- inLength = file.length();
- inputData = new InputData(inStream, inLength);
-
- break;
-
- case TARGET_STREAM:
- // TODO: not implemented
- break;
+ symmetric = false;
+ } catch (PGPMain.NoAsymmetricEncryptionException e) {
+ secretKeyId = Id.key.symmetric;
+ if (!PGPMain.hasSymmetricEncryption(ApgService.this, inputStream)) {
+ throw new PGPMain.ApgGeneralException(
+ getString(R.string.error_noKnownEncryptionFound));
}
-
- Bundle resultData = new Bundle();
- resultData = PGPMain.importKeyRings(this, keyType, inputData, this);
-
- sendMessageToHandler(ApgServiceHandler.MESSAGE_OKAY, resultData);
- } catch (Exception e) {
- sendErrorToHandler(e);
+ symmetric = true;
}
- break;
-
- case ACTION_EXPORT_KEY:
- try {
-
- /* Input */
- int keyType = Id.type.public_key;
- if (data.containsKey(EXPORT_KEY_TYPE)) {
- keyType = data.getInt(EXPORT_KEY_TYPE);
- }
-
- String outputFile = data.getString(EXPORT_FILENAME);
-
- boolean exportAll = data.getBoolean(EXPORT_ALL);
- int keyRingId = -1;
- if (!exportAll) {
- keyRingId = data.getInt(EXPORT_KEY_RING_ID);
- }
-
- /* Operation */
+ handler.onSuccessGetDecryptionKey(secretKeyId, symmetric);
- // check if storage is ready
- if (!FileHelper.isStorageMounted(outputFile)) {
- sendErrorToHandler(new ApgGeneralException(
- getString(R.string.error_externalStorageNotReady)));
- return;
- }
-
- // OutputStream
- FileOutputStream outStream = new FileOutputStream(outputFile);
-
- Vector<Integer> keyRingIds = new Vector<Integer>();
- if (exportAll) {
- if (keyType == Id.type.public_key) {
- keyRingIds = ProviderHelper.getPublicKeyRingsRowIds(this);
- } else {
- keyRingIds = ProviderHelper.getSecretKeyRingsRowIds(this);
- }
- } else {
- keyRingIds.add(keyRingId);
- }
-
- Bundle resultData = new Bundle();
- resultData = PGPMain.exportKeyRings(this, keyRingIds, outStream, this);
+ } catch (Exception e) {
+ Log.e(Constants.TAG, "ApgService, Exception!", e);
- sendMessageToHandler(ApgServiceHandler.MESSAGE_OKAY, resultData);
- } catch (Exception e) {
- sendErrorToHandler(e);
- }
-
- break;
-
- case ACTION_UPLOAD_KEY:
try {
-
- /* Input */
- int keyRingRowId = data.getInt(UPLOAD_KEY_KEYRING_ROW_ID);
- String keyServer = data.getString(UPLOAD_KEY_SERVER);
-
- /* Operation */
- HkpKeyServer server = new HkpKeyServer(keyServer);
-
- PGPPublicKeyRing keyring = ProviderHelper.getPGPPublicKeyRing(this, keyRingRowId);
- if (keyring != null) {
- boolean uploaded = PGPMain.uploadKeyRingToServer(server,
- (PGPPublicKeyRing) keyring);
- if (!uploaded) {
- sendErrorToHandler(new ApgGeneralException(
- "Unable to export key to selected server"));
- return;
- }
- }
-
- sendMessageToHandler(ApgServiceHandler.MESSAGE_OKAY);
- } catch (Exception e) {
- sendErrorToHandler(e);
+ handler.onException(getExceptionId(e), e.getMessage());
+ } catch (Exception t) {
+ Log.e(Constants.TAG, "Error returning exception to client", t);
}
+ }
+ }
- break;
-
- case ACTION_QUERY_KEY:
- try {
-
- /* Input */
- int queryType = data.getInt(QUERY_KEY_TYPE);
- String keyServer = data.getString(QUERY_KEY_SERVER);
-
- String queryString = data.getString(QUERY_KEY_STRING);
- long keyId = data.getLong(QUERY_KEY_ID);
-
- /* Operation */
- Bundle resultData = new Bundle();
-
- HkpKeyServer server = new HkpKeyServer(keyServer);
- if (queryType == Id.keyserver.search) {
- ArrayList<KeyInfo> searchResult = server.search(queryString);
-
- resultData.putParcelableArrayList(RESULT_QUERY_KEY_SEARCH_RESULT, searchResult);
- } else if (queryType == Id.keyserver.get) {
- String keyData = server.get(keyId);
-
- resultData.putString(RESULT_QUERY_KEY_KEY_DATA, keyData);
- }
+ /**
+ * This is the implementation of the interface IApgService. All methods are oneway, meaning
+ * asynchronous and return to the client using IApgHandler.
+ *
+ * The real PGP code is located in PGPMain.
+ */
+ private final IApgService.Stub mBinder = new IApgService.Stub() {
- sendMessageToHandler(ApgServiceHandler.MESSAGE_OKAY, resultData);
- } catch (Exception e) {
- sendErrorToHandler(e);
- }
+ @Override
+ public void encryptAsymmetric(byte[] inputBytes, String inputUri, boolean useAsciiArmor,
+ int compression, long[] encryptionKeyIds, int symmetricEncryptionAlgorithm,
+ IApgEncryptDecryptHandler handler) throws RemoteException {
- break;
+ encryptAndSignImplementation(inputBytes, inputUri, useAsciiArmor, compression,
+ encryptionKeyIds, null, symmetricEncryptionAlgorithm, Id.key.none, 0, false,
+ null, handler);
+ }
- case ACTION_SIGN_KEY:
- try {
+ @Override
+ public void encryptSymmetric(byte[] inputBytes, String inputUri, boolean useAsciiArmor,
+ int compression, String encryptionPassphrase, int symmetricEncryptionAlgorithm,
+ IApgEncryptDecryptHandler handler) throws RemoteException {
- /* Input */
- long masterKeyId = data.getLong(SIGN_KEY_MASTER_KEY_ID);
- long pubKeyId = data.getLong(SIGN_KEY_PUB_KEY_ID);
+ encryptAndSignImplementation(inputBytes, inputUri, useAsciiArmor, compression, null,
+ encryptionPassphrase, symmetricEncryptionAlgorithm, Id.key.none, 0, false,
+ null, handler);
+ }
- /* Operation */
- String signaturePassPhrase = PassphraseCacheService.getCachedPassphrase(this,
- masterKeyId);
+ @Override
+ public void encryptAndSignAsymmetric(byte[] inputBytes, String inputUri,
+ boolean useAsciiArmor, int compression, long[] encryptionKeyIds,
+ int symmetricEncryptionAlgorithm, long signatureKeyId, int signatureHashAlgorithm,
+ boolean signatureForceV3, String signaturePassphrase,
+ IApgEncryptDecryptHandler handler) throws RemoteException {
- PGPPublicKeyRing signedPubKeyRing = PGPMain.signKey(this, masterKeyId, pubKeyId,
- signaturePassPhrase);
+ encryptAndSignImplementation(inputBytes, inputUri, useAsciiArmor, compression,
+ encryptionKeyIds, null, symmetricEncryptionAlgorithm, signatureKeyId,
+ signatureHashAlgorithm, signatureForceV3, signaturePassphrase, handler);
+ }
- // store the signed key in our local cache
- int retval = PGPMain.storeKeyRingInCache(this, signedPubKeyRing);
- if (retval != Id.return_value.ok && retval != Id.return_value.updated) {
- throw new ApgGeneralException("Failed to store signed key in local cache");
- }
+ @Override
+ public void encryptAndSignSymmetric(byte[] inputBytes, String inputUri,
+ boolean useAsciiArmor, int compression, String encryptionPassphrase,
+ int symmetricEncryptionAlgorithm, long signatureKeyId, int signatureHashAlgorithm,
+ boolean signatureForceV3, String signaturePassphrase,
+ IApgEncryptDecryptHandler handler) throws RemoteException {
- sendMessageToHandler(ApgServiceHandler.MESSAGE_OKAY);
- } catch (Exception e) {
- sendErrorToHandler(e);
- }
+ encryptAndSignImplementation(inputBytes, inputUri, useAsciiArmor, compression, null,
+ encryptionPassphrase, symmetricEncryptionAlgorithm, signatureKeyId,
+ signatureHashAlgorithm, signatureForceV3, signaturePassphrase, handler);
+ }
- break;
+ @Override
+ public void decryptAndVerifyAsymmetric(byte[] inputBytes, String inputUri,
+ String keyPassphrase, IApgEncryptDecryptHandler handler) throws RemoteException {
- default:
- break;
+ decryptAndVerifyImplementation(inputBytes, inputUri, keyPassphrase, false, handler);
}
- }
+ @Override
+ public void decryptAndVerifySymmetric(byte[] inputBytes, String inputUri,
+ String encryptionPassphrase, IApgEncryptDecryptHandler handler)
+ throws RemoteException {
- private void sendErrorToHandler(Exception e) {
- Log.e(Constants.TAG, "ApgService Exception: ", e);
- e.printStackTrace();
+ decryptAndVerifyImplementation(inputBytes, inputUri, encryptionPassphrase, true,
+ handler);
+ }
- Bundle data = new Bundle();
- data.putString(ApgServiceHandler.DATA_ERROR, e.getMessage());
- sendMessageToHandler(ApgServiceHandler.MESSAGE_EXCEPTION, null, data);
- }
+ @Override
+ public void getDecryptionKey(byte[] inputBytes, String inputUri, IApgHelperHandler handler)
+ throws RemoteException {
- private void sendMessageToHandler(Integer arg1, Integer arg2, Bundle data) {
- Message msg = Message.obtain();
- msg.arg1 = arg1;
- if (arg2 != null) {
- msg.arg2 = arg2;
- }
- if (data != null) {
- msg.setData(data);
+ getDecryptionKeyImplementation(inputBytes, inputUri, handler);
}
- try {
- mMessenger.send(msg);
- } catch (RemoteException e) {
- Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
- } catch (NullPointerException e) {
- Log.w(Constants.TAG, "Messenger is null!", e);
+ };
+
+ /**
+ * As we can not throw an exception through Android RPC, we assign identifiers to the exception
+ * types.
+ *
+ * @param e
+ * @return
+ */
+ private int getExceptionId(Exception e) {
+ if (e instanceof NoSuchProviderException) {
+ return 0;
+ } else if (e instanceof NoSuchAlgorithmException) {
+ return 1;
+ } else if (e instanceof SignatureException) {
+ return 2;
+ } else if (e instanceof IOException) {
+ return 3;
+ } else if (e instanceof ApgGeneralException) {
+ return 4;
+ } else if (e instanceof PGPException) {
+ return 5;
+ } else {
+ return -1;
}
}
- private void sendMessageToHandler(Integer arg1, Bundle data) {
- sendMessageToHandler(arg1, null, data);
- }
+ @Override
+ public void setProgress(String message, int current, int total) {
+ // TODO Auto-generated method stub
- private void sendMessageToHandler(Integer arg1) {
- sendMessageToHandler(arg1, null, null);
}
- /**
- * Set progress of ProgressDialog by sending message to handler on UI thread
- */
- public void setProgress(String message, int progress, int max) {
- Log.d(Constants.TAG, "Send message by setProgress with progress=" + progress + ", max="
- + max);
-
- Bundle data = new Bundle();
- if (message != null) {
- data.putString(ApgServiceHandler.DATA_MESSAGE, message);
- }
- data.putInt(ApgServiceHandler.DATA_PROGRESS, progress);
- data.putInt(ApgServiceHandler.DATA_PROGRESS_MAX, max);
+ @Override
+ public void setProgress(int resourceId, int current, int total) {
+ // TODO Auto-generated method stub
- sendMessageToHandler(ApgServiceHandler.MESSAGE_UPDATE_PROGRESS, null, data);
}
- public void setProgress(int resourceId, int progress, int max) {
- setProgress(getString(resourceId), progress, max);
- }
+ @Override
+ public void setProgress(int current, int total) {
+ // TODO Auto-generated method stub
- public void setProgress(int progress, int max) {
- setProgress(null, progress, max);
}
}
diff --git a/org_apg/src/org/thialfihar/android/apg/service/IApgEncryptDecryptHandler.aidl b/org_apg/src/org/thialfihar/android/apg/service/IApgEncryptDecryptHandler.aidl
new file mode 100644
index 000000000..ff6b7254c
--- /dev/null
+++ b/org_apg/src/org/thialfihar/android/apg/service/IApgEncryptDecryptHandler.aidl
@@ -0,0 +1,16 @@
+package org.thialfihar.android.apg.service;
+
+interface IApgEncryptDecryptHandler {
+ /**
+ * Either output or streamUri is given. One of them is null
+ *
+ */
+ oneway void onSuccessEncrypt(in byte[] outputBytes, in String outputUri);
+
+ oneway void onSuccessDecrypt(in byte[] outputBytes, in String outputUri, in boolean signature,
+ in long signatureKeyId, in String signatureUserId, in boolean signatureSuccess,
+ in boolean signatureUnknown);
+
+
+ oneway void onException(in int exceptionNumber, in String message);
+} \ No newline at end of file
diff --git a/org_apg/src/org/thialfihar/android/apg/service/IApgHelperHandler.aidl b/org_apg/src/org/thialfihar/android/apg/service/IApgHelperHandler.aidl
new file mode 100644
index 000000000..bb405329a
--- /dev/null
+++ b/org_apg/src/org/thialfihar/android/apg/service/IApgHelperHandler.aidl
@@ -0,0 +1,9 @@
+package org.thialfihar.android.apg.service;
+
+interface IApgHelperHandler {
+
+ oneway void onSuccessGetDecryptionKey(in long secretKeyId, in boolean symmetric);
+
+
+ oneway void onException(in int exceptionNumber, in String message);
+} \ No newline at end of file
diff --git a/org_apg/src/org/thialfihar/android/apg/service/IApgService.aidl b/org_apg/src/org/thialfihar/android/apg/service/IApgService.aidl
new file mode 100644
index 000000000..71c6a9e42
--- /dev/null
+++ b/org_apg/src/org/thialfihar/android/apg/service/IApgService.aidl
@@ -0,0 +1,130 @@
+package org.thialfihar.android.apg.service;
+
+import org.thialfihar.android.apg.service.IApgEncryptDecryptHandler;
+import org.thialfihar.android.apg.service.IApgSignVerifyHandler;
+import org.thialfihar.android.apg.service.IApgHelperHandler;
+
+/**
+ * All methods are oneway, which means they are asynchronous and non-blocking.
+ * Results are returned into given Handler, which has to be implemented on client side.
+ */
+interface IApgService {
+
+ /**
+ * Encrypt
+ *
+ * Either inputBytes or inputUri is given, the other should be null.
+ *
+ * @param inputBytes
+ * Byte array you want to encrypt
+ * @param inputUri
+ * Blob in ContentProvider you want to encrypt
+ * @param useAsciiArmor
+ * Convert bytes to ascii armored text to guard against encoding problems
+ * @param compression
+ * Compression: 0x21070001: none, 1: Zip, 2: Zlib, 3: BZip2
+ * @param encryptionKeyIds
+ * Ids of public keys used for encryption
+ * @param symmetricEncryptionAlgorithm
+ * 7: AES-128, 8: AES-192, 9: AES-256, 4: Blowfish, 10: Twofish, 3: CAST5,
+ * 6: DES, 2: Triple DES, 1: IDEA
+ * @param handler
+ * Results are returned to this IApgEncryptDecryptHandler Handler
+ * to onSuccessEncrypt(in byte[] output), after successful encryption
+ */
+ oneway void encryptAsymmetric(in byte[] inputBytes, in String inputUri, in boolean useAsciiArmor,
+ in int compression, in long[] encryptionKeyIds, in int symmetricEncryptionAlgorithm,
+ in IApgEncryptDecryptHandler handler);
+
+ /**
+ * Same as encryptAsymmetric but using a passphrase for symmetric encryption
+ *
+ * @param encryptionPassphrase
+ * Passphrase for direct symmetric encryption using symmetricEncryptionAlgorithm
+ */
+ oneway void encryptSymmetric(in byte[] inputBytes, in String inputUri, in boolean useAsciiArmor,
+ in int compression, in String encryptionPassphrase, in int symmetricEncryptionAlgorithm,
+ in IApgEncryptDecryptHandler handler);
+
+ /**
+ * Encrypt and sign
+ *
+ * Either inputBytes or inputUri is given, the other should be null.
+ *
+ * @param inputBytes
+ * Byte array you want to encrypt
+ * @param inputUri
+ * Blob in ContentProvider you want to encrypt
+ * @param useAsciiArmor
+ * Convert bytes to ascii armored text to guard against encoding problems
+ * @param compression
+ * Compression: 0x21070001: none, 1: Zip, 2: Zlib, 3: BZip2
+ * @param encryptionKeyIds
+ * Ids of public keys used for encryption
+ * @param symmetricEncryptionAlgorithm
+ * 7: AES-128, 8: AES-192, 9: AES-256, 4: Blowfish, 10: Twofish, 3: CAST5,
+ * 6: DES, 2: Triple DES, 1: IDEA
+ * @param signatureKeyId
+ * Key id of key to sign with
+ * @param signatureHashAlgorithm
+ * 1: MD5, 3: RIPEMD-160, 2: SHA-1, 11: SHA-224, 8: SHA-256, 9: SHA-384,
+ * 10: SHA-512
+ * @param signatureForceV3
+ * Force V3 signatures
+ * @param signaturePassphrase
+ * Passphrase to unlock signature key
+ * @param handler
+ * Results are returned to this IApgEncryptDecryptHandler Handler
+ * to onSuccessEncrypt(in byte[] output), after successful encryption and signing
+ */
+ oneway void encryptAndSignAsymmetric(in byte[] inputBytes, in String inputUri,
+ in boolean useAsciiArmor, in int compression, in long[] encryptionKeyIds,
+ in int symmetricEncryptionAlgorithm, in long signatureKeyId, in int signatureHashAlgorithm,
+ in boolean signatureForceV3, in String signaturePassphrase,
+ in IApgEncryptDecryptHandler handler);
+
+ /**
+ * Same as encryptAndSignAsymmetric but using a passphrase for symmetric encryption
+ *
+ * @param encryptionPassphrase
+ * Passphrase for direct symmetric encryption using symmetricEncryptionAlgorithm
+ */
+ oneway void encryptAndSignSymmetric(in byte[] inputBytes, in String inputUri,
+ in boolean useAsciiArmor, in int compression, in String encryptionPassphrase,
+ in int symmetricEncryptionAlgorithm, in long signatureKeyId, in int signatureHashAlgorithm,
+ in boolean signatureForceV3, in String signaturePassphrase,
+ in IApgEncryptDecryptHandler handler);
+
+ /**
+ * Decrypts and verifies given input bytes. If no signature is present this method
+ * will only decrypt.
+ *
+ * @param inputBytes
+ * Byte array you want to decrypt and verify
+ * @param inputUri
+ * Blob in ContentProvider you want to decrypt and verify
+ * @param keyPassphrase
+ * Passphrase to unlock secret key for decryption.
+ * @param handler
+ * Handler where to return results to after successful encryption
+ */
+ oneway void decryptAndVerifyAsymmetric(in byte[] inputBytes, in String inputUri,
+ in String keyPassphrase, in IApgEncryptDecryptHandler handler);
+
+ /**
+ * Same as decryptAndVerifyAsymmetric but for symmetric decryption.
+ *
+ * @param encryptionPassphrase
+ * Passphrase to decrypt
+ */
+ oneway void decryptAndVerifySymmetric(in byte[] inputBytes, in String inputUri,
+ in String encryptionPassphrase, in IApgEncryptDecryptHandler handler);
+
+ /**
+ *
+ */
+ oneway void getDecryptionKey(in byte[] inputBytes, in String inputUri,
+ in IApgHelperHandler handler);
+
+
+} \ No newline at end of file
diff --git a/org_apg/src/org/thialfihar/android/apg/service/IApgSignVerifyHandler.aidl b/org_apg/src/org/thialfihar/android/apg/service/IApgSignVerifyHandler.aidl
new file mode 100644
index 000000000..1375d1548
--- /dev/null
+++ b/org_apg/src/org/thialfihar/android/apg/service/IApgSignVerifyHandler.aidl
@@ -0,0 +1,11 @@
+package org.thialfihar.android.apg.service;
+
+interface IApgSignVerifyHandler {
+ oneway void onSuccessSign(in byte[] outputBytes, in String outputUri);
+
+ oneway void onSuccessVerify(in boolean signature, in long signatureKeyId,
+ in String signatureUserId, in boolean signatureSuccess, in boolean signatureUnknown);
+
+
+ oneway void onException(in int exceptionNumber, in String message);
+} \ No newline at end of file
diff --git a/org_apg/src/org/thialfihar/android/apg/service/PassphraseCacheService.java b/org_apg/src/org/thialfihar/android/apg/service/PassphraseCacheService.java
index 403c4a20d..c2bc48aa7 100644
--- a/org_apg/src/org/thialfihar/android/apg/service/PassphraseCacheService.java
+++ b/org_apg/src/org/thialfihar/android/apg/service/PassphraseCacheService.java
@@ -85,10 +85,10 @@ public class PassphraseCacheService extends Service {
* @return
*/
public static String getCachedPassphrase(Context context, long keyId) {
- // try to get real key id
- long realId = keyId;
- if (realId != Id.key.symmetric) {
- PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingByMasterKeyId(context, keyId);
+ // try to get master key id which is used as an identifier for cached passphrases
+ long masterKeyId = keyId;
+ if (masterKeyId != Id.key.symmetric) {
+ PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingByKeyId(context, keyId);
if (keyRing == null) {
return null;
}
@@ -96,17 +96,17 @@ public class PassphraseCacheService extends Service {
if (masterKey == null) {
return null;
}
- realId = masterKey.getKeyID();
+ masterKeyId = masterKey.getKeyID();
}
// get cached passphrase
- String cachedPassphrase = mPassphraseCache.get(realId);
+ String cachedPassphrase = mPassphraseCache.get(masterKeyId);
if (cachedPassphrase == null) {
return null;
}
// set it again to reset the cache life cycle
Log.d(TAG, "Cache passphrase again when getting it!");
- addCachedPassphrase(context, realId, cachedPassphrase);
+ addCachedPassphrase(context, masterKeyId, cachedPassphrase);
return cachedPassphrase;
}
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java
index 880349760..498dfd93b 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/DecryptActivity.java
@@ -25,8 +25,8 @@ import org.thialfihar.android.apg.helper.OtherHelper;
import org.thialfihar.android.apg.helper.PGPHelper;
import org.thialfihar.android.apg.helper.PGPMain;
import org.thialfihar.android.apg.provider.ProviderHelper;
-import org.thialfihar.android.apg.service.ApgServiceHandler;
-import org.thialfihar.android.apg.service.ApgService;
+import org.thialfihar.android.apg.service.ApgIntentServiceHandler;
+import org.thialfihar.android.apg.service.ApgIntentService;
import org.thialfihar.android.apg.service.PassphraseCacheService;
import org.thialfihar.android.apg.ui.dialog.DeleteFileDialogFragment;
import org.thialfihar.android.apg.ui.dialog.FileDialogFragment;
@@ -115,7 +115,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
private String mOutputFilename = null;
private Uri mContentUri = null;
- private byte[] mData = null;
+ private byte[] mDataBytes = null;
private boolean mReturnBinary = false;
private long mUnknownSignatureKeyId = 0;
@@ -126,14 +126,6 @@ public class DecryptActivity extends SherlockFragmentActivity {
private boolean mLookupUnknownKey = true;
- public void setSecretKeyId(long id) {
- mSecretKeyId = id;
- }
-
- public long getSecretKeyId() {
- return mSecretKeyId;
- }
-
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@@ -334,8 +326,8 @@ public class DecryptActivity extends SherlockFragmentActivity {
if (mSignatureKeyId == 0) {
return;
}
- PGPPublicKeyRing key = ProviderHelper.getPGPPublicKeyRingByMasterKeyId(DecryptActivity.this,
- mSignatureKeyId);
+ PGPPublicKeyRing key = ProviderHelper.getPGPPublicKeyRingByKeyId(
+ DecryptActivity.this, mSignatureKeyId);
if (key != null) {
Intent intent = new Intent(DecryptActivity.this, KeyServerQueryActivity.class);
intent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID);
@@ -367,7 +359,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
if (decryptImmediately
|| (mSource.getCurrentView().getId() == R.id.sourceMessage && (mMessage.getText()
- .length() > 0 || mData != null || mContentUri != null))) {
+ .length() > 0 || mDataBytes != null || mContentUri != null))) {
decryptClicked();
}
}
@@ -388,9 +380,9 @@ public class DecryptActivity extends SherlockFragmentActivity {
Log.d(Constants.TAG, "got extras");
}
- mData = extras.getByteArray(EXTRA_DATA);
+ mDataBytes = extras.getByteArray(EXTRA_DATA);
String textData = null;
- if (mData == null) {
+ if (mDataBytes == null) {
Log.d(Constants.TAG, "EXTRA_DATA was null");
textData = extras.getString(EXTRA_TEXT);
} else {
@@ -456,7 +448,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
mReturnBinary = extras.getBoolean(EXTRA_BINARY, false);
if (mContentUri == null) {
- mData = extras.getByteArray(EXTRA_DATA);
+ mDataBytes = extras.getByteArray(EXTRA_DATA);
String data = extras.getString(EXTRA_TEXT);
if (data != null) {
Matcher matcher = PGPMain.PGP_MESSAGE.matcher(data);
@@ -567,11 +559,9 @@ public class DecryptActivity extends SherlockFragmentActivity {
getDecryptionKeyFromInputStream();
- Log.d(Constants.TAG, "secretKeyId: " + getSecretKeyId());
-
// if we need a symmetric passphrase or a passphrase to use a secret key ask for it
- if (getSecretKeyId() == Id.key.symmetric
- || PassphraseCacheService.getCachedPassphrase(this, getSecretKeyId()) == null) {
+ if (mSecretKeyId == Id.key.symmetric
+ || PassphraseCacheService.getCachedPassphrase(this, mSecretKeyId) == null) {
showPassphraseDialog();
} else {
if (mDecryptTarget == Id.target.file) {
@@ -618,7 +608,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
}
/**
- * TODO: externalize this into ApgService???
+ * TODO: Rework function, remove global variables
*/
private void getDecryptionKeyFromInputStream() {
InputStream inStream = null;
@@ -646,23 +636,24 @@ public class DecryptActivity extends SherlockFragmentActivity {
Toast.LENGTH_SHORT).show();
}
} else {
- if (mData != null) {
- inStream = new ByteArrayInputStream(mData);
+ if (mDataBytes != null) {
+ inStream = new ByteArrayInputStream(mDataBytes);
} else {
inStream = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
}
}
+ // get decryption key for this inStream
try {
try {
- setSecretKeyId(PGPMain.getDecryptionKeyId(this, inStream));
- if (getSecretKeyId() == Id.key.none) {
+ mSecretKeyId = PGPMain.getDecryptionKeyId(this, inStream);
+ if (mSecretKeyId == Id.key.none) {
throw new PGPMain.ApgGeneralException(
getString(R.string.error_noSecretKeyFound));
}
mAssumeSymmetricEncryption = false;
} catch (PGPMain.NoAsymmetricEncryptionException e) {
- setSecretKeyId(Id.key.symmetric);
+ mSecretKeyId = Id.key.symmetric;
if (!PGPMain.hasSymmetricEncryption(this, inStream)) {
throw new PGPMain.ApgGeneralException(
getString(R.string.error_noKnownEncryptionFound));
@@ -684,7 +675,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
intent.putExtra(EncryptActivity.EXTRA_TEXT, data);
intent.putExtra(EncryptActivity.EXTRA_SUBJECT, "Re: " + mSubject);
intent.putExtra(EncryptActivity.EXTRA_SEND_TO, mReplyTo);
- intent.putExtra(EncryptActivity.EXTRA_SIGNATURE_KEY_ID, getSecretKeyId());
+ intent.putExtra(EncryptActivity.EXTRA_SIGNATURE_KEY_ID, mSecretKeyId);
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, new long[] { mSignatureKeyId });
startActivity(intent);
}
@@ -742,62 +733,62 @@ public class DecryptActivity extends SherlockFragmentActivity {
Log.d(Constants.TAG, "decryptStart");
// Send all information needed to service to decrypt in other thread
- Intent intent = new Intent(this, ApgService.class);
+ Intent intent = new Intent(this, ApgIntentService.class);
// fill values for this action
Bundle data = new Bundle();
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_DECRYPT_VERIFY);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_DECRYPT_VERIFY);
// choose action based on input: decrypt stream, file or bytes
if (mContentUri != null) {
- data.putInt(ApgService.TARGET, ApgService.TARGET_STREAM);
+ data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_STREAM);
- data.putParcelable(ApgService.PROVIDER_URI, mContentUri);
+ data.putParcelable(ApgIntentService.PROVIDER_URI, mContentUri);
} else if (mDecryptTarget == Id.target.file) {
- data.putInt(ApgService.TARGET, ApgService.TARGET_FILE);
+ data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_FILE);
Log.d(Constants.TAG, "mInputFilename=" + mInputFilename + ", mOutputFilename="
+ mOutputFilename);
- data.putString(ApgService.INPUT_FILE, mInputFilename);
- data.putString(ApgService.OUTPUT_FILE, mOutputFilename);
+ data.putString(ApgIntentService.INPUT_FILE, mInputFilename);
+ data.putString(ApgIntentService.OUTPUT_FILE, mOutputFilename);
} else {
- data.putInt(ApgService.TARGET, ApgService.TARGET_BYTES);
+ data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_BYTES);
- if (mData != null) {
- data.putByteArray(ApgService.CIPHERTEXT_BYTES, mData);
+ if (mDataBytes != null) {
+ data.putByteArray(ApgIntentService.CIPHERTEXT_BYTES, mDataBytes);
} else {
String message = mMessage.getText().toString();
- data.putByteArray(ApgService.CIPHERTEXT_BYTES, message.getBytes());
+ data.putByteArray(ApgIntentService.CIPHERTEXT_BYTES, message.getBytes());
}
}
- data.putLong(ApgService.SECRET_KEY_ID, getSecretKeyId());
+ data.putLong(ApgIntentService.SECRET_KEY_ID, mSecretKeyId);
- data.putBoolean(ApgService.SIGNED_ONLY, mSignedOnly);
- data.putBoolean(ApgService.LOOKUP_UNKNOWN_KEY, mLookupUnknownKey);
- data.putBoolean(ApgService.RETURN_BYTES, mReturnBinary);
- data.putBoolean(ApgService.ASSUME_SYMMETRIC, mAssumeSymmetricEncryption);
+ data.putBoolean(ApgIntentService.SIGNED_ONLY, mSignedOnly);
+ data.putBoolean(ApgIntentService.LOOKUP_UNKNOWN_KEY, mLookupUnknownKey);
+ data.putBoolean(ApgIntentService.RETURN_BYTES, mReturnBinary);
+ data.putBoolean(ApgIntentService.ASSUME_SYMMETRIC, mAssumeSymmetricEncryption);
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
// Message is received after encrypting is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(this, R.string.progress_decrypting,
- ProgressDialog.STYLE_HORIZONTAL) {
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this,
+ R.string.progress_decrypting, ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
// get returned data bundle
Bundle returnData = message.getData();
// if key is unknown show lookup dialog
- if (returnData.getBoolean(ApgService.RESULT_SIGNATURE_LOOKUP_KEY)
+ if (returnData.getBoolean(ApgIntentService.RESULT_SIGNATURE_LOOKUP_KEY)
&& mLookupUnknownKey) {
mUnknownSignatureKeyId = returnData
- .getLong(ApgService.RESULT_SIGNATURE_KEY_ID);
+ .getLong(ApgIntentService.RESULT_SIGNATURE_KEY_ID);
lookupUnknownKey(mUnknownSignatureKeyId);
return;
}
@@ -822,7 +813,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
switch (mDecryptTarget) {
case Id.target.message:
String decryptedMessage = returnData
- .getString(ApgService.RESULT_DECRYPTED_MESSAGE);
+ .getString(ApgIntentService.RESULT_DECRYPTED_STRING);
mMessage.setText(decryptedMessage);
mMessage.setHorizontallyScrolling(false);
mReplyEnabled = false;
@@ -846,9 +837,11 @@ public class DecryptActivity extends SherlockFragmentActivity {
}
- if (returnData.getBoolean(ApgService.RESULT_SIGNATURE)) {
- String userId = returnData.getString(ApgService.RESULT_SIGNATURE_USER_ID);
- mSignatureKeyId = returnData.getLong(ApgService.RESULT_SIGNATURE_KEY_ID);
+ if (returnData.getBoolean(ApgIntentService.RESULT_SIGNATURE)) {
+ String userId = returnData
+ .getString(ApgIntentService.RESULT_SIGNATURE_USER_ID);
+ mSignatureKeyId = returnData
+ .getLong(ApgIntentService.RESULT_SIGNATURE_KEY_ID);
mUserIdRest
.setText("id: " + PGPHelper.getSmallFingerPrint(mSignatureKeyId));
if (userId == null) {
@@ -861,9 +854,9 @@ public class DecryptActivity extends SherlockFragmentActivity {
}
mUserId.setText(userId);
- if (returnData.getBoolean(ApgService.RESULT_SIGNATURE_SUCCESS)) {
+ if (returnData.getBoolean(ApgIntentService.RESULT_SIGNATURE_SUCCESS)) {
mSignatureStatusImage.setImageResource(R.drawable.overlay_ok);
- } else if (returnData.getBoolean(ApgService.RESULT_SIGNATURE_UNKNOWN)) {
+ } else if (returnData.getBoolean(ApgIntentService.RESULT_SIGNATURE_UNKNOWN)) {
mSignatureStatusImage.setImageResource(R.drawable.overlay_error);
Toast.makeText(DecryptActivity.this,
R.string.unknownSignatureKeyTouchToLookUp, Toast.LENGTH_LONG)
@@ -879,7 +872,7 @@ public class DecryptActivity extends SherlockFragmentActivity {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(this);
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/EditKeyActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/EditKeyActivity.java
index f781f1ac1..96bd0ea5e 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/EditKeyActivity.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/EditKeyActivity.java
@@ -26,8 +26,8 @@ import org.thialfihar.android.apg.helper.PGPHelper;
import org.thialfihar.android.apg.helper.PGPMain;
import org.thialfihar.android.apg.helper.PGPConversionHelper;
import org.thialfihar.android.apg.provider.ProviderHelper;
-import org.thialfihar.android.apg.service.ApgServiceHandler;
-import org.thialfihar.android.apg.service.ApgService;
+import org.thialfihar.android.apg.service.ApgIntentServiceHandler;
+import org.thialfihar.android.apg.service.ApgIntentService;
import org.thialfihar.android.apg.ui.dialog.SetPassphraseDialogFragment;
import org.thialfihar.android.apg.ui.widget.KeyEditor;
import org.thialfihar.android.apg.ui.widget.SectionView;
@@ -224,32 +224,32 @@ public class EditKeyActivity extends SherlockFragmentActivity {
mBuildLayout = false;
// Send all information needed to service generate keys in other thread
- Intent serviceIntent = new Intent(this, ApgService.class);
- serviceIntent.putExtra(ApgService.EXTRA_ACTION,
- ApgService.ACTION_GENERATE_DEFAULT_RSA_KEYS);
+ Intent serviceIntent = new Intent(this, ApgIntentService.class);
+ serviceIntent.putExtra(ApgIntentService.EXTRA_ACTION,
+ ApgIntentService.ACTION_GENERATE_DEFAULT_RSA_KEYS);
// fill values for this action
Bundle data = new Bundle();
- data.putString(ApgService.SYMMETRIC_PASSPHRASE, mCurrentPassPhrase);
+ data.putString(ApgIntentService.SYMMETRIC_PASSPHRASE, mCurrentPassPhrase);
- serviceIntent.putExtra(ApgService.EXTRA_DATA, data);
+ serviceIntent.putExtra(ApgIntentService.EXTRA_DATA, data);
// Message is received after generating is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(this,
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this,
R.string.progress_generating, ProgressDialog.STYLE_SPINNER) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
// get new key from data bundle returned from service
Bundle data = message.getData();
PGPSecretKeyRing masterKeyRing = (PGPSecretKeyRing) PGPConversionHelper
.BytesToPGPKeyRing(data
- .getByteArray(ApgService.RESULT_NEW_KEY));
+ .getByteArray(ApgIntentService.RESULT_NEW_KEY));
PGPSecretKeyRing subKeyRing = (PGPSecretKeyRing) PGPConversionHelper
.BytesToPGPKeyRing(data
- .getByteArray(ApgService.RESULT_NEW_KEY2));
+ .getByteArray(ApgIntentService.RESULT_NEW_KEY2));
// add master key
@SuppressWarnings("unchecked")
@@ -271,7 +271,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- serviceIntent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ serviceIntent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
saveHandler.showProgressDialog(this);
@@ -412,30 +412,30 @@ public class EditKeyActivity extends SherlockFragmentActivity {
}
// Send all information needed to service to edit key in other thread
- Intent intent = new Intent(this, ApgService.class);
+ Intent intent = new Intent(this, ApgIntentService.class);
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_SAVE_KEYRING);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_SAVE_KEYRING);
// fill values for this action
Bundle data = new Bundle();
- data.putString(ApgService.CURRENT_PASSPHRASE, mCurrentPassPhrase);
- data.putString(ApgService.NEW_PASSPHRASE, mNewPassPhrase);
- data.putStringArrayList(ApgService.USER_IDS, getUserIds(mUserIdsView));
+ data.putString(ApgIntentService.CURRENT_PASSPHRASE, mCurrentPassPhrase);
+ data.putString(ApgIntentService.NEW_PASSPHRASE, mNewPassPhrase);
+ data.putStringArrayList(ApgIntentService.USER_IDS, getUserIds(mUserIdsView));
ArrayList<PGPSecretKey> keys = getKeys(mKeysView);
- data.putByteArray(ApgService.KEYS, PGPConversionHelper.PGPSecretKeyListToBytes(keys));
- data.putIntegerArrayList(ApgService.KEYS_USAGES, getKeysUsages(mKeysView));
- data.putLong(ApgService.MASTER_KEY_ID, getMasterKeyId());
+ data.putByteArray(ApgIntentService.KEYS, PGPConversionHelper.PGPSecretKeyListToBytes(keys));
+ data.putIntegerArrayList(ApgIntentService.KEYS_USAGES, getKeysUsages(mKeysView));
+ data.putLong(ApgIntentService.MASTER_KEY_ID, getMasterKeyId());
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
// Message is received after saving is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(this, R.string.progress_saving,
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this, R.string.progress_saving,
ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
finish();
}
};
@@ -443,7 +443,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
saveHandler.showProgressDialog(this);
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java
index 65610f688..29b1ab86a 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/EncryptActivity.java
@@ -29,8 +29,8 @@ import org.thialfihar.android.apg.helper.PGPHelper;
import org.thialfihar.android.apg.helper.PGPMain;
import org.thialfihar.android.apg.helper.Preferences;
import org.thialfihar.android.apg.provider.ProviderHelper;
-import org.thialfihar.android.apg.service.ApgServiceHandler;
-import org.thialfihar.android.apg.service.ApgService;
+import org.thialfihar.android.apg.service.ApgIntentServiceHandler;
+import org.thialfihar.android.apg.service.ApgIntentService;
import org.thialfihar.android.apg.service.PassphraseCacheService;
import org.thialfihar.android.apg.ui.dialog.DeleteFileDialogFragment;
import org.thialfihar.android.apg.ui.dialog.FileDialogFragment;
@@ -768,14 +768,13 @@ public class EncryptActivity extends SherlockFragmentActivity {
private void encryptStart() {
// Send all information needed to service to edit key in other thread
- Intent intent = new Intent(this, ApgService.class);
+ Intent intent = new Intent(this, ApgIntentService.class);
// fill values for this action
Bundle data = new Bundle();
- boolean useAsciiArmour = true;
+ boolean useAsciiArmor = true;
long encryptionKeyIds[] = null;
- long signatureKeyId = Id.key.none;
int compressionId = 0;
boolean signOnly = false;
@@ -786,78 +785,76 @@ public class EncryptActivity extends SherlockFragmentActivity {
passPhrase = null;
}
- data.putString(ApgService.SYMMETRIC_PASSPHRASE, passPhrase);
+ data.putString(ApgIntentService.SYMMETRIC_PASSPHRASE, passPhrase);
} else {
encryptionKeyIds = mEncryptionKeyIds;
- signatureKeyId = getSecretKeyId();
signOnly = (mEncryptionKeyIds == null || mEncryptionKeyIds.length == 0);
}
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_ENCRYPT_SIGN);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_ENCRYPT_SIGN);
// choose default settings, target and data bundle by target
if (mContentUri != null) {
- data.putInt(ApgService.TARGET, ApgService.TARGET_STREAM);
- data.putParcelable(ApgService.PROVIDER_URI, mContentUri);
+ data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_STREAM);
+ data.putParcelable(ApgIntentService.PROVIDER_URI, mContentUri);
} else if (mEncryptTarget == Id.target.file) {
- useAsciiArmour = mAsciiArmour.isChecked();
+ useAsciiArmor = mAsciiArmour.isChecked();
compressionId = ((Choice) mFileCompression.getSelectedItem()).getId();
- data.putInt(ApgService.TARGET, ApgService.TARGET_FILE);
+ data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_FILE);
Log.d(Constants.TAG, "mInputFilename=" + mInputFilename + ", mOutputFilename="
+ mOutputFilename);
- data.putString(ApgService.INPUT_FILE, mInputFilename);
- data.putString(ApgService.OUTPUT_FILE, mOutputFilename);
+ data.putString(ApgIntentService.INPUT_FILE, mInputFilename);
+ data.putString(ApgIntentService.OUTPUT_FILE, mOutputFilename);
} else {
- useAsciiArmour = true;
+ useAsciiArmor = true;
compressionId = Preferences.getPreferences(this).getDefaultMessageCompression();
- data.putInt(ApgService.TARGET, ApgService.TARGET_BYTES);
+ data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_BYTES);
if (mData != null) {
- data.putByteArray(ApgService.MESSAGE_BYTES, mData);
+ data.putByteArray(ApgIntentService.MESSAGE_BYTES, mData);
} else {
String message = mMessage.getText().toString();
if (signOnly && !mReturnResult) {
fixBadCharactersForGmail(message);
}
- data.putByteArray(ApgService.MESSAGE_BYTES, message.getBytes());
+ data.putByteArray(ApgIntentService.MESSAGE_BYTES, message.getBytes());
}
}
if (mOverrideAsciiArmour) {
- useAsciiArmour = mAsciiArmourDemand;
+ useAsciiArmor = mAsciiArmourDemand;
}
- data.putLong(ApgService.SECRET_KEY_ID, getSecretKeyId());
- data.putBoolean(ApgService.USE_ASCII_AMOR, useAsciiArmour);
- data.putLongArray(ApgService.ENCRYPTION_KEYS_IDS, encryptionKeyIds);
- data.putLong(ApgService.SIGNATURE_KEY_ID, signatureKeyId);
- data.putInt(ApgService.COMPRESSION_ID, compressionId);
- data.putBoolean(ApgService.GENERATE_SIGNATURE, mGenerateSignature);
- data.putBoolean(ApgService.SIGN_ONLY, signOnly);
+ data.putLong(ApgIntentService.SECRET_KEY_ID, getSecretKeyId());
+ data.putBoolean(ApgIntentService.USE_ASCII_AMOR, useAsciiArmor);
+ data.putLongArray(ApgIntentService.ENCRYPTION_KEYS_IDS, encryptionKeyIds);
+ data.putInt(ApgIntentService.COMPRESSION_ID, compressionId);
+ data.putBoolean(ApgIntentService.GENERATE_SIGNATURE, mGenerateSignature);
+ data.putBoolean(ApgIntentService.SIGN_ONLY, signOnly);
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
// Message is received after encrypting is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(this, R.string.progress_encrypting,
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this, R.string.progress_encrypting,
ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
// get returned data bundle
Bundle data = message.getData();
String output;
switch (mEncryptTarget) {
case Id.target.clipboard:
- output = data.getString(ApgService.RESULT_ENCRYPTED_MESSAGE);
+ output = data.getString(ApgIntentService.RESULT_ENCRYPTED_STRING);
Log.d(Constants.TAG, "output: " + output);
Compatibility.copyToClipboard(EncryptActivity.this, output);
Toast.makeText(EncryptActivity.this,
@@ -874,7 +871,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
return;
}
- output = data.getString(ApgService.RESULT_ENCRYPTED_MESSAGE);
+ output = data.getString(ApgIntentService.RESULT_ENCRYPTED_STRING);
Log.d(Constants.TAG, "output: " + output);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
@@ -913,7 +910,7 @@ public class EncryptActivity extends SherlockFragmentActivity {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(this);
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/ImportFromQRCodeActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/ImportFromQRCodeActivity.java
index 4c5952b99..aac1fd15b 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/ImportFromQRCodeActivity.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/ImportFromQRCodeActivity.java
@@ -20,8 +20,8 @@ package org.thialfihar.android.apg.ui;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.helper.OtherHelper;
-import org.thialfihar.android.apg.service.ApgServiceHandler;
-import org.thialfihar.android.apg.service.ApgService;
+import org.thialfihar.android.apg.service.ApgIntentServiceHandler;
+import org.thialfihar.android.apg.service.ApgIntentService;
import org.thialfihar.android.apg.R;
import android.app.AlertDialog;
@@ -157,34 +157,34 @@ public class ImportFromQRCodeActivity extends SherlockFragmentActivity {
if (mScannedContent != null) {
// Send all information needed to service to import key in other thread
- Intent intent = new Intent(this, ApgService.class);
+ Intent intent = new Intent(this, ApgIntentService.class);
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_IMPORT_KEY);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_IMPORT_KEY);
// fill values for this action
Bundle data = new Bundle();
- data.putInt(ApgService.IMPORT_KEY_TYPE, Id.type.public_key);
+ data.putInt(ApgIntentService.IMPORT_KEY_TYPE, Id.type.public_key);
- data.putInt(ApgService.TARGET, ApgService.TARGET_BYTES);
- data.putByteArray(ApgService.IMPORT_BYTES, mScannedContent.getBytes());
+ data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_BYTES);
+ data.putByteArray(ApgIntentService.IMPORT_BYTES, mScannedContent.getBytes());
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
// Message is received after importing is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(this,
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this,
R.string.progress_importing, ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
// get returned data bundle
Bundle returnData = message.getData();
- int added = returnData.getInt(ApgService.RESULT_IMPORT_ADDED);
- int updated = returnData.getInt(ApgService.RESULT_IMPORT_UPDATED);
- int bad = returnData.getInt(ApgService.RESULT_IMPORT_BAD);
+ int added = returnData.getInt(ApgIntentService.RESULT_IMPORT_ADDED);
+ int updated = returnData.getInt(ApgIntentService.RESULT_IMPORT_UPDATED);
+ int bad = returnData.getInt(ApgIntentService.RESULT_IMPORT_BAD);
String toastMessage;
if (added > 0 && updated > 0) {
toastMessage = getString(R.string.keysAddedAndUpdated, added, updated);
@@ -221,7 +221,7 @@ public class ImportFromQRCodeActivity extends SherlockFragmentActivity {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(this);
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java
index 12567a9bd..3adae94a9 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyListActivity.java
@@ -20,8 +20,8 @@ package org.thialfihar.android.apg.ui;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.R;
-import org.thialfihar.android.apg.service.ApgService;
-import org.thialfihar.android.apg.service.ApgServiceHandler;
+import org.thialfihar.android.apg.service.ApgIntentService;
+import org.thialfihar.android.apg.service.ApgIntentServiceHandler;
import org.thialfihar.android.apg.ui.dialog.DeleteFileDialogFragment;
import org.thialfihar.android.apg.ui.dialog.DeleteKeyDialogFragment;
import org.thialfihar.android.apg.ui.dialog.FileDialogFragment;
@@ -302,39 +302,39 @@ public class KeyListActivity extends SherlockFragmentActivity {
Log.d(Constants.TAG, "importKeys started");
// Send all information needed to service to import key in other thread
- Intent intent = new Intent(this, ApgService.class);
+ Intent intent = new Intent(this, ApgIntentService.class);
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_IMPORT_KEY);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_IMPORT_KEY);
// fill values for this action
Bundle data = new Bundle();
- data.putInt(ApgService.IMPORT_KEY_TYPE, mKeyType);
+ data.putInt(ApgIntentService.IMPORT_KEY_TYPE, mKeyType);
if (mImportData != null) {
- data.putInt(ApgService.TARGET, ApgService.TARGET_BYTES);
- data.putByteArray(ApgService.IMPORT_BYTES, mImportData.getBytes());
+ data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_BYTES);
+ data.putByteArray(ApgIntentService.IMPORT_BYTES, mImportData.getBytes());
} else {
- data.putInt(ApgService.TARGET, ApgService.TARGET_FILE);
- data.putString(ApgService.IMPORT_FILENAME, mImportFilename);
+ data.putInt(ApgIntentService.TARGET, ApgIntentService.TARGET_FILE);
+ data.putString(ApgIntentService.IMPORT_FILENAME, mImportFilename);
}
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
// Message is received after importing is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(this, R.string.progress_importing,
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this, R.string.progress_importing,
ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
// get returned data bundle
Bundle returnData = message.getData();
- int added = returnData.getInt(ApgService.RESULT_IMPORT_ADDED);
- int updated = returnData.getInt(ApgService.RESULT_IMPORT_UPDATED);
- int bad = returnData.getInt(ApgService.RESULT_IMPORT_BAD);
+ int added = returnData.getInt(ApgIntentService.RESULT_IMPORT_ADDED);
+ int updated = returnData.getInt(ApgIntentService.RESULT_IMPORT_UPDATED);
+ int bad = returnData.getInt(ApgIntentService.RESULT_IMPORT_BAD);
String toastMessage;
if (added > 0 && updated > 0) {
toastMessage = getString(R.string.keysAddedAndUpdated, added, updated);
@@ -376,7 +376,7 @@ public class KeyListActivity extends SherlockFragmentActivity {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(this);
@@ -395,36 +395,36 @@ public class KeyListActivity extends SherlockFragmentActivity {
Log.d(Constants.TAG, "exportKeys started");
// Send all information needed to service to export key in other thread
- Intent intent = new Intent(this, ApgService.class);
+ Intent intent = new Intent(this, ApgIntentService.class);
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_EXPORT_KEY);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_EXPORT_KEY);
// fill values for this action
Bundle data = new Bundle();
- data.putString(ApgService.EXPORT_FILENAME, mExportFilename);
- data.putInt(ApgService.EXPORT_KEY_TYPE, mKeyType);
+ data.putString(ApgIntentService.EXPORT_FILENAME, mExportFilename);
+ data.putInt(ApgIntentService.EXPORT_KEY_TYPE, mKeyType);
if (keyRingId == -1) {
- data.putBoolean(ApgService.EXPORT_ALL, true);
+ data.putBoolean(ApgIntentService.EXPORT_ALL, true);
} else {
- data.putLong(ApgService.EXPORT_KEY_RING_ID, keyRingId);
+ data.putLong(ApgIntentService.EXPORT_KEY_RING_ID, keyRingId);
}
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
// Message is received after exporting is done in ApgService
- ApgServiceHandler exportHandler = new ApgServiceHandler(this, R.string.progress_exporting,
+ ApgIntentServiceHandler exportHandler = new ApgIntentServiceHandler(this, R.string.progress_exporting,
ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
// get returned data bundle
Bundle returnData = message.getData();
- int exported = returnData.getInt(ApgService.RESULT_EXPORT);
+ int exported = returnData.getInt(ApgIntentService.RESULT_EXPORT);
String toastMessage;
if (exported == 1) {
toastMessage = getString(R.string.keyExported);
@@ -441,7 +441,7 @@ public class KeyListActivity extends SherlockFragmentActivity {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(exportHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
exportHandler.showProgressDialog(this);
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java
index 6bf55a8c1..e1a93602c 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyListPublicFragment.java
@@ -90,7 +90,7 @@ public class KeyListPublicFragment extends KeyListFragment implements
switch (item.getItemId()) {
case Id.menu.update:
long updateKeyId = 0;
- PGPPublicKeyRing updateKeyRing = ProviderHelper.getPGPPublicKeyRing(mKeyListActivity,
+ PGPPublicKeyRing updateKeyRing = ProviderHelper.getPGPPublicKeyRingByRowId(mKeyListActivity,
keyRingRowId);
if (updateKeyRing != null) {
updateKeyId = PGPHelper.getMasterKey(updateKeyRing).getKeyID();
@@ -119,7 +119,7 @@ public class KeyListPublicFragment extends KeyListFragment implements
case Id.menu.signKey:
long keyId = 0;
- PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRing(mKeyListActivity,
+ PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingByRowId(mKeyListActivity,
keyRingRowId);
if (signKeyRing != null) {
keyId = PGPHelper.getMasterKey(signKeyRing).getKeyID();
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyServerQueryActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyServerQueryActivity.java
index 98b6eccf0..7cd54bf32 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/KeyServerQueryActivity.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyServerQueryActivity.java
@@ -25,8 +25,8 @@ import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.helper.PGPHelper;
import org.thialfihar.android.apg.helper.Preferences;
-import org.thialfihar.android.apg.service.ApgServiceHandler;
-import org.thialfihar.android.apg.service.ApgService;
+import org.thialfihar.android.apg.service.ApgIntentServiceHandler;
+import org.thialfihar.android.apg.service.ApgIntentService;
import org.thialfihar.android.apg.util.Log;
import org.thialfihar.android.apg.util.KeyServer.KeyInfo;
@@ -166,42 +166,42 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
Log.d(Constants.TAG, "start search with service");
// Send all information needed to service to query keys in other thread
- Intent intent = new Intent(this, ApgService.class);
+ Intent intent = new Intent(this, ApgIntentService.class);
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_QUERY_KEY);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_QUERY_KEY);
// fill values for this action
Bundle data = new Bundle();
String server = (String) mKeyServer.getSelectedItem();
- data.putString(ApgService.QUERY_KEY_SERVER, server);
+ data.putString(ApgIntentService.QUERY_KEY_SERVER, server);
- data.putInt(ApgService.QUERY_KEY_TYPE, mQueryType);
+ data.putInt(ApgIntentService.QUERY_KEY_TYPE, mQueryType);
if (mQueryType == Id.keyserver.search) {
- data.putString(ApgService.QUERY_KEY_STRING, mQueryString);
+ data.putString(ApgIntentService.QUERY_KEY_STRING, mQueryString);
} else if (mQueryType == Id.keyserver.get) {
- data.putLong(ApgService.QUERY_KEY_ID, mQueryId);
+ data.putLong(ApgIntentService.QUERY_KEY_ID, mQueryId);
}
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
// Message is received after querying is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(this, R.string.progress_querying,
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this, R.string.progress_querying,
ProgressDialog.STYLE_SPINNER) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
// get returned data bundle
Bundle returnData = message.getData();
if (mQueryType == Id.keyserver.search) {
mSearchResult = returnData
- .getParcelableArrayList(ApgService.RESULT_QUERY_KEY_SEARCH_RESULT);
+ .getParcelableArrayList(ApgIntentService.RESULT_QUERY_KEY_SEARCH_RESULT);
} else if (mQueryType == Id.keyserver.get) {
- mKeyData = returnData.getString(ApgService.RESULT_QUERY_KEY_KEY_DATA);
+ mKeyData = returnData.getString(ApgIntentService.RESULT_QUERY_KEY_KEY_DATA);
}
// TODO: IMPROVE CODE!!! some global variables can be avoided!!!
@@ -240,7 +240,7 @@ public class KeyServerQueryActivity extends SherlockFragmentActivity {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(this);
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/KeyServerUploadActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/KeyServerUploadActivity.java
index 8470488a2..db907ed48 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/KeyServerUploadActivity.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/KeyServerUploadActivity.java
@@ -20,8 +20,8 @@ package org.thialfihar.android.apg.ui;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.helper.Preferences;
-import org.thialfihar.android.apg.service.ApgServiceHandler;
-import org.thialfihar.android.apg.service.ApgService;
+import org.thialfihar.android.apg.service.ApgIntentServiceHandler;
+import org.thialfihar.android.apg.service.ApgIntentService;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
@@ -102,29 +102,29 @@ public class KeyServerUploadActivity extends SherlockFragmentActivity {
private void uploadKey() {
// Send all information needed to service to upload key in other thread
- Intent intent = new Intent(this, ApgService.class);
+ Intent intent = new Intent(this, ApgIntentService.class);
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_UPLOAD_KEY);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_UPLOAD_KEY);
// fill values for this action
Bundle data = new Bundle();
int keyRingId = getIntent().getIntExtra(EXTRA_KEYRING_ROW_ID, -1);
- data.putInt(ApgService.UPLOAD_KEY_KEYRING_ROW_ID, keyRingId);
+ data.putInt(ApgIntentService.UPLOAD_KEY_KEYRING_ROW_ID, keyRingId);
String server = (String) keyServer.getSelectedItem();
- data.putString(ApgService.UPLOAD_KEY_SERVER, server);
+ data.putString(ApgIntentService.UPLOAD_KEY_SERVER, server);
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
// Message is received after uploading is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(this, R.string.progress_exporting,
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this, R.string.progress_exporting,
ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
Toast.makeText(KeyServerUploadActivity.this, R.string.keySendSuccess,
Toast.LENGTH_SHORT).show();
@@ -135,7 +135,7 @@ public class KeyServerUploadActivity extends SherlockFragmentActivity {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(this);
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/SignKeyActivity.java b/org_apg/src/org/thialfihar/android/apg/ui/SignKeyActivity.java
index 9c6c1d50f..b970cb3d3 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/SignKeyActivity.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/SignKeyActivity.java
@@ -26,8 +26,8 @@ import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.helper.PGPMain;
import org.thialfihar.android.apg.helper.Preferences;
import org.thialfihar.android.apg.provider.ProviderHelper;
-import org.thialfihar.android.apg.service.ApgService;
-import org.thialfihar.android.apg.service.ApgServiceHandler;
+import org.thialfihar.android.apg.service.ApgIntentService;
+import org.thialfihar.android.apg.service.ApgIntentServiceHandler;
import org.thialfihar.android.apg.service.PassphraseCacheService;
import org.thialfihar.android.apg.ui.dialog.PassphraseDialogFragment;
@@ -196,26 +196,26 @@ public class SignKeyActivity extends SherlockFragmentActivity {
*/
private void startSigning() {
// Send all information needed to service to sign key in other thread
- Intent intent = new Intent(this, ApgService.class);
+ Intent intent = new Intent(this, ApgIntentService.class);
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_SIGN_KEY);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_SIGN_KEY);
// fill values for this action
Bundle data = new Bundle();
- data.putLong(ApgService.SIGN_KEY_MASTER_KEY_ID, mMasterKeyId);
- data.putLong(ApgService.SIGN_KEY_PUB_KEY_ID, mPubKeyId);
+ data.putLong(ApgIntentService.SIGN_KEY_MASTER_KEY_ID, mMasterKeyId);
+ data.putLong(ApgIntentService.SIGN_KEY_PUB_KEY_ID, mPubKeyId);
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
// Message is received after signing is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(this, R.string.progress_signing,
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this, R.string.progress_signing,
ProgressDialog.STYLE_SPINNER) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
Toast.makeText(SignKeyActivity.this, R.string.keySignSuccess,
Toast.LENGTH_SHORT).show();
@@ -236,7 +236,7 @@ public class SignKeyActivity extends SherlockFragmentActivity {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(this);
@@ -247,29 +247,29 @@ public class SignKeyActivity extends SherlockFragmentActivity {
private void uploadKey() {
// Send all information needed to service to upload key in other thread
- Intent intent = new Intent(this, ApgService.class);
+ Intent intent = new Intent(this, ApgIntentService.class);
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_UPLOAD_KEY);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_UPLOAD_KEY);
// fill values for this action
Bundle data = new Bundle();
- data.putLong(ApgService.UPLOAD_KEY_KEYRING_ROW_ID, mPubKeyId);
+ data.putLong(ApgIntentService.UPLOAD_KEY_KEYRING_ROW_ID, mPubKeyId);
Spinner keyServer = (Spinner) findViewById(R.id.keyServer);
String server = (String) keyServer.getSelectedItem();
- data.putString(ApgService.UPLOAD_KEY_SERVER, server);
+ data.putString(ApgIntentService.UPLOAD_KEY_SERVER, server);
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
// Message is received after uploading is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(this, R.string.progress_exporting,
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this, R.string.progress_exporting,
ProgressDialog.STYLE_HORIZONTAL) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
Toast.makeText(SignKeyActivity.this, R.string.keySendSuccess,
Toast.LENGTH_SHORT).show();
@@ -281,7 +281,7 @@ public class SignKeyActivity extends SherlockFragmentActivity {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
saveHandler.showProgressDialog(this);
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/dialog/DeleteFileDialogFragment.java b/org_apg/src/org/thialfihar/android/apg/ui/dialog/DeleteFileDialogFragment.java
index 8d111fc02..311066389 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/dialog/DeleteFileDialogFragment.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/dialog/DeleteFileDialogFragment.java
@@ -17,8 +17,8 @@
package org.thialfihar.android.apg.ui.dialog;
import org.thialfihar.android.apg.R;
-import org.thialfihar.android.apg.service.ApgServiceHandler;
-import org.thialfihar.android.apg.service.ApgService;
+import org.thialfihar.android.apg.service.ApgIntentServiceHandler;
+import org.thialfihar.android.apg.service.ApgIntentService;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -70,25 +70,25 @@ public class DeleteFileDialogFragment extends DialogFragment {
dismiss();
// Send all information needed to service to edit key in other thread
- Intent intent = new Intent(activity, ApgService.class);
+ Intent intent = new Intent(activity, ApgIntentService.class);
// fill values for this action
Bundle data = new Bundle();
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_DELETE_FILE_SECURELY);
- data.putString(ApgService.DELETE_FILE, deleteFile);
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_DELETE_FILE_SECURELY);
+ data.putString(ApgIntentService.DELETE_FILE, deleteFile);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
ProgressDialogFragment deletingDialog = ProgressDialogFragment.newInstance(
R.string.progress_deletingSecurely, ProgressDialog.STYLE_HORIZONTAL);
// Message is received after deleting is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(activity, deletingDialog) {
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(activity, deletingDialog) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
Toast.makeText(activity, R.string.fileDeleteSuccessful,
Toast.LENGTH_SHORT).show();
}
@@ -97,7 +97,7 @@ public class DeleteFileDialogFragment extends DialogFragment {
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
// show progress dialog
deletingDialog.show(activity.getSupportFragmentManager(), "deletingDialog");
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/dialog/DeleteKeyDialogFragment.java b/org_apg/src/org/thialfihar/android/apg/ui/dialog/DeleteKeyDialogFragment.java
index 3e2de6a67..bb5271ce7 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/dialog/DeleteKeyDialogFragment.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/dialog/DeleteKeyDialogFragment.java
@@ -76,11 +76,11 @@ public class DeleteKeyDialogFragment extends DialogFragment {
String userId = activity.getString(R.string.unknownUserId);
if (keyType == Id.type.public_key) {
- PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(activity,
+ PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRingByRowId(activity,
deleteKeyRingRowId);
userId = PGPHelper.getMainUserIdSafe(activity, PGPHelper.getMasterKey(keyRing));
} else {
- PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(activity,
+ PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingByRowId(activity,
deleteKeyRingRowId);
userId = PGPHelper.getMainUserIdSafe(activity, PGPHelper.getMasterKey(keyRing));
}
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/dialog/PassphraseDialogFragment.java b/org_apg/src/org/thialfihar/android/apg/ui/dialog/PassphraseDialogFragment.java
index de2462b39..fb8f4b6d1 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/dialog/PassphraseDialogFragment.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/dialog/PassphraseDialogFragment.java
@@ -104,9 +104,8 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
private static boolean hasPassphrase(Context context, long secretKeyId) {
// check if the key has no passphrase
try {
- // TODO: by master key id???
PGPSecretKey secretKey = PGPHelper.getMasterKey(ProviderHelper
- .getPGPSecretKeyRingByMasterKeyId(context, secretKeyId));
+ .getPGPSecretKeyRingByKeyId(context, secretKeyId));
// PGPSecretKey secretKey =
// PGPHelper.getMasterKey(PGPMain.getSecretKeyRing(secretKeyId));
diff --git a/org_apg/src/org/thialfihar/android/apg/ui/widget/SectionView.java b/org_apg/src/org/thialfihar/android/apg/ui/widget/SectionView.java
index 881aa769e..45fbbaba1 100644
--- a/org_apg/src/org/thialfihar/android/apg/ui/widget/SectionView.java
+++ b/org_apg/src/org/thialfihar/android/apg/ui/widget/SectionView.java
@@ -20,8 +20,8 @@ import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.helper.PGPConversionHelper;
-import org.thialfihar.android.apg.service.ApgServiceHandler;
-import org.thialfihar.android.apg.service.ApgService;
+import org.thialfihar.android.apg.service.ApgIntentServiceHandler;
+import org.thialfihar.android.apg.service.ApgIntentService;
import org.thialfihar.android.apg.service.PassphraseCacheService;
import org.thialfihar.android.apg.ui.dialog.ProgressDialogFragment;
import org.thialfihar.android.apg.ui.widget.Editor.EditorListener;
@@ -249,9 +249,9 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
private void createKey() {
// Send all information needed to service to edit key in other thread
- Intent intent = new Intent(mActivity, ApgService.class);
+ Intent intent = new Intent(mActivity, ApgIntentService.class);
- intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_GENERATE_KEY);
+ intent.putExtra(ApgIntentService.EXTRA_ACTION, ApgIntentService.ACTION_GENERATE_KEY);
// fill values for this action
Bundle data = new Bundle();
@@ -262,32 +262,32 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
passPhrase = PassphraseCacheService
.getCachedPassphrase(mActivity, masterKey.getKeyID());
- data.putByteArray(ApgService.MASTER_KEY,
+ data.putByteArray(ApgIntentService.MASTER_KEY,
PGPConversionHelper.PGPSecretKeyToBytes(masterKey));
} else {
passPhrase = "";
}
- data.putString(ApgService.SYMMETRIC_PASSPHRASE, passPhrase);
- data.putInt(ApgService.ALGORITHM, mNewKeyAlgorithmChoice.getId());
- data.putInt(ApgService.KEY_SIZE, mNewKeySize);
+ data.putString(ApgIntentService.SYMMETRIC_PASSPHRASE, passPhrase);
+ data.putInt(ApgIntentService.ALGORITHM, mNewKeyAlgorithmChoice.getId());
+ data.putInt(ApgIntentService.KEY_SIZE, mNewKeySize);
- intent.putExtra(ApgService.EXTRA_DATA, data);
+ intent.putExtra(ApgIntentService.EXTRA_DATA, data);
// show progress dialog
mGeneratingDialog = ProgressDialogFragment.newInstance(R.string.progress_generating,
ProgressDialog.STYLE_SPINNER);
// Message is received after generating is done in ApgService
- ApgServiceHandler saveHandler = new ApgServiceHandler(mActivity, mGeneratingDialog) {
+ ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(mActivity, mGeneratingDialog) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
- if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
+ if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
// get new key from data bundle returned from service
Bundle data = message.getData();
PGPSecretKeyRing newKeyRing = (PGPSecretKeyRing) PGPConversionHelper
- .BytesToPGPKeyRing(data.getByteArray(ApgService.RESULT_NEW_KEY));
+ .BytesToPGPKeyRing(data.getByteArray(ApgIntentService.RESULT_NEW_KEY));
boolean isMasterKey = (mEditors.getChildCount() == 0);
@@ -317,7 +317,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
// Create a new Messenger for the communication back
Messenger messenger = new Messenger(saveHandler);
- intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
+ intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);
mGeneratingDialog.show(mActivity.getSupportFragmentManager(), "dialog");