]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/Domain.java
Merge "Update notes about password security"
[gigi.git] / src / org / cacert / gigi / dbObjects / Domain.java
index 78ebc9bbf78ff3f96edee4b8ef27a3888925f183..fa6a6d0e10240b75b37d205c0a33e7645d02980f 100644 (file)
@@ -51,6 +51,7 @@ public class Domain implements IdCachable, Verifyable {
     }
 
     public Domain(User actor, CertificateOwner owner, String suffix) throws GigiApiException {
+        suffix = suffix.toLowerCase();
         synchronized (Domain.class) {
             checkCertifyableDomain(suffix, actor.isInGroup(Group.CODESIGNING));
             this.owner = owner;
@@ -73,6 +74,12 @@ public class Domain implements IdCachable, Verifyable {
         if ( !s.equals(publicSuffix)) {
             throw new GigiApiException("You may only register a domain with exactly one lable before the public suffix.");
         }
+        if (("." + s).matches("(\\.[0-9]*)*")) {
+            // This is not reached because we currently have no TLD that is
+            // numbers only. But who knows..
+            // Better safe than sorry.
+            throw new GigiApiException("IP Addresses are not allowed");
+        }
         checkPunycode(parts[0], s.substring(parts[0].length() + 1));
     }
 
@@ -123,7 +130,7 @@ public class Domain implements IdCachable, Verifyable {
             boolean existed = rs.next();
             rs.close();
             if (existed) {
-                throw new GigiApiException("Domain could not be inserted. Domain is already valid.");
+                throw new GigiApiException("Domain could not be inserted. Domain is already known to the system.");
             }
         }
     }
@@ -171,7 +178,7 @@ public class Domain implements IdCachable, Verifyable {
         LinkedList<DomainPingConfiguration> configs = this.configs;
         if (configs == null) {
             configs = new LinkedList<>();
-            try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT id FROM pingconfig WHERE domainid=?")) {
+            try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT id FROM pingconfig WHERE domainid=? AND `deleted` IS NULL")) {
                 ps.setInt(1, id);
                 GigiResultSet rs = ps.executeQuery();
                 while (rs.next()) {
@@ -194,6 +201,14 @@ public class Domain implements IdCachable, Verifyable {
         configs = null;
     }
 
+    public void clearPings() throws GigiApiException {
+        try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `pingconfig` SET `deleted`=CURRENT_TIMESTAMP WHERE `deleted` is NULL AND `domainid`=?")) {
+            ps.setInt(1, id);
+            ps.execute();
+        }
+        configs = null;
+    }
+
     public synchronized void verify(String hash) throws GigiApiException {
         try (GigiPreparedStatement ps = new GigiPreparedStatement("UPDATE `domainPinglog` SET `state`='success' WHERE `challenge`=? AND `state`='open' AND `configId` IN (SELECT `id` FROM `pingconfig` WHERE `domainid`=? AND `type`='email')")) {
             ps.setString(1, hash);