/************************************************************************* * * * EJBCA Community: The OpenSource Certificate Authority * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/ package org.ejbca.ui.web.protocol; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; import java.security.cert.X509Certificate; import javax.ejb.EJB; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.cesecore.certificates.ca.internal.CaCertificateCache; import org.cesecore.certificates.certificate.CertificateStoreSessionLocal; import org.cesecore.certificates.certificate.HashID; import org.ejbca.config.VAConfiguration; /** * Base class for servlets (CRL or Certificate) implementing rfc4378 * * @version $Id: StoreServletBase.java 25645 2017-04-04 09:22:52Z anatom $ */ public abstract class StoreServletBase extends HttpServlet { private static final String SPACE = "|     "; private static final long serialVersionUID = 1L; private static final Logger log = Logger.getLogger(StoreServletBase.class); protected CaCertificateCache certCache; @EJB private CertificateStoreSessionLocal certificateStoreSession; /** * Called when the servlet is initialized. * @param config see {@link HttpServlet#init(ServletConfig)} * @throws ServletException */ public void init(ServletConfig config) throws ServletException { super.init(config); this.certCache = CaCertificateCache.INSTANCE; } /** * Return certificate or CRL for the RFC4387 sHash http parameter * @param sHash * @param resp * @param req * @throws IOException * @throws ServletException */ public abstract void sHash(String sHash, HttpServletResponse resp, HttpServletRequest req) throws IOException, ServletException; /** * Return certificate or CRL for the RFC4387 iHash http parameter * @param iHash * @param resp * @param req * @throws IOException * @throws ServletException */ public abstract void iHash(String iHash, HttpServletResponse resp, HttpServletRequest req) throws IOException, ServletException; /** * Return certificate or CRL for the RFC4387 sKIDHash http parameter * @param sKIDHash * @param resp * @param req * @throws IOException * @throws ServletException */ public abstract void sKIDHash(String sKIDHash, HttpServletResponse resp, HttpServletRequest req) throws IOException, ServletException; /** * Return certificate or CRL for the RFC4387 sKIDHash http parameter. In this case the alias name has been used to get the parameter. * @param sKIDHash * @param resp * @param req * @param name alias name of the object * @throws IOException * @throws ServletException */ public abstract void sKIDHash(String sKIDHash, HttpServletResponse resp, HttpServletRequest req, String name) throws IOException, ServletException; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, java.io.IOException { if (log.isTraceEnabled()) { log.trace(">doGet()"); } if (!req.getRequestURI().substring(req.getContextPath().length()).contains("search.cgi")) { resp.sendRedirect(req.getRequestURI() + "search.cgi"); return; } try { if (alias(req, resp)) { return; } if (performReload(req, resp)) { return; } if (fromName(req, resp)) { return; } rfcRequest(req, resp); } finally { if (log.isTraceEnabled()) { log.trace(""); writer.println(""); writer.println(""+getTitle()+""); writer.println(""); writer.println(""); writer.println(""); writer.println(""); writer.println(""); writer.println(""); writer.println("
"); writer.println("

"+getTitle()+"

"); writer.println("

When searching for certificates you can use iHash, sHash and sKIDHash. iHash is the ASN1 encoded DN of the issuer in a certificate, sHash of the subject and sKIDHash is the subjectKeyIdentifier. If you search with it you get all certificates that has the same issuer, except for the root certificate. You do not find a root certificate if you search with the iHash of the root. It has been assumed that sHash should be used when searching for a root.

"); writer.println("

When searching for CRLs you can use iHash and sKIDHash. iHash is the ASN1 encoded DN of the issuer in a certificate and sKIDHash is the subjectKeyIdentifier."); writer.println("
To get the latest delta CRL you can append the parameter 'delta='."); writer.println("
To get a CRL with a specific CRL number you can append the parameter 'crlnumber=<number>'.

"); writer.println("
"); writer.println(info); writer.println("
"); writer.println(""); writer.println(""); writer.flush(); } private void printInfo(HttpServletRequest req, HttpServletResponse resp) throws IOException { final StringWriter sw = new StringWriter(); final PrintWriter pw = new HtmlPrintWriter(sw); printInfo(this.certCache.getRootCertificates(), "", pw, req.getRequestURL().toString()); pw.flush(); pw.close(); sw.flush(); returnInfoPage(resp, sw.toString()); sw.close(); } private class HtmlPrintWriter extends PrintWriter { public HtmlPrintWriter(Writer out) { super(out); } @Override public void println() { super.print("
"); super.println(); } @Override public void println(String s) { super.print(s); println(); } } }