X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Fclub%2Fwpia%2Fgigi%2FdbObjects%2FCACertificate.java;h=1240cd896e97a902d9eb33da7b1e37e2e49d13c7;hp=a1a8f9bd3d54b5e50c1639bcef3b47342c4baa04;hb=00ae4dde24b2b284ed8dbe085a5b42c9ceeb32d1;hpb=bccd4cc0dba0f89aa045b113bac46eb8cc1dab4e diff --git a/src/club/wpia/gigi/dbObjects/CACertificate.java b/src/club/wpia/gigi/dbObjects/CACertificate.java index a1a8f9bd..1240cd89 100644 --- a/src/club/wpia/gigi/dbObjects/CACertificate.java +++ b/src/club/wpia/gigi/dbObjects/CACertificate.java @@ -8,6 +8,7 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.ArrayDeque; +import java.util.Arrays; import java.util.Deque; import java.util.HashMap; @@ -16,6 +17,7 @@ import javax.security.auth.x500.X500Principal; import club.wpia.gigi.database.GigiPreparedStatement; import club.wpia.gigi.database.GigiResultSet; import club.wpia.gigi.util.ServerConstants; +import club.wpia.gigi.util.ServerConstants.Host; public class CACertificate implements IdCachable { @@ -29,6 +31,10 @@ public class CACertificate implements IdCachable { private final String link; + private static final CACertificate[] instances; + + private static ObjectCache myCache = new ObjectCache<>(); + private CACertificate(int id) { this.id = id; int parentRoot; @@ -77,6 +83,17 @@ public class CACertificate implements IdCachable { static { try { update(); + try (GigiPreparedStatement q = new GigiPreparedStatement("SELECT `id` FROM `cacerts`", true)) { + GigiResultSet res = q.executeQuery(); + res.last(); + CACertificate[] certs = new CACertificate[res.getRow()]; + res.beforeFirst(); + int i = 0; + while (res.next()) { + certs[i++] = getById(res.getInt(1)); + } + instances = certs; + } } catch (CertificateException e) { throw new Error(e); } catch (FileNotFoundException e) { @@ -128,10 +145,10 @@ public class CACertificate implements IdCachable { String link; String keyname = names.get(subj); if ( !keyname.contains("_")) { - link = "https://g2.crt." + ServerConstants.getSuffix() + "/g2/" + keyname + ".crt"; + link = "https://" + ServerConstants.getHostNamePortSecure(Host.CRT_REPO) + "/g2/" + keyname + ".crt"; } else { String[] parts = keyname.split("_"); - link = "https://g2.crt." + ServerConstants.getSuffix() + "/g2/" + parts[1] + "/" + parts[0] + "-" + parts[2] + ".crt"; + link = "https://" + ServerConstants.getHostNamePortSecure(Host.CRT_REPO) + "/g2/" + parts[1] + "/" + parts[0] + "-" + parts[2] + ".crt"; } try (GigiPreparedStatement q2 = new GigiPreparedStatement("INSERT INTO `cacerts` SET `parentRoot`=?, `keyname`=?, `link`=?")) { @@ -160,8 +177,6 @@ public class CACertificate implements IdCachable { return id; } - private static ObjectCache myCache = new ObjectCache<>(); - public String getKeyname() { return keyname; } @@ -182,4 +197,8 @@ public class CACertificate implements IdCachable { return this == getParent(); } + public static synchronized CACertificate[] getAll() { + return Arrays.copyOf(instances, instances.length); + } + }