836f48c4f13c1ff1e035ff5a9f7accb4d20ee1e8
[gigi.git] / src / org / cacert / gigi / pages / account / MailCertificateAdd.java
1 package org.cacert.gigi.pages.account;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.sql.SQLException;
6 import java.util.HashMap;
7
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10
11 import org.cacert.gigi.Certificate;
12 import org.cacert.gigi.output.ClientCSRGenerate;
13 import org.cacert.gigi.pages.LoginPage;
14 import org.cacert.gigi.pages.Page;
15
16 public class MailCertificateAdd extends Page {
17         public static final String PATH = "/account/certs/email/new";
18
19         public MailCertificateAdd() {
20                 super("Create Email certificate");
21         }
22
23         @Override
24         public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
25                 HashMap<String, Object> vars = new HashMap<String, Object>();
26                 vars.put("CCA", "<a href='/policy/CAcertCommunityAgreement.html'>CCA</a>");
27                 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
28         }
29
30         @Override
31         public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
32                 PrintWriter out = resp.getWriter();
33                 if (req.getParameter("optionalCSR") == null || req.getParameter("optionalCSR").equals("")) {
34                         out.println("csr missing");
35                         ClientCSRGenerate.output(req, resp);
36                 }
37                 String csr = req.getParameter("optionalCSR");
38                 if (!"on".equals(req.getParameter("CCA"))) {
39                         // Error.
40                         return;
41                 }
42                 Certificate c = new Certificate(LoginPage.getUser(req).getId(), "/commonName=CAcert WoT User", "sha256", csr);
43                 c.issue();
44                 try {
45                         c.waitFor(60000);
46                         resp.sendRedirect(MailCertificates.PATH + "/" + c.getSerial());
47                 } catch (SQLException e) {
48                         e.printStackTrace();
49                 } catch (InterruptedException e) {
50                         e.printStackTrace();
51                 }
52
53         }
54
55 }