mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-18 02:12:06 +01:00
Add issuer-fingerprint to message signatures
This commit is contained in:
parent
5422468d73
commit
6a11e39d76
1 changed files with 12 additions and 2 deletions
|
@ -29,6 +29,7 @@ import org.bouncycastle.openpgp.PGPSecretKey;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||||
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
import org.bouncycastle.openpgp.PGPSignatureGenerator;
|
||||||
|
import org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator;
|
||||||
import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder;
|
import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder;
|
||||||
import org.pgpainless.PGPainless;
|
import org.pgpainless.PGPainless;
|
||||||
import org.pgpainless.algorithm.DocumentSignatureType;
|
import org.pgpainless.algorithm.DocumentSignatureType;
|
||||||
|
@ -266,7 +267,7 @@ public final class SigningOptions {
|
||||||
boolean detached)
|
boolean detached)
|
||||||
throws PGPException {
|
throws PGPException {
|
||||||
SubkeyIdentifier signingKeyIdentifier = new SubkeyIdentifier(secretKey, signingSubkey.getKeyID());
|
SubkeyIdentifier signingKeyIdentifier = new SubkeyIdentifier(secretKey, signingSubkey.getKeyID());
|
||||||
PGPSignatureGenerator generator = createSignatureGenerator(signingSubkey, hashAlgorithm, signatureType);
|
PGPSignatureGenerator generator = createSignatureGenerator(secretKey.getSecretKey(signingSubkey.getKeyID()), signingSubkey, hashAlgorithm, signatureType);
|
||||||
SigningMethod signingMethod = detached ? SigningMethod.detachedSignature(generator) : SigningMethod.inlineSignature(generator);
|
SigningMethod signingMethod = detached ? SigningMethod.detachedSignature(generator) : SigningMethod.inlineSignature(generator);
|
||||||
signingMethods.put(signingKeyIdentifier, signingMethod);
|
signingMethods.put(signingKeyIdentifier, signingMethod);
|
||||||
}
|
}
|
||||||
|
@ -302,7 +303,8 @@ public final class SigningOptions {
|
||||||
return algorithm;
|
return algorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PGPSignatureGenerator createSignatureGenerator(PGPPrivateKey privateKey,
|
private PGPSignatureGenerator createSignatureGenerator(PGPSecretKey secretKey,
|
||||||
|
PGPPrivateKey privateKey,
|
||||||
HashAlgorithm hashAlgorithm,
|
HashAlgorithm hashAlgorithm,
|
||||||
DocumentSignatureType signatureType)
|
DocumentSignatureType signatureType)
|
||||||
throws PGPException {
|
throws PGPException {
|
||||||
|
@ -310,11 +312,19 @@ public final class SigningOptions {
|
||||||
PGPContentSignerBuilder signerBuilder = ImplementationFactory.getInstance()
|
PGPContentSignerBuilder signerBuilder = ImplementationFactory.getInstance()
|
||||||
.getPGPContentSignerBuilder(publicKeyAlgorithm, hashAlgorithm.getAlgorithmId());
|
.getPGPContentSignerBuilder(publicKeyAlgorithm, hashAlgorithm.getAlgorithmId());
|
||||||
PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(signerBuilder);
|
PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(signerBuilder);
|
||||||
|
signatureGenerator.setUnhashedSubpackets(unhashedSubpackets(secretKey).generate());
|
||||||
signatureGenerator.init(signatureType.getSignatureType().getCode(), privateKey);
|
signatureGenerator.init(signatureType.getSignatureType().getCode(), privateKey);
|
||||||
|
|
||||||
return signatureGenerator;
|
return signatureGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PGPSignatureSubpacketGenerator unhashedSubpackets(PGPSecretKey key) {
|
||||||
|
PGPSignatureSubpacketGenerator generator = new PGPSignatureSubpacketGenerator();
|
||||||
|
generator.setIssuerKeyID(false, key.getKeyID());
|
||||||
|
generator.setIssuerFingerprint(false, key);
|
||||||
|
return generator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a map of key-ids and signing methods.
|
* Return a map of key-ids and signing methods.
|
||||||
* For internal use.
|
* For internal use.
|
||||||
|
|
Loading…
Reference in a new issue