From: Benny Baumann Date: Tue, 27 Sep 2016 18:21:21 +0000 (+0200) Subject: Merge "Fix error message" X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=a34a7467a812ed5735b8ce196f9821f75134250b;hp=13c4d02b2101b4239a7fc47b92befff58ff101f1 Merge "Fix error message" --- diff --git a/src/org/cacert/gigi/crypto/SMIME.java b/src/org/cacert/gigi/crypto/SMIME.java index 2ca455c1..de39f5a1 100644 --- a/src/org/cacert/gigi/crypto/SMIME.java +++ b/src/org/cacert/gigi/crypto/SMIME.java @@ -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) { diff --git a/src/org/cacert/gigi/database/GigiPreparedStatement.java b/src/org/cacert/gigi/database/GigiPreparedStatement.java index a779f965..4dea5f98 100644 --- a/src/org/cacert/gigi/database/GigiPreparedStatement.java +++ b/src/org/cacert/gigi/database/GigiPreparedStatement.java @@ -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(); diff --git a/src/org/cacert/gigi/dbObjects/Domain.java b/src/org/cacert/gigi/dbObjects/Domain.java index 36b7dc6f..3ecf7285 100644 --- a/src/org/cacert/gigi/dbObjects/Domain.java +++ b/src/org/cacert/gigi/dbObjects/Domain.java @@ -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)."); + } } } diff --git a/src/org/cacert/gigi/dbObjects/EmailAddress.java b/src/org/cacert/gigi/dbObjects/EmailAddress.java index afd7f2c1..b2106d8b 100644 --- a/src/org/cacert/gigi/dbObjects/EmailAddress.java +++ b/src/org/cacert/gigi/dbObjects/EmailAddress.java @@ -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'")) { diff --git a/src/org/cacert/gigi/output/template/MailFooter.templ b/src/org/cacert/gigi/output/template/MailFooter.templ index b92e9718..ca8f594c 100644 --- a/src/org/cacert/gigi/output/template/MailFooter.templ +++ b/src/org/cacert/gigi/output/template/MailFooter.templ @@ -3,9 +3,10 @@ -- + -\ + \ diff --git a/src/org/cacert/gigi/pages/Verify.java b/src/org/cacert/gigi/pages/Verify.java index d7e5aed6..2b4cd826 100644 --- a/src/org/cacert/gigi/pages/Verify.java +++ b/src/org/cacert/gigi/pages/Verify.java @@ -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 {