Search in sources :

Example 1 with OpenPgpApi

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);
}
Also used : Entry(org.shadowice.flocke.andotp.Database.Entry) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) OpenPgpApi(org.openintents.openpgp.util.OpenPgpApi) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with OpenPgpApi

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();
}
Also used : OnBound(org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound) OpenPgpServiceConnection(org.openintents.openpgp.util.OpenPgpServiceConnection) OpenPgpApi(org.openintents.openpgp.util.OpenPgpApi)

Example 3 with OpenPgpApi

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) OpenPgpApi(org.openintents.openpgp.util.OpenPgpApi) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with OpenPgpApi

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;
            }
    }
}
Also used : InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) OpenPgpApi(org.openintents.openpgp.util.OpenPgpApi) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PendingIntent(android.app.PendingIntent) OpenPgpError(org.openintents.openpgp.OpenPgpError) PasswordEntry(com.zeapo.pwdstore.PasswordEntry)

Aggregations

OpenPgpApi (org.openintents.openpgp.util.OpenPgpApi)4 PendingIntent (android.app.PendingIntent)3 Intent (android.content.Intent)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 PasswordEntry (com.zeapo.pwdstore.PasswordEntry)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 OpenPgpError (org.openintents.openpgp.OpenPgpError)1 OpenPgpServiceConnection (org.openintents.openpgp.util.OpenPgpServiceConnection)1 OnBound (org.openintents.openpgp.util.OpenPgpServiceConnection.OnBound)1 Entry (org.shadowice.flocke.andotp.Database.Entry)1