import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.security.GeneralSecurityException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
return this == getParent();
}
+ public String getFingerprint(String algorithm) throws CertificateEncodingException, NoSuchAlgorithmException {
+ return Certificate.getFingerprint(cert, algorithm);
+ }
+
public static synchronized CACertificate[] getAll() {
return Arrays.copyOf(instances, instances.length);
}
-
}
Map<String, Object> map = Page.getDefaultVars(req);
map.put("root", rootP);
map.put("bundle", appName + "_intermediate_bundle.p7b");
- getDefaultTemplate().output(resp.getWriter(), getLanguage(req), map);
+ try {
+ map.put("fingerprintSHA1", rootP.target.getFingerprint("sha-1"));
+ map.put("fingerprintSHA256", rootP.target.getFingerprint("sha-256"));
+ } catch (GeneralSecurityException e) {
+ e.printStackTrace();
+ }
+
+ getDefaultTemplate().output(resp.getWriter(), getLanguage(req), map);
}
@Override
public boolean needsLogin() {
return false;
}
-
}
--- /dev/null
+package club.wpia.gigi.dbObjects;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import club.wpia.gigi.testUtils.ClientBusinessTest;
+
+public class TestCACertificate extends ClientBusinessTest {
+
+ public CertificateFactory fact;
+
+ public CACertificate root, orga;
+
+ public int rootId, orgaId;
+
+ public X509Certificate configRoot;
+
+ @Before
+ public void getTestCertificates() throws CertificateException, FileNotFoundException {
+ fact = CertificateFactory.getInstance("X.509");
+
+ for (CACertificate cert : CACertificate.getAll()) {
+ if ("root".equals(cert.getKeyname())) {
+ root = cert;
+ rootId = cert.getId();
+ } else if ("orga".equals(cert.getKeyname())) {
+ orga = cert;
+ orgaId = cert.getId();
+ }
+ }
+ FileInputStream fis = new FileInputStream(new File("config/ca/root.crt"));
+ configRoot = (X509Certificate) fact.generateCertificate(fis);
+ }
+
+ @Test
+ public void testGetParent() {
+ assertEquals(root, orga.getParent());
+ }
+
+ @Test
+ public void testGetCertificate() {
+ assertEquals(configRoot, root.getCertificate());
+ }
+
+ @Test
+ public void testToString() {
+ assertEquals("CACertificate: root", root.toString());
+ assertEquals("CACertificate: orga", orga.toString());
+ }
+
+ @Test
+ public void testGetId() {
+ assertEquals(rootId, root.getId());
+ assertEquals(orgaId, orga.getId());
+ }
+
+ @Test
+ public void testGetKeyname() {
+ assertEquals("root", root.getKeyname());
+ assertEquals("orga", orga.getKeyname());
+ }
+
+ // TODO: test getLink
+
+ @Test
+ public void testGetById() {
+ assertEquals(root, CACertificate.getById(rootId));
+ assertEquals(orga, CACertificate.getById(orgaId));
+ }
+
+ @Test
+ public void testIsSelfsigned() {
+ assertTrue(root.isSelfsigned());
+ assertFalse(orga.isSelfsigned());
+ }
+
+ @Test
+ public void testGetFingerprint() throws CertificateEncodingException, NoSuchAlgorithmException {
+ assertEquals(Certificate.getFingerprint(configRoot, "sha-1"), root.getFingerprint("sha-1"));
+ assertEquals(Certificate.getFingerprint(configRoot, "sha-256"), root.getFingerprint("sha-256"));
+ }
+
+ @Test
+ public void testGetAll() throws FileNotFoundException, CertificateException {
+ for (CACertificate cert : CACertificate.getAll()) {
+ FileInputStream fis = new FileInputStream(new File(String.format("config/ca/%s.crt", cert.getKeyname())));
+ assertEquals(cert.getCertificate(), (X509Certificate) fact.generateCertificate(fis));
+ }
+ }
+}