mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-05 03:41:07 +01:00
KeyRingBuilder: Properly respect custom keyGenerationTimes
This commit is contained in:
parent
5220597d75
commit
ce6866fd6d
1 changed files with 14 additions and 2 deletions
|
|
@ -103,6 +103,7 @@ class KeyRingBuilder(private val version: OpenPGPKeyVersion, private val api: PG
|
||||||
|
|
||||||
val hashedSignatureSubpackets: SignatureSubpackets =
|
val hashedSignatureSubpackets: SignatureSubpackets =
|
||||||
SignatureSubpackets.createHashedSubpackets(certKey.publicKey).apply {
|
SignatureSubpackets.createHashedSubpackets(certKey.publicKey).apply {
|
||||||
|
primaryKeySpec!!.keyCreationDate?.let { setSignatureCreationTime(it) }
|
||||||
setKeyFlags(primaryKeySpec!!.keyFlags)
|
setKeyFlags(primaryKeySpec!!.keyFlags)
|
||||||
(primaryKeySpec!!.preferredHashAlgorithmsOverride ?: algorithmSuite.hashAlgorithms)
|
(primaryKeySpec!!.preferredHashAlgorithmsOverride ?: algorithmSuite.hashAlgorithms)
|
||||||
?.let { setPreferredHashAlgorithms(it) }
|
?.let { setPreferredHashAlgorithms(it) }
|
||||||
|
|
@ -191,8 +192,10 @@ class KeyRingBuilder(private val version: OpenPGPKeyVersion, private val api: PG
|
||||||
private fun addSubKeys(primaryKey: PGPKeyPair, ringGenerator: PGPKeyRingGenerator) {
|
private fun addSubKeys(primaryKey: PGPKeyPair, ringGenerator: PGPKeyRingGenerator) {
|
||||||
for (subKeySpec in subKeySpecs) {
|
for (subKeySpec in subKeySpecs) {
|
||||||
val subKey = generateKeyPair(subKeySpec, version, api.implementation)
|
val subKey = generateKeyPair(subKeySpec, version, api.implementation)
|
||||||
|
val creationTime = subKeySpec.keyCreationDate ?: Date()
|
||||||
val hashedSignatureSubpackets: SignatureSubpackets =
|
val hashedSignatureSubpackets: SignatureSubpackets =
|
||||||
SignatureSubpackets.createHashedSubpackets(primaryKey.publicKey).apply {
|
SignatureSubpackets.createHashedSubpackets(primaryKey.publicKey).apply {
|
||||||
|
setSignatureCreationTime(creationTime)
|
||||||
setKeyFlags(subKeySpec.keyFlags)
|
setKeyFlags(subKeySpec.keyFlags)
|
||||||
subKeySpec.preferredHashAlgorithmsOverride?.let {
|
subKeySpec.preferredHashAlgorithmsOverride?.let {
|
||||||
setPreferredHashAlgorithms(it)
|
setPreferredHashAlgorithms(it)
|
||||||
|
|
@ -213,7 +216,8 @@ class KeyRingBuilder(private val version: OpenPGPKeyVersion, private val api: PG
|
||||||
hashedSignatureSubpackets.subpacketsGenerator.generate()
|
hashedSignatureSubpackets.subpacketsGenerator.generate()
|
||||||
try {
|
try {
|
||||||
hashedSubpackets =
|
hashedSubpackets =
|
||||||
addPrimaryKeyBindingSignatureIfNecessary(primaryKey, subKey, hashedSubpackets)
|
addPrimaryKeyBindingSignatureIfNecessary(
|
||||||
|
primaryKey, subKey, hashedSubpackets, creationTime)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
throw PGPException(
|
throw PGPException(
|
||||||
"Exception while adding primary key binding signature to signing subkey.", e)
|
"Exception while adding primary key binding signature to signing subkey.", e)
|
||||||
|
|
@ -225,7 +229,8 @@ class KeyRingBuilder(private val version: OpenPGPKeyVersion, private val api: PG
|
||||||
private fun addPrimaryKeyBindingSignatureIfNecessary(
|
private fun addPrimaryKeyBindingSignatureIfNecessary(
|
||||||
primaryKey: PGPKeyPair,
|
primaryKey: PGPKeyPair,
|
||||||
subKey: PGPKeyPair,
|
subKey: PGPKeyPair,
|
||||||
hashedSubpackets: PGPSignatureSubpacketVector
|
hashedSubpackets: PGPSignatureSubpacketVector,
|
||||||
|
bindingTime: Date
|
||||||
): PGPSignatureSubpacketVector {
|
): PGPSignatureSubpacketVector {
|
||||||
val keyFlagMask = hashedSubpackets.keyFlags
|
val keyFlagMask = hashedSubpackets.keyFlags
|
||||||
if (!KeyFlag.hasKeyFlag(keyFlagMask, KeyFlag.SIGN_DATA) &&
|
if (!KeyFlag.hasKeyFlag(keyFlagMask, KeyFlag.SIGN_DATA) &&
|
||||||
|
|
@ -236,6 +241,13 @@ class KeyRingBuilder(private val version: OpenPGPKeyVersion, private val api: PG
|
||||||
val bindingSignatureGenerator =
|
val bindingSignatureGenerator =
|
||||||
PGPSignatureGenerator(buildContentSigner(subKey), subKey.publicKey)
|
PGPSignatureGenerator(buildContentSigner(subKey), subKey.publicKey)
|
||||||
bindingSignatureGenerator.init(SignatureType.PRIMARYKEY_BINDING.code, subKey.privateKey)
|
bindingSignatureGenerator.init(SignatureType.PRIMARYKEY_BINDING.code, subKey.privateKey)
|
||||||
|
bindingSignatureGenerator.setHashedSubpackets(
|
||||||
|
PGPSignatureSubpacketGenerator()
|
||||||
|
.apply {
|
||||||
|
setSignatureCreationTime(bindingTime)
|
||||||
|
setIssuerFingerprint(false, subKey.publicKey)
|
||||||
|
}
|
||||||
|
.generate())
|
||||||
val primaryKeyBindingSig =
|
val primaryKeyBindingSig =
|
||||||
bindingSignatureGenerator.generateCertification(primaryKey.publicKey, subKey.publicKey)
|
bindingSignatureGenerator.generateCertification(primaryKey.publicKey, subKey.publicKey)
|
||||||
val subpacketGenerator = PGPSignatureSubpacketGenerator(hashedSubpackets)
|
val subpacketGenerator = PGPSignatureSubpacketGenerator(hashedSubpackets)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue