Implement first issuing for email cert.
[gigi.git] / src / org / cacert / gigi / pages / account / MailCertificateAdd.java
index 35899c5da73e82ebf328f052dd30a41214f9282e..97038898e8e704619dead0ded5b15f57eee6f66b 100644 (file)
@@ -2,11 +2,14 @@ package org.cacert.gigi.pages.account;
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.security.GeneralSecurityException;
+import java.sql.SQLException;
 import java.util.HashMap;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.cacert.gigi.Certificate;
 import org.cacert.gigi.output.ClientCSRGenerate;
 import org.cacert.gigi.pages.Page;
 
@@ -21,6 +24,8 @@ public class MailCertificateAdd extends Page {
        public void doGet(HttpServletRequest req, HttpServletResponse resp)
                        throws IOException {
                HashMap<String, Object> vars = new HashMap<String, Object>();
+               vars.put("CCA",
+                               "<a href='/policy/CAcertCommunityAgreement.html'>CCA</a>");
                getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
        }
        @Override
@@ -32,7 +37,25 @@ public class MailCertificateAdd extends Page {
                        out.println("csr missing");
                        ClientCSRGenerate.output(req, resp);
                }
-               out.println("could now start processing the cert request");
+               String csr = req.getParameter("optionalCSR");
+               if (!"on".equals(req.getParameter("CCA"))) {
+                       // Error.
+                       return;
+               }
+               Certificate c = new Certificate("/commonName=felix@dogcraft.de",
+                               "sha256", csr);
+               c.issue();
+               try {
+                       c.waitFor(60000);
+                       out.println(c.getStatus());
+                       out.println(c.cert());
+               } catch (SQLException e1) {
+                       e1.printStackTrace();
+               } catch (GeneralSecurityException e) {
+                       e.printStackTrace();
+               } catch (InterruptedException e) {
+                       e.printStackTrace();
+               }
        }
 
 }