1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-30 00:02:06 +01:00

Adapt changes to PGPSignatureGenerator

This commit is contained in:
Paul Schaub 2024-06-30 18:55:27 +02:00
parent e2cf1a474e
commit a230c48393
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
6 changed files with 18 additions and 11 deletions

View file

@ -7,6 +7,7 @@ package org.pgpainless.encryption_signing
import java.security.MessageDigest
import org.bouncycastle.openpgp.PGPException
import org.bouncycastle.openpgp.PGPPrivateKey
import org.bouncycastle.openpgp.PGPPublicKey
import org.bouncycastle.openpgp.PGPSecretKeyRing
import org.bouncycastle.openpgp.PGPSignature
import org.bouncycastle.openpgp.PGPSignatureGenerator
@ -29,7 +30,9 @@ class BcHashContextSigner {
return info.signingSubkeys
.mapNotNull { info.getSecretKey(it.keyID) }
.firstOrNull()
?.let { signHashContext(hashContext, signatureType, it.unlock(protector)) }
?.let {
signHashContext(hashContext, signatureType, it.unlock(protector), it.publicKey)
}
?: throw PGPException("Key does not contain suitable signing subkey.")
}
@ -45,9 +48,11 @@ class BcHashContextSigner {
internal fun signHashContext(
hashContext: MessageDigest,
signatureType: SignatureType,
privateKey: PGPPrivateKey
privateKey: PGPPrivateKey,
publicKey: PGPPublicKey
): PGPSignature {
return PGPSignatureGenerator(BcPGPHashContextContentSignerBuilder(hashContext))
return PGPSignatureGenerator(
BcPGPHashContextContentSignerBuilder(hashContext), publicKey)
.apply { init(signatureType.code, privateKey) }
.generate()
}

View file

@ -385,7 +385,7 @@ class SigningOptions {
val generator: PGPSignatureGenerator =
createSignatureGenerator(
signingSubkey,
signingKey.getPublicKey(signingSubkey.keyID).version,
signingKey.getPublicKey(signingSubkey.keyID),
hashAlgorithm,
signatureType)
@ -429,7 +429,7 @@ class SigningOptions {
@Throws(PGPException::class)
private fun createSignatureGenerator(
privateKey: PGPPrivateKey,
signatureVersion: Int,
publicKey: PGPPublicKey,
hashAlgorithm: HashAlgorithm,
signatureType: DocumentSignatureType
): PGPSignatureGenerator {
@ -437,7 +437,7 @@ class SigningOptions {
.getPGPContentSignerBuilder(
privateKey.publicKeyPacket.algorithm, hashAlgorithm.algorithmId)
.let { csb ->
PGPSignatureGenerator(csb, signatureVersion).also {
PGPSignatureGenerator(csb, publicKey).also {
it.init(signatureType.signatureType.code, privateKey)
}
}

View file

@ -94,7 +94,7 @@ class KeyRingBuilder : KeyRingBuilderInterface<KeyRingBuilder> {
requireNotNull(primaryKeySpec) { "Primary Key spec required." }
val certKey = generateKeyPair(primaryKeySpec!!)
val signer = buildContentSigner(certKey)
val signatureGenerator = PGPSignatureGenerator(signer)
val signatureGenerator = PGPSignatureGenerator(signer, certKey.publicKey)
val hashedSubPacketGenerator = primaryKeySpec!!.subpacketGenerator
hashedSubPacketGenerator.setIssuerFingerprintAndKeyId(certKey.publicKey)
@ -206,7 +206,8 @@ class KeyRingBuilder : KeyRingBuilderInterface<KeyRingBuilder> {
return hashedSubpackets
}
val bindingSignatureGenerator = PGPSignatureGenerator(buildContentSigner(subKey))
val bindingSignatureGenerator =
PGPSignatureGenerator(buildContentSigner(subKey), subKey.publicKey)
bindingSignatureGenerator.init(SignatureType.PRIMARYKEY_BINDING.code, subKey.privateKey)
val primaryKeyBindingSig =
bindingSignatureGenerator.generateCertification(primaryKey.publicKey, subKey.publicKey)

View file

@ -226,7 +226,8 @@ class PublicKeyParameterValidationUtil {
PGPSignatureGenerator(
getInstance()
.getPGPContentSignerBuilder(
requireFromId(publicKey.algorithm), HashAlgorithm.SHA256))
requireFromId(publicKey.algorithm), HashAlgorithm.SHA256),
publicKey)
return try {
signatureGenerator
.apply {

View file

@ -111,7 +111,8 @@ abstract class AbstractSignatureBuilder<B : AbstractSignatureBuilder<B>>(
PGPSignatureGenerator(
ImplementationFactory.getInstance()
.getPGPContentSignerBuilder(
publicSigningKey.algorithm, hashAlgorithm.algorithmId))
publicSigningKey.algorithm, hashAlgorithm.algorithmId),
publicSigningKey)
.apply {
setUnhashedSubpackets(SignatureSubpacketsHelper.toVector(_unhashedSubpackets))
setHashedSubpackets(SignatureSubpacketsHelper.toVector(_hashedSubpackets))

View file

@ -6,7 +6,6 @@ package org.pgpainless.key
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.pgpainless.PGPainless