Skip to content

Commit

Permalink
error prone cleanups.
Browse files Browse the repository at this point in the history
added mail and jmail back into the build.
added prov:test11, prov:test17, prov:test21 to base test stanza.
  • Loading branch information
dghgit committed Feb 3, 2024
1 parent 438be0c commit 31da5cb
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 95 deletions.
2 changes: 1 addition & 1 deletion bc-build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# intended to hold user-specific settings that are *not* committed to
# the repository.

release.suffix: 178b02
release.suffix: 178b04
release.name: 1.77.99
release.version: 1.77.99
release.debug: true
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,4 @@ subprojects {

}

test.dependsOn([':core:test', ':prov:test', ':pkix:test', 'pg:test', ':tls:test'])
test.dependsOn([':core:test', ':prov:test', ':prov:test11', ':prov:test17', ':prov:test21', ':pkix:test', 'pg:test', ':tls:test', 'mls:test', 'mail:test', 'jmail:test'])
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private void setKey(byte[] keyBytes, byte[] ivBytes)
workingKey = keyBytes;
workingIV = ivBytes;

/**
/*
* Load NFSR and LFSR
*/
int j = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ private static void quarterRound(long[] v, int x, int y, int z, int s)

private void initialize(byte[] tmpBlockBytes, byte[] password, int outputLength)
{
/**
/*
* H0 = H64(p, τ, m, t, v, y, |P|, P, |S|, S, |L|, K, |X|, X)
* -> 64 byte (ARGON2_PREHASH_DIGEST_LENGTH)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.bouncycastle.crypto.test;

import java.io.UnsupportedEncodingException;

import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.Blake2bDigest;
import org.bouncycastle.util.Arrays;
Expand Down Expand Up @@ -124,23 +122,15 @@ public void performTest()
for (int i = 0; i < unkeyedTestVectors.length; i++)
{

try
{
// blake2bunkeyed.update(
// unkeyedTestVectors[i][1].getBytes("UTF-8"));
// test update(byte b)
byte[] unkeyedInput = unkeyedTestVectors[i][1]
.getBytes("UTF-8");
for (int j = 0; j < unkeyedInput.length; j++)
{
blake2bunkeyed.update(unkeyedInput[j]);
}
}
catch (UnsupportedEncodingException e)
// blake2bunkeyed.update(
// unkeyedTestVectors[i][1].getBytes("UTF-8"));
// test update(byte b)
byte[] unkeyedInput = Strings.toUTF8ByteArray(unkeyedTestVectors[i][1]);
for (int j = 0; j < unkeyedInput.length; j++)
{
// TODO Auto-generated catch block
e.printStackTrace();
blake2bunkeyed.update(unkeyedInput[j]);
}

byte[] unkeyedHash = new byte[64];
blake2bunkeyed.doFinal(unkeyedHash, 0);
blake2bunkeyed.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bouncycastle.pqc.crypto.xmss.XMSSParameters;
import org.bouncycastle.pqc.crypto.xmss.XMSSPrivateKeyParameters;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.Strings;
import org.bouncycastle.util.encoders.Base64;

/**
Expand All @@ -27,11 +28,8 @@ public void testPrivateKeySerialisation()

XMSSParameters params = new XMSSParameters(10, new SHA256Digest());

byte[] output = Base64.decode(new String(stream).getBytes("UTF-8"));


byte[] output = Base64.decode(Strings.toUTF8ByteArray(stream));
//Simple Exploit

try
{
new XMSSPrivateKeyParameters.Builder(params).withPrivateKey(output).build();
Expand Down
25 changes: 10 additions & 15 deletions jmail/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,32 @@ sourceSets {
}
}


java9 {
java {
srcDirs = ['src/main/jdk1.9']
}
}


}

dependencies {
// implementation project(':prov')
// implementation project(':util')
implementation project(':prov')
implementation project(':util')
implementation project(':pkix')

implementation group: 'jakarta.mail', name: 'jakarta.mail-api', version: '2.0.1'
implementation group: 'jakarta.activation', name: 'jakarta.activation-api', version: '2.0.0'
// implementation files("$bc_prov")
// implementation files("$bc_util")
// implementation files("$bc_pkix")
// implementation project(path: ':core')

java9Implementation group: 'jakarta.mail', name: 'jakarta.mail-api', version: '2.0.1'
java9Implementation group: 'jakarta.activation', name: 'jakarta.activation-api', version: '2.0.0'
// java9Implementation files("$bc_prov")
// java9Implementation files("$bc_util")
// java9Implementation files("$bc_pkix")
implementation files("$bc_prov")
implementation files("$bc_util")
implementation files("$bc_pkix")
implementation project(path: ':core')

java9Implementation files("$bc_prov")
java9Implementation files("$bc_util")
java9Implementation files("$bc_pkix")
java9Implementation files(sourceSets.main.output.classesDirs) {
builtBy compileJava
}

}

task copyTask(type: Copy) {
Expand Down
27 changes: 11 additions & 16 deletions mail/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,25 @@ sourceSets {
srcDirs = ['src/main/jdk1.9']
}
}


}

dependencies {
// implementation project(':prov')
// implementation project(':util')
implementation project(':prov')
implementation project(':util')
implementation project(':pkix')

implementation group: 'javax.mail', name: 'mail', version: '1.4'
// implementation files("$bc_prov")
// implementation files("$bc_util")
// implementation files("$bc_pkix")
// implementation project(path: ':core')

java9Implementation group: 'javax.mail', name: 'mail', version: '1.4'
// java9Implementation files("$bc_prov")
// java9Implementation files("$bc_util")
// java9Implementation files("$bc_pkix")
implementation files("$bc_prov")
implementation files("$bc_util")
implementation files("$bc_pkix")
implementation project(path: ':core')

java9Implementation files(":prov")
java9Implementation files(":util")
java9Implementation files(":pkix")
java9Implementation files(sourceSets.main.output.classesDirs) {
builtBy compileJava
}


}

compileJava {
Expand Down Expand Up @@ -92,4 +87,4 @@ artifacts {
test {
forkEvery = 1;
maxParallelForks = 8;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.AlgorithmParameters;
import java.security.KeyFactory;
Expand Down Expand Up @@ -1387,27 +1386,27 @@ private void pemTest()
{
fail("PEM cert with extraneous header not read");
}
CRL crl = cf.generateCRL(new ByteArrayInputStream(PEMData.CRL_1.getBytes("US-ASCII")));
CRL crl = cf.generateCRL(new ByteArrayInputStream(Strings.toByteArray(PEMData.CRL_1)));
if (crl == null)
{
fail("PEM crl not read");
}
Collection col = cf.generateCertificates(new ByteArrayInputStream(PEMData.CERTIFICATE_2.getBytes("US-ASCII")));
Collection col = cf.generateCertificates(new ByteArrayInputStream(Strings.toByteArray(PEMData.CERTIFICATE_2)));
if (col.size() != 1 || !col.contains(cert))
{
fail("PEM cert collection not right");
}
col = cf.generateCertificates(new ByteArrayInputStream((PEMData.CERTIFICATE_2 + "z\n").getBytes("US-ASCII")));
col = cf.generateCertificates(new ByteArrayInputStream(Strings.toByteArray((PEMData.CERTIFICATE_2 + "z\n"))));
if (col.size() != 1 || !col.contains(cert))
{
fail("PEM cert collection with extra not right");
}
col = cf.generateCRLs(new ByteArrayInputStream(PEMData.CRL_2.getBytes("US-ASCII")));
col = cf.generateCRLs(new ByteArrayInputStream(Strings.toByteArray(PEMData.CRL_2)));
if (col.size() != 1 || !col.contains(crl))
{
fail("PEM crl collection not right");
}
col = cf.generateCRLs(new ByteArrayInputStream((PEMData.CRL_2 + "z\n").getBytes("US-ASCII")));
col = cf.generateCRLs(new ByteArrayInputStream(Strings.toByteArray((PEMData.CRL_2 + "z\n"))));
if (col.size() != 1 || !col.contains(crl))
{
fail("PEM crl collection with extra not right");
Expand All @@ -1429,9 +1428,9 @@ private void pemTest()
}

private static Certificate readPEMCert(CertificateFactory cf, String pemData)
throws CertificateException, UnsupportedEncodingException
throws CertificateException
{
return cf.generateCertificate(new ByteArrayInputStream(pemData.getBytes("US-ASCII")));
return cf.generateCertificate(new ByteArrayInputStream(Strings.toByteArray(pemData)));
}

private void pkcs7Test()
Expand Down Expand Up @@ -1531,7 +1530,7 @@ private void pkcs7Test()
fail("wrong number of Certs: " + certCol.size());
}

in = new ByteArrayInputStream(pemPKCS7.getBytes("US-ASCII"));
in = new ByteArrayInputStream(Strings.toByteArray(pemPKCS7));
certCol = cf.generateCertificates(in);

in.reset();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package org.bouncycastle.jce.provider.test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.security.Security;
import java.security.cert.X509CRL;
import java.security.cert.X509Certificate;
import java.util.Collection;

import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.DERSet;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.internal.asn1.cms.CMSObjectIdentifiers;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.Strings;
import org.bouncycastle.util.encoders.Base64;
import org.bouncycastle.util.test.SimpleTest;
import org.bouncycastle.x509.X509AttributeCertificate;
import org.bouncycastle.x509.X509CertificatePair;
import org.bouncycastle.x509.X509StreamParser;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.security.Security;
import java.security.cert.X509CRL;
import java.security.cert.X509Certificate;
import java.util.Collection;

public class X509StreamParserTest
extends SimpleTest
{
Expand Down Expand Up @@ -139,7 +139,7 @@ public void performTest()
//
parser = X509StreamParser.getInstance("Certificate", "BC");

parser.init(PEMData.CERTIFICATE_1.getBytes("US-ASCII"));
parser.init(Strings.toByteArray(PEMData.CERTIFICATE_1));

res = parser.readAll();

Expand All @@ -150,7 +150,7 @@ public void performTest()

parser = X509StreamParser.getInstance("Certificate", "BC");

parser.init(PEMData.CERTIFICATE_2.getBytes("US-ASCII"));
parser.init(Strings.toByteArray(PEMData.CERTIFICATE_2));

res = parser.readAll();

Expand All @@ -161,7 +161,7 @@ public void performTest()

parser = X509StreamParser.getInstance("CRL", "BC");

parser.init(PEMData.CRL_1.getBytes("US-ASCII"));
parser.init(Strings.toByteArray(PEMData.CRL_1));

res = parser.readAll();

Expand All @@ -172,7 +172,7 @@ public void performTest()

parser = X509StreamParser.getInstance("CRL", "BC");

parser.init(PEMData.CRL_2.getBytes("US-ASCII"));
parser.init(Strings.toByteArray(PEMData.CRL_2));

res = parser.readAll();

Expand All @@ -183,7 +183,7 @@ public void performTest()

parser = X509StreamParser.getInstance("AttributeCertificate", "BC");

parser.init(PEMData.ATTRIBUTE_CERTIFICATE_1.getBytes("US-ASCII"));
parser.init(Strings.toByteArray(PEMData.ATTRIBUTE_CERTIFICATE_1));

res = parser.readAll();

Expand All @@ -194,7 +194,7 @@ public void performTest()

parser = X509StreamParser.getInstance("AttributeCertificate", "BC");

parser.init(PEMData.ATTRIBUTE_CERTIFICATE_2.getBytes("US-ASCII"));
parser.init(Strings.toByteArray(PEMData.ATTRIBUTE_CERTIFICATE_2));

res = parser.readAll();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
class PKITSTest
{
private Set trustAnchors = new HashSet();
private ArrayList certs = new ArrayList();
private ArrayList crls = new ArrayList();
private List certs = new ArrayList();
private List crls = new ArrayList();
private Set policies = new HashSet();

//
Expand Down Expand Up @@ -293,12 +293,12 @@ public Set getTrustAnchors()
return trustAnchors;
}

public ArrayList getCerts()
public List getCerts()
{
return certs;
}

public ArrayList getCrls()
public List getCrls()
{
return crls;
}
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ include "prov"
include "tls"
include "test"
include "mls"
//include "mail"
//include "jmail"
include "mail"
include "jmail"
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
import org.bouncycastle.jsse.BCExtendedSSLSession;
import org.bouncycastle.jsse.BCSSLSocket;
import org.bouncycastle.util.Strings;
import org.bouncycastle.util.encoders.Hex;
import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemReader;
Expand Down Expand Up @@ -260,7 +261,7 @@ public void handshakeCompleted(HandshakeCompletedEvent event)
private static void writeUTF8Line(OutputStream output, String line)
throws IOException
{
output.write((line + "\r\n").getBytes("UTF-8"));
output.write(Strings.toUTF8ByteArray(line + "\r\n"));
System.out.println(">>> " + line);
}

Expand Down
Loading

0 comments on commit 31da5cb

Please sign in to comment.