mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -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);
|
||||
|
||||
/**
|
||||
* 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.R;
|
||||
import org.sufficientlysecure.keychain.helper.PgpMain;
|
||||
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
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
|
||||
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);
|
||||
|
||||
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();
|
||||
extras.putLong(CryptoServiceActivity.EXTRA_SECRET_KEY_ID, keyId);
|
||||
pauseQueueAndStartServiceActivity(CryptoServiceActivity.ACTION_CACHE_PASSPHRASE, extras);
|
||||
|
||||
// get again after it was entered
|
||||
passphrase = PassphraseCacheService.getCachedPassphrase(mContext, keyId);
|
||||
}
|
||||
|
||||
return passphrase;
|
||||
@ -153,13 +158,7 @@ public class CryptoService extends Service {
|
||||
|
||||
private synchronized void encryptAndSignSafe(byte[] inputBytes, String[] encryptionUserIds,
|
||||
ICryptoCallback callback, AppSettings appSettings, boolean sign) throws RemoteException {
|
||||
|
||||
try {
|
||||
String passphrase = null;
|
||||
if (sign) {
|
||||
passphrase = getCachedPassphrase(appSettings.getKeyId());
|
||||
}
|
||||
|
||||
// build InputData and write into OutputStream
|
||||
InputStream inputStream = new ByteArrayInputStream(inputBytes);
|
||||
long inputLength = inputBytes.length;
|
||||
@ -170,6 +169,8 @@ public class CryptoService extends Service {
|
||||
long[] keyIds = getKeyIdsFromEmails(encryptionUserIds, appSettings.getKeyId());
|
||||
|
||||
if (sign) {
|
||||
String passphrase = getCachedPassphrase(appSettings.getKeyId());
|
||||
|
||||
PgpMain.encryptAndSign(mContext, null, inputData, outputStream,
|
||||
appSettings.isAsciiArmor(), appSettings.getCompression(), keyIds, null,
|
||||
appSettings.getEncryptionAlgorithm(), appSettings.getKeyId(),
|
||||
@ -196,12 +197,41 @@ public class CryptoService extends Service {
|
||||
Log.e(Constants.TAG, "Error returning exception to client", t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void signSafe(byte[] inputBytes, ICryptoCallback callback, AppSettings appSettings)
|
||||
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,
|
||||
@ -358,12 +388,12 @@ public class CryptoService extends Service {
|
||||
checkAndEnqueue(r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup(boolean asciiArmor, boolean newKeyring, String newKeyringUserId)
|
||||
throws RemoteException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
// @Override
|
||||
// public void setup(boolean asciiArmor, boolean newKeyring, String newKeyringUserId)
|
||||
// throws RemoteException {
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
@ -371,6 +401,7 @@ public class CryptoService extends Service {
|
||||
|
||||
@Override
|
||||
public void onRegistered(boolean success, String packageName) throws RemoteException {
|
||||
Log.d(Constants.TAG, "current therad id: " + Thread.currentThread().getId());
|
||||
|
||||
if (success) {
|
||||
// resume threads
|
||||
@ -378,17 +409,22 @@ public class CryptoService extends Service {
|
||||
mThreadPool.resume();
|
||||
} else {
|
||||
// TODO: should not happen?
|
||||
mThreadPool.shutdownNow();
|
||||
}
|
||||
} else {
|
||||
mThreadPool.resume();
|
||||
// TODO
|
||||
mPoolQueue.clear();
|
||||
// mPoolQueue.clear();
|
||||
// mPoolQueue.re
|
||||
// mThreadPool.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCachedPassphrase(boolean success) throws RemoteException {
|
||||
|
||||
Log.d(Constants.TAG, "current therad id: " + Thread.currentThread().getId());
|
||||
mThreadPool.resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -187,24 +187,6 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
||||
|
||||
AppSettings settings = new AppSettings(packageName);
|
||||
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)) {
|
||||
long secretKeyId = extras.getLong(EXTRA_SECRET_KEY_ID);
|
||||
|
||||
@ -287,6 +269,13 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
||||
Log.e(Constants.TAG, "ServiceActivity");
|
||||
}
|
||||
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";
|
||||
|
||||
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_MESSENGER = "messenger";
|
||||
|
||||
|
@ -1,17 +1,18 @@
|
||||
/*
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
* 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.
|
||||
* 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.util;
|
||||
|
Loading…
Reference in New Issue
Block a user