aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider
diff options
context:
space:
mode:
Diffstat (limited to 'OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider')
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoActivity.java92
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java196
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/RegisterActivity.java74
3 files changed, 0 insertions, 362 deletions
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoActivity.java
deleted file mode 100644
index b1d248e42..000000000
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoActivity.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package org.sufficientlysecure.keychain.crypto_provider;
-
-import org.sufficientlysecure.keychain.Constants;
-import org.sufficientlysecure.keychain.Id;
-import org.sufficientlysecure.keychain.R;
-import org.sufficientlysecure.keychain.helper.PgpMain;
-import org.sufficientlysecure.keychain.provider.ProviderHelper;
-import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
-import org.sufficientlysecure.keychain.util.Log;
-
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.os.Messenger;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-
-public class CryptoActivity extends SherlockFragmentActivity {
-
- public static final String ACTION_CACHE_PASSPHRASE = "org.sufficientlysecure.keychain.CRYPTO_CACHE_PASSPHRASE";
-
- public static final String EXTRA_SECRET_KEY_ID = "secret_key_id";
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- handleActions(getIntent());
- }
-
- protected void handleActions(Intent intent) {
-
- // TODO: Important: Check if calling package is in list!
-
- String action = intent.getAction();
- Bundle extras = intent.getExtras();
-
- if (extras == null) {
- extras = new Bundle();
- }
-
- /**
- * com.android.crypto actions
- */
- if (ACTION_CACHE_PASSPHRASE.equals(action)) {
- long secretKeyId = extras.getLong(EXTRA_SECRET_KEY_ID);
-
- showPassphraseDialog(secretKeyId);
- } else {
- Log.e(Constants.TAG, "Wrong action!");
- setResult(RESULT_CANCELED);
- finish();
- }
- }
-
- /**
- * Shows passphrase dialog to cache a new passphrase the user enters for using it later for
- * encryption. Based on mSecretKeyId it asks for a passphrase to open a private key or it asks
- * for a symmetric passphrase
- */
- private void showPassphraseDialog(long secretKeyId) {
- // Message is received after passphrase is cached
- Handler returnHandler = new Handler() {
- @Override
- public void handleMessage(Message message) {
- if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
- setResult(RESULT_OK);
- finish();
- }
- }
- };
-
- // Create a new Messenger for the communication back
- Messenger messenger = new Messenger(returnHandler);
-
- try {
- PassphraseDialogFragment passphraseDialog = PassphraseDialogFragment.newInstance(this,
- messenger, secretKeyId);
-
- passphraseDialog.show(getSupportFragmentManager(), "passphraseDialog");
- } catch (PgpMain.PgpGeneralException e) {
- Log.d(Constants.TAG, "No passphrase for this secret key, encrypt directly!");
- // send message to handler to start encryption directly
- returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY);
- }
- }
-}
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java
deleted file mode 100644
index 1a57a457d..000000000
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * 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.sufficientlysecure.keychain.crypto_provider;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import org.sufficientlysecure.keychain.Constants;
-import org.sufficientlysecure.keychain.Id;
-import org.sufficientlysecure.keychain.helper.PgpMain;
-import org.sufficientlysecure.keychain.util.InputData;
-import org.sufficientlysecure.keychain.util.Log;
-import org.sufficientlysecure.keychain.R;
-import org.sufficientlysecure.keychain.service.KeychainIntentService;
-import org.sufficientlysecure.keychain.service.PassphraseCacheService;
-
-import com.android.crypto.CryptoError;
-import com.android.crypto.ICryptoCallback;
-import com.android.crypto.ICryptoService;
-import com.android.crypto.CryptoSignatureResult;
-
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.RemoteException;
-
-public class CryptoService extends Service {
- Context mContext;
-
- @Override
- public void onCreate() {
- super.onCreate();
- mContext = this;
- Log.d(Constants.TAG, "CryptoService, onCreate()");
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- Log.d(Constants.TAG, "CryptoService, onDestroy()");
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- return mBinder;
- }
-
- private synchronized void decryptAndVerifySafe(byte[] inputBytes, ICryptoCallback callback)
- throws RemoteException {
- try {
- // build InputData and write into OutputStream
- InputStream inputStream = new ByteArrayInputStream(inputBytes);
- long inputLength = inputBytes.length;
- InputData inputData = new InputData(inputStream, inputLength);
-
- OutputStream outputStream = new ByteArrayOutputStream();
-
- long secretKeyId = PgpMain.getDecryptionKeyId(mContext, inputStream);
- if (secretKeyId == Id.key.none) {
- throw new PgpMain.PgpGeneralException(getString(R.string.error_noSecretKeyFound));
- }
-
- Log.d(Constants.TAG, "Got input:\n"+new String(inputBytes));
-
- Log.d(Constants.TAG, "secretKeyId " + secretKeyId);
-
- String passphrase = PassphraseCacheService.getCachedPassphrase(mContext, secretKeyId);
-
- if (passphrase == null) {
- Log.d(Constants.TAG, "No passphrase! Activity required!");
- // No passphrase cached for this ciphertext! Intent required to cache
- // passphrase!
- Intent intent = new Intent(CryptoActivity.ACTION_CACHE_PASSPHRASE);
- intent.putExtra(CryptoActivity.EXTRA_SECRET_KEY_ID, secretKeyId);
- callback.onActivityRequired(intent);
- return;
- }
-
- // if (signedOnly) {
- // resultData = PgpMain.verifyText(this, this, inputData, outStream,
- // lookupUnknownKey);
- // } else {
- // resultData = PgpMain.decryptAndVerify(this, this, inputData, outStream,
- // PassphraseCacheService.getCachedPassphrase(this, secretKeyId),
- // assumeSymmetricEncryption);
- // }
-
- Bundle outputBundle = PgpMain.decryptAndVerify(mContext, null, inputData, outputStream,
- passphrase, false);
-
- outputStream.close();
-
- byte[] outputBytes = ((ByteArrayOutputStream) outputStream).toByteArray();
-
- // get signature informations from bundle
- boolean signature = outputBundle.getBoolean(KeychainIntentService.RESULT_SIGNATURE);
- long signatureKeyId = outputBundle
- .getLong(KeychainIntentService.RESULT_SIGNATURE_KEY_ID);
- String signatureUserId = outputBundle
- .getString(KeychainIntentService.RESULT_SIGNATURE_USER_ID);
- boolean signatureSuccess = outputBundle
- .getBoolean(KeychainIntentService.RESULT_SIGNATURE_SUCCESS);
- boolean signatureUnknown = outputBundle
- .getBoolean(KeychainIntentService.RESULT_SIGNATURE_UNKNOWN);
-
- CryptoSignatureResult sigResult = new CryptoSignatureResult(signatureUserId, signature,
- signatureSuccess, signatureUnknown);
-
- // return over handler on client side
- callback.onDecryptVerifySuccess(outputBytes, sigResult);
- } catch (Exception e) {
- Log.e(Constants.TAG, "KeychainService, Exception!", e);
-
- try {
- callback.onError(new CryptoError(0, e.getMessage()));
- } catch (Exception t) {
- Log.e(Constants.TAG, "Error returning exception to client", t);
- }
- }
- }
-
- private final ICryptoService.Stub mBinder = new ICryptoService.Stub() {
-
- @Override
- public void encrypt(byte[] inputBytes, String[] encryptionUserIds, ICryptoCallback callback)
- throws RemoteException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void encryptAndSign(byte[] inputBytes, String[] encryptionUserIds,
- String signatureUserId, ICryptoCallback callback) throws RemoteException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void sign(byte[] inputBytes, String signatureUserId, ICryptoCallback callback)
- throws RemoteException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void decryptAndVerify(byte[] inputBytes, ICryptoCallback callback)
- throws RemoteException {
- decryptAndVerifySafe(inputBytes, callback);
- }
-
- };
-
- // /**
- // * 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 PgpGeneralException) {
- // return 4;
- // } else if (e instanceof PGPException) {
- // return 5;
- // } else {
- // return -1;
- // }
- // }
-
-}
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/RegisterActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/RegisterActivity.java
deleted file mode 100644
index 39b29f9a0..000000000
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/RegisterActivity.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.sufficientlysecure.keychain.crypto_provider;
-
-import org.sufficientlysecure.keychain.Constants;
-import org.sufficientlysecure.keychain.R;
-import org.sufficientlysecure.keychain.provider.ProviderHelper;
-import org.sufficientlysecure.keychain.util.Log;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-
-public class RegisterActivity extends Activity {
-
- public static final String ACTION_REGISTER = "com.android.crypto.REGISTER";
-
- public static final String EXTRA_PACKAGE_NAME = "packageName";
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- handleActions(getIntent());
- }
-
- protected void handleActions(Intent intent) {
- String action = intent.getAction();
- Bundle extras = intent.getExtras();
-
- if (extras == null) {
- extras = new Bundle();
- }
-
- final String callingPackageName = this.getCallingPackage();
-
- /**
- * com.android.crypto actions
- */
- if (ACTION_REGISTER.equals(action)) {
- setContentView(R.layout.register_crypto_consumer_activity);
-
- Button allowButton = (Button) findViewById(R.id.register_crypto_consumer_allow);
- Button disallowButton = (Button) findViewById(R.id.register_crypto_consumer_disallow);
-
- allowButton.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- ProviderHelper.addCryptoConsumer(RegisterActivity.this, callingPackageName);
- Intent data = new Intent();
- data.putExtra(EXTRA_PACKAGE_NAME, "org.sufficientlysecure.keychain");
-
- setResult(RESULT_OK, data);
- finish();
- }
- });
-
- disallowButton.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- setResult(RESULT_CANCELED);
- finish();
- }
- });
-
- } else {
- Log.e(Constants.TAG, "Please use com.android.crypto.REGISTER as intent action!");
- finish();
- }
- }
-}