]> WPIA git - gigi.git/commitdiff
Show the generated certificate better.
authorFelix Dörre <felix@dogcraft.de>
Wed, 9 Jul 2014 15:21:10 +0000 (17:21 +0200)
committerFelix Dörre <felix@dogcraft.de>
Thu, 10 Jul 2014 22:35:13 +0000 (00:35 +0200)
src/org/cacert/gigi/Certificate.java
src/org/cacert/gigi/Gigi.java
src/org/cacert/gigi/pages/account/MailCertificateAdd.java
src/org/cacert/gigi/pages/account/MailCertificates.java
static/static/default.css

index c6924132cdc8c0445e3bcbee2e88d34112251b31..f2011052c7b4fb16b84a3a3bd5e51bec99b9af5c 100644 (file)
@@ -29,6 +29,28 @@ public class Certificate {
                this.csr = csr;
        }
 
                this.csr = csr;
        }
 
+       public Certificate(int id) {
+               try {
+                       PreparedStatement ps = DatabaseConnection
+                                       .getInstance()
+                                       .prepare(
+                                                       "SELECT subject, md, csr_name, crt_name FROM `emailcerts` WHERE id=?");
+                       ps.setInt(1, id);
+                       ResultSet rs = ps.executeQuery();
+                       if (!rs.next()) {
+                               throw new IllegalArgumentException("Invalid mid " + id);
+                       }
+                       this.id = id;
+                       dn = rs.getString(1);
+                       md = rs.getString(2);
+                       csrName = rs.getString(3);
+                       crtName = rs.getString(4);
+                       rs.close();
+               } catch (SQLException e) {
+                       e.printStackTrace();
+               }
+       }
+
        public enum CertificateStatus {
                /**
                 * This certificate is not in the database, has no id and only exists as
        public enum CertificateStatus {
                /**
                 * This certificate is not in the database, has no id and only exists as
index 2ede0a525330db9fcade3e424f60a58268160743..82223a261124da531511217d064a2c5c7068301c 100644 (file)
@@ -54,7 +54,7 @@ public class Gigi extends HttpServlet {
                pages.put("/secure", new TestSecure());
                pages.put(Verify.PATH, new Verify());
                pages.put(AssurePage.PATH + "/*", new AssurePage());
                pages.put("/secure", new TestSecure());
                pages.put(Verify.PATH, new Verify());
                pages.put(AssurePage.PATH + "/*", new AssurePage());
-               pages.put(MailCertificates.PATH, new MailCertificates());
+               pages.put(MailCertificates.PATH + "/*", new MailCertificates());
                pages.put(MyDetails.PATH, new MyDetails());
                pages.put(ChangePasswordPage.PATH, new ChangePasswordPage());
                pages.put(RegisterPage.PATH, new RegisterPage());
                pages.put(MyDetails.PATH, new MyDetails());
                pages.put(ChangePasswordPage.PATH, new ChangePasswordPage());
                pages.put(RegisterPage.PATH, new RegisterPage());
index 97038898e8e704619dead0ded5b15f57eee6f66b..fe93959da6493118dd312c466e7441065ac43ec6 100644 (file)
@@ -2,7 +2,6 @@ package org.cacert.gigi.pages.account;
 
 import java.io.IOException;
 import java.io.PrintWriter;
 
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.security.GeneralSecurityException;
 import java.sql.SQLException;
 import java.util.HashMap;
 
 import java.sql.SQLException;
 import java.util.HashMap;
 
@@ -42,20 +41,18 @@ public class MailCertificateAdd extends Page {
                        // Error.
                        return;
                }
                        // Error.
                        return;
                }
-               Certificate c = new Certificate("/commonName=felix@dogcraft.de",
+               Certificate c = new Certificate("/commonName=CAcert WoT User",
                                "sha256", csr);
                c.issue();
                try {
                        c.waitFor(60000);
                                "sha256", csr);
                c.issue();
                try {
                        c.waitFor(60000);
-                       out.println(c.getStatus());
-                       out.println(c.cert());
-               } catch (SQLException e1) {
-                       e1.printStackTrace();
-               } catch (GeneralSecurityException e) {
+                       resp.sendRedirect(MailCertificates.PATH + "/" + c.getId());
+               } catch (SQLException e) {
                        e.printStackTrace();
                } catch (InterruptedException e) {
                        e.printStackTrace();
                }
                        e.printStackTrace();
                } catch (InterruptedException e) {
                        e.printStackTrace();
                }
+
        }
 
 }
        }
 
 }
index 72952d4bb4d9bc516a6068763e42ccc0d7e6d6b0..6eae585a2c787cee2ab2691712e58346713feffc 100644 (file)
@@ -1,6 +1,8 @@
 package org.cacert.gigi.pages.account;
 
 import java.io.IOException;
 package org.cacert.gigi.pages.account;
 
 import java.io.IOException;
+import java.io.PrintWriter;
+import java.security.GeneralSecurityException;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -9,6 +11,7 @@ import java.util.HashMap;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.cacert.gigi.Certificate;
 import org.cacert.gigi.User;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.output.CertificateTable;
 import org.cacert.gigi.User;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.output.CertificateTable;
@@ -26,6 +29,25 @@ public class MailCertificates extends Page {
        @Override
        public void doGet(HttpServletRequest req, HttpServletResponse resp)
                        throws IOException {
        @Override
        public void doGet(HttpServletRequest req, HttpServletResponse resp)
                        throws IOException {
+               PrintWriter out = resp.getWriter();
+               String pi = req.getPathInfo().substring(PATH.length());
+               if (pi.length() != 0) {
+                       pi = pi.substring(1);
+                       int id = Integer.parseInt(pi);
+                       Certificate c = new Certificate(id);
+                       // TODO check ownership
+                       out.println("<pre>");
+                       try {
+                               out.print(c.cert());
+                       } catch (GeneralSecurityException e) {
+                               e.printStackTrace();
+                       } catch (SQLException e) {
+                               e.printStackTrace();
+                       }
+                       out.println("</pre>");
+                       return;
+               }
+
                HashMap<String, Object> vars = new HashMap<String, Object>();
                User us = LoginPage.getUser(req);
                try {
                HashMap<String, Object> vars = new HashMap<String, Object>();
                User us = LoginPage.getUser(req);
                try {
@@ -36,7 +58,7 @@ public class MailCertificates extends Page {
                        ps.setInt(1, us.getId());
                        ResultSet rs = ps.executeQuery();
                        vars.put("mailcerts", rs);
                        ps.setInt(1, us.getId());
                        ResultSet rs = ps.executeQuery();
                        vars.put("mailcerts", rs);
-                       myTable.output(resp.getWriter(), getLanguage(req), vars);
+                       myTable.output(out, getLanguage(req), vars);
                        rs.close();
                } catch (SQLException e) {
                        e.printStackTrace();
                        rs.close();
                } catch (SQLException e) {
                        e.printStackTrace();
index 5372aa136525409dd3958abeca5710b2ccf65c59..e9308c46a49ee285e7d3efa35fe8ac089a305ab9 100644 (file)
@@ -744,4 +744,8 @@ formMandatory{
 }
 .expertoff{
        display:none;   
 }
 .expertoff{
        display:none;   
+}
+pre{
+       word-wrap: break-word;
+       white-space: pre-wrap;
 }
\ No newline at end of file
 }
\ No newline at end of file