1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-23 03:17:58 +01:00

Rename heyKeyId -> openPgpKeyId

This commit is contained in:
Paul Schaub 2023-09-06 11:35:44 +02:00
parent 39e170064c
commit d8df6c35d0
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
8 changed files with 32 additions and 32 deletions

View file

@ -2,19 +2,19 @@
// //
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package _kotlin package openpgp
/** /**
* Format this Long as a 16 digit uppercase hex number. * Format this Long as an OpenPGP key-ID (16 digit uppercase hex number).
*/ */
fun Long.hexKeyId(): String { fun Long.openPgpKeyId(): String {
return String.format("%016X", this).uppercase() return String.format("%016X", this).uppercase()
} }
/** /**
* Parse a 16 digit hex number into a Long. * Parse a Long form a 16 digit hex encoded OpenPgp key-ID.
*/ */
fun Long.Companion.fromHexKeyId(hexKeyId: String): Long { fun Long.Companion.fromOpenPgpKeyId(hexKeyId: String): Long {
require("^[0-9A-Fa-f]{16}$".toRegex().matches(hexKeyId)) { require("^[0-9A-Fa-f]{16}$".toRegex().matches(hexKeyId)) {
"Provided long key-id does not match expected format. " + "Provided long key-id does not match expected format. " +
"A long key-id consists of 16 hexadecimal characters." "A long key-id consists of 16 hexadecimal characters."

View file

@ -4,7 +4,7 @@
package org.pgpainless.decryption_verification package org.pgpainless.decryption_verification
import _kotlin.hexKeyId import openpgp.openPgpKeyId
import org.bouncycastle.bcpg.BCPGInputStream import org.bouncycastle.bcpg.BCPGInputStream
import org.bouncycastle.bcpg.UnsupportedPacketVersionException import org.bouncycastle.bcpg.UnsupportedPacketVersionException
import org.bouncycastle.openpgp.* import org.bouncycastle.openpgp.*
@ -180,7 +180,7 @@ class OpenPgpMessageInputStream(
private fun processOnePassSignature() { private fun processOnePassSignature() {
syntaxVerifier.next(InputSymbol.ONE_PASS_SIGNATURE) syntaxVerifier.next(InputSymbol.ONE_PASS_SIGNATURE)
val ops = packetInputStream!!.readOnePassSignature() val ops = packetInputStream!!.readOnePassSignature()
LOGGER.debug("One-Pass-Signature Packet by key ${ops.keyID.hexKeyId()} at depth ${layerMetadata.depth} encountered.") LOGGER.debug("One-Pass-Signature Packet by key ${ops.keyID.openPgpKeyId()} at depth ${layerMetadata.depth} encountered.")
signatures.addOnePassSignature(ops) signatures.addOnePassSignature(ops)
} }
@ -197,11 +197,11 @@ class OpenPgpMessageInputStream(
val keyId = SignatureUtils.determineIssuerKeyId(signature) val keyId = SignatureUtils.determineIssuerKeyId(signature)
if (isSigForOps) { if (isSigForOps) {
LOGGER.debug("Signature Packet corresponding to One-Pass-Signature by key ${keyId.hexKeyId()} at depth ${layerMetadata.depth} encountered.") LOGGER.debug("Signature Packet corresponding to One-Pass-Signature by key ${keyId.openPgpKeyId()} at depth ${layerMetadata.depth} encountered.")
signatures.leaveNesting() // TODO: Only leave nesting if all OPSs of the nesting layer are dealt with signatures.leaveNesting() // TODO: Only leave nesting if all OPSs of the nesting layer are dealt with
signatures.addCorrespondingOnePassSignature(signature, layerMetadata, policy) signatures.addCorrespondingOnePassSignature(signature, layerMetadata, policy)
} else { } else {
LOGGER.debug("Prepended Signature Packet by key ${keyId.hexKeyId()} at depth ${layerMetadata.depth} encountered.") LOGGER.debug("Prepended Signature Packet by key ${keyId.openPgpKeyId()} at depth ${layerMetadata.depth} encountered.")
signatures.addPrependedSignature(signature) signatures.addPrependedSignature(signature)
} }
} }
@ -282,10 +282,10 @@ class OpenPgpMessageInputStream(
// try (known) secret keys // try (known) secret keys
for (pkesk in esks.pkesks) { for (pkesk in esks.pkesks) {
val keyId = pkesk.keyID val keyId = pkesk.keyID
LOGGER.debug("Encountered PKESK for recipient ${keyId.hexKeyId()}") LOGGER.debug("Encountered PKESK for recipient ${keyId.openPgpKeyId()}")
val decryptionKeys = getDecryptionKey(keyId) val decryptionKeys = getDecryptionKey(keyId)
if (decryptionKeys == null) { if (decryptionKeys == null) {
LOGGER.debug("Skipping PKESK because no matching key ${keyId.hexKeyId()} was provided.") LOGGER.debug("Skipping PKESK because no matching key ${keyId.openPgpKeyId()} was provided.")
continue continue
} }
val secretKey = decryptionKeys.getSecretKey(keyId) val secretKey = decryptionKeys.getSecretKey(keyId)
@ -618,7 +618,7 @@ class OpenPgpMessageInputStream(
if (check != null) { if (check != null) {
detachedSignatures.add(check) detachedSignatures.add(check)
} else { } else {
LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.hexKeyId()} found.") LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.openPgpKeyId()} found.")
detachedSignaturesWithMissingCert.add(SignatureVerification.Failure( detachedSignaturesWithMissingCert.add(SignatureVerification.Failure(
SignatureVerification(signature, null), SignatureVerification(signature, null),
SignatureValidationException("Missing verification key."))) SignatureValidationException("Missing verification key.")))
@ -631,7 +631,7 @@ class OpenPgpMessageInputStream(
if (check != null) { if (check != null) {
prependedSignatures.add(check) prependedSignatures.add(check)
} else { } else {
LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.hexKeyId()} found.") LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.openPgpKeyId()} found.")
prependedSignaturesWithMissingCert.add(SignatureVerification.Failure( prependedSignaturesWithMissingCert.add(SignatureVerification.Failure(
SignatureVerification(signature, null), SignatureVerification(signature, null),
SignatureValidationException("Missing verification key") SignatureValidationException("Missing verification key")
@ -693,7 +693,7 @@ class OpenPgpMessageInputStream(
} }
if (!found) { if (!found) {
LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.hexKeyId()} found.") LOGGER.debug("No suitable certificate for verification of signature by key ${keyId.openPgpKeyId()} found.")
inbandSignaturesWithMissingCert.add(SignatureVerification.Failure( inbandSignaturesWithMissingCert.add(SignatureVerification.Failure(
SignatureVerification(signature, null), SignatureVerification(signature, null),
SignatureValidationException("Missing verification key.") SignatureValidationException("Missing verification key.")

View file

@ -4,7 +4,7 @@
package org.pgpainless.key package org.pgpainless.key
import _kotlin.hexKeyId import openpgp.openPgpKeyId
import org.bouncycastle.openpgp.PGPKeyRing import org.bouncycastle.openpgp.PGPKeyRing
import org.bouncycastle.openpgp.PGPPublicKey import org.bouncycastle.openpgp.PGPPublicKey
@ -22,7 +22,7 @@ class SubkeyIdentifier(
constructor(keys: PGPKeyRing, keyId: Long): this( constructor(keys: PGPKeyRing, keyId: Long): this(
OpenPgpFingerprint.of(keys.publicKey), OpenPgpFingerprint.of(keys.publicKey),
OpenPgpFingerprint.of(keys.getPublicKey(keyId) ?: OpenPgpFingerprint.of(keys.getPublicKey(keyId) ?:
throw NoSuchElementException("OpenPGP key does not contain subkey ${keyId.hexKeyId()}"))) throw NoSuchElementException("OpenPGP key does not contain subkey ${keyId.openPgpKeyId()}")))
constructor(keys: PGPKeyRing, subkeyFingerprint: OpenPgpFingerprint): this(OpenPgpFingerprint.of(keys), subkeyFingerprint) constructor(keys: PGPKeyRing, subkeyFingerprint: OpenPgpFingerprint): this(OpenPgpFingerprint.of(keys), subkeyFingerprint)
val keyId = subkeyFingerprint.keyId val keyId = subkeyFingerprint.keyId

View file

@ -4,7 +4,7 @@
package org.pgpainless.key.protection package org.pgpainless.key.protection
import _kotlin.hexKeyId import openpgp.openPgpKeyId
import org.bouncycastle.openpgp.PGPKeyRing import org.bouncycastle.openpgp.PGPKeyRing
import org.bouncycastle.openpgp.PGPPublicKey import org.bouncycastle.openpgp.PGPPublicKey
import org.pgpainless.key.OpenPgpFingerprint import org.pgpainless.key.OpenPgpFingerprint
@ -54,7 +54,7 @@ class CachingSecretKeyRingProtector : SecretKeyRingProtector, SecretKeyPassphras
*/ */
fun addPassphrase(keyId: Long, passphrase: Passphrase) = apply { fun addPassphrase(keyId: Long, passphrase: Passphrase) = apply {
require(!cache.containsKey(keyId)) { require(!cache.containsKey(keyId)) {
"The cache already holds a passphrase for ID ${keyId.hexKeyId()}.\n" + "The cache already holds a passphrase for ID ${keyId.openPgpKeyId()}.\n" +
"If you want to replace this passphrase, use replacePassphrase(Long, Passphrase) instead." "If you want to replace this passphrase, use replacePassphrase(Long, Passphrase) instead."
} }
cache[keyId] = passphrase cache[keyId] = passphrase
@ -90,7 +90,7 @@ class CachingSecretKeyRingProtector : SecretKeyRingProtector, SecretKeyPassphras
// check for existing passphrases before doing anything // check for existing passphrases before doing anything
keyRing.publicKeys.forEach { keyRing.publicKeys.forEach {
require(!cache.containsKey(it.keyID)) { require(!cache.containsKey(it.keyID)) {
"The cache already holds a passphrase for the key with ID ${it.keyID.hexKeyId()}.\n" + "The cache already holds a passphrase for the key with ID ${it.keyID.openPgpKeyId()}.\n" +
"If you want to replace the passphrase, use replacePassphrase(PGPKeyRing, Passphrase) instead." "If you want to replace the passphrase, use replacePassphrase(PGPKeyRing, Passphrase) instead."
} }
} }

View file

@ -5,7 +5,7 @@
package org.pgpainless.key.protection package org.pgpainless.key.protection
import _kotlin.hexKeyId import openpgp.openPgpKeyId
import org.bouncycastle.openpgp.PGPException import org.bouncycastle.openpgp.PGPException
import org.bouncycastle.openpgp.PGPPrivateKey import org.bouncycastle.openpgp.PGPPrivateKey
import org.bouncycastle.openpgp.PGPSecretKey import org.bouncycastle.openpgp.PGPSecretKey
@ -43,7 +43,7 @@ class UnlockSecretKey {
if (privateKey == null) { if (privateKey == null) {
if (secretKey.s2K.type in 100..110) { if (secretKey.s2K.type in 100..110) {
throw PGPException("Cannot decrypt secret key ${secretKey.keyID.hexKeyId()}: \n" + throw PGPException("Cannot decrypt secret key ${secretKey.keyID.openPgpKeyId()}: \n" +
"Unsupported private S2K type ${secretKey.s2K.type}") "Unsupported private S2K type ${secretKey.s2K.type}")
} }
throw PGPException("Cannot decrypt secret key.") throw PGPException("Cannot decrypt secret key.")

View file

@ -4,8 +4,8 @@
package org.pgpainless.key.util package org.pgpainless.key.util
import _kotlin.fromHexKeyId import openpgp.fromOpenPgpKeyId
import _kotlin.hexKeyId import openpgp.openPgpKeyId
class KeyIdUtil { class KeyIdUtil {
@ -21,7 +21,7 @@ class KeyIdUtil {
@JvmStatic @JvmStatic
@Deprecated("Superseded by Long extension method.", @Deprecated("Superseded by Long extension method.",
ReplaceWith("Long.fromHexKeyId(longKeyId)")) ReplaceWith("Long.fromHexKeyId(longKeyId)"))
fun fromLongKeyId(longKeyId: String) = Long.fromHexKeyId(longKeyId) fun fromLongKeyId(longKeyId: String) = Long.fromOpenPgpKeyId(longKeyId)
/** /**
* Format a long key-ID as upper-case hex string. * Format a long key-ID as upper-case hex string.
@ -31,6 +31,6 @@ class KeyIdUtil {
@JvmStatic @JvmStatic
@Deprecated("Superseded by Long extension method.", @Deprecated("Superseded by Long extension method.",
ReplaceWith("keyId.hexKeyId()")) ReplaceWith("keyId.hexKeyId()"))
fun formatKeyId(keyId: Long) = keyId.hexKeyId() fun formatKeyId(keyId: Long) = keyId.openPgpKeyId()
} }
} }

View file

@ -4,7 +4,7 @@
package org.pgpainless.key.util package org.pgpainless.key.util
import _kotlin.hexKeyId import openpgp.openPgpKeyId
import org.bouncycastle.bcpg.S2K import org.bouncycastle.bcpg.S2K
import org.bouncycastle.bcpg.SecretKeyPacket import org.bouncycastle.bcpg.SecretKeyPacket
import org.bouncycastle.extensions.certificate import org.bouncycastle.extensions.certificate
@ -100,7 +100,7 @@ class KeyRingUtils {
@JvmStatic @JvmStatic
fun requirePublicKeyFrom(keyRing: PGPKeyRing, subKeyId: Long): PGPPublicKey { fun requirePublicKeyFrom(keyRing: PGPKeyRing, subKeyId: Long): PGPPublicKey {
return keyRing.getPublicKey(subKeyId) return keyRing.getPublicKey(subKeyId)
?: throw NoSuchElementException("KeyRing does not contain public key with keyId ${subKeyId.hexKeyId()}.") ?: throw NoSuchElementException("KeyRing does not contain public key with keyId ${subKeyId.openPgpKeyId()}.")
} }
/** /**
@ -114,7 +114,7 @@ class KeyRingUtils {
@JvmStatic @JvmStatic
fun requireSecretKeyFrom(keyRing: PGPSecretKeyRing, subKeyId: Long): PGPSecretKey { fun requireSecretKeyFrom(keyRing: PGPSecretKeyRing, subKeyId: Long): PGPSecretKey {
return keyRing.getSecretKey(subKeyId) return keyRing.getSecretKey(subKeyId)
?: throw NoSuchElementException("KeyRing does not contain secret key with keyID ${subKeyId.hexKeyId()}.") ?: throw NoSuchElementException("KeyRing does not contain secret key with keyID ${subKeyId.openPgpKeyId()}.")
} }
@JvmStatic @JvmStatic
@ -233,7 +233,7 @@ class KeyRingUtils {
var certificate: PGPPublicKeyRing = secretAndPublicKeys.second var certificate: PGPPublicKeyRing = secretAndPublicKeys.second
if (!keyRingContainsKeyWithId(certificate, certifiedKey.keyID)) { if (!keyRingContainsKeyWithId(certificate, certifiedKey.keyID)) {
throw NoSuchElementException("Cannot find public key with id ${certifiedKey.keyID.hexKeyId()} in the provided key ring.") throw NoSuchElementException("Cannot find public key with id ${certifiedKey.keyID.openPgpKeyId()} in the provided key ring.")
} }
certificate = PGPPublicKeyRing( certificate = PGPPublicKeyRing(
@ -389,7 +389,7 @@ class KeyRingUtils {
"Bouncy Castle currently cannot deal with stripped primary secret keys." "Bouncy Castle currently cannot deal with stripped primary secret keys."
} }
if (secretKeys.getSecretKey(keyId) == null) { if (secretKeys.getSecretKey(keyId) == null) {
throw NoSuchElementException("PGPSecretKeyRing does not contain secret key ${keyId.hexKeyId()}.") throw NoSuchElementException("PGPSecretKeyRing does not contain secret key ${keyId.openPgpKeyId()}.")
} }
val out = ByteArrayOutputStream() val out = ByteArrayOutputStream()

View file

@ -4,7 +4,7 @@
package org.pgpainless.signature.subpackets package org.pgpainless.signature.subpackets
import _kotlin.hexKeyId import openpgp.openPgpKeyId
import org.bouncycastle.bcpg.sig.* import org.bouncycastle.bcpg.sig.*
import org.bouncycastle.openpgp.PGPPublicKey import org.bouncycastle.openpgp.PGPPublicKey
import org.bouncycastle.openpgp.PGPSignature import org.bouncycastle.openpgp.PGPSignature
@ -143,7 +143,7 @@ class SignatureSubpacketsUtil {
@JvmStatic @JvmStatic
fun getKeyExpirationTimeAsDate(signature: PGPSignature, signingKey: PGPPublicKey): Date? = fun getKeyExpirationTimeAsDate(signature: PGPSignature, signingKey: PGPPublicKey): Date? =
require(signature.keyID == signingKey.keyID) { require(signature.keyID == signingKey.keyID) {
"Provided key (${signingKey.keyID.hexKeyId()}) did not create the signature (${signature.keyID.hexKeyId()})" "Provided key (${signingKey.keyID.openPgpKeyId()}) did not create the signature (${signature.keyID.openPgpKeyId()})"
}.run { }.run {
getKeyExpirationTime(signature)?.let { getKeyExpirationTime(signature)?.let {
SignatureUtils.datePlusSeconds(signingKey.creationTime, it.time) SignatureUtils.datePlusSeconds(signingKey.creationTime, it.time)