Skip to content

Commit 7035b29

Browse files
committed
Refactor to not require bouncycastle, add actions for importing certs
1 parent cf5b5b4 commit 7035b29

File tree

3 files changed

+256
-123
lines changed

3 files changed

+256
-123
lines changed

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/sys/cert/CertificateVerifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static PKIXCertPathBuilderResult verifyCertificate(X509Certificate cert,
7777

7878
// Check whether the certificate is revoked by the CRL
7979
// given in its CRL distribution point extension
80-
CRLVerifier.verifyCertificateCRLs(cert);
80+
// CRLVerifier.verifyCertificateCRLs(cert);
8181

8282
// The chain is built and verified. Return it as a result
8383
return verifiedCertChain;
@@ -144,7 +144,7 @@ private static PKIXCertPathBuilderResult verifyCertificate(X509Certificate cert,
144144
new PKIXBuilderParameters(trustAnchors, selector);
145145

146146
// Disable CRL checks (this is done manually as additional step)
147-
pkixParams.setRevocationEnabled(false);
147+
pkixParams.setRevocationEnabled(true);
148148

149149
// Specify a list of intermediate certificates
150150
CertStore intermediateCertStore = CertStore.getInstance("Collection",
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.acuity.iot.dsa.dslink.sys.cert;
2+
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Paths;
9+
10+
import org.iot.dsa.logging.DSLogger;
11+
import org.iot.dsa.time.DSTime;
12+
13+
public class KeyToolUtil extends DSLogger {
14+
15+
private static KeyToolUtil inst = new KeyToolUtil();
16+
private KeyToolUtil() {
17+
18+
}
19+
20+
private void executeCommand(String[] cmd) {
21+
try {
22+
ProcessBuilder builder = new ProcessBuilder();
23+
Process process = builder.command(cmd).start();
24+
process.waitFor();
25+
} catch (Exception e) {
26+
error("", e);
27+
}
28+
}
29+
30+
public static void generateSelfSigned(String keystore, String password) {
31+
String[] cmd = new String[]{
32+
"keytool",
33+
"-genkey",
34+
"-keystore", keystore,
35+
"-storepass", password,
36+
"-keypass", password,
37+
"-alias", "dsa",
38+
"-keyalg", "RSA",
39+
"-validity", "18000",
40+
"-dname", "\"CN=dslink-java-v2, O=DSA, C=US\""
41+
};
42+
inst.executeCommand(cmd);
43+
}
44+
45+
public static String generateCSR(String keystore) throws IOException {
46+
String filename = "dsa.csr";
47+
String[] cmd = new String[]{
48+
"keytool",
49+
"-certreq",
50+
"-keystore", keystore,
51+
"-alias", "dsa",
52+
"-keyalg", "RSA",
53+
"-validity", "18000",
54+
"-dname", "\"CN=dslink-java-v2, O=DSA, C=US\"",
55+
"-file", filename
56+
};
57+
inst.executeCommand(cmd);
58+
return new String(Files.readAllBytes(Paths.get(filename)));
59+
}
60+
61+
public static void importCACert(String keystore, String certStr, String alias) throws IOException {
62+
String filename = DSTime.encodeForFiles(DSTime.getCalendar(System.currentTimeMillis()), new StringBuilder("tempCACert")).toString();
63+
Files.write(Paths.get(filename), certStr.getBytes());
64+
String[] cmd = new String[]{
65+
"keytool",
66+
"-import",
67+
"-trustcacerts",
68+
"-keystore", keystore,
69+
"-alias", alias,
70+
"-file", filename
71+
};
72+
inst.executeCommand(cmd);
73+
74+
new File(filename).delete();
75+
}
76+
77+
public static void importPrimaryCert(String keystore, String certStr) throws IOException {
78+
String filename = DSTime.encodeForFiles(DSTime.getCalendar(System.currentTimeMillis()), new StringBuilder("tempCert")).toString();
79+
Files.write(Paths.get(filename), certStr.getBytes());
80+
String[] cmd = new String[]{
81+
"keytool",
82+
"-import",
83+
"-trustcacerts",
84+
"-keystore", keystore,
85+
"-alias", "dsa",
86+
"-file", filename
87+
};
88+
inst.executeCommand(cmd);
89+
90+
new File(filename).delete();
91+
}
92+
93+
}

0 commit comments

Comments
 (0)