X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Fclub%2Fwpia%2Fgigi%2Fpages%2Fmain%2FKeyCompromiseForm.java;fp=src%2Fclub%2Fwpia%2Fgigi%2Fpages%2Fmain%2FKeyCompromiseForm.java;h=ee0110f4fc4acbf4ca1a33379f6217cffc4ca3b3;hp=321059b8d5fe226dedd50fd44ec54b45705e084a;hb=04a81b06f668688c5ebacd4444ef55fb3c8ef89d;hpb=95b55c578887e480cc3fbed014b2b3b4d0b24eef diff --git a/src/club/wpia/gigi/pages/main/KeyCompromiseForm.java b/src/club/wpia/gigi/pages/main/KeyCompromiseForm.java index 321059b8..ee0110f4 100644 --- a/src/club/wpia/gigi/pages/main/KeyCompromiseForm.java +++ b/src/club/wpia/gigi/pages/main/KeyCompromiseForm.java @@ -15,6 +15,8 @@ import java.security.interfaces.RSAPrivateKey; import java.security.spec.PKCS8EncodedKeySpec; import java.util.Arrays; import java.util.Base64; +import java.util.HashMap; +import java.util.Locale; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -22,18 +24,25 @@ import javax.servlet.http.HttpServletRequest; import club.wpia.gigi.GigiApiException; import club.wpia.gigi.dbObjects.Certificate; import club.wpia.gigi.dbObjects.Certificate.CertificateStatus; +import club.wpia.gigi.dbObjects.CertificateOwner; import club.wpia.gigi.dbObjects.Job; +import club.wpia.gigi.dbObjects.Organisation; +import club.wpia.gigi.dbObjects.User; import club.wpia.gigi.localisation.Language; import club.wpia.gigi.output.template.Form; +import club.wpia.gigi.output.template.MailTemplate; import club.wpia.gigi.output.template.Template; import club.wpia.gigi.output.template.TranslateCommand; import club.wpia.gigi.util.PEM; import club.wpia.gigi.util.RandomToken; import club.wpia.gigi.util.RateLimit; import club.wpia.gigi.util.RateLimit.RateLimitException; +import club.wpia.gigi.util.ServerConstants; public class KeyCompromiseForm extends Form { + public static final String CONFIDENTIAL_MARKER = "*CONFIDENTIAL*"; + private static final Template t = new Template(KeyCompromiseForm.class.getResource("KeyCompromiseForm.templ")); // 50 per 5 min @@ -47,6 +56,8 @@ public class KeyCompromiseForm extends Form { public static final TranslateCommand NOT_FOUND = new TranslateCommand("Certificate to revoke not found"); + private static final MailTemplate revocationNotice = new MailTemplate(KeyCompromiseForm.class.getResource("RevocationNotice.templ")); + public KeyCompromiseForm(HttpServletRequest hsr) { super(hsr); challenge = RandomToken.generateToken(16); @@ -139,7 +150,50 @@ public class KeyCompromiseForm extends Form { } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } - Job j = c.revoke(challenge, Base64.getEncoder().encodeToString(signature), ""); + String message = req.getParameter("message"); + if (message != null && message.isEmpty()) { + message = null; + } + if (message != null) { + if (message.startsWith(CONFIDENTIAL_MARKER)) { + message = " " + message; + } + String confidential = req.getParameter("confidential"); + if (confidential != null && !confidential.isEmpty()) { + message = CONFIDENTIAL_MARKER + "\n" + message; + } + if (message.contains("---")) { + throw new GigiApiException("Your message may not contain '---'."); + } + if ( !message.matches("[ -~\r\n\t]*")) { + throw new GigiApiException("Your message may only contain printable ASCII characters, tab, newline and space."); + } + } + CertificateOwner co = c.getOwner(); + String primaryEmail; + Language l = Language.getInstance(Locale.ENGLISH); + if (co instanceof User) { + primaryEmail = ((User) co).getEmail(); + l = Language.getInstance(((User) co).getPreferredLocale()); + } else if (co instanceof Organisation) { + primaryEmail = ((Organisation) co).getContactEmail(); + } else { + throw new IllegalArgumentException("certificate owner of unknown type"); + } + HashMap vars = new HashMap<>(); + vars.put("appName", ServerConstants.getAppName()); + if (message != null && !message.startsWith(CONFIDENTIAL_MARKER)) { + vars.put("message", message); + } else { + vars.put("message", null); + } + vars.put("serial", c.getSerial()); + try { + revocationNotice.sendMail(l, vars, primaryEmail); + } catch (IOException e) { + throw new GigiApiException("Sending the notification mail failed."); + } + Job j = c.revoke(challenge, Base64.getEncoder().encodeToString(signature), message); if ( !j.waitFor(60000)) { throw new PermamentFormException(new GigiApiException("Revocation timed out.")); }