+
+ public void setLoginEnabled(boolean activate) {
+ if (activate) {
+ if ( !isLoginEnabled()) {
+ try (GigiPreparedStatement prep = new GigiPreparedStatement("INSERT INTO `logincerts` SET `id`=?")) {
+ prep.setInt(1, id);
+ prep.execute();
+ }
+ }
+ } else {
+ try (GigiPreparedStatement prep = new GigiPreparedStatement("DELETE FROM `logincerts` WHERE `id`=?")) {
+ prep.setInt(1, id);
+ prep.execute();
+ }
+ }
+ }
+
+ public boolean isLoginEnabled() {
+ try (GigiPreparedStatement prep = new GigiPreparedStatement("SELECT 1 FROM `logincerts` WHERE `id`=?")) {
+ prep.setInt(1, id);
+ GigiResultSet res = prep.executeQuery();
+ return res.next();
+ }
+ }
+
+ public static Certificate[] findBySerialPattern(String serial) {
+ try (GigiPreparedStatement prep = new GigiPreparedStatement("SELECT `id` FROM `certs` WHERE `serial` LIKE ? GROUP BY `id` LIMIT 100", true)) {
+ prep.setString(1, serial);
+ return fetchCertsToArray(prep);
+ }
+ }
+
+ public static Certificate[] findBySANPattern(String request, SANType type) {
+ try (GigiPreparedStatement prep = new GigiPreparedStatement("SELECT `certId` FROM `subjectAlternativeNames` WHERE `contents` LIKE ? and `type`=?::`SANType` GROUP BY `certId` LIMIT 100", true)) {
+ prep.setString(1, request);
+ prep.setString(2, type.getOpensslName());
+ return fetchCertsToArray(prep);
+ }
+ }
+
+ private static Certificate[] fetchCertsToArray(GigiPreparedStatement prep) {
+ GigiResultSet res = prep.executeQuery();
+ res.last();
+ Certificate[] certs = new Certificate[res.getRow()];
+ res.beforeFirst();
+ for (int i = 0; res.next(); i++) {
+ certs[i] = Certificate.getById(res.getInt(1));
+ }
+ return certs;
+ }