+ private static ObjectCache<Certificate> cache = new ObjectCache<>();
+
+ public synchronized static Certificate getById(int id) {
+ Certificate cacheRes = cache.get(id);
+ if (cacheRes != null) {
+ return cacheRes;
+ }
+
+ try {
+ String concat = "string_agg(concat('/', `name`, '=', REPLACE(REPLACE(value, '\\\\', '\\\\\\\\'), '/', '\\\\/')), '')";
+ GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT certs.id, " + concat + " as subject, md, csr_name, crt_name,memid, profile, certs.serial FROM `certs` LEFT JOIN `certAvas` ON `certAvas`.`certId`=certs.id WHERE certs.id=? GROUP BY certs.id");
+ ps.setInt(1, id);
+ GigiResultSet rs = ps.executeQuery();
+
+ Certificate c = new Certificate(rs);
+ cache.put(c);
+ return c;
+ } catch (IllegalArgumentException e) {
+
+ }
+ return null;
+ }
+
+ public static String escapeAVA(String value) {
+
+ return value.replace("\\", "\\\\").replace("/", "\\/");
+ }
+
+ public static String stringifyDN(HashMap<String, String> contents) {
+ StringBuffer res = new StringBuffer();
+ for (Entry<String, String> i : contents.entrySet()) {
+ res.append("/" + i.getKey() + "=");
+ res.append(escapeAVA(i.getValue()));
+ }
+ return res.toString();
+ }
+
+ public static HashMap<String, String> buildDN(String... contents) {
+ HashMap<String, String> res = new HashMap<>();
+ for (int i = 0; i + 1 < contents.length; i += 2) {
+ res.put(contents[i], contents[i + 1]);
+ }
+ return res;
+ }
+
+ public java.util.Date getRevocationDate() {
+ if (getStatus() == CertificateStatus.REVOKED) {
+ GigiPreparedStatement prep = DatabaseConnection.getInstance().prepare("SELECT revoked FROM certs WHERE id=?");
+ prep.setInt(1, getId());
+ GigiResultSet res = prep.executeQuery();
+ res.beforeFirst();
+ if (res.next()) {
+ return new java.util.Date(res.getDate("revoked").getTime());
+ }
+ }
+ return null;
+ }