1 package org.cacert.gigi.pages;
3 import java.io.IOException;
4 import java.security.KeyStore;
5 import java.security.KeyStoreException;
6 import java.security.cert.Certificate;
7 import java.security.cert.CertificateEncodingException;
8 import java.util.HashMap;
10 import javax.servlet.ServletOutputStream;
11 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletResponse;
14 import org.cacert.gigi.util.PEM;
16 public class RootCertPage extends Page {
18 private Certificate root;
20 public RootCertPage(KeyStore ks) {
21 super("Root Certificates");
23 root = ks.getCertificate("root");
24 } catch (KeyStoreException e) {
30 public boolean beforeTemplate(HttpServletRequest req, HttpServletResponse resp) throws IOException {
31 if (req.getParameter("pem") != null && root != null) {
32 resp.setContentType("application/x-x509-ca-cert");
33 ServletOutputStream out = resp.getOutputStream();
35 out.println(PEM.encode("CERTIFICATE", root.getEncoded()));
36 } catch (CertificateEncodingException e) {
40 } else if (req.getParameter("cer") != null && root != null) {
41 resp.setContentType("application/x-x509-ca-cert");
42 ServletOutputStream out = resp.getOutputStream();
44 out.write(root.getEncoded());
45 } catch (CertificateEncodingException e) {
54 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
55 getDefaultTemplate().output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
60 public boolean needsLogin() {