]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/pages/account/certs/CertificateIssueForm.java
upd: modified text displayed during certificate creation process
[gigi.git] / src / org / cacert / gigi / pages / account / certs / CertificateIssueForm.java
index 7774fd814ea8007b619df1c67d9c75216aff0232..0a29fb2d7506e8037750e455426485508048b564 100644 (file)
@@ -10,6 +10,7 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Certificate;
+import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
 import org.cacert.gigi.dbObjects.Certificate.SubjectAlternateName;
 import org.cacert.gigi.dbObjects.CertificateProfile;
 import org.cacert.gigi.dbObjects.Organisation;
@@ -20,7 +21,6 @@ import org.cacert.gigi.output.template.Form;
 import org.cacert.gigi.output.template.IterableDataset;
 import org.cacert.gigi.output.template.Template;
 import org.cacert.gigi.pages.LoginPage;
-import org.cacert.gigi.pages.Page;
 import org.cacert.gigi.util.AuthorizationContext;
 import org.cacert.gigi.util.RandomToken;
 
@@ -57,62 +57,66 @@ public class CertificateIssueForm extends Form {
     CertificateValiditySelector issueDate = new CertificateValiditySelector();
 
     @Override
-    public boolean submit(PrintWriter out, HttpServletRequest req) {
+    public SubmissionResult submit(HttpServletRequest req) throws GigiApiException {
         String csr = req.getParameter("CSR");
         String spkac = req.getParameter("SPKAC");
         try {
-            try {
-                if (csr != null) {
-                    cr = new CertificateRequest(c, csr);
-                    cr.checkKeyStrength(out);
-                } else if (spkac != null) {
-                    cr = new CertificateRequest(c, spkac, spkacChallenge);
-                    cr.checkKeyStrength(out);
-                } else if (cr != null) {
-                    login = "1".equals(req.getParameter("login"));
-                    issueDate.update(req);
-                    GigiApiException error = new GigiApiException();
-
-                    try {
-                        cr.update(req.getParameter("CN"), req.getParameter("hash_alg"), req.getParameter("profile"), //
-                                req.getParameter("org"), req.getParameter("OU"), req.getParameter("SANs"), out, req);
-                    } catch (GigiApiException e) {
-                        error.mergeInto(e);
-                    }
-                    if (req.getParameter("CCA") == null) {
-                        error.mergeInto(new GigiApiException("You need to accept the CCA."));
-                    }
-                    Certificate result = null;
-                    try {
-                        result = cr.draft();
-                    } catch (GigiApiException e) {
-                        error.mergeInto(e);
-                    }
-                    if ( !error.isEmpty() || result == null) {
-                        error.format(out, Page.getLanguage(req));
-                        return false;
-                    }
-                    result.issue(issueDate.getFrom(), issueDate.getTo(), c.getActor()).waitFor(60000);
-                    this.result = result;
-                    return true;
-                } else {
-                    throw new GigiApiException("Error no action.");
+            if (csr != null) {
+                cr = new CertificateRequest(c, csr);
+                // TODO cr.checkKeyStrength(out);
+                return new FormContinue();
+            } else if (spkac != null) {
+                cr = new CertificateRequest(c, spkac, spkacChallenge);
+                // TODO cr.checkKeyStrength(out);
+                return new FormContinue();
+            } else if (cr != null) {
+                login = "1".equals(req.getParameter("login"));
+                issueDate.update(req);
+                GigiApiException error = new GigiApiException();
+
+                try {
+                    cr.update(req.getParameter("CN"), req.getParameter("hash_alg"), req.getParameter("profile"), //
+                            req.getParameter("org"), req.getParameter("OU"), req.getParameter("SANs"));
+                } catch (GigiApiException e) {
+                    error.mergeInto(e);
+                }
+
+                Certificate result = null;
+                try {
+                    result = cr.draft();
+                } catch (GigiApiException e) {
+                    error.mergeInto(e);
+                }
+                if ( !error.isEmpty() || result == null) {
+                    throw error;
+                }
+                if (login) {
+                    result.setLoginEnabled(true);
+                }
+                result.issue(issueDate.getFrom(), issueDate.getTo(), c.getActor()).waitFor(60000);
+                this.result = result;
+                Certificate c = result;
+                if (c.getStatus() != CertificateStatus.ISSUED) {
+                    throw new PermamentFormException(new GigiApiException("Timeout while waiting for certificate."));
+                }
+                String ser = c.getSerial();
+                if (ser.isEmpty()) {
+                    throw new PermamentFormException(new GigiApiException("Timeout while waiting for certificate."));
                 }
-            } catch (IOException e) {
-                e.printStackTrace();
-            } catch (IllegalArgumentException e) {
-                e.printStackTrace();
-                throw new GigiApiException("Certificate Request format is invalid.");
-            } catch (GeneralSecurityException e) {
-                e.printStackTrace();
-                throw new GigiApiException("Certificate Request format is invalid.");
-            } catch (InterruptedException e) {
-                e.printStackTrace();
+                return new RedirectResult(Certificates.PATH + "/" + ser);
+            } else {
+                throw new GigiApiException("Error no action.");
             }
-        } catch (GigiApiException e) {
-            e.format(out, Page.getLanguage(req));
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new GigiApiException("Certificate Request format is invalid.");
+        } catch (IllegalArgumentException e) {
+            e.printStackTrace();
+            throw new GigiApiException("Certificate Request format is invalid.");
+        } catch (GeneralSecurityException e) {
+            e.printStackTrace();
+            throw new GigiApiException("Certificate Request format is invalid.");
         }
-        return false;
     }
 
     @Override
@@ -132,7 +136,6 @@ public class CertificateIssueForm extends Form {
     @Override
     protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
         HashMap<String, Object> vars2 = new HashMap<String, Object>(vars);
-        vars2.put("CCA", "<a href='/policy/CAcertCommunityAgreement.html'>CCA</a>");
 
         StringBuffer content = new StringBuffer();
         for (SubjectAlternateName SAN : cr.getSANs()) {