Search in sources :

Example 1 with PasswordEntry

use of com.zeapo.pwdstore.PasswordEntry 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

PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 PasswordEntry (com.zeapo.pwdstore.PasswordEntry)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 OpenPgpError (org.openintents.openpgp.OpenPgpError)1 OpenPgpApi (org.openintents.openpgp.util.OpenPgpApi)1