mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
Basic v6 key generation test
This commit is contained in:
parent
da9c610d14
commit
0fceb4db2d
3 changed files with 44 additions and 24 deletions
|
@ -91,7 +91,7 @@ class KeyRingBuilder(private val version: OpenPGPKeyVersion) :
|
||||||
requireNotNull(primaryKeySpec) { "Primary Key spec required." }
|
requireNotNull(primaryKeySpec) { "Primary Key spec required." }
|
||||||
val certKey = generateKeyPair(primaryKeySpec!!, version)
|
val certKey = generateKeyPair(primaryKeySpec!!, version)
|
||||||
val signer = buildContentSigner(certKey)
|
val signer = buildContentSigner(certKey)
|
||||||
val signatureGenerator = PGPSignatureGenerator(signer)
|
val signatureGenerator = PGPSignatureGenerator(signer, certKey.publicKey)
|
||||||
|
|
||||||
val hashedSubPacketGenerator = primaryKeySpec!!.subpacketGenerator
|
val hashedSubPacketGenerator = primaryKeySpec!!.subpacketGenerator
|
||||||
hashedSubPacketGenerator.setIssuerFingerprintAndKeyId(certKey.publicKey)
|
hashedSubPacketGenerator.setIssuerFingerprintAndKeyId(certKey.publicKey)
|
||||||
|
@ -203,7 +203,8 @@ class KeyRingBuilder(private val version: OpenPGPKeyVersion) :
|
||||||
return hashedSubpackets
|
return hashedSubpackets
|
||||||
}
|
}
|
||||||
|
|
||||||
val bindingSignatureGenerator = PGPSignatureGenerator(buildContentSigner(subKey))
|
val bindingSignatureGenerator =
|
||||||
|
PGPSignatureGenerator(buildContentSigner(subKey), subKey.publicKey)
|
||||||
bindingSignatureGenerator.init(SignatureType.PRIMARYKEY_BINDING.code, subKey.privateKey)
|
bindingSignatureGenerator.init(SignatureType.PRIMARYKEY_BINDING.code, subKey.privateKey)
|
||||||
val primaryKeyBindingSig =
|
val primaryKeyBindingSig =
|
||||||
bindingSignatureGenerator.generateCertification(primaryKey.publicKey, subKey.publicKey)
|
bindingSignatureGenerator.generateCertification(primaryKey.publicKey, subKey.publicKey)
|
||||||
|
|
|
@ -125,25 +125,25 @@ class KeyRingTemplates(private val version: OpenPGPKeyVersion) {
|
||||||
fun simpleEcKeyRing(
|
fun simpleEcKeyRing(
|
||||||
userId: CharSequence?,
|
userId: CharSequence?,
|
||||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing {
|
||||||
buildKeyRing(version)
|
val signingKeyType =
|
||||||
|
if (version == OpenPGPKeyVersion.v6) KeyType.Ed25519()
|
||||||
|
else KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519)
|
||||||
|
val encryptionKeyType =
|
||||||
|
if (version == OpenPGPKeyVersion.v6) KeyType.X25519()
|
||||||
|
else KeyType.XDH_LEGACY(XDHLegacySpec._X25519)
|
||||||
|
return buildKeyRing(version)
|
||||||
.apply {
|
.apply {
|
||||||
setPrimaryKey(
|
setPrimaryKey(getBuilder(signingKeyType, KeyFlag.CERTIFY_OTHER, KeyFlag.SIGN_DATA))
|
||||||
getBuilder(
|
|
||||||
KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519),
|
|
||||||
KeyFlag.CERTIFY_OTHER,
|
|
||||||
KeyFlag.SIGN_DATA))
|
|
||||||
addSubkey(
|
addSubkey(
|
||||||
getBuilder(
|
getBuilder(encryptionKeyType, KeyFlag.ENCRYPT_STORAGE, KeyFlag.ENCRYPT_COMMS))
|
||||||
KeyType.XDH_LEGACY(XDHLegacySpec._X25519),
|
|
||||||
KeyFlag.ENCRYPT_STORAGE,
|
|
||||||
KeyFlag.ENCRYPT_COMMS))
|
|
||||||
setPassphrase(passphrase)
|
setPassphrase(passphrase)
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
addUserId(userId.toString())
|
addUserId(userId.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a key ring consisting of an ed25519 EdDSA primary key and a X25519 XDH subkey. The
|
* Creates a key ring consisting of an ed25519 EdDSA primary key and a X25519 XDH subkey. The
|
||||||
|
@ -175,25 +175,26 @@ class KeyRingTemplates(private val version: OpenPGPKeyVersion) {
|
||||||
fun modernKeyRing(
|
fun modernKeyRing(
|
||||||
userId: CharSequence?,
|
userId: CharSequence?,
|
||||||
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
passphrase: Passphrase = Passphrase.emptyPassphrase()
|
||||||
): PGPSecretKeyRing =
|
): PGPSecretKeyRing {
|
||||||
buildKeyRing(version)
|
val signingKeyType =
|
||||||
|
if (version == OpenPGPKeyVersion.v6) KeyType.Ed25519()
|
||||||
|
else KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519)
|
||||||
|
val encryptionKeyType =
|
||||||
|
if (version == OpenPGPKeyVersion.v6) KeyType.X25519()
|
||||||
|
else KeyType.XDH_LEGACY(XDHLegacySpec._X25519)
|
||||||
|
return buildKeyRing(version)
|
||||||
.apply {
|
.apply {
|
||||||
setPrimaryKey(
|
setPrimaryKey(getBuilder(signingKeyType, KeyFlag.CERTIFY_OTHER))
|
||||||
getBuilder(
|
|
||||||
KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.CERTIFY_OTHER))
|
|
||||||
addSubkey(
|
addSubkey(
|
||||||
getBuilder(
|
getBuilder(encryptionKeyType, KeyFlag.ENCRYPT_COMMS, KeyFlag.ENCRYPT_STORAGE))
|
||||||
KeyType.XDH_LEGACY(XDHLegacySpec._X25519),
|
addSubkey(getBuilder(signingKeyType, KeyFlag.SIGN_DATA))
|
||||||
KeyFlag.ENCRYPT_COMMS,
|
|
||||||
KeyFlag.ENCRYPT_STORAGE))
|
|
||||||
addSubkey(
|
|
||||||
getBuilder(KeyType.EDDSA_LEGACY(EdDSALegacyCurve._Ed25519), KeyFlag.SIGN_DATA))
|
|
||||||
setPassphrase(passphrase)
|
setPassphrase(passphrase)
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
addUserId(userId)
|
addUserId(userId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a modern PGP key ring consisting of an ed25519 EdDSA primary key which is used to
|
* Generate a modern PGP key ring consisting of an ed25519 EdDSA primary key which is used to
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package org.pgpainless.key.generation;
|
||||||
|
|
||||||
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.pgpainless.PGPainless;
|
||||||
|
import org.pgpainless.algorithm.OpenPGPKeyVersion;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
public class GenerateV6KeyTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void generateModernV6Key() {
|
||||||
|
PGPSecretKeyRing secretKey = PGPainless.generateKeyRing(OpenPGPKeyVersion.v6)
|
||||||
|
.modernKeyRing("Alice <alice@example.org>");
|
||||||
|
assertEquals(6, secretKey.getPublicKey().getVersion());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue