]> WPIA git - gigi.git/commitdiff
Implement issuing with the new form.
authorFelix Dörre <felix@dogcraft.de>
Tue, 15 Jul 2014 21:29:17 +0000 (23:29 +0200)
committerFelix Dörre <felix@dogcraft.de>
Tue, 15 Jul 2014 22:55:55 +0000 (00:55 +0200)
src/org/cacert/gigi/pages/account/IssueCertificateForm.java
src/org/cacert/gigi/pages/account/IssueCertificateForm.templ
src/org/cacert/gigi/pages/account/MailCertificateAdd.java

index e8e50001506da91a20f7bd7c88e7b1b8b7ab1267..a318408078ac5368e1f49bdc2e9727c976ac6791 100644 (file)
@@ -15,8 +15,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
 import org.cacert.gigi.Certificate;
 import org.cacert.gigi.Digest;
 import org.cacert.gigi.Language;
@@ -39,6 +37,8 @@ import sun.security.pkcs10.PKCS10;
 public class IssueCertificateForm extends Form {
        User u;
        Digest selectedDigest = Digest.getDefault();
+       boolean login;
+       String csr;
 
        private final static Template t = new Template(IssueCertificateForm.class.getResource("IssueCertificateForm.templ"));
 
@@ -47,12 +47,18 @@ public class IssueCertificateForm extends Form {
                u = LoginPage.getUser(hsr);
        }
 
+       Certificate result;
+
+       public Certificate getResult() {
+               return result;
+       }
+
        @Override
        public boolean submit(PrintWriter out, HttpServletRequest req) {
                String csr = req.getParameter("CSR");
                String spkac = req.getParameter("spkac");
                try {
-                       if (csr != null && !"".equals(csr)) {
+                       if (csr != null) {
                                PKCS10 parsed = parseCSR(csr);
                                out.println(parsed.getSubjectName().getCommonName());
                                out.println(parsed.getSubjectName().getCountry());
@@ -73,7 +79,32 @@ public class IssueCertificateForm extends Form {
                                        out.println(epk.getParams().getCurve());
                                }
                                out.println("<br/>digest: sha256<br/>");
+                               this.csr = csr;
+                       } else if (spkac != null) {
 
+                       } else {
+                               login = "1".equals(req.getParameter("login"));
+                               String hashAlg = req.getParameter("hash_alg");
+                               if (hashAlg != null) {
+                                       selectedDigest = Digest.valueOf(hashAlg);
+                               }
+                               if (req.getParameter("CCA") == null) {
+                                       outputError(out, req, "You need to accept the CCA.");
+                                       return false;
+                               }
+                               System.out.println("issuing " + selectedDigest);
+                               result = new Certificate(LoginPage.getUser(req).getId(), "/commonName=CAcert WoT User",
+                                       selectedDigest.toString(), this.csr);
+                               result.issue();
+                               try {
+                                       result.waitFor(60000);
+                                       return true;
+                               } catch (SQLException e) {
+                                       e.printStackTrace();
+                               } catch (InterruptedException e) {
+                                       e.printStackTrace();
+                               }
+                               return false;
                        }
                } catch (IOException e) {
                        e.printStackTrace();
@@ -83,19 +114,6 @@ public class IssueCertificateForm extends Form {
                return false;
        }
 
-       private void issue(HttpServletRequest req, HttpServletResponse resp, String csr) throws IOException {
-               Certificate c = new Certificate(LoginPage.getUser(req).getId(), "/commonName=CAcert WoT User", "sha256", csr);
-               c.issue();
-               try {
-                       c.waitFor(60000);
-                       resp.sendRedirect(MailCertificates.PATH + "/" + c.getSerial());
-               } catch (SQLException e) {
-                       e.printStackTrace();
-               } catch (InterruptedException e) {
-                       e.printStackTrace();
-               }
-       }
-
        private PKCS10 parseCSR(String csr) throws IOException, GeneralSecurityException {
                csr = csr.replaceFirst("-----BEGIN (NEW )?CERTIFICATE REQUEST-----", "");
                csr = csr.replaceFirst("-----END (NEW )?CERTIFICATE REQUEST-----", "");
index 575066fb130e42ebec0bdb7512392f5d389da479..16f038d486cf43f551cdd6a41da90f7802ad25d8 100644 (file)
@@ -7,7 +7,6 @@
 
 <p><?=_If the Subscriber's name and/or domain name registration change the subscriber will immediately inform CAcert Inc. who shall revoke the digital certificate. When the Digital Certificate expires or is revoked the company will permanently remove the certificate from the server on which it is installed and will not use it for any purpose thereafter. The person responsible for key management and security is fully authorized to install and utilize the certificate to represent this organization's electronic presence.?></p>
 
-<form method="post">
 <table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper dataTable">
   <thead>
   <tr>
   </tr>
   </tbody>
 </table>
-</form>
index 4a9a2c826398f29f39c36d420d524e3cb251dce3..92b6a106d04ae91d5440f6ca622b2e4c1baba550 100644 (file)
@@ -16,6 +16,7 @@ import org.cacert.gigi.User;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.output.template.IterableDataset;
 import org.cacert.gigi.pages.LoginPage;
+import org.cacert.gigi.Certificate;
 import org.cacert.gigi.output.Form;
 import org.cacert.gigi.output.template.Template;
 import org.cacert.gigi.pages.Page;
@@ -68,6 +69,11 @@ public class MailCertificateAdd extends Page {
                IssueCertificateForm f;
                if (req.getParameter(Form.CSRF_FIELD) != null) {
                        f = Form.getForm(req, IssueCertificateForm.class);
+                       if (f.submit(resp.getWriter(), req)) {
+                               Certificate c = f.getResult();
+                               String ser = c.getSerial();
+                               resp.sendRedirect(MailCertificates.PATH + "/" + ser);
+                       }
                } else {
                        f = new IssueCertificateForm(req);
                        f.submit(resp.getWriter(), req);