use of org.openintents.openpgp.util.OpenPgpApi in project andOTP by andOTP.
the class BackupActivity method backupEncryptedWithPGP.
private void backupEncryptedWithPGP(Uri uri, Intent encryptIntent) {
ArrayList<Entry> entries = DatabaseHelper.loadDatabase(this, encryptionKey);
String plainJSON = DatabaseHelper.entriesToString(entries);
if (encryptIntent == null) {
encryptIntent = new Intent();
if (settings.getOpenPGPSign()) {
encryptIntent.setAction(OpenPgpApi.ACTION_SIGN_AND_ENCRYPT);
encryptIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, pgpKeyId);
} else {
encryptIntent.setAction(OpenPgpApi.ACTION_ENCRYPT);
}
encryptIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[] { pgpKeyId });
encryptIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
}
InputStream is = new ByteArrayInputStream(plainJSON.getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream os = new ByteArrayOutputStream();
OpenPgpApi api = new OpenPgpApi(this, pgpServiceConnection.getService());
Intent result = api.executeApi(encryptIntent, is, os);
handleOpenPGPResult(result, os, uri, Constants.INTENT_BACKUP_ENCRYPT_PGP);
}
use of org.openintents.openpgp.util.OpenPgpApi in project k-9 by k9mail.
the class OpenPgpApiManager method setupCryptoProvider.
private void setupCryptoProvider() {
if (TextUtils.isEmpty(openPgpProvider)) {
setOpenPgpProviderState(OpenPgpProviderState.UNCONFIGURED);
return;
}
boolean providerIsBound = openPgpServiceConnection != null && openPgpServiceConnection.isBound();
if (providerIsBound) {
refreshConnection();
return;
}
if (openPgpServiceConnection != null) {
// We'll just wait for OnBound.onBound() to be called.
return;
}
setOpenPgpProviderState(OpenPgpProviderState.UNINITIALIZED);
openPgpServiceConnection = new OpenPgpServiceConnection(context, openPgpProvider, new OnBound() {
@Override
public void onBound(IOpenPgpService2 service) {
openPgpApi = new OpenPgpApi(context, service);
refreshConnection();
}
@Override
public void onError(Exception e) {
Timber.e(e, "error connecting to crypto provider!");
setOpenPgpProviderState(OpenPgpProviderState.ERROR);
callbackOpenPgpProviderError(OpenPgpProviderError.ConnectionFailed);
}
});
refreshConnection();
}
use of org.openintents.openpgp.util.OpenPgpApi in project andOTP by andOTP.
the class BackupActivity method restoreEncryptedWithPGP.
/* OpenPGP backup functions */
private void restoreEncryptedWithPGP(Uri uri, Intent decryptIntent) {
if (decryptIntent == null)
decryptIntent = new Intent(OpenPgpApi.ACTION_DECRYPT_VERIFY);
String input = FileHelper.readFileToString(this, uri);
Log.d("OpenPGP", input);
InputStream is = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream os = new ByteArrayOutputStream();
OpenPgpApi api = new OpenPgpApi(this, pgpServiceConnection.getService());
Intent result = api.executeApi(decryptIntent, is, os);
handleOpenPGPResult(result, os, uri, Constants.INTENT_BACKUP_DECRYPT_PGP);
}
use of org.openintents.openpgp.util.OpenPgpApi in project Android-Password-Store by zeapo.
the class AutofillService method decryptAndVerify.
private void decryptAndVerify() {
packageName = info.getPackageName();
Intent data;
if (resultData == null) {
data = new Intent();
data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
} else {
data = resultData;
resultData = null;
}
InputStream is = null;
try {
is = FileUtils.openInputStream(items.get(lastWhichItem));
} catch (IOException e) {
e.printStackTrace();
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
OpenPgpApi api = new OpenPgpApi(AutofillService.this, serviceConnection.getService());
// TODO we are dropping frames, (did we before??) find out why and maybe make this async
Intent result = api.executeApi(data, is, os);
switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
{
try {
final PasswordEntry entry = new PasswordEntry(os);
pasteText(info, entry.getPassword());
// save password entry for pasting the username as well
if (entry.hasUsername()) {
lastPassword = entry;
final int ttl = Integer.parseInt(settings.getString("general_show_time", "45"));
Toast.makeText(this, getString(R.string.autofill_toast_username, ttl), Toast.LENGTH_LONG).show();
lastPasswordMaxDate = System.currentTimeMillis() + ttl * 1000L;
}
} catch (UnsupportedEncodingException e) {
Log.e(Constants.TAG, "UnsupportedEncodingException", e);
}
break;
}
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
{
Log.i("PgpHandler", "RESULT_CODE_USER_INTERACTION_REQUIRED");
PendingIntent pi = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
// need to start a blank activity to call startIntentSenderForResult
Intent intent = new Intent(AutofillService.this, AutofillActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra("pending_intent", pi);
startActivity(intent);
break;
}
case OpenPgpApi.RESULT_CODE_ERROR:
{
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
Toast.makeText(AutofillService.this, "Error from OpenKeyChain : " + error.getMessage(), Toast.LENGTH_LONG).show();
Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId());
Log.e(Constants.TAG, "onError getMessage:" + error.getMessage());
break;
}
}
}
Aggregations