1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-09-09 18:29:39 +02:00

Fix addSubkey method

This commit is contained in:
Paul Schaub 2025-02-24 12:32:45 +01:00
parent d5a0c83abe
commit 2eca5f0ef0
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -12,7 +12,9 @@ import openpgp.openPgpKeyId
import org.bouncycastle.bcpg.KeyIdentifier
import org.bouncycastle.bcpg.sig.KeyExpirationTime
import org.bouncycastle.openpgp.*
import org.bouncycastle.openpgp.api.OpenPGPCertificate.OpenPGPSubkey
import org.bouncycastle.openpgp.api.OpenPGPKey
import org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPSecretKey
import org.bouncycastle.openpgp.api.OpenPGPSignature
import org.pgpainless.PGPainless
import org.pgpainless.PGPainless.Companion.inspectKeyRing
@ -302,6 +304,13 @@ class SecretKeyRingEditor(var key: OpenPGPKey, override val referenceTime: Date
ImplementationFactory.getInstance().v4FingerprintCalculator,
false,
subkeyProtector.getEncryptor(subkey.keyID))
val componentKey =
OpenPGPSecretKey(
OpenPGPSubkey(subkey.publicKey, key),
secretSubkey,
PGPainless.getInstance().implementation.pbeSecretKeyDecryptorBuilderProvider())
val skBindingBuilder =
SubkeyBindingSignatureBuilder(key.primarySecretKey, primaryKeyProtector, hashAlgorithm)
skBindingBuilder.apply {
@ -309,8 +318,7 @@ class SecretKeyRingEditor(var key: OpenPGPKey, override val referenceTime: Date
hashedSubpackets.setKeyFlags(flags)
if (subkeyAlgorithm.isSigningCapable()) {
val pkBindingBuilder =
PrimaryKeyBindingSignatureBuilder(
key.primarySecretKey, primaryKeyProtector, hashAlgorithm)
PrimaryKeyBindingSignatureBuilder(componentKey, subkeyProtector, hashAlgorithm)
pkBindingBuilder.hashedSubpackets.setSignatureCreationTime(referenceTime)
hashedSubpackets.addEmbeddedSignature(pkBindingBuilder.build(primaryKey.publicKey))
}