From e32c1a9ced4c3409d4cf581dc1206968b6c86ef4 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 17 Dec 2015 01:08:23 +0100 Subject: api: add micalg result extra to detached signature api call --- .../keychain/operations/results/PgpSignEncryptResult.java | 10 ++++++++++ .../keychain/pgp/PgpSignEncryptOperation.java | 8 ++++++++ .../org/sufficientlysecure/keychain/remote/OpenPgpService.java | 1 + extern/openpgp-api-lib | 2 +- extern/spongycastle | 2 +- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/PgpSignEncryptResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/PgpSignEncryptResult.java index 12b091e32..c4f66b950 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/PgpSignEncryptResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/PgpSignEncryptResult.java @@ -27,6 +27,9 @@ public class PgpSignEncryptResult extends InputPendingResult { byte[] mDetachedSignature; public long mOperationTime; + // this is the micalg parameter used in PGP/MIME, see RFC3156: + // https://tools.ietf.org/html/rfc3156#section-5 + private String mMicAlgDigestName; public void setDetachedSignature(byte[] detachedSignature) { mDetachedSignature = detachedSignature; @@ -74,4 +77,11 @@ public class PgpSignEncryptResult extends InputPendingResult { } }; + public void setMicAlgDigestName(String micAlgDigestName) { + mMicAlgDigestName = micAlgDigestName; + } + + public String getMicAlgDigestName() { + return mMicAlgDigestName; + } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java index 45641b33a..40d6a710b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncryptOperation.java @@ -32,6 +32,7 @@ import org.spongycastle.openpgp.PGPException; import org.spongycastle.openpgp.PGPLiteralData; import org.spongycastle.openpgp.PGPLiteralDataGenerator; import org.spongycastle.openpgp.PGPSignatureGenerator; +import org.spongycastle.openpgp.PGPUtil; import org.spongycastle.openpgp.operator.jcajce.JcePBEKeyEncryptionMethodGenerator; import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.NfcSyncPGPContentSignerBuilder; @@ -574,6 +575,13 @@ public class PgpSignEncryptOperation extends BaseOperation { // silently catch } result.setDetachedSignature(detachedByteOut.toByteArray()); + try { + String digestName = PGPUtil.getDigestName(input.getSignatureHashAlgorithm()); + // construct micalg parameter according to https://tools.ietf.org/html/rfc3156#section-5 + result.setMicAlgDigestName("pgp-" + digestName.toLowerCase()); + } catch (PGPException e) { + Log.e(Constants.TAG, "error setting micalg parameter!", e); + } } return result; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index 78c02681b..a6d505763 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -327,6 +327,7 @@ public class OpenPgpService extends Service { Intent result = new Intent(); if (pgpResult.getDetachedSignature() != null && !cleartextSign) { result.putExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE, pgpResult.getDetachedSignature()); + result.putExtra(OpenPgpApi.RESULT_SIGNATURE_MICALG, pgpResult.getMicAlgDigestName()); } result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); return result; diff --git a/extern/openpgp-api-lib b/extern/openpgp-api-lib index 89bf03c49..075616c46 160000 --- a/extern/openpgp-api-lib +++ b/extern/openpgp-api-lib @@ -1 +1 @@ -Subproject commit 89bf03c4985bde93d196d28beddf73ac5d7f421d +Subproject commit 075616c461f5ce2bd76a4078c31a51a6ee6b8605 diff --git a/extern/spongycastle b/extern/spongycastle index 432b7f1bf..b0acac582 160000 --- a/extern/spongycastle +++ b/extern/spongycastle @@ -1 +1 @@ -Subproject commit 432b7f1bfdc554f3b5e4e5ee1cac35bca0a6b496 +Subproject commit b0acac5821e3cc58549c76ecc16df147796e08e1 -- cgit v1.2.3