⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scepservlet.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/************************************************************************* *                                                                       * *  EJBCA: 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.ByteArrayOutputStream;import java.io.IOException;import java.security.cert.X509Certificate;import java.util.Collection;import java.util.Iterator;import javax.ejb.EJBException;import javax.servlet.ServletConfig;import javax.servlet.ServletException;import javax.servlet.ServletInputStream;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.ejbca.core.ejb.ServiceLocator;import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal;import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocalHome;import org.ejbca.core.ejb.ca.sign.ISignSessionLocal;import org.ejbca.core.ejb.ca.sign.ISignSessionLocalHome;import org.ejbca.core.model.InternalResources;import org.ejbca.core.model.authorization.AuthorizationDeniedException;import org.ejbca.core.model.ca.AuthLoginException;import org.ejbca.core.model.ca.AuthStatusException;import org.ejbca.core.model.ca.caadmin.CADoesntExistsException;import org.ejbca.core.model.ca.caadmin.CAInfo;import org.ejbca.core.model.log.Admin;import org.ejbca.ui.web.RequestHelper;import org.ejbca.util.Base64;import org.ejbca.util.CertTools;/** * Servlet implementing server side of the Simple Certificate Enrollment Protocol (SCEP)  * -----  * This processes does the following:  * 1. decode a PKCS#7 signed data message from the standard input  * 2. extract the signed attributes from the the message, which indicate the type of request  * 3. decrypt the enveloped data PKCS#7 inside  * 4. branch to different actions depending on the type of the message:  * - PKCSReq  * - GetCertInitial  * - GetCert  * - GetCRL  * - v2PKCSReq or Proxy request  * 5. envelop (PKCS#7) the reply data from the previous step  * 6. sign the reply data (PKCS#7) from the previous step  * 7. output the result as a der encoded block on stdout  * ----- * * @version $Id: ScepServlet.java,v 1.8 2006/12/20 08:33:31 anatom Exp $ */public class ScepServlet extends HttpServlet {    private static final Logger log = Logger.getLogger(ScepServlet.class);    /** Internal localization of logs and errors */    private static final InternalResources intres = InternalResources.getInstance();    private ISignSessionLocal signsession = null;    private ICAAdminSessionLocal casession = null;    private synchronized ISignSessionLocal getSignSession(){    	if(signsession == null){	    		try {    			ISignSessionLocalHome signhome = (ISignSessionLocalHome)ServiceLocator.getInstance().getLocalHome(ISignSessionLocalHome.COMP_NAME);    			signsession = signhome.create();    		}catch(Exception e){    			throw new EJBException(e);      	  	    	  	    		}    	}    	return signsession;    }    private synchronized ICAAdminSessionLocal getCASession(){    	if(casession == null){	    		try {    			ICAAdminSessionLocalHome cahome = (ICAAdminSessionLocalHome)ServiceLocator.getInstance().getLocalHome(ICAAdminSessionLocalHome.COMP_NAME);    			casession = cahome.create();    		}catch(Exception e){    			throw new EJBException(e);      	  	    	  	    		}    	}    	return casession;    }    /**     * Inits the SCEP servlet     *     * @param config servlet configuration     *     * @throws ServletException on error during initialization     */    public void init(ServletConfig config) throws ServletException {        super.init(config);        try {            // Install BouncyCastle provider            CertTools.installBCProvider();        } catch (Exception e) {            throw new ServletException(e);        }    }    /**     * Handles HTTP post     *     * @param request java standard arg     * @param response java standard arg     *     * @throws IOException input/output error     * @throws ServletException if the post could not be handled     */    public void doPost(HttpServletRequest request, HttpServletResponse response)            throws IOException, ServletException {        log.debug(">doPost()");        /*          If the remote CA supports it, any of the PKCS#7-encoded SCEP messages         may be sent via HTTP POST instead of HTTP GET.   This is allowed for         any SCEP message except GetCACert, GetCACertChain, GetNextCACert,         or GetCACaps.  In this form of the message, Base 64 encoding is not         used.                  POST /cgi-bin/pkiclient.exe?operation=PKIOperation         <binary PKCS7 data>         */        String operation = "PKIOperation";        ServletInputStream sin = request.getInputStream();        // This small code snippet is inspired/copied by apache IO utils to Tomas Gustavsson...        ByteArrayOutputStream output = new ByteArrayOutputStream();        byte[] buf = new byte[1024];        int n = 0;        while (-1 != (n = sin.read(buf))) {            output.write(buf, 0, n);        }        String message = new String(Base64.encode(output.toByteArray()));        service(operation, message, request.getRemoteAddr(), response);        log.debug("<doPost()");    } //doPost    /**     * Handles HTTP get     *     * @param request java standard arg     * @param response java standard arg     *     * @throws IOException input/output error     * @throws ServletException if the post could not be handled

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -