mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 12:27:58 +01:00
Fix method hierarchy of addBindingSignature()
This commit is contained in:
parent
7f07503064
commit
13f9702b9b
1 changed files with 26 additions and 44 deletions
|
@ -12,7 +12,6 @@ import org.bouncycastle.extensions.plusCertification
|
||||||
import org.bouncycastle.openpgp.PGPKeyPair
|
import org.bouncycastle.openpgp.PGPKeyPair
|
||||||
import org.bouncycastle.openpgp.PGPSecretKey
|
import org.bouncycastle.openpgp.PGPSecretKey
|
||||||
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
import org.bouncycastle.openpgp.PGPSecretKeyRing
|
||||||
import org.bouncycastle.openpgp.PGPSignature
|
|
||||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector
|
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector
|
||||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator
|
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVectorGenerator
|
||||||
import org.bouncycastle.util.io.Streams
|
import org.bouncycastle.util.io.Streams
|
||||||
|
@ -926,11 +925,22 @@ internal constructor(
|
||||||
* @param bindingTime creation time of the binding signature
|
* @param bindingTime creation time of the binding signature
|
||||||
* @return modified subkey pair
|
* @return modified subkey pair
|
||||||
*/
|
*/
|
||||||
abstract fun addBindingSignature(
|
fun addBindingSignature(
|
||||||
subpacketsCallback: SelfSignatureSubpackets.Callback = SelfSignatureSubpackets.nop(),
|
subpacketsCallback: SelfSignatureSubpackets.Callback = SelfSignatureSubpackets.nop(),
|
||||||
hashAlgorithm: HashAlgorithm =
|
hashAlgorithm: HashAlgorithm =
|
||||||
builder.policy.certificationSignatureHashAlgorithmPolicy.defaultHashAlgorithm,
|
builder.policy.certificationSignatureHashAlgorithmPolicy.defaultHashAlgorithm,
|
||||||
bindingTime: Date = subkey.publicKey.creationTime
|
bindingTime: Date = subkey.publicKey.creationTime
|
||||||
|
): PGPKeyPair {
|
||||||
|
builder.sanitizeHashAlgorithm(hashAlgorithm)
|
||||||
|
builder.sanitizeBindingTime(bindingTime, subkey)
|
||||||
|
|
||||||
|
return doAddBindingSignature(subpacketsCallback, hashAlgorithm, bindingTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun doAddBindingSignature(
|
||||||
|
subpacketsCallback: SelfSignatureSubpackets.Callback,
|
||||||
|
hashAlgorithm: HashAlgorithm,
|
||||||
|
bindingTime: Date
|
||||||
): PGPKeyPair
|
): PGPKeyPair
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -945,57 +955,29 @@ class ApplyToSubkeyV4
|
||||||
internal constructor(primaryKey: PGPKeyPair, subkey: PGPKeyPair, builder: DefineSubkeys<*>) :
|
internal constructor(primaryKey: PGPKeyPair, subkey: PGPKeyPair, builder: DefineSubkeys<*>) :
|
||||||
ApplyToSubkey(primaryKey, subkey, builder) {
|
ApplyToSubkey(primaryKey, subkey, builder) {
|
||||||
|
|
||||||
override fun addBindingSignature(
|
override fun doAddBindingSignature(
|
||||||
subpacketsCallback: SelfSignatureSubpackets.Callback,
|
subpacketsCallback: SelfSignatureSubpackets.Callback,
|
||||||
hashAlgorithm: HashAlgorithm,
|
hashAlgorithm: HashAlgorithm,
|
||||||
bindingTime: Date
|
bindingTime: Date
|
||||||
): PGPKeyPair {
|
): PGPKeyPair {
|
||||||
builder.sanitizeHashAlgorithm(hashAlgorithm)
|
val sigBuilder = SubkeyBindingSignatureBuilder(primaryKey, hashAlgorithm)
|
||||||
builder.sanitizeBindingTime(bindingTime, subkey)
|
sigBuilder.applyCallback(
|
||||||
|
subpacketsCallback
|
||||||
val sig =
|
.then(SelfSignatureSubpackets.applyHashed { setSignatureCreationTime(bindingTime) })
|
||||||
buildBindingSignature(
|
.then(
|
||||||
primaryKey, subkey, hashAlgorithm, bindingTime, subpacketsCallback)
|
SelfSignatureSubpackets.applyHashed {
|
||||||
|
if (isSigningCapable(getKeyFlags())) {
|
||||||
|
addEmbeddedSignature(
|
||||||
|
PrimaryKeyBindingSignatureBuilder(subkey, hashAlgorithm)
|
||||||
|
.build(primaryKey))
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
val sig = sigBuilder.build(subkey)
|
||||||
|
|
||||||
subkey = subkey.plusCertification(sig)
|
subkey = subkey.plusCertification(sig)
|
||||||
return subkey
|
return subkey
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a version 4 binding signature that binds the [subkey] to the [primaryKey].
|
|
||||||
*
|
|
||||||
* @param primaryKey primary key pair
|
|
||||||
* @param subkey subkey pair
|
|
||||||
* @param hashAlgorithm hash algorithm to be used during signature calculation
|
|
||||||
* @param bindingTime creation time of the subkey
|
|
||||||
* @param subpacketsCallback callback to modify the subpackets of the binding signature
|
|
||||||
* @return subkey binding signature
|
|
||||||
*/
|
|
||||||
private fun buildBindingSignature(
|
|
||||||
primaryKey: PGPKeyPair,
|
|
||||||
subkey: PGPKeyPair,
|
|
||||||
hashAlgorithm: HashAlgorithm,
|
|
||||||
bindingTime: Date,
|
|
||||||
subpacketsCallback: SelfSignatureSubpackets.Callback
|
|
||||||
): PGPSignature {
|
|
||||||
return SubkeyBindingSignatureBuilder(primaryKey, hashAlgorithm)
|
|
||||||
.applyCallback(
|
|
||||||
subpacketsCallback
|
|
||||||
.then(
|
|
||||||
SelfSignatureSubpackets.applyHashed {
|
|
||||||
setSignatureCreationTime(bindingTime)
|
|
||||||
})
|
|
||||||
.then(
|
|
||||||
SelfSignatureSubpackets.applyHashed {
|
|
||||||
if (isSigningCapable(getKeyFlags())) {
|
|
||||||
addEmbeddedSignature(
|
|
||||||
PrimaryKeyBindingSignatureBuilder(subkey, hashAlgorithm)
|
|
||||||
.build(primaryKey))
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
.build(subkey)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return `true` if the given [flags] list contains either [KeyFlag.SIGN_DATA] or
|
* Return `true` if the given [flags] list contains either [KeyFlag.SIGN_DATA] or
|
||||||
* [KeyFlag.CERTIFY_OTHER].
|
* [KeyFlag.CERTIFY_OTHER].
|
||||||
|
|
Loading…
Reference in a new issue