Skip to content

Commit

Permalink
Make MR304 fix optional
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed May 23, 2023
1 parent f5951f6 commit 651e0d6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class PublicKeyEncSessionPacket
private int keyVersion; // v6
private byte[] keyFingerprint; // v6

// https://gitlab.com/openpgp-wg/rfc4880bis/-/merge_requests/304/
private boolean MR304 = false;

PublicKeyEncSessionPacket(
BCPGInputStream in)
throws IOException
Expand All @@ -50,17 +53,24 @@ public class PublicKeyEncSessionPacket
}
else if (version == VERSION_6)
{
int keyInfoLen = in.read();
if (keyInfoLen == 0)
{
// anon recipient
keyVersion = 0;
keyFingerprint = new byte[0];
}
else
{
if (MR304) {
int keyInfoLen = in.read();
if (keyInfoLen == 0) {
// anon recipient
keyVersion = 0;
keyFingerprint = new byte[0];
} else {
keyVersion = in.read();
keyFingerprint = new byte[keyInfoLen - 1];
in.readFully(keyFingerprint);
}
} else {
keyVersion = in.read();
keyFingerprint = new byte[keyInfoLen - 1];
if (keyVersion == 6) {
keyFingerprint = new byte[32];
} else {
keyFingerprint = new byte[20];
}
in.readFully(keyFingerprint);
}
}
Expand Down Expand Up @@ -263,7 +273,9 @@ public void encode(
}
else if (version == VERSION_6)
{
pOut.write(keyFingerprint.length + 1);
if (MR304) {
pOut.write(keyFingerprint.length + 1);
}
pOut.write(keyVersion);
pOut.write(keyFingerprint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.bouncycastle.bcpg.AEADAlgorithmTags;
import org.bouncycastle.bcpg.ArmoredInputStream;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.bcpg.SymmetricEncDataPacket;
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.bouncycastle.openpgp.PGPEncryptedDataGenerator;
import org.bouncycastle.openpgp.PGPEncryptedDataList;
Expand All @@ -25,9 +24,7 @@
import org.bouncycastle.openpgp.operator.bc.BcPGPDataEncryptorBuilder;
import org.bouncycastle.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory;
import org.bouncycastle.openpgp.operator.bc.BcPublicKeyKeyEncryptionMethodGenerator;
import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.encoders.Hex;
import org.bouncycastle.util.io.Streams;
import org.bouncycastle.util.test.SimpleTest;

Expand Down Expand Up @@ -114,14 +111,15 @@ public String getName() {

@Override
public void performTest() throws Exception {
System.out.println(KEY);
byte[] data = "Hello, World!\n".getBytes(StandardCharsets.UTF_8);

PGPPublicKeyRing publicKeys = readCert(CERT);
PGPPublicKey encKey = publicKeys.getPublicKey(5939832804746992246L);

PGPDataEncryptorBuilder dataEncBuilder = new BcPGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.AES_256);
dataEncBuilder.setUseV6AEAD();
dataEncBuilder.setWithAEAD(AEADAlgorithmTags.OCB, 6);
dataEncBuilder.setWithAEAD(AEADAlgorithmTags.EAX, 6);

PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(dataEncBuilder);
PublicKeyKeyEncryptionMethodGenerator method = new BcPublicKeyKeyEncryptionMethodGenerator(encKey, true);
Expand Down

0 comments on commit 651e0d6

Please sign in to comment.