api: add micalg result extra to detached signature api call

This commit is contained in:
Vincent Breitmoser
2015-12-17 01:08:23 +01:00
parent 5344307e22
commit e32c1a9ced
5 changed files with 21 additions and 2 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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;