8000 Signature Packet format fixes by vanitasvitae · Pull Request #2078 · bcgit/bc-java · GitHub
[go: up one dir, main page]

Skip to content

Signature Packet format fixes #2078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions pg/src/main/java/org/bouncycastle/bcpg/SignaturePacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,22 @@ public SignaturePacket(
byte[] fingerPrint,
MPInteger[] signature)
{
super(SIGNATURE);
this(version, false, signatureType, keyID, keyAlgorithm, hashAlgorithm, hashedData, unhashedData, fingerPrint, signature);
}

public SignaturePacket(
int version,
boolean hasNewPacketFormat,
int signatureType,
long keyID,
int keyAlgorithm,
int hashAlgorithm,
SignatureSubpacket[] hashedData,
SignatureSubpacket[] unhashedDa 8000 ta,
byte[] fingerPrint,
MPInteger[] signature)
{
super(SIGNATURE, hasNewPacketFormat);

this.version = version;
this.signatureType = signatureType;
Expand Down Expand Up @@ -383,7 +398,7 @@ public SignaturePacket(
byte[] signatureEncoding,
byte[] salt)
{
super(SIGNATURE);
super(SIGNATURE, true);

this.version = version;
this.signatureType = signatureType;
Expand Down Expand Up @@ -413,7 +428,7 @@ public SignaturePacket(
MPInteger[] signature,
byte[] salt)
{
super(SIGNATURE);
super(SIGNATURE, true);

this.version = version;
this.signatureType = signatureType;
Expand Down
4 changes: 3 additions & 1 deletion pg/src/main/java/org/bouncycastle/openpgp/PGPSignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public class PGPSignature
*/
public static final int THIRD_PARTY_CONFIRMATION = 0x50;

private final SignaturePacket sigPck;
final SignaturePacket sigPck;
private final TrustPacket trustPck;

private volatile PGPContentVerifier verifier;
Expand Down Expand Up @@ -1034,6 +1034,8 @@ public static PGPSignature join(PGPSignature sig1, PGPSignature sig2)
SignatureSubpacket[] unhashed = (SignatureSubpacket[])merged.toArray(new SignatureSubpacket[0]);
return new PGPSignature(
new SignaturePacket(
sig1.getVersion(),
sig1.sigPck.hasNewPacketFormat(),
sig1.getSignatureType(),
sig1.getKeyID(),
sig1.getKeyAlgorithm(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.bouncycastle.openpgp;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.bouncycastle.bcpg.BCPGOutputStream;
import org.bouncycastle.bcpg.PacketFormat;
import org.bouncycastle.bcpg.SignatureSubpacket;
import org.bouncycastle.bcpg.SignatureSubpacketTags;
import org.bouncycastle.bcpg.sig.EmbeddedSignature;
Expand Down Expand Up @@ -445,9 +448,16 @@ public void setEmbeddedSignature(boolean isCritical, PGPSignature pgpSignature)
public void addEmbeddedSignature(boolean isCritical, PGPSignature pgpSignature)
throws IOException
{
byte[] sig = pgpSignature.getEncoded();
// Encode the signature forcing legacy packet format, such that we consistently cut off the proper amount
// of header bytes
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
BCPGOutputStream pOut = new BCPGOutputStream(bOut, PacketFormat.LEGACY);
pgpSignature.encode(pOut);
pOut.close();
byte[] sig = bOut.toByteArray();
byte[] data;

// Cut off the header bytes
if (sig.length - 1 > 256)
{
data = new byte[sig.length - 3];
Expand Down
0