mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-25 12:27:58 +01:00
Add tests for keys with malformed sig subpackets
This commit is contained in:
parent
b164900a59
commit
0d3fb446a8
1 changed files with 47 additions and 7 deletions
|
@ -4,7 +4,9 @@
|
||||||
|
|
||||||
package org.pgpainless.key.generation
|
package org.pgpainless.key.generation
|
||||||
|
|
||||||
|
import org.bouncycastle.bcpg.sig.Exportable
|
||||||
import org.bouncycastle.bcpg.sig.PrimaryUserID
|
import org.bouncycastle.bcpg.sig.PrimaryUserID
|
||||||
|
import org.bouncycastle.bcpg.sig.Revocable
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.pgpainless.PGPainless
|
import org.pgpainless.PGPainless
|
||||||
import org.pgpainless.key.generation.type.KeyType
|
import org.pgpainless.key.generation.type.KeyType
|
||||||
|
@ -17,17 +19,55 @@ class MalformedKeyGenerationTest {
|
||||||
@Test
|
@Test
|
||||||
fun malformedPrimaryUserIdSubpacket() {
|
fun malformedPrimaryUserIdSubpacket() {
|
||||||
val userId = "Alice <alice@pgpainless.org>"
|
val userId = "Alice <alice@pgpainless.org>"
|
||||||
val key = GenerateOpenPgpKey(Policy.getInstance())
|
val key =
|
||||||
.buildV4Key(KeyType.EDDSA(EdDSACurve._Ed25519))
|
GenerateOpenPgpKey(Policy.getInstance())
|
||||||
.addUserId(userId,
|
.buildV4Key(KeyType.EDDSA(EdDSACurve._Ed25519))
|
||||||
SelfSignatureSubpackets.applyHashed {
|
.addUserId(
|
||||||
setPrimaryUserId(PrimaryUserID(false, false, byteArrayOf(0x02)))
|
userId,
|
||||||
})
|
SelfSignatureSubpackets.applyHashed {
|
||||||
.build()
|
setPrimaryUserId(PrimaryUserID(false, false, byteArrayOf(0x02)))
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
|
||||||
println(PGPainless.asciiArmor(key))
|
println(PGPainless.asciiArmor(key))
|
||||||
|
|
||||||
PGPainless.readKeyRing().secretKeyRing(key.encoded)!!
|
PGPainless.readKeyRing().secretKeyRing(key.encoded)!!
|
||||||
// TODO: Check interpretation of faulty PrimaryUserID packet
|
// TODO: Check interpretation of faulty PrimaryUserID packet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun malformedExportableSubpacket() {
|
||||||
|
val key =
|
||||||
|
GenerateOpenPgpKey(Policy.getInstance())
|
||||||
|
.buildV4Key(KeyType.EDDSA(EdDSACurve._Ed25519))
|
||||||
|
.addUserId(
|
||||||
|
"Alice <alice@pgpainless.org>",
|
||||||
|
SelfSignatureSubpackets.applyHashed {
|
||||||
|
setExportable(Exportable(false, false, byteArrayOf(0x03)))
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
|
||||||
|
println(PGPainless.asciiArmor(key))
|
||||||
|
|
||||||
|
PGPainless.readKeyRing().secretKeyRing(key.encoded)!!
|
||||||
|
// TODO: Check interpretation of faulty packet
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun malformedRevocableSubpacket() {
|
||||||
|
val key =
|
||||||
|
GenerateOpenPgpKey(Policy.getInstance())
|
||||||
|
.buildV4Key(KeyType.EDDSA(EdDSACurve._Ed25519))
|
||||||
|
.addUserId(
|
||||||
|
"Alice <alice@pgpainless.org>",
|
||||||
|
SelfSignatureSubpackets.applyHashed {
|
||||||
|
setRevocable(Revocable(false, false, byteArrayOf(0x04)))
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
|
||||||
|
println(PGPainless.asciiArmor(key))
|
||||||
|
|
||||||
|
PGPainless.readKeyRing().secretKeyRing(key.encoded)!!
|
||||||
|
// TODO: Check interpretation of faulty packet
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue