Skip to content

Commit

Permalink
compatibility updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Oct 6, 2019
1 parent a8614ff commit 503239b
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 13 deletions.
1 change: 1 addition & 0 deletions ant/jdk13.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
</fileset>
<fileset dir="pkix/src/main/jdk1.4" includes="**/*.java" />
<fileset dir="pg/src/main/jdk1.4" includes="**/*.java" />
<fileset dir="pg/src/main/jdk1.3" includes="**/*.java" />
<fileset dir="core/src/test/jdk1.4" includes="**/*.java" />
</copy>
<copy todir="${src.dir}" overwrite="true">
Expand Down
8 changes: 8 additions & 0 deletions build1-1
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ then
tar cf - index.html LICENSE.html CONTRIBUTORS.html docs | (cd $artifacts/bcpg-jdk11-$base; tar xf -)
((cd pg/src/main/java && tar cf - * ) | (cd $artifacts/bcpg-jdk11-$base/src && tar xf -))
((cd pg/src/main/jdk1.4 && tar cf - * ) | (cd $artifacts/bcpg-jdk11-$base/src && tar xf -))
((cd pg/src/main/jdk1.3 && tar cf - * ) | (cd $artifacts/bcpg-jdk11-$base/src && tar xf -))
((cd pg/src/main/jdk1.1 && tar cf - * ) | (cd $artifacts/bcpg-jdk11-$base/src && tar xf -))
((cd pg/src/test/java && tar cf - * ) | (cd $artifacts/bcpg-jdk11-$base/src && tar xf -))
((cd pg/src/test/jdk1.4 && tar cf - * ) | (cd $artifacts/bcpg-jdk11-$base/src && tar xf -))
Expand Down Expand Up @@ -594,6 +595,13 @@ then

echo "compiling"


ed src/org/bouncycastle/bcpg/SignatureSubpacketInputStream.java <<%
g/private.*final.*;/s/final//
w
q
%

ed src/org/bouncycastle/bcpg/ArmoredOutputStream.java <<%
/@RELEASE_NAME@/s//$version/
w
Expand Down
1 change: 1 addition & 0 deletions build1-2
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ then
tar cf - index.html LICENSE.html CONTRIBUTORS.html docs | (cd $artifacts/bcpg-jdk12-$base; tar xf -)
((cd pg/src/main/java && tar cf - * ) | (cd $artifacts/bcpg-jdk12-$base/src && tar xf -))
((cd pg/src/main/jdk1.4 && tar cf - * ) | (cd $artifacts/bcpg-jdk12-$base/src && tar xf -))
((cd pg/src/main/jdk1.3 && tar cf - * ) | (cd $artifacts/bcpg-jdk12-$base/src && tar xf -))
((cd pg/src/test/java && tar cf - * ) | (cd $artifacts/bcpg-jdk12-$base/src && tar xf -))
((cd pg/src/test/jdk1.4 && tar cf - * ) | (cd $artifacts/bcpg-jdk12-$base/src && tar xf -))
((cd pg/src/test/jdk1.3 && tar cf - * ) | (cd $artifacts/bcpg-jdk12-$base/src && tar xf -))
Expand Down
30 changes: 27 additions & 3 deletions core/src/main/jdk1.3/org/bouncycastle/crypto/util/SSHBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;

import org.bouncycastle.util.Strings;

Expand All @@ -17,7 +18,12 @@ public void u32(long value)
bos.write((int)(value & 0xFF));
}

public void rawArray(byte[] value)
public void writeBigNum(BigInteger n)
{
writeBlock(n.toByteArray());
}

public void writeBlock(byte[] value)
{
u32(value.length);
try
Expand All @@ -30,7 +36,7 @@ public void rawArray(byte[] value)
}
}

public void write(byte[] value)
public void writeBytes(byte[] value)
{
try
{
Expand All @@ -44,12 +50,30 @@ public void write(byte[] value)

public void writeString(String str)
{
rawArray(Strings.toByteArray(str));
writeBlock(Strings.toByteArray(str));
}

public byte[] getBytes()
{
return bos.toByteArray();
}

public byte[] getPaddedBytes()
{
return getPaddedBytes(8);
}

public byte[] getPaddedBytes(int blockSize)
{
int align = bos.size() % blockSize;
if (0 != align)
{
int padCount = blockSize - align;
for (int i = 1; i <= padCount; ++i)
{
bos.write(i);
}
}
return bos.toByteArray();
}
}
112 changes: 112 additions & 0 deletions core/src/test/jdk1.3/org/bouncycastle/asn1/test/InputStreamTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package org.bouncycastle.asn1.test;

import java.io.IOException;

import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.util.encoders.Base64;
import org.bouncycastle.util.test.SimpleTest;

public class InputStreamTest
extends SimpleTest
{
private static final byte[] outOfBoundsLength = new byte[]{(byte)0x30, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff};
private static final byte[] negativeLength = new byte[]{(byte)0x30, (byte)0x84, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff};
private static final byte[] outsideLimitLength = new byte[]{(byte)0x30, (byte)0x83, (byte)0x0f, (byte)0xff, (byte)0xff};

private static final byte[] classCast1 = Base64.decode("p1AkHmYAvfOEIrL4ESfrNg==");
private static final byte[] classCast2 = Base64.decode("JICNbaBUTTq7uxj5mg==");
private static final byte[] classCast3 = Base64.decode("JAKzADNCxhrrBSVS");
private static final byte[] memoryError1 = Base64.decode("vm66gOiEe+FV/NvujMwSkUp5Lffw5caQlaRU5sdMPC70IGWmyK2/");
private static final byte[] memoryError2 = Base64.decode("vm4ogOSEfVGsS3w+KTzb2A0ALYR8VBOQqQeuRwnsPC4AAGWEDLjd");

public String getName()
{
return "InputStream";
}

public void performTest()
throws Exception
{
ASN1InputStream aIn = new ASN1InputStream(outOfBoundsLength);

try
{
aIn.readObject();
fail("out of bounds length not detected.");
}
catch (IOException e)
{
if (!e.getMessage().startsWith("DER length more than 4 bytes"))
{
fail("wrong exception: " + e.getMessage());
}
}

aIn = new ASN1InputStream(negativeLength);

try
{
aIn.readObject();
fail("negative length not detected.");
}
catch (IOException e)
{
if (!e.getMessage().equals("corrupted stream - negative length found"))
{
fail("wrong exception: " + e.getMessage());
}
}

aIn = new ASN1InputStream(outsideLimitLength);

try
{
aIn.readObject();
fail("outside limit length not detected.");
}
catch (IOException e)
{
if (!e.getMessage().equals("corrupted stream - out of bounds length found: 1048575 >= 5"))
{
fail("wrong exception: " + e.getMessage());
}
}

testWithByteArray(classCast1, "unknown object encountered: class org.bouncycastle.asn1.DLApplicationSpecific");
testWithByteArray(classCast2, "unknown object encountered: class org.bouncycastle.asn1.BERTaggedObjectParser");
testWithByteArray(classCast3, "unknown object encountered in constructed OCTET STRING: class org.bouncycastle.asn1.DLTaggedObject");

testWithByteArray(memoryError1, "corrupted stream - out of bounds length found: 2078365180 >= 110");
testWithByteArray(memoryError2, "corrupted stream - out of bounds length found: 2102504523 >= 110");
}

private void testWithByteArray(byte[] data, String message)
{
try
{
ASN1InputStream input = new ASN1InputStream(data);

ASN1Primitive p;
while ((p = input.readObject()) != null)
{
ASN1Sequence asn1 = ASN1Sequence.getInstance(p);
for (int i = 0; i < asn1.size(); i++)
{
asn1.getObjectAt(i);
}
}
}
catch (java.io.IOException e)
{
isEquals(e.getMessage(), message, e.getMessage());
}
}

public static void main(
String[] args)
{
runTest(new InputStreamTest());
}
}
1 change: 1 addition & 0 deletions docs/releasenotes.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ <h3>2.1.3 Additional Features and Functionality</h3>
<li>BCJSSE: SSLContext algorithms updated for SunJSSE compatibility (default enabled protocols).</li>
<li>The digest functions Haraka-256 and Haraka-512 have been added to the provider and the light-weight API</li>
<li>XMSS/XMSS^MT key management now allows for allocating subsets of the private key space using the extraKeyShard() method. Use of StateAwareSignature is now deprecated.</li>
<li>Support for Java 11's NamedParameterSpec class has been added (using reflection) to the EC and EdEC KeyPairGenerator implementations.</li>
</ul>

<h3>2.1.4 Security Advisory</h3>
Expand Down
24 changes: 24 additions & 0 deletions pg/src/main/jdk1.3/org/bouncycastle/bcpg/StreamUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.bouncycastle.bcpg;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

class StreamUtil
{
/**
* Find out possible longest length...
*
* @param in input stream of interest
* @return length calculation or MAX_VALUE.
*/
static int findLimit(InputStream in)
{
if (in instanceof ByteArrayInputStream)
{
return ((ByteArrayInputStream)in).available();
}

return Integer.MAX_VALUE;
}
}
1 change: 1 addition & 0 deletions prov/src/main/core
37 changes: 31 additions & 6 deletions prov/src/main/jdk1.3/org/bouncycastle/jce/ECKeyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.asn1.x9.X962Parameters;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.asn1.x9.X9ECPoint;
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
Expand Down Expand Up @@ -84,12 +85,24 @@ public static PublicKey publicToExplicitParameters(PublicKey key, Provider provi
ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(params.getParameters());

curveParams = ECUtil.getNamedCurveByOid(oid);
// ignore seed value due to JDK bug
curveParams = new X9ECParameters(curveParams.getCurve(), curveParams.getG(), curveParams.getN(), curveParams.getH());

if (curveParams.hasSeed())
{
// ignore seed value due to JDK bug
curveParams = new X9ECParameters(
curveParams.getCurve(),
curveParams.getBaseEntry(),
curveParams.getN(),
curveParams.getH());
}
}
else if (params.isImplicitlyCA())
{
curveParams = new X9ECParameters(BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getCurve(), BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getG(), BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getN(), BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getH());
curveParams = new X9ECParameters(
BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getCurve(),
new X9ECPoint(BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getG(), false),
BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getN(),
BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getH());
}
else
{
Expand Down Expand Up @@ -174,12 +187,24 @@ public static PrivateKey privateToExplicitParameters(PrivateKey key, Provider pr
ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(params.getParameters());

curveParams = ECUtil.getNamedCurveByOid(oid);
// ignore seed value due to JDK bug
curveParams = new X9ECParameters(curveParams.getCurve(), curveParams.getG(), curveParams.getN(), curveParams.getH());

if (curveParams.hasSeed())
{
// ignore seed value due to JDK bug
curveParams = new X9ECParameters(
curveParams.getCurve(),
curveParams.getBaseEntry(),
curveParams.getN(),
curveParams.getH());
}
}
else if (params.isImplicitlyCA())
{
curveParams = new X9ECParameters(BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getCurve(), BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getG(), BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getN(), BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getH());
curveParams = new X9ECParameters(
BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getCurve(),
new X9ECPoint(BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getG(), false),
BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getN(),
BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa().getH());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ void test(String algorithm, byte[] message)
fail("Result object 5 not equal");
}

// Harak has a fixed length input
if (algorithm.startsWith("Haraka"))
// Haraka has a fixed length input
if (algorithm.startsWith("HARAKA"))
{
return;
}
Expand Down Expand Up @@ -208,8 +208,8 @@ public void performTest()
abcTest(abcVectors[i][0], abcVectors[i][1]);
}

test("Haraka-256", Hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"));
test("Haraka-512", Hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
test("HARAKA-256", Hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"));
test("HARAKA-512", Hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
+ "202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f"));
}

Expand Down
6 changes: 6 additions & 0 deletions scripts/jdk1.1ed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,9 @@ w
q
%

ed org/bouncycastle/bcpg/SignatureSubpacketInputStream.java <<%
g/private.*final.*;/s/final//
w
q
%

0 comments on commit 503239b

Please sign in to comment.