mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-02 13:32:19 -05:00
sign via api
This commit is contained in:
parent
4d1d3f6f5e
commit
03d9afffce
@ -71,10 +71,4 @@ interface ICryptoService {
|
|||||||
*/
|
*/
|
||||||
oneway void decryptAndVerify(in byte[] inputBytes, in ICryptoCallback callback);
|
oneway void decryptAndVerify(in byte[] inputBytes, in ICryptoCallback callback);
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens setup using default parameters
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
oneway void setup(boolean asciiArmor, boolean newKeyring, String newKeyringUserId);
|
|
||||||
|
|
||||||
}
|
}
|
@ -33,6 +33,7 @@ import org.sufficientlysecure.keychain.Constants;
|
|||||||
import org.sufficientlysecure.keychain.Id;
|
import org.sufficientlysecure.keychain.Id;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.helper.PgpMain;
|
import org.sufficientlysecure.keychain.helper.PgpMain;
|
||||||
|
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
@ -56,7 +57,8 @@ public class CryptoService extends Service {
|
|||||||
|
|
||||||
// just one pool of 4 threads, pause on every user action needed
|
// just one pool of 4 threads, pause on every user action needed
|
||||||
final ArrayBlockingQueue<Runnable> mPoolQueue = new ArrayBlockingQueue<Runnable>(20);
|
final ArrayBlockingQueue<Runnable> mPoolQueue = new ArrayBlockingQueue<Runnable>(20);
|
||||||
PausableThreadPoolExecutor mThreadPool = new PausableThreadPoolExecutor(2, 4, 10,
|
// TODO: ? only one pool, -> one thread at a time
|
||||||
|
PausableThreadPoolExecutor mThreadPool = new PausableThreadPoolExecutor(1, 1, 10,
|
||||||
TimeUnit.SECONDS, mPoolQueue);
|
TimeUnit.SECONDS, mPoolQueue);
|
||||||
|
|
||||||
public static final String ACTION_SERVICE_ACTIVITY = "org.sufficientlysecure.keychain.crypto_provider.IServiceActivityCallback";
|
public static final String ACTION_SERVICE_ACTIVITY = "org.sufficientlysecure.keychain.crypto_provider.IServiceActivityCallback";
|
||||||
@ -101,6 +103,9 @@ public class CryptoService extends Service {
|
|||||||
Bundle extras = new Bundle();
|
Bundle extras = new Bundle();
|
||||||
extras.putLong(CryptoServiceActivity.EXTRA_SECRET_KEY_ID, keyId);
|
extras.putLong(CryptoServiceActivity.EXTRA_SECRET_KEY_ID, keyId);
|
||||||
pauseQueueAndStartServiceActivity(CryptoServiceActivity.ACTION_CACHE_PASSPHRASE, extras);
|
pauseQueueAndStartServiceActivity(CryptoServiceActivity.ACTION_CACHE_PASSPHRASE, extras);
|
||||||
|
|
||||||
|
// get again after it was entered
|
||||||
|
passphrase = PassphraseCacheService.getCachedPassphrase(mContext, keyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return passphrase;
|
return passphrase;
|
||||||
@ -153,13 +158,7 @@ public class CryptoService extends Service {
|
|||||||
|
|
||||||
private synchronized void encryptAndSignSafe(byte[] inputBytes, String[] encryptionUserIds,
|
private synchronized void encryptAndSignSafe(byte[] inputBytes, String[] encryptionUserIds,
|
||||||
ICryptoCallback callback, AppSettings appSettings, boolean sign) throws RemoteException {
|
ICryptoCallback callback, AppSettings appSettings, boolean sign) throws RemoteException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String passphrase = null;
|
|
||||||
if (sign) {
|
|
||||||
passphrase = getCachedPassphrase(appSettings.getKeyId());
|
|
||||||
}
|
|
||||||
|
|
||||||
// build InputData and write into OutputStream
|
// build InputData and write into OutputStream
|
||||||
InputStream inputStream = new ByteArrayInputStream(inputBytes);
|
InputStream inputStream = new ByteArrayInputStream(inputBytes);
|
||||||
long inputLength = inputBytes.length;
|
long inputLength = inputBytes.length;
|
||||||
@ -170,6 +169,8 @@ public class CryptoService extends Service {
|
|||||||
long[] keyIds = getKeyIdsFromEmails(encryptionUserIds, appSettings.getKeyId());
|
long[] keyIds = getKeyIdsFromEmails(encryptionUserIds, appSettings.getKeyId());
|
||||||
|
|
||||||
if (sign) {
|
if (sign) {
|
||||||
|
String passphrase = getCachedPassphrase(appSettings.getKeyId());
|
||||||
|
|
||||||
PgpMain.encryptAndSign(mContext, null, inputData, outputStream,
|
PgpMain.encryptAndSign(mContext, null, inputData, outputStream,
|
||||||
appSettings.isAsciiArmor(), appSettings.getCompression(), keyIds, null,
|
appSettings.isAsciiArmor(), appSettings.getCompression(), keyIds, null,
|
||||||
appSettings.getEncryptionAlgorithm(), appSettings.getKeyId(),
|
appSettings.getEncryptionAlgorithm(), appSettings.getKeyId(),
|
||||||
@ -196,12 +197,41 @@ public class CryptoService extends Service {
|
|||||||
Log.e(Constants.TAG, "Error returning exception to client", t);
|
Log.e(Constants.TAG, "Error returning exception to client", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void signSafe(byte[] inputBytes, ICryptoCallback callback, AppSettings appSettings)
|
private void signSafe(byte[] inputBytes, ICryptoCallback callback, AppSettings appSettings)
|
||||||
throws RemoteException {
|
throws RemoteException {
|
||||||
// TODO!
|
try {
|
||||||
|
Log.d(Constants.TAG, "current therad id: " + Thread.currentThread().getId());
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
String passphrase = getCachedPassphrase(appSettings.getKeyId());
|
||||||
|
|
||||||
|
PgpMain.signText(this, null, inputData, outputStream, appSettings.getKeyId(),
|
||||||
|
passphrase, appSettings.getHashAlgorithm(), Preferences.getPreferences(this)
|
||||||
|
.getForceV3Signatures());
|
||||||
|
|
||||||
|
outputStream.close();
|
||||||
|
|
||||||
|
byte[] outputBytes = ((ByteArrayOutputStream) outputStream).toByteArray();
|
||||||
|
|
||||||
|
// return over handler on client side
|
||||||
|
callback.onSuccess(outputBytes, null);
|
||||||
|
} 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 synchronized void decryptAndVerifySafe(byte[] inputBytes, ICryptoCallback callback,
|
private synchronized void decryptAndVerifySafe(byte[] inputBytes, ICryptoCallback callback,
|
||||||
@ -358,12 +388,12 @@ public class CryptoService extends Service {
|
|||||||
checkAndEnqueue(r);
|
checkAndEnqueue(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public void setup(boolean asciiArmor, boolean newKeyring, String newKeyringUserId)
|
// public void setup(boolean asciiArmor, boolean newKeyring, String newKeyringUserId)
|
||||||
throws RemoteException {
|
// throws RemoteException {
|
||||||
// TODO Auto-generated method stub
|
//
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -371,6 +401,7 @@ public class CryptoService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRegistered(boolean success, String packageName) throws RemoteException {
|
public void onRegistered(boolean success, String packageName) throws RemoteException {
|
||||||
|
Log.d(Constants.TAG, "current therad id: " + Thread.currentThread().getId());
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
// resume threads
|
// resume threads
|
||||||
@ -378,17 +409,22 @@ public class CryptoService extends Service {
|
|||||||
mThreadPool.resume();
|
mThreadPool.resume();
|
||||||
} else {
|
} else {
|
||||||
// TODO: should not happen?
|
// TODO: should not happen?
|
||||||
|
mThreadPool.shutdownNow();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
mThreadPool.resume();
|
||||||
// TODO
|
// TODO
|
||||||
mPoolQueue.clear();
|
// mPoolQueue.clear();
|
||||||
|
// mPoolQueue.re
|
||||||
|
// mThreadPool.
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCachedPassphrase(boolean success) throws RemoteException {
|
public void onCachedPassphrase(boolean success) throws RemoteException {
|
||||||
|
Log.d(Constants.TAG, "current therad id: " + Thread.currentThread().getId());
|
||||||
|
mThreadPool.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -187,24 +187,6 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
|||||||
|
|
||||||
AppSettings settings = new AppSettings(packageName);
|
AppSettings settings = new AppSettings(packageName);
|
||||||
mSettingsFragment.setAppSettings(settings);
|
mSettingsFragment.setAppSettings(settings);
|
||||||
|
|
||||||
// TODO: handle if app is already registered
|
|
||||||
// LinearLayout layoutRegister = (LinearLayout)
|
|
||||||
// findViewById(R.id.register_crypto_consumer_register_layout);
|
|
||||||
// LinearLayout layoutEdit = (LinearLayout)
|
|
||||||
// findViewById(R.id.register_crypto_consumer_edit_layout);
|
|
||||||
//
|
|
||||||
// // if already registered show edit buttons
|
|
||||||
// ArrayList<String> allowedPkgs = ProviderHelper.getCryptoConsumers(this);
|
|
||||||
// if (allowedPkgs.contains(packageName)) {
|
|
||||||
// Log.d(Constants.TAG, "Package is allowed! packageName: " + packageName);
|
|
||||||
// layoutRegister.setVisibility(View.GONE);
|
|
||||||
// layoutEdit.setVisibility(View.VISIBLE);
|
|
||||||
// } else {
|
|
||||||
// layoutRegister.setVisibility(View.VISIBLE);
|
|
||||||
// layoutEdit.setVisibility(View.GONE);
|
|
||||||
// }
|
|
||||||
|
|
||||||
} else if (ACTION_CACHE_PASSPHRASE.equals(action)) {
|
} else if (ACTION_CACHE_PASSPHRASE.equals(action)) {
|
||||||
long secretKeyId = extras.getLong(EXTRA_SECRET_KEY_ID);
|
long secretKeyId = extras.getLong(EXTRA_SECRET_KEY_ID);
|
||||||
|
|
||||||
@ -287,6 +269,13 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
|||||||
Log.e(Constants.TAG, "ServiceActivity");
|
Log.e(Constants.TAG, "ServiceActivity");
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
mServiceCallback.onCachedPassphrase(false);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(Constants.TAG, "ServiceActivity");
|
||||||
|
}
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -67,7 +67,7 @@ public class PassphraseCacheService extends Service {
|
|||||||
+ "PASSPHRASE_CACHE_BROADCAST";
|
+ "PASSPHRASE_CACHE_BROADCAST";
|
||||||
|
|
||||||
public static final String EXTRA_TTL = "ttl";
|
public static final String EXTRA_TTL = "ttl";
|
||||||
public static final String EXTRA_KEY_ID = "keyId";
|
public static final String EXTRA_KEY_ID = "key_id";
|
||||||
public static final String EXTRA_PASSPHRASE = "passphrase";
|
public static final String EXTRA_PASSPHRASE = "passphrase";
|
||||||
public static final String EXTRA_MESSENGER = "messenger";
|
public static final String EXTRA_MESSENGER = "messenger";
|
||||||
|
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
|
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* you may not use this file except in compliance with the License.
|
* it under the terms of the GNU General Public License as published by
|
||||||
* You may obtain a copy of the License at
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* 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.
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* You should have received a copy of the GNU General Public License
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* 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.util;
|
package org.sufficientlysecure.keychain.util;
|
||||||
|
Loading…
Reference in New Issue
Block a user