aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-03-18 18:25:44 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2015-03-18 18:25:44 +0100
commitaca54e31eae450e7deec54cca6654ee202c7a90f (patch)
tree19832f3076bc13b65eca38b2a4862e0bf39c4776 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service
parent4499caef1e64d2e1afec37d360958f516da4dd40 (diff)
downloadopen-keychain-aca54e31eae450e7deec54cca6654ee202c7a90f.tar.gz
open-keychain-aca54e31eae450e7deec54cca6654ee202c7a90f.tar.bz2
open-keychain-aca54e31eae450e7deec54cca6654ee202c7a90f.zip
generalize nfc crypto input structure
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java13
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/CryptoInputParcel.java81
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/CryptoOperationParcel.java52
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/NfcOperationsParcel.java85
4 files changed, 172 insertions, 59 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java
index d6da18e6e..485d5de72 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java
@@ -26,31 +26,31 @@ import java.util.ArrayList;
import java.util.Date;
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
-import org.sufficientlysecure.keychain.service.input.CryptoOperationParcel;
+import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
/**
* This class is a a transferable representation for a number of keyrings to
* be certified.
*/
-public class CertifyActionsParcel extends CryptoOperationParcel {
+public class CertifyActionsParcel implements Parcelable {
// the master key id to certify with
final public long mMasterKeyId;
public CertifyLevel mLevel;
public ArrayList<CertifyAction> mCertifyActions = new ArrayList<>();
+ public CryptoInputParcel mCryptoInput;
public CertifyActionsParcel(Date operationTime, long masterKeyId) {
- super(operationTime);
mMasterKeyId = masterKeyId;
+ mCryptoInput = new CryptoInputParcel(operationTime);
mLevel = CertifyLevel.DEFAULT;
}
public CertifyActionsParcel(Parcel source) {
- super(source);
-
mMasterKeyId = source.readLong();
+ mCryptoInput = source.readParcelable(CertifyActionsParcel.class.getClassLoader());
// just like parcelables, this is meant for ad-hoc IPC only and is NOT portable!
mLevel = CertifyLevel.values()[source.readInt()];
@@ -63,9 +63,8 @@ public class CertifyActionsParcel extends CryptoOperationParcel {
@Override
public void writeToParcel(Parcel destination, int flags) {
- super.writeToParcel(destination, flags);
-
destination.writeLong(mMasterKeyId);
+ destination.writeParcelable(mCryptoInput, 0);
destination.writeInt(mLevel.ordinal());
destination.writeSerializable(mCertifyActions);
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/CryptoInputParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/CryptoInputParcel.java
new file mode 100644
index 000000000..e02eda4b3
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/CryptoInputParcel.java
@@ -0,0 +1,81 @@
+package org.sufficientlysecure.keychain.service.input;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+
+/** This is a base class for the input of crypto operations.
+ *
+ */
+public class CryptoInputParcel implements Parcelable {
+
+ Date mSignatureTime;
+
+ // this map contains both decrypted session keys and signed hashes to be
+ // used in the crypto operation described by this parcel.
+ private HashMap<ByteBuffer,byte[]> mCryptoData = new HashMap<>();
+
+ public CryptoInputParcel(Date signatureTime) {
+ mSignatureTime = signatureTime == null ? new Date() : signatureTime;
+ }
+
+ protected CryptoInputParcel(Parcel source) {
+ mSignatureTime = new Date(source.readLong());
+
+ {
+ int count = source.readInt();
+ mCryptoData = new HashMap<>(count);
+ for (int i = 0; i < count; i++) {
+ byte[] key = source.createByteArray();
+ byte[] value = source.createByteArray();
+ mCryptoData.put(ByteBuffer.wrap(key), value);
+ }
+ }
+
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeLong(mSignatureTime.getTime());
+
+ dest.writeInt(mCryptoData.size());
+ for (HashMap.Entry<ByteBuffer,byte[]> entry : mCryptoData.entrySet()) {
+ dest.writeByteArray(entry.getKey().array());
+ dest.writeByteArray(entry.getValue());
+ }
+ }
+
+ public void addCryptoData(byte[] hash, byte[] signedHash) {
+ mCryptoData.put(ByteBuffer.wrap(hash), signedHash);
+ }
+
+ public Map<ByteBuffer, byte[]> getCryptoData() {
+ return Collections.unmodifiableMap(mCryptoData);
+ }
+
+ public Date getSignatureTime() {
+ return mSignatureTime;
+ }
+
+ public static final Creator<CryptoInputParcel> CREATOR = new Creator<CryptoInputParcel>() {
+ public CryptoInputParcel createFromParcel(final Parcel source) {
+ return new CryptoInputParcel(source);
+ }
+
+ public CryptoInputParcel[] newArray(final int size) {
+ return new CryptoInputParcel[size];
+ }
+ };
+
+}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/CryptoOperationParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/CryptoOperationParcel.java
deleted file mode 100644
index 2101755ad..000000000
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/CryptoOperationParcel.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.sufficientlysecure.keychain.service.input;
-
-import java.nio.ByteBuffer;
-import java.util.Date;
-import java.util.HashMap;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-
-/** This is a base class for the input of crypto operations.
- *
- */
-public abstract class CryptoOperationParcel implements Parcelable {
-
- Date mOperationTime;
-
- // this map contains both decrypted session keys and signed hashes to be
- // used in the crypto operation described by this parcel.
- HashMap<ByteBuffer,byte[]> mCryptoData;
-
- protected CryptoOperationParcel(Date operationTime) {
- mOperationTime = operationTime;
- }
-
- protected CryptoOperationParcel(Parcel source) {
- mOperationTime = new Date(source.readLong());
-
- {
- int count = source.readInt();
- mCryptoData = new HashMap<>(count);
- for (int i = 0; i < count; i++) {
- byte[] key = source.createByteArray();
- byte[] value = source.createByteArray();
- mCryptoData.put(ByteBuffer.wrap(key), value);
- }
- }
-
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeLong(mOperationTime.getTime());
-
- dest.writeInt(mCryptoData.size());
- for (HashMap.Entry<ByteBuffer,byte[]> entry : mCryptoData.entrySet()) {
- dest.writeByteArray(entry.getKey().array());
- dest.writeByteArray(entry.getValue());
- }
- }
-
-}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/NfcOperationsParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/NfcOperationsParcel.java
new file mode 100644
index 000000000..5d35e94e0
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/input/NfcOperationsParcel.java
@@ -0,0 +1,85 @@
+package org.sufficientlysecure.keychain.service.input;
+
+import java.util.Date;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+
+public class NfcOperationsParcel implements Parcelable {
+
+ public enum NfcOperationType {
+ NFC_SIGN, NFC_DECRYPT
+ }
+
+ public Date mSignatureTime;
+ public final NfcOperationType mType;
+ public final byte[][] mInputHash;
+ public final int[] mSignAlgo;
+
+ private NfcOperationsParcel(NfcOperationType type, byte[] inputHash, int signAlgo, Date signatureTime) {
+ mType = type;
+ mInputHash = new byte[][] { inputHash };
+ mSignAlgo = new int[] { signAlgo };
+ mSignatureTime = signatureTime;
+ }
+
+ public NfcOperationsParcel(Parcel source) {
+ mType = NfcOperationType.values()[source.readInt()];
+
+ {
+ int count = source.readInt();
+ mInputHash = new byte[count][];
+ mSignAlgo = new int[count];
+ for (int i = 0; i < count; i++) {
+ mInputHash[i] = source.createByteArray();
+ mSignAlgo[i] = source.readInt();
+ }
+ }
+
+ mSignatureTime = source.readInt() != 0 ? new Date(source.readLong()) : null;
+
+ }
+
+ public static NfcOperationsParcel createNfcSignOperation(
+ byte[] inputHash, int signAlgo, Date signatureTime) {
+ return new NfcOperationsParcel(NfcOperationType.NFC_SIGN, inputHash, signAlgo, signatureTime);
+ }
+
+ public static NfcOperationsParcel createNfcDecryptOperation(byte[] inputHash) {
+ return new NfcOperationsParcel(NfcOperationType.NFC_DECRYPT, inputHash, 0, null);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(mType.ordinal());
+ dest.writeInt(mInputHash.length);
+ for (int i = 0; i < mInputHash.length; i++) {
+ dest.writeByteArray(mInputHash[i]);
+ dest.writeInt(mSignAlgo[i]);
+ }
+ if (mSignatureTime != null) {
+ dest.writeInt(1);
+ dest.writeLong(mSignatureTime.getTime());
+ } else {
+ dest.writeInt(0);
+ }
+
+ }
+
+ public static final Creator<NfcOperationsParcel> CREATOR = new Creator<NfcOperationsParcel>() {
+ public NfcOperationsParcel createFromParcel(final Parcel source) {
+ return new NfcOperationsParcel(source);
+ }
+
+ public NfcOperationsParcel[] newArray(final int size) {
+ return new NfcOperationsParcel[size];
+ }
+ };
+
+}