]> WPIA git - gigi.git/commitdiff
Merge "Fix error message"
authorBenny Baumann <BenBE1987@gmx.net>
Tue, 27 Sep 2016 18:21:21 +0000 (20:21 +0200)
committerGerrit Code Review <gigi-system@dogcraft.de>
Tue, 27 Sep 2016 18:21:21 +0000 (20:21 +0200)
src/org/cacert/gigi/crypto/SMIME.java
src/org/cacert/gigi/database/GigiPreparedStatement.java
src/org/cacert/gigi/dbObjects/Domain.java
src/org/cacert/gigi/dbObjects/EmailAddress.java
src/org/cacert/gigi/output/template/MailFooter.templ
src/org/cacert/gigi/pages/Verify.java

index 2ca455c173621ef8ca7e6836e2d960e65ce7078f..de39f5a190793e267e16828f027d9cbcba86e220 100644 (file)
@@ -45,6 +45,7 @@ public class SMIME {
     }
 
     public static void smime(String contents, PrivateKey pKey, X509Certificate c, PrintWriter to) throws IOException, GeneralSecurityException {
+        contents = normalizeNewlinesToCRLF(contents);
 
         Signature signature = Signature.getInstance("SHA1WithRSA");
         signature.initSign(pKey);
@@ -75,6 +76,10 @@ public class SMIME {
         mimeEncode(contents, PEM.formatBase64(bOut.toByteArray()), to);
     }
 
+    private static String normalizeNewlinesToCRLF(String contents) {
+        return contents.replace("\r\n", "\r").replace("\r", "\n").replace("\n", "\r\n");
+    }
+
     private static Random r = new Random();
 
     private static void mimeEncode(String contents, String signature, PrintWriter to) {
index a779f965fb56c150a2329b9dc6bddb6fd4842424..4dea5f981f68eb28679734eb1ed88c74e2dc7328 100644 (file)
@@ -49,6 +49,19 @@ public class GigiPreparedStatement implements AutoCloseable {
         }
     }
 
+    public boolean executeMaybeUpdate() {
+        try {
+            int updated = target.executeUpdate();
+            if (updated > 1) {
+                throw new Error("More than one record (" + updated + ") updated.");
+            }
+            return updated == 1;
+        } catch (SQLException e) {
+            handleSQL(e);
+            throw new Error(e);
+        }
+    }
+
     public boolean execute() {
         try {
             return target.execute();
index 36b7dc6f651dec5c071f15796ac38c42a3117a56..3ecf728567f6c166aa5dc960091c8c26061c6f28 100644 (file)
@@ -129,7 +129,9 @@ public class Domain implements IdCachable, Verifyable {
         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);
             ps.setInt(2, id);
-            ps.executeUpdate();
+            if ( !ps.executeMaybeUpdate()) {
+                throw new IllegalArgumentException("Given token could not be found to complete the verification process (Domain Ping).");
+            }
         }
     }
 
index afd7f2c1fa13321e2beee95e1f063f03b02d8b1e..b2106d8bff71c901c3e51c1bfe9e6b3d8f160c8c 100644 (file)
@@ -96,11 +96,13 @@ public class EmailAddress implements IdCachable, Verifyable {
     }
 
     public synchronized void verify(String hash) throws GigiApiException {
-        try (GigiPreparedStatement stmt = new GigiPreparedStatement("UPDATE `emailPinglog` SET `status`='success'::`pingState` WHERE `email`=? AND `uid`=? AND `type`='active' AND `challenge`=?")) {
+        try (GigiPreparedStatement stmt = new GigiPreparedStatement("UPDATE `emailPinglog` SET `status`='success'::`pingState` WHERE `email`=? AND `uid`=? AND `type`='active' AND `challenge`=? AND `status`='open'::`pingState`")) {
             stmt.setString(1, address);
             stmt.setInt(2, owner.getId());
             stmt.setString(3, hash);
-            stmt.executeUpdate();
+            if ( !stmt.executeMaybeUpdate()) {
+                throw new IllegalArgumentException("Given token could not be found to complete the verification process (Domain Ping).");
+            }
         }
         // Verify user with that primary email
         try (GigiPreparedStatement ps2 = new GigiPreparedStatement("update `users` set `verified`='1' where `id`=? and `email`=? and `verified`='0'")) {
index b92e9718d1f891a8a79f5993a76e357eef1bfc44..ca8f594c309ace9a048e38c814fdbbce9befc37c 100644 (file)
@@ -3,9 +3,10 @@
 <?=_SomeCA.org?>
 
 --
+
 <?=_This message has automatically been sent by the system.?>
 
-<?=_All emails originating from this domain use S/MIME protection through digital signatures and optional encryption.?>\
+<?=_All emails originating from this domain use S/MIME protection through digital signatures and optional encryption.?> \
 <?=_Please report any unsigned emails, claiming to have originated from this service, to our support (please sign your email if available), by forwarding them including full email headers.?>
 
 <?=_Our support AND all personnel working on our behalf will NEVER ask you to reveal or provide your account credentials (i.e. passwords); although be aware that you might be asked to prove your identity (e.g. by signing your email) in order for support tickets regarding your account to be carried out.?>
index d7e5aed6bfe405c22512822755ab108da412c759..2b4cd82605cfe2ffc62fa76b2cde50e489717ad0 100644 (file)
@@ -62,14 +62,14 @@ public class Verify extends Page {
                 try {
                     target.verify(hash);
                 } catch (IllegalArgumentException e) {
-                    throw new GigiApiException("The email address is invalid.");
+                    throw new PermamentFormException(new GigiApiException("Given token could not be found to complete the verification process (Email Ping)."));
                 }
                 return new SuccessMessageResult(new Scope(emailAddressVerified, data));
             } else if ("domain".equals(type)) {
                 try {
                     target.verify(hash);
                 } catch (IllegalArgumentException e) {
-                    throw new GigiApiException("The domain is invalid.");
+                    throw new PermamentFormException(new GigiApiException("Given token could not be found to complete the verification process (Domain Ping)."));
                 }
                 return new SuccessMessageResult(new Scope(domainVerified, data));
             } else {