AIDL API changes

This commit is contained in:
Dominik Schürmann
2012-12-14 18:22:03 +01:00
parent 2dcaad3d3b
commit be4e3a10b0
36 changed files with 1113 additions and 275 deletions

View File

@@ -31,6 +31,9 @@ import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.helper.PGPMain;
import org.thialfihar.android.apg.helper.PGPMain.ApgGeneralException;
import org.thialfihar.android.apg.service.handler.IApgDecryptHandler;
import org.thialfihar.android.apg.service.handler.IApgEncryptHandler;
import org.thialfihar.android.apg.service.handler.IApgGetDecryptionKeyIdHandler;
import org.thialfihar.android.apg.util.InputData;
import org.thialfihar.android.apg.util.Log;
@@ -47,20 +50,20 @@ import android.os.RemoteException;
* - is this service thread safe? Probably not!
*
*/
public class ApgService extends Service {
public class ApgApiService extends Service {
Context mContext;
@Override
public void onCreate() {
super.onCreate();
mContext = this;
Log.d(Constants.TAG, "ApgService, onCreate()");
Log.d(Constants.TAG, "ApgApiService, onCreate()");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d(Constants.TAG, "ApgService, onDestroy()");
Log.d(Constants.TAG, "ApgApiService, onDestroy()");
}
@Override
@@ -68,19 +71,19 @@ public class ApgService extends Service {
return mBinder;
}
private static void writeToOutputStream(InputStream is, OutputStream os) throws IOException {
byte[] buffer = new byte[8];
int len = 0;
while ((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
}
// private static void writeToOutputStream(InputStream is, OutputStream os) throws IOException {
// byte[] buffer = new byte[8];
// int len = 0;
// while ((len = is.read(buffer)) != -1) {
// os.write(buffer, 0, len);
// }
// }
private void encryptAndSignImplementation(byte[] inputBytes, String inputUri,
boolean useAsciiArmor, int compression, long[] encryptionKeyIds,
String encryptionPassphrase, int symmetricEncryptionAlgorithm, long signatureKeyId,
int signatureHashAlgorithm, boolean signatureForceV3, String signaturePassphrase,
IApgEncryptSignHandler handler) throws RemoteException {
IApgEncryptHandler handler) throws RemoteException {
try {
// TODO use inputUri
@@ -128,7 +131,7 @@ public class ApgService extends Service {
byte[] outputBytes = ((ByteArrayOutputStream) output).toByteArray();
// return over handler on client side
handler.onSuccessEncrypt(outputBytes, null);
handler.onSuccess(outputBytes, null);
} catch (Exception e) {
Log.e(Constants.TAG, "ApgService, Exception!", e);
@@ -141,7 +144,7 @@ public class ApgService extends Service {
}
private void decryptAndVerifyImplementation(byte[] inputBytes, String inputUri,
String passphrase, boolean assumeSymmetric, IApgDecryptVerifyHandler handler)
String passphrase, boolean assumeSymmetric, IApgDecryptHandler handler)
throws RemoteException {
try {
@@ -170,7 +173,7 @@ public class ApgService extends Service {
.getBoolean(ApgIntentService.RESULT_SIGNATURE_UNKNOWN);
// return over handler on client side
handler.onSuccessDecrypt(outputBytes, null, signature, signatureKeyId, signatureUserId,
handler.onSuccess(outputBytes, null, signature, signatureKeyId, signatureUserId,
signatureSuccess, signatureUnknown);
} catch (Exception e) {
Log.e(Constants.TAG, "ApgService, Exception!", e);
@@ -184,7 +187,7 @@ public class ApgService extends Service {
}
private void getDecryptionKeyImplementation(byte[] inputBytes, String inputUri,
IApgHelperHandler handler) {
IApgGetDecryptionKeyIdHandler handler) {
// TODO: implement inputUri
@@ -195,20 +198,20 @@ public class ApgService extends Service {
boolean symmetric;
try {
secretKeyId = PGPMain.getDecryptionKeyId(ApgService.this, inputStream);
secretKeyId = PGPMain.getDecryptionKeyId(ApgApiService.this, inputStream);
if (secretKeyId == Id.key.none) {
throw new ApgGeneralException(getString(R.string.error_noSecretKeyFound));
}
symmetric = false;
} catch (PGPMain.NoAsymmetricEncryptionException e) {
secretKeyId = Id.key.symmetric;
if (!PGPMain.hasSymmetricEncryption(ApgService.this, inputStream)) {
if (!PGPMain.hasSymmetricEncryption(ApgApiService.this, inputStream)) {
throw new ApgGeneralException(getString(R.string.error_noKnownEncryptionFound));
}
symmetric = true;
}
handler.onSuccessGetDecryptionKey(secretKeyId, symmetric);
handler.onSuccess(secretKeyId, symmetric);
} catch (Exception e) {
Log.e(Constants.TAG, "ApgService, Exception!", e);
@@ -227,12 +230,12 @@ public class ApgService extends Service {
*
* The real PGP code is located in PGPMain.
*/
private final IApgService.Stub mBinder = new IApgService.Stub() {
private final IApgApiService.Stub mBinder = new IApgApiService.Stub() {
@Override
public void encryptAsymmetric(byte[] inputBytes, String inputUri, boolean useAsciiArmor,
int compression, long[] encryptionKeyIds, int symmetricEncryptionAlgorithm,
IApgEncryptSignHandler handler) throws RemoteException {
IApgEncryptHandler handler) throws RemoteException {
encryptAndSignImplementation(inputBytes, inputUri, useAsciiArmor, compression,
encryptionKeyIds, null, symmetricEncryptionAlgorithm, Id.key.none, 0, false,
@@ -242,7 +245,7 @@ public class ApgService extends Service {
@Override
public void encryptSymmetric(byte[] inputBytes, String inputUri, boolean useAsciiArmor,
int compression, String encryptionPassphrase, int symmetricEncryptionAlgorithm,
IApgEncryptSignHandler handler) throws RemoteException {
IApgEncryptHandler handler) throws RemoteException {
encryptAndSignImplementation(inputBytes, inputUri, useAsciiArmor, compression, null,
encryptionPassphrase, symmetricEncryptionAlgorithm, Id.key.none, 0, false,
@@ -253,7 +256,7 @@ public class ApgService extends Service {
public void encryptAndSignAsymmetric(byte[] inputBytes, String inputUri,
boolean useAsciiArmor, int compression, long[] encryptionKeyIds,
int symmetricEncryptionAlgorithm, long signatureKeyId, int signatureHashAlgorithm,
boolean signatureForceV3, String signaturePassphrase, IApgEncryptSignHandler handler)
boolean signatureForceV3, String signaturePassphrase, IApgEncryptHandler handler)
throws RemoteException {
encryptAndSignImplementation(inputBytes, inputUri, useAsciiArmor, compression,
@@ -265,7 +268,7 @@ public class ApgService extends Service {
public void encryptAndSignSymmetric(byte[] inputBytes, String inputUri,
boolean useAsciiArmor, int compression, String encryptionPassphrase,
int symmetricEncryptionAlgorithm, long signatureKeyId, int signatureHashAlgorithm,
boolean signatureForceV3, String signaturePassphrase, IApgEncryptSignHandler handler)
boolean signatureForceV3, String signaturePassphrase, IApgEncryptHandler handler)
throws RemoteException {
encryptAndSignImplementation(inputBytes, inputUri, useAsciiArmor, compression, null,
@@ -275,23 +278,22 @@ public class ApgService extends Service {
@Override
public void decryptAndVerifyAsymmetric(byte[] inputBytes, String inputUri,
String keyPassphrase, IApgDecryptVerifyHandler handler) throws RemoteException {
String keyPassphrase, IApgDecryptHandler handler) throws RemoteException {
decryptAndVerifyImplementation(inputBytes, inputUri, keyPassphrase, false, handler);
}
@Override
public void decryptAndVerifySymmetric(byte[] inputBytes, String inputUri,
String encryptionPassphrase, IApgDecryptVerifyHandler handler)
throws RemoteException {
String encryptionPassphrase, IApgDecryptHandler handler) throws RemoteException {
decryptAndVerifyImplementation(inputBytes, inputUri, encryptionPassphrase, true,
handler);
}
@Override
public void getDecryptionKey(byte[] inputBytes, String inputUri, IApgHelperHandler handler)
throws RemoteException {
public void getDecryptionKeyId(byte[] inputBytes, String inputUri,
IApgGetDecryptionKeyIdHandler handler) throws RemoteException {
getDecryptionKeyImplementation(inputBytes, inputUri, handler);
}

View File

@@ -0,0 +1,125 @@
/*
* 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.util.ArrayList;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.provider.ProviderHelper;
import org.thialfihar.android.apg.service.handler.IApgGetKeyringsHandler;
import org.thialfihar.android.apg.util.Log;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
/**
* TODO:
*
* - is this service thread safe? Probably not!
*
*/
public class ApgKeyService extends Service {
Context mContext;
@Override
public void onCreate() {
super.onCreate();
mContext = this;
Log.d(Constants.TAG, "ApgKeyService, onCreate()");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d(Constants.TAG, "ApgKeyService, onDestroy()");
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
/**
* 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 IApgKeyService.Stub mBinder = new IApgKeyService.Stub() {
@Override
public void getPublicKeyRings(long[] masterKeyIds, boolean asAsciiArmoredStringArray,
IApgGetKeyringsHandler handler) throws RemoteException {
if (asAsciiArmoredStringArray) {
ArrayList<String> output = ProviderHelper.getPublicKeyRingsAsArmoredString(
mContext, masterKeyIds);
handler.onSuccess(null, output);
} else {
byte[] outputBytes = ProviderHelper.getPublicKeyRingsAsByteArray(mContext,
masterKeyIds);
handler.onSuccess(outputBytes, null);
}
}
@Override
public void getSecretKeyRings(long[] masterKeyIds, boolean asAsciiArmoredStringArray,
IApgGetKeyringsHandler handler) throws RemoteException {
if (asAsciiArmoredStringArray) {
ArrayList<String> output = ProviderHelper.getSecretKeyRingsAsArmoredString(
mContext, masterKeyIds);
handler.onSuccess(null, output);
} else {
byte[] outputBytes = ProviderHelper.getSecretKeyRingsAsByteArray(mContext,
masterKeyIds);
handler.onSuccess(outputBytes, null);
}
}
};
/**
* 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;
// }
// }
}

View File

@@ -16,15 +16,15 @@
package org.thialfihar.android.apg.service;
import org.thialfihar.android.apg.service.IApgEncryptSignHandler;
import org.thialfihar.android.apg.service.IApgDecryptVerifyHandler;
import org.thialfihar.android.apg.service.IApgHelperHandler;
import org.thialfihar.android.apg.service.handler.IApgEncryptHandler;
import org.thialfihar.android.apg.service.handler.IApgDecryptHandler;
import org.thialfihar.android.apg.service.handler.IApgGetDecryptionKeyIdHandler;
/**
* 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 {
interface IApgApiService {
/**
* Encrypt
@@ -50,7 +50,7 @@ interface IApgService {
*/
oneway void encryptAsymmetric(in byte[] inputBytes, in String inputUri, in boolean useAsciiArmor,
in int compression, in long[] encryptionKeyIds, in int symmetricEncryptionAlgorithm,
in IApgEncryptSignHandler handler);
in IApgEncryptHandler handler);
/**
* Same as encryptAsymmetric but using a passphrase for symmetric encryption
@@ -60,7 +60,7 @@ interface IApgService {
*/
oneway void encryptSymmetric(in byte[] inputBytes, in String inputUri, in boolean useAsciiArmor,
in int compression, in String encryptionPassphrase, in int symmetricEncryptionAlgorithm,
in IApgEncryptSignHandler handler);
in IApgEncryptHandler handler);
/**
* Encrypt and sign
@@ -97,7 +97,7 @@ interface IApgService {
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 IApgEncryptSignHandler handler);
in IApgEncryptHandler handler);
/**
* Same as encryptAndSignAsymmetric but using a passphrase for symmetric encryption
@@ -109,7 +109,7 @@ interface IApgService {
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 IApgEncryptSignHandler handler);
in IApgEncryptHandler handler);
/**
* Decrypts and verifies given input bytes. If no signature is present this method
@@ -125,7 +125,7 @@ interface IApgService {
* Handler where to return results to after successful encryption
*/
oneway void decryptAndVerifyAsymmetric(in byte[] inputBytes, in String inputUri,
in String keyPassphrase, in IApgDecryptVerifyHandler handler);
in String keyPassphrase, in IApgDecryptHandler handler);
/**
* Same as decryptAndVerifyAsymmetric but for symmetric decryption.
@@ -134,13 +134,13 @@ interface IApgService {
* Passphrase to decrypt
*/
oneway void decryptAndVerifySymmetric(in byte[] inputBytes, in String inputUri,
in String encryptionPassphrase, in IApgDecryptVerifyHandler handler);
in String encryptionPassphrase, in IApgDecryptHandler handler);
/**
*
*/
oneway void getDecryptionKey(in byte[] inputBytes, in String inputUri,
in IApgHelperHandler handler);
oneway void getDecryptionKeyId(in byte[] inputBytes, in String inputUri,
in IApgGetDecryptionKeyIdHandler handler);
}

View File

@@ -0,0 +1,32 @@
/*
* 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 org.thialfihar.android.apg.service.handler.IApgGetKeyringsHandler;
/**
* 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 IApgKeyService {
oneway void getPublicKeyRings(in long[] masterKeyIds, in boolean asAsciiArmoredStringArray,
in IApgGetKeyringsHandler handler);
oneway void getSecretKeyRings(in long[] masterKeyIds, in boolean asAsciiArmoredStringArray,
in IApgGetKeyringsHandler handler);
}

View File

@@ -14,17 +14,14 @@
* limitations under the License.
*/
package org.thialfihar.android.apg.service;
package org.thialfihar.android.apg.service.handler;
interface IApgDecryptVerifyHandler {
interface IApgDecryptHandler {
oneway void onSuccessDecrypt(in byte[] outputBytes, in String outputUri, in boolean signature,
oneway void onSuccess(in byte[] outputBytes, in String outputUri, in boolean signature,
in long signatureKeyId, in String signatureUserId, in boolean signatureSuccess,
in boolean signatureUnknown);
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);
}

View File

@@ -14,17 +14,15 @@
* limitations under the License.
*/
package org.thialfihar.android.apg.service;
package org.thialfihar.android.apg.service.handler;
interface IApgEncryptSignHandler {
interface IApgEncryptHandler {
/**
* Either output or streamUri is given. One of them is null
*
*/
oneway void onSuccessEncrypt(in byte[] outputBytes, in String outputUri);
oneway void onSuccessSign(in byte[] outputBytes, in String outputUri);
oneway void onSuccess(in byte[] outputBytes, in String outputUri);
oneway void onException(in int exceptionNumber, in String message);
}

View File

@@ -14,12 +14,12 @@
* limitations under the License.
*/
package org.thialfihar.android.apg.service;
package org.thialfihar.android.apg.service.handler;
interface IApgGetDecryptionKeyIdHandler {
oneway void onSuccess(in long secretKeyId, in boolean symmetric);
interface IApgHelperHandler {
oneway void onSuccessGetDecryptionKey(in long secretKeyId, in boolean symmetric);
oneway void onException(in int exceptionNumber, in String message);
}

View File

@@ -0,0 +1,28 @@
/*
* 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.handler;
interface IApgGetKeyringsHandler {
/**
* Either outputBytes or outputString is given. One of them is null
*
*/
oneway void onSuccess(in byte[] outputBytes, in List<String> outputString);
oneway void onException(in int exceptionNumber, in String message);
}

View File

@@ -0,0 +1,28 @@
/*
* 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.handler;
interface IApgSignHandler {
/**
* Either output or streamUri is given. One of them is null
*
*/
oneway void onSuccess(in byte[] outputBytes, in String outputUri);
oneway void onException(in int exceptionNumber, in String message);
}

View File

@@ -0,0 +1,26 @@
/*
* 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.handler;
interface IApgVerifyHandler {
oneway void onSuccess(in boolean signature, in long signatureKeyId,
in String signatureUserId, in boolean signatureSuccess, in boolean signatureUnknown);
oneway void onException(in int exceptionNumber, in String message);
}