@Override
public boolean beforeTemplate(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+
String pi = req.getPathInfo().substring(PATH.length());
if (pi.length() == 0) {
return false;
pi = pi.substring(1);
boolean crt = false;
boolean cer = false;
+ resp.setContentType("application/pkix-cert");
if (pi.endsWith(".crt")) {
crt = true;
pi = pi.substring(0, pi.length() - 4);
+ } else if (pi.endsWith(".cer")) {
+ if (req.getParameter("install") != null) {
+ resp.setContentType("application/x-x509-user-cert");
+ }
+ cer = true;
+ pi = pi.substring(0, pi.length() - 4);
} else if (pi.endsWith(".cer")) {
cer = true;
pi = pi.substring(0, pi.length() - 4);
}
- int serial = 0;
- try {
- serial = Integer.parseInt(pi);
- } catch (NumberFormatException nfe) {
- resp.sendError(404);
- return true;
- }
+ String serial = pi;
try {
- Certificate c = new Certificate(serial);
- if (LoginPage.getUser(req).getId() != c.getOwnerId()) {
+ Certificate c = Certificate.getBySerial(serial);
+ if (c == null || LoginPage.getUser(req).getId() != c.getOwnerId()) {
resp.sendError(404);
return true;
}
if (pi.length() != 0) {
pi = pi.substring(1);
- int serial = 0;
- try {
- serial = Integer.parseInt(pi);
- } catch (NumberFormatException nfe) {
- }
- Certificate c = null;
- if (serial != 0) {
- c = new Certificate(serial);
- }
+ String serial = pi;
+ Certificate c = Certificate.getBySerial(serial);
if (c == null || LoginPage.getUser(req).getId() != c.getOwnerId()) {
resp.sendError(404);
return;
out.print(".cer'>");
out.print(translate(req, "DER encoded Certificate"));
out.println("</a><br/>");
+ out.print("<a href='");
+ out.print(serial);
+ out.print(".cer?install'>");
+ out.print(translate(req, "Install into browser."));
+ out.println("</a><br/>");
out.println("<pre>");
try {