aboutsummaryrefslogtreecommitdiffstats
path: root/Resources
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-02-14 17:19:54 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-02-14 17:19:54 +0100
commit581e6edb4cdfb6274f21e532ba60a610a3ce1fc1 (patch)
treef144c513af5bff1dc4ddec43bc871ab7cc1263c3 /Resources
parentd6953745810bd4c6dee3bfefb538236b2b7bdbb9 (diff)
downloadopen-keychain-581e6edb4cdfb6274f21e532ba60a610a3ce1fc1.tar.gz
open-keychain-581e6edb4cdfb6274f21e532ba60a610a3ce1fc1.tar.bz2
open-keychain-581e6edb4cdfb6274f21e532ba60a610a3ce1fc1.zip
cleanup
Diffstat (limited to 'Resources')
-rw-r--r--Resources/old extended service/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiCallback.aidl24
-rw-r--r--Resources/old extended service/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiService.aidl48
-rw-r--r--Resources/old extended service/src/main/java/ExtendedApiService.java122
3 files changed, 194 insertions, 0 deletions
diff --git a/Resources/old extended service/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiCallback.aidl b/Resources/old extended service/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiCallback.aidl
new file mode 100644
index 000000000..f69f66fd7
--- /dev/null
+++ b/Resources/old extended service/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiCallback.aidl
@@ -0,0 +1,24 @@
+/*
+ * 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.service.remote;
+
+interface IExtendedApiCallback {
+
+ oneway void onSuccess(in byte[] outputBytes);
+
+ oneway void onError(in String error);
+} \ No newline at end of file
diff --git a/Resources/old extended service/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiService.aidl b/Resources/old extended service/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiService.aidl
new file mode 100644
index 000000000..669bd31b5
--- /dev/null
+++ b/Resources/old extended service/src/main/aidl/org/sufficientlysecure/keychain/service/remote/IExtendedApiService.aidl
@@ -0,0 +1,48 @@
+/*
+ * 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.service.remote;
+
+import org.sufficientlysecure.keychain.service.remote.IExtendedApiCallback;
+
+/**
+ * All methods are oneway, which means they are asynchronous and non-blocking.
+ * Results are returned to the callback, which has to be implemented on client side.
+ */
+interface IExtendedApiService {
+
+ /**
+ * Symmetric Encrypt
+ *
+ * @param inputBytes
+ * Byte array you want to encrypt
+ * @param passphrase
+ * symmetric passhprase
+ * @param callback
+ * Callback where to return results
+ */
+ oneway void encrypt(in byte[] inputBytes, in String passphrase, in IExtendedApiCallback callback);
+
+ /**
+ * Generates self signed X509 certificate signed by OpenPGP private key (from app settings)
+ *
+ * @param subjAltNameURI
+ * @param callback
+ * Callback where to return results
+ */
+ oneway void selfSignedX509Cert(in String subjAltNameURI, in IExtendedApiCallback callback);
+
+} \ No newline at end of file
diff --git a/Resources/old extended service/src/main/java/ExtendedApiService.java b/Resources/old extended service/src/main/java/ExtendedApiService.java
new file mode 100644
index 000000000..427e6bb8f
--- /dev/null
+++ b/Resources/old extended service/src/main/java/ExtendedApiService.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.sufficientlysecure.keychain.service.remote;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+import java.security.cert.X509Certificate;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.PasswordCallback;
+
+import org.spongycastle.openpgp.PGPPrivateKey;
+import org.spongycastle.openpgp.PGPSecretKey;
+import org.spongycastle.openssl.PEMWriter;
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
+import org.sufficientlysecure.keychain.pgp.PgpToX509;
+import org.sufficientlysecure.keychain.util.Log;
+
+import android.content.Intent;
+import android.os.IBinder;
+import android.os.RemoteException;
+
+public class ExtendedApiService extends RemoteService {
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return mBinder;
+ }
+
+ private void selfSignedX509CertSafe(String subjAltNameURI, IExtendedApiCallback callback,
+ AppSettings appSettings) {
+
+ // TODO: for pgp keyrings with password
+ CallbackHandler pgpPwdCallbackHandler = new PgpToX509.PredefinedPasswordCallbackHandler("");
+
+ try {
+ long keyId = appSettings.getKeyId();
+ PGPSecretKey pgpSecretKey = PgpKeyHelper.getSigningKey(this, keyId);
+
+ PasswordCallback pgpSecKeyPasswordCallBack = new PasswordCallback("pgp passphrase?",
+ false);
+ pgpPwdCallbackHandler.handle(new Callback[] { pgpSecKeyPasswordCallBack });
+ PGPPrivateKey pgpPrivKey = pgpSecretKey.extractPrivateKey(
+ pgpSecKeyPasswordCallBack.getPassword(), Constants.BOUNCY_CASTLE_PROVIDER_NAME);
+ pgpSecKeyPasswordCallBack.clearPassword();
+
+ X509Certificate selfSignedCert = PgpToX509.createSelfSignedCert(pgpSecretKey,
+ pgpPrivKey, subjAltNameURI);
+
+ // Write x509cert and privKey into files
+ // FileOutputStream fosCert = context.openFileOutput(CERT_FILENAME,
+ // Context.MODE_PRIVATE);
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ PEMWriter pemWriterCert = new PEMWriter(new PrintWriter(outStream));
+ pemWriterCert.writeObject(selfSignedCert);
+ pemWriterCert.close();
+
+ byte[] outputBytes = outStream.toByteArray();
+
+ callback.onSuccess(outputBytes);
+ } catch (Exception e) {
+ Log.e(Constants.TAG, "ExtendedApiService", e);
+ try {
+ callback.onError(e.getMessage());
+ } catch (RemoteException e1) {
+ Log.e(Constants.TAG, "ExtendedApiService", e);
+ }
+ }
+
+ // TODO: no private key at the moment! Don't give it to others
+ // PrivateKey privKey = pgpPrivKey.getKey();
+ // FileOutputStream fosKey = context.openFileOutput(PRIV_KEY_FILENAME,
+ // Context.MODE_PRIVATE);
+ // PEMWriter pemWriterKey = new PEMWriter(new PrintWriter(fosKey));
+ // pemWriterKey.writeObject(privKey);
+ // pemWriterKey.close();
+ }
+
+ private final IExtendedApiService.Stub mBinder = new IExtendedApiService.Stub() {
+
+ @Override
+ public void encrypt(byte[] inputBytes, String passphrase, IExtendedApiCallback callback)
+ throws RemoteException {
+ // TODO : implement
+
+ }
+
+ @Override
+ public void selfSignedX509Cert(final String subjAltNameURI,
+ final IExtendedApiCallback callback) throws RemoteException {
+ final AppSettings settings = getAppSettings();
+
+ Runnable r = new Runnable() {
+ @Override
+ public void run() {
+ selfSignedX509CertSafe(subjAltNameURI, callback, settings);
+ }
+ };
+
+ checkAndEnqueue(r);
+ }
+
+ };
+
+}