aboutsummaryrefslogtreecommitdiffstats
path: root/org_apg/src/org/thialfihar/android/apg/helper
diff options
context:
space:
mode:
authorDominik <dominik@dominikschuermann.de>2012-09-10 11:13:32 +0200
committerDominik <dominik@dominikschuermann.de>2012-09-10 11:13:32 +0200
commit45d760008cddaa1125027edbc8a65b6df86e28f1 (patch)
tree09e167478532ec862c81dad68f3b436597567e3c /org_apg/src/org/thialfihar/android/apg/helper
parent5cd51b2ad08ee7bef57b2bbe24209a32ee5dbd35 (diff)
downloadopen-keychain-45d760008cddaa1125027edbc8a65b6df86e28f1.tar.gz
open-keychain-45d760008cddaa1125027edbc8a65b6df86e28f1.tar.bz2
open-keychain-45d760008cddaa1125027edbc8a65b6df86e28f1.zip
externalized import, export, started working on qr code import
Diffstat (limited to 'org_apg/src/org/thialfihar/android/apg/helper')
-rw-r--r--org_apg/src/org/thialfihar/android/apg/helper/OtherHelper.java28
-rw-r--r--org_apg/src/org/thialfihar/android/apg/helper/PGPHelper.java40
-rw-r--r--org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java4
3 files changed, 55 insertions, 17 deletions
diff --git a/org_apg/src/org/thialfihar/android/apg/helper/OtherHelper.java b/org_apg/src/org/thialfihar/android/apg/helper/OtherHelper.java
index 67b4d9c9f..516d7fccb 100644
--- a/org_apg/src/org/thialfihar/android/apg/helper/OtherHelper.java
+++ b/org_apg/src/org/thialfihar/android/apg/helper/OtherHelper.java
@@ -86,22 +86,26 @@ public class OtherHelper {
*/
public static void logDebugBundle(Bundle bundle, String bundleName) {
if (Constants.DEBUG) {
- Set<String> ks = bundle.keySet();
- Iterator<String> iterator = ks.iterator();
+ if (bundle != null) {
+ Set<String> ks = bundle.keySet();
+ Iterator<String> iterator = ks.iterator();
- Log.d(Constants.TAG, "Bundle " + bundleName + ":");
- Log.d(Constants.TAG, "------------------------------");
- while (iterator.hasNext()) {
- String key = iterator.next();
- Object value = bundle.get(key);
+ Log.d(Constants.TAG, "Bundle " + bundleName + ":");
+ Log.d(Constants.TAG, "------------------------------");
+ while (iterator.hasNext()) {
+ String key = iterator.next();
+ Object value = bundle.get(key);
- if (value != null) {
- Log.d(Constants.TAG, key + " : " + value.toString());
- } else {
- Log.d(Constants.TAG, key + " : null");
+ if (value != null) {
+ Log.d(Constants.TAG, key + " : " + value.toString());
+ } else {
+ Log.d(Constants.TAG, key + " : null");
+ }
}
+ Log.d(Constants.TAG, "------------------------------");
+ } else {
+ Log.d(Constants.TAG, "Bundle " + bundleName + ": null");
}
- Log.d(Constants.TAG, "------------------------------");
}
}
}
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 0b6191f67..6d5a07f56 100644
--- a/org_apg/src/org/thialfihar/android/apg/helper/PGPHelper.java
+++ b/org_apg/src/org/thialfihar/android/apg/helper/PGPHelper.java
@@ -17,6 +17,7 @@
package org.thialfihar.android.apg.helper;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
@@ -24,6 +25,7 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Vector;
+import org.spongycastle.bcpg.ArmoredOutputStream;
import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.openpgp.PGPKeyRing;
import org.spongycastle.openpgp.PGPObjectFactory;
@@ -34,8 +36,10 @@ import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.spongycastle.openpgp.PGPSignature;
import org.spongycastle.openpgp.PGPSignatureSubpacketVector;
import org.spongycastle.openpgp.PGPUtil;
+import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.util.IterableIterator;
+import org.thialfihar.android.apg.util.Log;
import android.content.Context;
@@ -186,7 +190,7 @@ public class PGPHelper {
}
public static PGPPublicKey getEncryptPublicKey(long masterKeyId) {
- //TODO: externalize getSecretKeyRing from PGPWrapper into a DatabaseHelper
+ // TODO: externalize getSecretKeyRing from PGPWrapper into a DatabaseHelper
PGPPublicKeyRing keyRing = PGPMain.getPublicKeyRing(masterKeyId);
if (keyRing == null) {
return null;
@@ -199,7 +203,7 @@ public class PGPHelper {
}
public static PGPSecretKey getSigningKey(long masterKeyId) {
- //TODO: externalize getSecretKeyRing from PGPWrapper into a DatabaseHelper
+ // TODO: externalize getSecretKeyRing from PGPWrapper into a DatabaseHelper
PGPSecretKeyRing keyRing = PGPMain.getSecretKeyRing(masterKeyId);
if (keyRing == null) {
return null;
@@ -380,12 +384,42 @@ public class PGPHelper {
}
+ public static String getPubkeyAsArmoredString(long keyId) {
+ PGPPublicKey key = PGPMain.getPublicKey(keyId);
+ // if it is no public key get it from your own keys...
+ if (key == null) {
+ PGPSecretKey secretKey = PGPMain.getSecretKey(keyId);
+ if (secretKey == null) {
+ Log.e(Constants.TAG, "Key could not be found!");
+ return null;
+ }
+ key = secretKey.getPublicKey();
+ }
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ArmoredOutputStream aos = new ArmoredOutputStream(bos);
+ String armouredKey = null;
+ try {
+ aos.write(key.getEncoded());
+ aos.close();
+
+ armouredKey = bos.toString("UTF-8");
+ } catch (IOException e) {
+ Log.e(Constants.TAG, "Problems while encoding key as armored string", e);
+ }
+
+ Log.d(Constants.TAG, "key:" + armouredKey);
+
+ return armouredKey;
+ }
+
public static String getFingerPrint(long keyId) {
PGPPublicKey key = PGPMain.getPublicKey(keyId);
if (key == null) {
PGPSecretKey secretKey = PGPMain.getSecretKey(keyId);
if (secretKey == null) {
- return "";
+ Log.e(Constants.TAG, "Key could not be found!");
+ return null;
}
key = secretKey.getPublicKey();
}
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 00e9e707d..3fcbeb7a7 100644
--- a/org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java
+++ b/org_apg/src/org/thialfihar/android/apg/helper/PGPMain.java
@@ -662,7 +662,7 @@ public class PGPMain {
}
}
- public static Bundle importKeyRings(Activity context, int type, InputData data,
+ public static Bundle importKeyRings(Context context, int type, InputData data,
ProgressDialogUpdater progress) throws GeneralException, FileNotFoundException,
PGPException, IOException {
Bundle returnData = new Bundle();
@@ -733,7 +733,7 @@ public class PGPMain {
return returnData;
}
- public static Bundle exportKeyRings(Activity context, Vector<Integer> keyRingIds,
+ public static Bundle exportKeyRings(Context context, Vector<Integer> keyRingIds,
OutputStream outStream, ProgressDialogUpdater progress) throws GeneralException,
FileNotFoundException, PGPException, IOException {
Bundle returnData = new Bundle();