New API version, import from clipboard
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.openintents.openpgp;
|
||||
|
||||
import org.openintents.openpgp.OpenPgpData;
|
||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||
import org.openintents.openpgp.OpenPgpError;
|
||||
|
||||
@@ -24,14 +25,14 @@ interface IOpenPgpCallback {
|
||||
/**
|
||||
* onSuccess returns on successful OpenPGP operations.
|
||||
*
|
||||
* @param outputBytes
|
||||
* contains resulting output bytes (decrypted content (when input was encrypted)
|
||||
* @param output
|
||||
* contains resulting output (decrypted content (when input was encrypted)
|
||||
* or content without signature (when input was signed-only))
|
||||
* @param signatureResult
|
||||
* signatureResult is only non-null if decryptAndVerify() was called and the content
|
||||
* was encrypted or signed-and-encrypted.
|
||||
*/
|
||||
oneway void onSuccess(in byte[] outputBytes, in OpenPgpSignatureResult signatureResult);
|
||||
oneway void onSuccess(in OpenPgpData output, in OpenPgpSignatureResult signatureResult);
|
||||
|
||||
/**
|
||||
* onError returns on errors or when allowUserInteraction was set to false, but user interaction
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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.openintents.openpgp;
|
||||
|
||||
import org.openintents.openpgp.OpenPgpError;
|
||||
|
||||
interface IOpenPgpKeyIdsCallback {
|
||||
|
||||
/**
|
||||
* onSuccess returns on successful getKeyIds operations.
|
||||
*
|
||||
* @param keyIds
|
||||
* returned key ids
|
||||
*/
|
||||
oneway void onSuccess(in long[] keyIds);
|
||||
|
||||
/**
|
||||
* onError returns on errors or when allowUserInteraction was set to false, but user interaction
|
||||
* was required execute an OpenPGP operation.
|
||||
*
|
||||
* @param error
|
||||
* See OpenPgpError class for more information.
|
||||
*/
|
||||
oneway void onError(in OpenPgpError error);
|
||||
}
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.openintents.openpgp;
|
||||
|
||||
import org.openintents.openpgp.OpenPgpData;
|
||||
import org.openintents.openpgp.IOpenPgpCallback;
|
||||
import org.openintents.openpgp.IOpenPgpKeyIdsCallback;
|
||||
|
||||
/**
|
||||
* All methods are oneway, which means they are asynchronous and non-blocking.
|
||||
@@ -29,54 +31,76 @@ interface IOpenPgpService {
|
||||
*
|
||||
* After successful encryption, callback's onSuccess will contain the resulting output bytes.
|
||||
*
|
||||
* @param inputBytes
|
||||
* Byte array you want to encrypt
|
||||
* @param encryptionUserIds
|
||||
* User Ids (emails) of recipients
|
||||
* @param asciiArmor
|
||||
* Encode result for ASCII (Radix-64, 33 percent overhead compared to binary)
|
||||
* @param allowUserInteraction
|
||||
* Allows the OpenPGP Provider to handle missing keys by showing activities
|
||||
* @param input
|
||||
* OpenPgpData object containing String, byte[], ParcelFileDescriptor, or Uri
|
||||
* @param output
|
||||
* Request output format by defining OpenPgpData object
|
||||
*
|
||||
* new OpenPgpData(OpenPgpData.TYPE_STRING)
|
||||
* Returns as String
|
||||
* (OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53)
|
||||
* new OpenPgpData(OpenPgpData.TYPE_BYTE_ARRAY)
|
||||
* Returns as byte[]
|
||||
* new OpenPgpData(uri)
|
||||
* Writes output to given Uri
|
||||
* new OpenPgpData(fileDescriptor)
|
||||
* Writes output to given ParcelFileDescriptor
|
||||
* @param keyIds
|
||||
* Key Ids of recipients. Can be retrieved with getKeyIds()
|
||||
* @param callback
|
||||
* Callback where to return results
|
||||
*/
|
||||
oneway void encrypt(in byte[] inputBytes, in String[] encryptionUserIds, in boolean asciiArmor,
|
||||
in IOpenPgpCallback callback);
|
||||
oneway void encrypt(in OpenPgpData input, in OpenPgpData output, in long[] keyIds, in IOpenPgpCallback callback);
|
||||
|
||||
/**
|
||||
* Sign
|
||||
*
|
||||
* After successful signing, callback's onSuccess will contain the resulting output bytes.
|
||||
*
|
||||
* @param inputBytes
|
||||
* Byte array you want to sign
|
||||
* @param asciiArmor
|
||||
* Encode result for ASCII (Radix-64, 33 percent overhead compared to binary)
|
||||
* @param allowUserInteraction
|
||||
* Allows the OpenPGP Provider to handle missing keys by showing activities
|
||||
* @param input
|
||||
* OpenPgpData object containing String, byte[], ParcelFileDescriptor, or Uri
|
||||
* @param output
|
||||
* Request output format by defining OpenPgpData object
|
||||
*
|
||||
* new OpenPgpData(OpenPgpData.TYPE_STRING)
|
||||
* Returns as String
|
||||
* (OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53)
|
||||
* new OpenPgpData(OpenPgpData.TYPE_BYTE_ARRAY)
|
||||
* Returns as byte[]
|
||||
* new OpenPgpData(uri)
|
||||
* Writes output to given Uri
|
||||
* new OpenPgpData(fileDescriptor)
|
||||
* Writes output to given ParcelFileDescriptor
|
||||
* @param callback
|
||||
* Callback where to return results
|
||||
*/
|
||||
oneway void sign(in byte[] inputBytes, in boolean asciiArmor, in IOpenPgpCallback callback);
|
||||
oneway void sign(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback);
|
||||
|
||||
/**
|
||||
* Sign then encrypt
|
||||
*
|
||||
* After successful signing and encryption, callback's onSuccess will contain the resulting output bytes.
|
||||
*
|
||||
* @param inputBytes
|
||||
* Byte array you want to sign and encrypt
|
||||
* @param encryptionUserIds
|
||||
* User Ids (emails) of recipients
|
||||
* @param asciiArmor
|
||||
* Encode result for ASCII (Radix-64, 33 percent overhead compared to binary)
|
||||
* @param allowUserInteraction
|
||||
* Allows the OpenPGP Provider to handle missing keys by showing activities
|
||||
* @param input
|
||||
* OpenPgpData object containing String, byte[], ParcelFileDescriptor, or Uri
|
||||
* @param output
|
||||
* Request output format by defining OpenPgpData object
|
||||
*
|
||||
* new OpenPgpData(OpenPgpData.TYPE_STRING)
|
||||
* Returns as String
|
||||
* (OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53)
|
||||
* new OpenPgpData(OpenPgpData.TYPE_BYTE_ARRAY)
|
||||
* Returns as byte[]
|
||||
* new OpenPgpData(uri)
|
||||
* Writes output to given Uri
|
||||
* new OpenPgpData(fileDescriptor)
|
||||
* Writes output to given ParcelFileDescriptor
|
||||
* @param keyIds
|
||||
* Key Ids of recipients. Can be retrieved with getKeyIds()
|
||||
* @param callback
|
||||
* Callback where to return results
|
||||
*/
|
||||
oneway void signAndEncrypt(in byte[] inputBytes, in String[] encryptionUserIds, in boolean asciiArmor,
|
||||
in IOpenPgpCallback callback);
|
||||
oneway void signAndEncrypt(in OpenPgpData input, in OpenPgpData output, in long[] keyIds, in IOpenPgpCallback callback);
|
||||
|
||||
/**
|
||||
* Decrypts and verifies given input bytes. This methods handles encrypted-only, signed-and-encrypted,
|
||||
@@ -85,15 +109,35 @@ interface IOpenPgpService {
|
||||
* After successful decryption/verification, callback's onSuccess will contain the resulting output bytes.
|
||||
* The signatureResult in onSuccess is only non-null if signed-and-encrypted or signed-only inputBytes were given.
|
||||
*
|
||||
* @param inputBytes
|
||||
* Byte array you want to decrypt and verify
|
||||
* @param allowUserInteraction
|
||||
* Allows the OpenPGP Provider to handle missing keys by showing activities
|
||||
* @param input
|
||||
* OpenPgpData object containing String, byte[], ParcelFileDescriptor, or Uri
|
||||
* @param output
|
||||
* Request output format by defining OpenPgpData object
|
||||
*
|
||||
* new OpenPgpData(OpenPgpData.TYPE_STRING)
|
||||
* Returns as String
|
||||
* (OpenPGP Radix-64, 33 percent overhead compared to binary, see http://tools.ietf.org/html/rfc4880#page-53)
|
||||
* new OpenPgpData(OpenPgpData.TYPE_BYTE_ARRAY)
|
||||
* Returns as byte[]
|
||||
* new OpenPgpData(uri)
|
||||
* Writes output to given Uri
|
||||
* new OpenPgpData(fileDescriptor)
|
||||
* Writes output to given ParcelFileDescriptor
|
||||
* @param callback
|
||||
* Callback where to return results
|
||||
*/
|
||||
oneway void decryptAndVerify(in byte[] inputBytes, in IOpenPgpCallback callback);
|
||||
oneway void decryptAndVerify(in OpenPgpData input, in OpenPgpData output, in IOpenPgpCallback callback);
|
||||
|
||||
boolean isKeyAvailable(in String[] userIds);
|
||||
/**
|
||||
* Get available key ids based on given user ids
|
||||
*
|
||||
* @param ids
|
||||
* User Ids (emails) of recipients OR key ids
|
||||
* @param allowUserInteraction
|
||||
* Enable user interaction to lookup and import unknown keys
|
||||
* @param callback
|
||||
* Callback where to return results (different type than callback in other functions!)
|
||||
*/
|
||||
oneway void getKeyIds(in String[] ids, in boolean allowUserInteraction, in IOpenPgpKeyIdsCallback callback);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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.openintents.openpgp;
|
||||
|
||||
// Declare OpenPgpData so AIDL can find it and knows that it implements the parcelable protocol.
|
||||
parcelable OpenPgpData;
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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.openintents.openpgp;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class OpenPgpData implements Parcelable {
|
||||
public static final int TYPE_STRING = 0;
|
||||
public static final int TYPE_BYTE_ARRAY = 1;
|
||||
public static final int TYPE_FILE_DESCRIPTOR = 2;
|
||||
public static final int TYPE_URI = 3;
|
||||
|
||||
int type;
|
||||
|
||||
String string;
|
||||
byte[] bytes = new byte[0];
|
||||
ParcelFileDescriptor fileDescriptor;
|
||||
Uri uri;
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return string;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public ParcelFileDescriptor getFileDescriptor() {
|
||||
return fileDescriptor;
|
||||
}
|
||||
|
||||
public Uri getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public OpenPgpData() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Not a real constructor. This can be used to define requested output type.
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public OpenPgpData(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public OpenPgpData(String string) {
|
||||
this.string = string;
|
||||
this.type = TYPE_STRING;
|
||||
}
|
||||
|
||||
public OpenPgpData(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
this.type = TYPE_BYTE_ARRAY;
|
||||
}
|
||||
|
||||
public OpenPgpData(ParcelFileDescriptor fileDescriptor) {
|
||||
this.fileDescriptor = fileDescriptor;
|
||||
this.type = TYPE_FILE_DESCRIPTOR;
|
||||
}
|
||||
|
||||
public OpenPgpData(Uri uri) {
|
||||
this.uri = uri;
|
||||
this.type = TYPE_URI;
|
||||
}
|
||||
|
||||
public OpenPgpData(OpenPgpData b) {
|
||||
this.string = b.string;
|
||||
this.bytes = b.bytes;
|
||||
this.fileDescriptor = b.fileDescriptor;
|
||||
this.uri = b.uri;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(string);
|
||||
dest.writeInt(bytes.length);
|
||||
dest.writeByteArray(bytes);
|
||||
dest.writeParcelable(fileDescriptor, 0);
|
||||
dest.writeParcelable(uri, 0);
|
||||
}
|
||||
|
||||
public static final Creator<OpenPgpData> CREATOR = new Creator<OpenPgpData>() {
|
||||
public OpenPgpData createFromParcel(final Parcel source) {
|
||||
OpenPgpData vr = new OpenPgpData();
|
||||
vr.string = source.readString();
|
||||
vr.bytes = new byte[source.readInt()];
|
||||
source.readByteArray(vr.bytes);
|
||||
vr.fileDescriptor = source.readParcelable(ParcelFileDescriptor.class.getClassLoader());
|
||||
vr.fileDescriptor = source.readParcelable(Uri.class.getClassLoader());
|
||||
return vr;
|
||||
}
|
||||
|
||||
public OpenPgpData[] newArray(final int size) {
|
||||
return new OpenPgpData[size];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -23,7 +23,9 @@ import android.app.AlertDialog.Builder;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
@@ -34,15 +36,17 @@ import android.widget.ListAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class OpenPgpListPreference extends DialogPreference {
|
||||
static final Intent intent = new Intent(IOpenPgpService.class.getName());
|
||||
|
||||
ArrayList<OpenPgpProviderEntry> mProviderList = new ArrayList<OpenPgpProviderEntry>();
|
||||
private String mSelectedPackage;
|
||||
|
||||
public static final int REQUIRED_API_VERSION = 1;
|
||||
|
||||
public OpenPgpListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(intent, 0);
|
||||
List<ResolveInfo> resInfo =
|
||||
context.getPackageManager().queryIntentServices(
|
||||
new Intent(IOpenPgpService.class.getName()), PackageManager.GET_META_DATA);
|
||||
if (!resInfo.isEmpty()) {
|
||||
for (ResolveInfo resolveInfo : resInfo) {
|
||||
if (resolveInfo.serviceInfo == null)
|
||||
@@ -52,7 +56,13 @@ public class OpenPgpListPreference extends DialogPreference {
|
||||
String simpleName = String.valueOf(resolveInfo.serviceInfo
|
||||
.loadLabel(context.getPackageManager()));
|
||||
Drawable icon = resolveInfo.serviceInfo.loadIcon(context.getPackageManager());
|
||||
mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon));
|
||||
|
||||
// get api version
|
||||
ServiceInfo si = resolveInfo.serviceInfo;
|
||||
int apiVersion = si.metaData.getInt("api_version");
|
||||
|
||||
mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon,
|
||||
apiVersion));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,8 +78,10 @@ public class OpenPgpListPreference extends DialogPreference {
|
||||
* @param simpleName
|
||||
* @param icon
|
||||
*/
|
||||
public void addProvider(int position, String packageName, String simpleName, Drawable icon) {
|
||||
mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon));
|
||||
public void addProvider(int position, String packageName, String simpleName, Drawable icon,
|
||||
int apiVersion) {
|
||||
mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon,
|
||||
apiVersion));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,13 +103,23 @@ public class OpenPgpListPreference extends DialogPreference {
|
||||
int dp5 = (int) (5 * getContext().getResources().getDisplayMetrics().density + 0.5f);
|
||||
tv.setCompoundDrawablePadding(dp5);
|
||||
|
||||
// disable if it has the wrong api_version
|
||||
if (mProviderList.get(position).apiVersion == REQUIRED_API_VERSION) {
|
||||
tv.setEnabled(true);
|
||||
} else {
|
||||
tv.setEnabled(false);
|
||||
tv.setText(tv.getText() + " (API v"
|
||||
+ mProviderList.get(position).apiVersion + ", needs v"
|
||||
+ REQUIRED_API_VERSION + ")");
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
builder.setSingleChoiceItems(adapter, getIndexOfProviderList(getValue()),
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mSelectedPackage = mProviderList.get(which).packageName;
|
||||
@@ -167,11 +189,14 @@ public class OpenPgpListPreference extends DialogPreference {
|
||||
private String packageName;
|
||||
private String simpleName;
|
||||
private Drawable icon;
|
||||
private int apiVersion;
|
||||
|
||||
public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon) {
|
||||
public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon,
|
||||
int apiVersion) {
|
||||
this.packageName = packageName;
|
||||
this.simpleName = simpleName;
|
||||
this.icon = icon;
|
||||
this.apiVersion = apiVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,40 +25,50 @@ public class OpenPgpSignatureResult implements Parcelable {
|
||||
// successfully verified signature, with trusted public key
|
||||
public static final int SIGNATURE_SUCCESS_TRUSTED = 1;
|
||||
// no public key was found for this signature verification
|
||||
// you can retrieve the key with
|
||||
// getKeys(new String[] {String.valueOf(signatureResult.getKeyId)}, true, callback)
|
||||
public static final int SIGNATURE_UNKNOWN_PUB_KEY = 2;
|
||||
// successfully verified signature, but with untrusted public key
|
||||
public static final int SIGNATURE_SUCCESS_UNTRUSTED = 3;
|
||||
|
||||
int signatureStatus;
|
||||
String signatureUserId;
|
||||
int status;
|
||||
boolean signatureOnly;
|
||||
String userId;
|
||||
long keyId;
|
||||
|
||||
public int getSignatureStatus() {
|
||||
return signatureStatus;
|
||||
}
|
||||
|
||||
public String getSignatureUserId() {
|
||||
return signatureUserId;
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public boolean isSignatureOnly() {
|
||||
return signatureOnly;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public long getKeyId() {
|
||||
return keyId;
|
||||
}
|
||||
|
||||
public OpenPgpSignatureResult() {
|
||||
|
||||
}
|
||||
|
||||
public OpenPgpSignatureResult(int signatureStatus, String signatureUserId, boolean signatureOnly) {
|
||||
this.signatureStatus = signatureStatus;
|
||||
this.signatureUserId = signatureUserId;
|
||||
public OpenPgpSignatureResult(int signatureStatus, String signatureUserId,
|
||||
boolean signatureOnly, long keyId) {
|
||||
this.status = signatureStatus;
|
||||
this.signatureOnly = signatureOnly;
|
||||
this.userId = signatureUserId;
|
||||
this.keyId = keyId;
|
||||
}
|
||||
|
||||
public OpenPgpSignatureResult(OpenPgpSignatureResult b) {
|
||||
this.signatureStatus = b.signatureStatus;
|
||||
this.signatureUserId = b.signatureUserId;
|
||||
this.status = b.status;
|
||||
this.userId = b.userId;
|
||||
this.signatureOnly = b.signatureOnly;
|
||||
this.keyId = b.keyId;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
@@ -66,17 +76,19 @@ public class OpenPgpSignatureResult implements Parcelable {
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(signatureStatus);
|
||||
dest.writeString(signatureUserId);
|
||||
dest.writeInt(status);
|
||||
dest.writeByte((byte) (signatureOnly ? 1 : 0));
|
||||
dest.writeString(userId);
|
||||
dest.writeLong(keyId);
|
||||
}
|
||||
|
||||
public static final Creator<OpenPgpSignatureResult> CREATOR = new Creator<OpenPgpSignatureResult>() {
|
||||
public OpenPgpSignatureResult createFromParcel(final Parcel source) {
|
||||
OpenPgpSignatureResult vr = new OpenPgpSignatureResult();
|
||||
vr.signatureStatus = source.readInt();
|
||||
vr.signatureUserId = source.readString();
|
||||
vr.status = source.readInt();
|
||||
vr.signatureOnly = source.readByte() == 1;
|
||||
vr.userId = source.readString();
|
||||
vr.keyId = source.readLong();
|
||||
return vr;
|
||||
}
|
||||
|
||||
@@ -88,9 +100,10 @@ public class OpenPgpSignatureResult implements Parcelable {
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = new String();
|
||||
out += "\nsignatureStatus: " + signatureStatus;
|
||||
out += "\nsignatureUserId: " + signatureUserId;
|
||||
out += "\nstatus: " + status;
|
||||
out += "\nuserId: " + userId;
|
||||
out += "\nsignatureOnly: " + signatureOnly;
|
||||
out += "\nkeyId: " + keyId;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,6 @@ public final class Constants {
|
||||
|
||||
public static final boolean DEBUG = BuildConfig.DEBUG;
|
||||
|
||||
public static final String TAG = "Keychain API";
|
||||
public static final String TAG = "Keychain";
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.sufficientlysecure.keychain.demo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.openintents.openpgp.IOpenPgpKeyIdsCallback;
|
||||
import org.openintents.openpgp.OpenPgpData;
|
||||
import org.openintents.openpgp.OpenPgpError;
|
||||
import org.openintents.openpgp.OpenPgpServiceConnection;
|
||||
import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||
@@ -66,12 +68,75 @@ public class OpenPgpProviderActivity extends Activity {
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback from remote crypto service
|
||||
* Callback from remote openpgp service
|
||||
*/
|
||||
final IOpenPgpKeyIdsCallback.Stub getKeysEncryptCallback = new IOpenPgpKeyIdsCallback.Stub() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(final long[] keyIds) throws RemoteException {
|
||||
Log.d(Constants.TAG, "getKeysEncryptCallback keyId " + keyIds[0]);
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// encrypt after getting key ids
|
||||
String inputStr = mMessage.getText().toString();
|
||||
OpenPgpData input = new OpenPgpData(inputStr);
|
||||
|
||||
Log.d(Constants.TAG, "getKeysEncryptCallback inputStr " + inputStr);
|
||||
|
||||
try {
|
||||
mCryptoServiceConnection.getService().encrypt(input,
|
||||
new OpenPgpData(OpenPgpData.TYPE_STRING), keyIds, encryptCallback);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "CryptoProviderDemo", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(OpenPgpError error) throws RemoteException {
|
||||
handleError(error);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
final IOpenPgpKeyIdsCallback.Stub getKeysSignAndEncryptCallback = new IOpenPgpKeyIdsCallback.Stub() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(final long[] keyIds) throws RemoteException {
|
||||
Log.d(Constants.TAG, "getKeysSignAndEncryptCallback keyId " + keyIds[0]);
|
||||
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// encrypt after getting key ids
|
||||
String inputStr = mMessage.getText().toString();
|
||||
OpenPgpData input = new OpenPgpData(inputStr);
|
||||
|
||||
try {
|
||||
mCryptoServiceConnection.getService().signAndEncrypt(input,
|
||||
new OpenPgpData(OpenPgpData.TYPE_STRING), keyIds, encryptCallback);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "CryptoProviderDemo", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(OpenPgpError error) throws RemoteException {
|
||||
handleError(error);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
final IOpenPgpCallback.Stub encryptCallback = new IOpenPgpCallback.Stub() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(final byte[] outputBytes, OpenPgpSignatureResult signatureResult)
|
||||
public void onSuccess(final OpenPgpData output, OpenPgpSignatureResult signatureResult)
|
||||
throws RemoteException {
|
||||
Log.d(Constants.TAG, "encryptCallback");
|
||||
|
||||
@@ -79,7 +144,7 @@ public class OpenPgpProviderActivity extends Activity {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mCiphertext.setText(new String(outputBytes));
|
||||
mCiphertext.setText(output.getString());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -94,7 +159,7 @@ public class OpenPgpProviderActivity extends Activity {
|
||||
final IOpenPgpCallback.Stub decryptAndVerifyCallback = new IOpenPgpCallback.Stub() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(final byte[] outputBytes, final OpenPgpSignatureResult signatureResult)
|
||||
public void onSuccess(final OpenPgpData output, final OpenPgpSignatureResult signatureResult)
|
||||
throws RemoteException {
|
||||
Log.d(Constants.TAG, "decryptAndVerifyCallback");
|
||||
|
||||
@@ -102,7 +167,7 @@ public class OpenPgpProviderActivity extends Activity {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mMessage.setText(new String(outputBytes));
|
||||
mMessage.setText(output.getString());
|
||||
if (signatureResult != null) {
|
||||
Toast.makeText(OpenPgpProviderActivity.this,
|
||||
"signature result:\n" + signatureResult.toString(),
|
||||
@@ -135,43 +200,43 @@ public class OpenPgpProviderActivity extends Activity {
|
||||
}
|
||||
|
||||
public void encryptOnClick(View view) {
|
||||
byte[] inputBytes = mMessage.getText().toString().getBytes();
|
||||
|
||||
try {
|
||||
mCryptoServiceConnection.getService().encrypt(inputBytes,
|
||||
mEncryptUserIds.getText().toString().split(","), true, encryptCallback);
|
||||
mCryptoServiceConnection.getService().getKeyIds(
|
||||
mEncryptUserIds.getText().toString().split(","), true, getKeysEncryptCallback);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "CryptoProviderDemo", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void signOnClick(View view) {
|
||||
byte[] inputBytes = mMessage.getText().toString().getBytes();
|
||||
String inputStr = mMessage.getText().toString();
|
||||
OpenPgpData input = new OpenPgpData(inputStr);
|
||||
|
||||
try {
|
||||
mCryptoServiceConnection.getService().sign(inputBytes, true, encryptCallback);
|
||||
mCryptoServiceConnection.getService().sign(input,
|
||||
new OpenPgpData(OpenPgpData.TYPE_STRING), encryptCallback);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "CryptoProviderDemo", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void encryptAndSignOnClick(View view) {
|
||||
byte[] inputBytes = mMessage.getText().toString().getBytes();
|
||||
|
||||
public void signAndEncryptOnClick(View view) {
|
||||
try {
|
||||
mCryptoServiceConnection.getService().signAndEncrypt(inputBytes,
|
||||
mEncryptUserIds.getText().toString().split(","), true, encryptCallback);
|
||||
mCryptoServiceConnection.getService().getKeyIds(
|
||||
mEncryptUserIds.getText().toString().split(","), true,
|
||||
getKeysSignAndEncryptCallback);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "CryptoProviderDemo", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void decryptAndVerifyOnClick(View view) {
|
||||
byte[] inputBytes = mCiphertext.getText().toString().getBytes();
|
||||
String inputStr = mCiphertext.getText().toString();
|
||||
OpenPgpData input = new OpenPgpData(inputStr);
|
||||
|
||||
try {
|
||||
mCryptoServiceConnection.getService().decryptAndVerify(inputBytes,
|
||||
decryptAndVerifyCallback);
|
||||
mCryptoServiceConnection.getService().decryptAndVerify(input,
|
||||
new OpenPgpData(OpenPgpData.TYPE_STRING), decryptAndVerifyCallback);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "CryptoProviderDemo", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user