}
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);
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) {
}
}
+ 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();
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).");
+ }
}
}
}
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'")) {
<?=_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.?>
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 {