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:
parent
e2cf1a474e
commit
a230c48393
6 changed files with 18 additions and 11 deletions
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -226,7 +226,8 @@ class PublicKeyParameterValidationUtil {
|
|||
PGPSignatureGenerator(
|
||||
getInstance()
|
||||
.getPGPContentSignerBuilder(
|
||||
requireFromId(publicKey.algorithm), HashAlgorithm.SHA256))
|
||||
requireFromId(publicKey.algorithm), HashAlgorithm.SHA256),
|
||||
publicKey)
|
||||
return try {
|
||||
signatureGenerator
|
||||
.apply {
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue