]> WPIA git - gigi.git/blob - src/club/wpia/gigi/pages/RootCertPage.java
fix: ResultSet.getDate is often wrong as it fetches day-precision times
[gigi.git] / src / club / wpia / gigi / pages / RootCertPage.java
1 package club.wpia.gigi.pages;
2
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;
9
10 import javax.servlet.ServletOutputStream;
11 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletResponse;
13
14 import club.wpia.gigi.util.PEM;
15
16 public class RootCertPage extends Page {
17
18     private Certificate root;
19
20     public RootCertPage(KeyStore ks) {
21         super("Root Certificates");
22         try {
23             root = ks.getCertificate("root");
24         } catch (KeyStoreException e) {
25             e.printStackTrace();
26         }
27     }
28
29     @Override
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();
34             try {
35                 out.println(PEM.encode("CERTIFICATE", root.getEncoded()));
36             } catch (CertificateEncodingException e) {
37                 e.printStackTrace();
38             }
39             return true;
40         } else if (req.getParameter("cer") != null && root != null) {
41             resp.setContentType("application/x-x509-ca-cert");
42             ServletOutputStream out = resp.getOutputStream();
43             try {
44                 out.write(root.getEncoded());
45             } catch (CertificateEncodingException e) {
46                 e.printStackTrace();
47             }
48             return true;
49         }
50         return false;
51     }
52
53     @Override
54     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
55         getDefaultTemplate().output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
56
57     }
58
59     @Override
60     public boolean needsLogin() {
61         return false;
62     }
63
64 }