Skip to content

Commit

Permalink
Removed anything related building the suffix list in Gradle.
Browse files Browse the repository at this point in the history
Updated examples to read suffix list as file.
Updated fetch jars to also fetch the latest suffix list.
  • Loading branch information
Megan Woods committed Apr 9, 2017
1 parent 2433690 commit 2397b33
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 10,903 deletions.
115 changes: 1 addition & 114 deletions test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,120 +4,7 @@ dependencies {
compile project(":mail")
compile project(":pg")
compile project(":pkix")
compile project(":prov")
// compile project(":prov")
compile project(":tls")
}

task updateSuffixes {
URL url = new URL("https://www.publicsuffix.org/list/public_suffix_list.dat");
HttpURLConnection hurl = (HttpURLConnection)url.openConnection();
hurl.setDoInput(true);
if (hurl.getResponseCode() < 200 || hurl.getResponseCode() >= 300)
{
System.err.println("Got " + hurl.getResponseCode() + " " + hurl.getResponseMessage());
return;
}
String line = null;
BufferedReader bin = new BufferedReader(new InputStreamReader(hurl.getInputStream()));
ArrayList<String> suffixes = new ArrayList<>();

while ((line = bin.readLine()) != null)
{
if (line.isEmpty() || (line.startsWith("//") && !line.startsWith("// xn--")))
{
continue;
}

if (line.startsWith("!")) {
continue;
}

line = line.trim();
if (line.startsWith("// xn--"))
{
String[] j = line.split(" ");
suffixes.add(j[1]);
}
else
{
suffixes.add(line);
}
}

bin.close();
hurl.disconnect();

for (int t=0; t<suffixes.size(); t++) {
String j = suffixes.get(t);

if (!j.startsWith("*.")) {
j = "*."+j;
}

byte[] b = j.getBytes("UTF-8");

j = Arrays.toString(b);
j = j.substring(1,j.length()-1);

suffixes.set(t,j);
}



FileWriter fw = new FileWriter("${projectDir}/src/main/java/org/bouncycastle/test/est/examples/SuffixList.java");
PrintWriter pw = new PrintWriter(fw);

pw.println("package org.bouncycastle.test.est.examples;");
pw.println("");
pw.println("import java.util.Collections;\n" +
"import java.util.HashSet;\n" +
"import java.util.Set;");
pw.println("// This file is machine generated from gradle pkix:updateSuffixes");
pw.println("public class SuffixList {");

pw.println("private static String c = \"UTF-8\";");

int m = 0;

pw.println("private static void d"+(m++)+"(HashSet<String> s) throws Exception { ")
int i =0;
for (String s:suffixes) {

if ((++i % 20) == 0) {
pw.println("}");
pw.println("private static void d"+(m++)+"(HashSet<String> s) throws Exception {");
}
pw.println("s.add(new String(new byte[]{"+s+"}, c));");
}

pw.println("}");




pw.println(" public static final Set<String> publicSuffix;\n" +
" \n" +
" static {\n" +
" HashSet<String> s = new HashSet<String>();\n" +
" \n");

pw.println("try {");

while(--m >=0) {
pw.println("d"+m+"(s);");
}

pw.println("} catch(Exception ex) { throw new RuntimeException(ex.getMessage(),ex);}");



pw.println(
" publicSuffix = Collections.unmodifiableSet(s);\n" +
" }");

pw.println("}");

pw.flush();
pw.close();

}
2 changes: 1 addition & 1 deletion test/est/example/cacerts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ popd
$DIR/ensurejar.sh

CP="$DIR/jars/pkix.jar:$DIR/jars/bcprov.jar:$DIR/jars/test.jar:$DIR/jars/bctls.jar"
java -classpath $CP org.bouncycastle.test.est.examples.CaCertsExample $@
java -classpath $CP org.bouncycastle.test.est.examples.CaCertsExample --sl $DIR/jars/suffixlist.dat $@

2 changes: 1 addition & 1 deletion test/est/example/csrattrs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ popd
$DIR/ensurejar.sh

CP="$DIR/jars/pkix.jar:$DIR/jars/bcprov.jar:$DIR/jars/test.jar:$DIR/jars/bctls.jar"
java -classpath $CP org.bouncycastle.test.est.examples.CSRAttributesExample $@
java -classpath $CP org.bouncycastle.test.est.examples.CSRAttributesExample --sl $DIR/jars/suffixlist.dat $@

2 changes: 1 addition & 1 deletion test/est/example/enroll.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ $DIR/ensurejar.sh

CP="$DIR/jars/pkix.jar:$DIR/jars/bcprov.jar:$DIR/jars/test.jar:$DIR/jars/bctls.jar"
echo $CP
java -classpath $CP org.bouncycastle.test.est.examples.EnrollExample $@
java -classpath $CP org.bouncycastle.test.est.examples.EnrollExample --sl $DIR/jars/suffixlist.dat $@
3 changes: 2 additions & 1 deletion test/est/example/ensurejar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ pushd $DIR/jars
if type curl > /dev/null; then
curl -o bcprov.jar https://downloads.bouncycastle.org/betas/bcprov-jdk15on-157b11.jar
curl -o bctls.jar https://downloads.bouncycastle.org/betas/bctls-jdk15on-157b11.jar
curl -o suffixlist.dat https://www.publicsuffix.org/list/public_suffix_list.dat
elif type wget > /dev/null ; then
wget -O bcprov.jar https://downloads.bouncycastle.org/betas/bcprov-jdk15on-157b11.jar
wget -O bctls.jar https://downloads.bouncycastle.org/betas/bctls-jdk15on-157b11.jar
wget -O suffixlist.dat https://www.publicsuffix.org/list/public_suffix_list.dat
else
echo "No wget or curl to download provider jar"
fi
Expand All @@ -31,7 +33,6 @@ popd

cd $BCDIR

gradle test:updateSuffixes
gradle -x test clean jar

cp $BCDIR/test/build/libs/test-*.jar $DIR/jars/test.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public CSRAttributesExample(String[] args)
boolean noNameVerifier = false;
int timeout = 0;
String label = null;
String suffixList = null;

try
{
Expand Down Expand Up @@ -84,6 +85,11 @@ else if (arg.equals("--label"))
label = ExampleUtils.nextArgAsString("CA Label", args, t);
t += 1;
}
else if (arg.equals("--sl"))
{
suffixList = ExampleUtils.nextArgAsString("Suffix List", args, t);
t += 1;
}
else
{
throw new IllegalArgumentException("Unknown argument " + arg);
Expand All @@ -106,6 +112,12 @@ else if (arg.equals("--label"))
System.exit(-1);
}

if (suffixList == null)
{
System.err.println("Known Suffix List (--sl) must be defined.");
System.exit(-1);
}

//
// Read the trust anchor.
//
Expand Down Expand Up @@ -152,7 +164,7 @@ else if (arg.equals("--label"))
}
else
{
builder.withHostNameAuthorizer(new JsseDefaultHostnameAuthorizer(SuffixList.publicSuffix));
builder.withHostNameAuthorizer(new JsseDefaultHostnameAuthorizer(SuffixList.loadSuffixes(suffixList)));
}

//
Expand Down Expand Up @@ -194,6 +206,7 @@ public void printArguments()
System.out.println("--to <milliseconds> Timeout in milliseconds.");
System.out.println("--no-name-verifier No hostname verifier.");
System.out.println("--label <ca label> CA Label.");
System.out.println("--sl <file> List of known suffixes.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public CaCertsExample(String[] args)
boolean noNameVerifier = false;
String label = null;
int timeout = 0;

String suffixList = null;
try
{
for (int t = 0; t < args.length; t++)
Expand Down Expand Up @@ -90,6 +90,9 @@ else if (arg.equals("--label"))
{
label = ExampleUtils.nextArgAsString("CA Label", args, t);
t += 1;
} else if (arg.equals("--sl")) {
suffixList = ExampleUtils.nextArgAsString("Suffix List", args, t);
t += 1;
}
else
{
Expand All @@ -113,6 +116,11 @@ else if (arg.equals("--label"))
System.exit(-1);
}

if (suffixList == null) {
System.err.println("Known Suffix List (--sl) must be defined.");
System.exit(-1);
}

//
// Read the trust anchor.
//
Expand Down Expand Up @@ -154,7 +162,7 @@ else if (arg.equals("--label"))
}
else
{
builder.withHostNameAuthorizer(new JsseDefaultHostnameAuthorizer(SuffixList.publicSuffix));
builder.withHostNameAuthorizer(new JsseDefaultHostnameAuthorizer(SuffixList.loadSuffixes(suffixList)));
}


Expand Down Expand Up @@ -288,6 +296,7 @@ public void printArguments()
System.out.println("--to <milliseconds> Timeout in milliseconds.");
System.out.println("--no-name-verifier No hostname verifier.");
System.out.println("--label <ca label> CA Label.");
System.out.println("--sl <file> List of known suffixes.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public EnrollExample(String[] args)
String label = null;
String saveKeysToFile = null;
String keyFile = null;
String suffixList = null;
try
{
for (int t = 0; t < args.length; t++)
Expand Down Expand Up @@ -159,6 +160,10 @@ else if (arg.equals("--load"))
{
keyFile = ExampleUtils.nextArgAsString("Load keys from file", args, t);
t += 1;
} else if (arg.equals("--sl"))
{
suffixList = ExampleUtils.nextArgAsString("Suffix List", args, t);
t += 1;
}
else
{
Expand Down Expand Up @@ -205,6 +210,12 @@ else if (arg.equals("--load"))
}


if (suffixList == null)
{
System.err.println("Known Suffix List (--sl) must be defined.");
System.exit(-1);
}

//
// Make a CSR here
//
Expand Down Expand Up @@ -291,7 +302,7 @@ else if ("PUBLIC KEY".equals(o.getType()))
}
else
{
est.withHostNameAuthorizer(new JsseDefaultHostnameAuthorizer(SuffixList.publicSuffix));
est.withHostNameAuthorizer(new JsseDefaultHostnameAuthorizer(SuffixList.loadSuffixes(suffixList)));
}

ESTAuth auth = null;
Expand Down Expand Up @@ -416,5 +427,6 @@ public void printArgs()
System.out.println("--label <ca label> CA Label.");
System.out.println("--save <path to file> Save generated public and private key to file, (PEM)");
System.out.println("--load <path to file> Load generated public and private key from a file, (PEM)");
System.out.println("--sl <file> List of known suffixes.");
}
}
Loading

0 comments on commit 2397b33

Please sign in to comment.