From: Felix Dörre Date: Wed, 9 Jul 2014 15:21:10 +0000 (+0200) Subject: Show the generated certificate better. X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=e9336bb2781a287a5542179208a869acd17c9a5a;hp=8f5c95aa7beae740cbc43bf3958e14eb98d7eb36 Show the generated certificate better. --- diff --git a/src/org/cacert/gigi/Certificate.java b/src/org/cacert/gigi/Certificate.java index c6924132..f2011052 100644 --- a/src/org/cacert/gigi/Certificate.java +++ b/src/org/cacert/gigi/Certificate.java @@ -29,6 +29,28 @@ public class Certificate { 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 diff --git a/src/org/cacert/gigi/Gigi.java b/src/org/cacert/gigi/Gigi.java index 2ede0a52..82223a26 100644 --- a/src/org/cacert/gigi/Gigi.java +++ b/src/org/cacert/gigi/Gigi.java @@ -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(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()); diff --git a/src/org/cacert/gigi/pages/account/MailCertificateAdd.java b/src/org/cacert/gigi/pages/account/MailCertificateAdd.java index 97038898..fe93959d 100644 --- a/src/org/cacert/gigi/pages/account/MailCertificateAdd.java +++ b/src/org/cacert/gigi/pages/account/MailCertificateAdd.java @@ -2,7 +2,6 @@ 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; @@ -42,20 +41,18 @@ public class MailCertificateAdd extends Page { // 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); - 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(); } + } } diff --git a/src/org/cacert/gigi/pages/account/MailCertificates.java b/src/org/cacert/gigi/pages/account/MailCertificates.java index 72952d4b..6eae585a 100644 --- a/src/org/cacert/gigi/pages/account/MailCertificates.java +++ b/src/org/cacert/gigi/pages/account/MailCertificates.java @@ -1,6 +1,8 @@ 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; @@ -9,6 +11,7 @@ import java.util.HashMap; 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; @@ -26,6 +29,25 @@ public class MailCertificates extends Page { @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("
");
+			try {
+				out.print(c.cert());
+			} catch (GeneralSecurityException e) {
+				e.printStackTrace();
+			} catch (SQLException e) {
+				e.printStackTrace();
+			}
+			out.println("
"); + return; + } + HashMap vars = new HashMap(); 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); - myTable.output(resp.getWriter(), getLanguage(req), vars); + myTable.output(out, getLanguage(req), vars); rs.close(); } catch (SQLException e) { e.printStackTrace(); diff --git a/static/static/default.css b/static/static/default.css index 5372aa13..e9308c46 100644 --- a/static/static/default.css +++ b/static/static/default.css @@ -744,4 +744,8 @@ formMandatory{ } .expertoff{ display:none; +} +pre{ + word-wrap: break-word; + white-space: pre-wrap; } \ No newline at end of file