X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Fclub%2Fwpia%2Fgigi%2FdbObjects%2FDomain.java;h=1d3ba17de35c62b1d65322946e7b3e1407879553;hb=3889444cb95132e342e4b7156245dd032ed3b16b;hp=d7de209c28ae069e1c03e29d9a6417f858b4032b;hpb=bccd4cc0dba0f89aa045b113bac46eb8cc1dab4e;p=gigi.git diff --git a/src/club/wpia/gigi/dbObjects/Domain.java b/src/club/wpia/gigi/dbObjects/Domain.java index d7de209c..1d3ba17d 100644 --- a/src/club/wpia/gigi/dbObjects/Domain.java +++ b/src/club/wpia/gigi/dbObjects/Domain.java @@ -7,6 +7,7 @@ import java.util.List; import club.wpia.gigi.GigiApiException; import club.wpia.gigi.database.GigiPreparedStatement; import club.wpia.gigi.database.GigiResultSet; +import club.wpia.gigi.dbObjects.Certificate.RevocationType; import club.wpia.gigi.util.DomainAssessment; public class Domain implements IdCachable, Verifyable { @@ -34,7 +35,7 @@ public class Domain implements IdCachable, Verifyable { } private static void checkInsert(String suffix) throws GigiApiException { - try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT 1 FROM `domains` WHERE (`domain`=? OR (CONCAT('.', `domain`)=RIGHT(?,LENGTH(`domain`)+1) OR RIGHT(`domain`,LENGTH(?)+1)=CONCAT('.',?))) AND `deleted` IS NULL")) { + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT 1 FROM `domains` WHERE (`domain`=? OR (CONCAT('.', `domain`)=RIGHT(?,LENGTH(`domain`)+1) OR RIGHT(`domain`,LENGTH(?)+1)=CONCAT('.',?::VARCHAR))) AND `deleted` IS NULL")) { ps.setString(1, suffix); ps.setString(2, suffix); ps.setString(3, suffix); @@ -72,6 +73,19 @@ public class Domain implements IdCachable, Verifyable { ps.setInt(1, id); ps.execute(); } + LinkedList revokes = new LinkedList(); + for (Certificate cert : fetchActiveCertificates()) { + revokes.add(cert.revoke(RevocationType.USER)); + } + long start = System.currentTimeMillis(); + for (Job job : revokes) { + int toWait = (int) (60000 + start - System.currentTimeMillis()); + if (toWait > 0) { + job.waitFor(toWait); + } else { + break; // canceled... waited too log + } + } } } @@ -90,7 +104,7 @@ public class Domain implements IdCachable, Verifyable { private LinkedList configs = null; - public List getConfiguredPings() throws GigiApiException { + public List getConfiguredPings() { LinkedList configs = this.configs; if (configs == null) { configs = new LinkedList<>(); @@ -143,12 +157,26 @@ public class Domain implements IdCachable, Verifyable { } } + /** + * Determines current domain validity. A domain is valid, iff at least two + * configured pings are currently successful. + * + * @return true, iff domain is valid + * @throws GigiApiException + */ public boolean isVerified() { - try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT 1 FROM `domainPinglog` INNER JOIN `pingconfig` ON `pingconfig`.`id`=`domainPinglog`.`configId` WHERE `domainid`=? AND `state`='success'")) { - ps.setInt(1, id); - GigiResultSet rs = ps.executeQuery(); - return rs.next(); + int count = 0; + boolean[] used = new boolean[DomainPingType.values().length]; + for (DomainPingConfiguration config : getConfiguredPings()) { + if (config.isValid() && !used[config.getType().ordinal()]) { + count++; + used[config.getType().ordinal()] = true; + } + if (count >= 2) { + return true; + } } + return false; } public DomainPingExecution[] getPings() throws GigiApiException { @@ -195,4 +223,22 @@ public class Domain implements IdCachable, Verifyable { } } + public Certificate[] fetchActiveCertificates() { + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `certs`.`id` FROM `certs` INNER JOIN `subjectAlternativeNames` ON `subjectAlternativeNames`.`certId` = `certs`.`id` WHERE (`contents`=? OR RIGHT(`contents`,LENGTH(?)+1)=CONCAT('.',?::VARCHAR)) AND `type`='DNS' AND `revoked` IS NULL AND `expire` > CURRENT_TIMESTAMP AND `memid`=? GROUP BY `certs`.`id`", true)) { + ps.setString(1, suffix); + ps.setString(2, suffix); + ps.setString(3, suffix); + ps.setInt(4, owner.getId()); + GigiResultSet rs = ps.executeQuery(); + rs.last(); + Certificate[] res = new Certificate[rs.getRow()]; + rs.beforeFirst(); + int i = 0; + while (rs.next()) { + res[i++] = Certificate.getById(rs.getInt(1)); + } + return res; + } + } + }