Search in sources :

Example 1 with OpenPgpSignatureResult

use of org.openintents.openpgp.OpenPgpSignatureResult in project k-9 by k9mail.

the class MessageCryptoHelper method handleCryptoOperationSuccess.

private void handleCryptoOperationSuccess(MimeBodyPart outputPart) {
    OpenPgpDecryptionResult decryptionResult = currentCryptoResult.getParcelableExtra(OpenPgpApi.RESULT_DECRYPTION);
    OpenPgpSignatureResult signatureResult = currentCryptoResult.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
    PendingIntent pendingIntent = currentCryptoResult.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
    CryptoResultAnnotation resultAnnotation = CryptoResultAnnotation.createOpenPgpResultAnnotation(decryptionResult, signatureResult, pendingIntent, outputPart);
    onCryptoOperationSuccess(resultAnnotation);
}
Also used : OpenPgpDecryptionResult(org.openintents.openpgp.OpenPgpDecryptionResult) CryptoResultAnnotation(com.fsck.k9.mailstore.CryptoResultAnnotation) PendingIntent(android.app.PendingIntent) OpenPgpSignatureResult(org.openintents.openpgp.OpenPgpSignatureResult)

Example 2 with OpenPgpSignatureResult

use of org.openintents.openpgp.OpenPgpSignatureResult in project Conversations by siacs.

the class PgpEngine method fetchKeyId.

public long fetchKeyId(Account account, String status, String signature) {
    if ((signature == null) || (api == null)) {
        return 0;
    }
    if (status == null) {
        status = "";
    }
    final StringBuilder pgpSig = new StringBuilder();
    pgpSig.append("-----BEGIN PGP SIGNED MESSAGE-----");
    pgpSig.append('\n');
    pgpSig.append('\n');
    pgpSig.append(status);
    pgpSig.append('\n');
    pgpSig.append("-----BEGIN PGP SIGNATURE-----");
    pgpSig.append('\n');
    pgpSig.append('\n');
    pgpSig.append(signature.replace("\n", "").trim());
    pgpSig.append('\n');
    pgpSig.append("-----END PGP SIGNATURE-----");
    Intent params = new Intent();
    params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
    params.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
    InputStream is = new ByteArrayInputStream(pgpSig.toString().getBytes());
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    Intent result = api.executeApi(params, is, os);
    switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
        case OpenPgpApi.RESULT_CODE_SUCCESS:
            OpenPgpSignatureResult sigResult = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
            if (sigResult != null) {
                return sigResult.getKeyId();
            } else {
                return 0;
            }
        case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
            return 0;
        case OpenPgpApi.RESULT_CODE_ERROR:
            logError(account, (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
            return 0;
    }
    return 0;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OpenPgpSignatureResult(org.openintents.openpgp.OpenPgpSignatureResult)

Aggregations

PendingIntent (android.app.PendingIntent)2 OpenPgpSignatureResult (org.openintents.openpgp.OpenPgpSignatureResult)2 Intent (android.content.Intent)1 CryptoResultAnnotation (com.fsck.k9.mailstore.CryptoResultAnnotation)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 OpenPgpDecryptionResult (org.openintents.openpgp.OpenPgpDecryptionResult)1