001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.geronimo.ca.helper;
018:
019: import java.io.ByteArrayOutputStream;
020: import java.io.IOException;
021: import java.io.PrintStream;
022: import java.util.Properties;
023:
024: import javax.servlet.ServletException;
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpServletResponse;
027:
028: import org.apache.geronimo.ca.helper.util.CAHelperUtils;
029: import org.apache.geronimo.crypto.CaUtils;
030:
031: /**
032: * Servlet implementation class for Servlet: CertificateRequestServlet
033: *
034: * @version $Rev: 617588 $ $Date: 2008-02-01 10:20:07 -0800 (Fri, 01 Feb 2008) $
035: */
036: public class CertificateRequestServlet extends
037: javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
038: /* (non-Java-doc)
039: * @see javax.servlet.http.HttpServlet#HttpServlet()
040: */
041: public CertificateRequestServlet() {
042: super ();
043: }
044:
045: /* (non-Java-doc)
046: * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
047: */
048: protected void doGet(HttpServletRequest request,
049: HttpServletResponse response) throws ServletException,
050: IOException {
051: doPost(request, response);
052: }
053:
054: /* (non-Java-doc)
055: * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
056: */
057: protected void doPost(HttpServletRequest request,
058: HttpServletResponse response) throws ServletException,
059: IOException {
060: // Retrieve the values submitted by the user
061: String reqCN = request.getParameter("reqCN");
062: String reqOU = request.getParameter("reqOU");
063: String reqO = request.getParameter("reqO");
064: String reqL = request.getParameter("reqL");
065: String reqST = request.getParameter("reqST");
066: String reqC = request.getParameter("reqC");
067: String spkac = request.getParameter("spkac");
068: String pkcs10req = request.getParameter("pkcs10req");
069:
070: String toStore = null;
071: if (pkcs10req != null && !pkcs10req.equals("")) {
072: // Either generated from Internet Explorer or submitted as PKCS10 request
073: if (!pkcs10req.startsWith(CaUtils.CERT_REQ_HEADER)) {
074: ByteArrayOutputStream baos = new ByteArrayOutputStream();
075: PrintStream out = new PrintStream(baos);
076: out.println(CaUtils.CERT_REQ_HEADER);
077: out.println(pkcs10req.trim());
078: out.println(CaUtils.CERT_REQ_FOOTER);
079: out.close();
080: toStore = baos.toString();
081: } else {
082: toStore = pkcs10req;
083: }
084: } else if (spkac != null && !spkac.equals("")) {
085: // Received from a web browser that supports KEYGEN tag
086: // Create a Properties object with user supplied values
087: Properties csrProps = new Properties();
088: csrProps.setProperty("CN", reqCN);
089: csrProps.setProperty("OU", reqOU);
090: csrProps.setProperty("O", reqO);
091: csrProps.setProperty("L", reqL);
092: csrProps.setProperty("ST", reqST);
093: csrProps.setProperty("C", reqC);
094: csrProps.setProperty("SPKAC", spkac);
095: ByteArrayOutputStream baos = new ByteArrayOutputStream();
096: csrProps.store(baos,
097: "Request received through CA Helper Application");
098: baos.close();
099: toStore = baos.toString();
100: } else {
101: // Did not receive a SignedPublicKeyAndChallenge or a PKCS10 Cerificate Request
102: throw new ServletException(
103: "Did not receive a SignedPublicKeyAndChallenge or a PKCS10 Cerificate Request. Resubmit your certificate request.");
104: }
105:
106: // Store the CSR in the Certificate Request Store.
107: String csrId = CAHelperUtils.getCertificateRequestStore()
108: .storeRequest(null, toStore);
109:
110: // Display the CSR Id to the user and confirm the receipt of CSR
111: request.setAttribute("id", csrId);
112: getServletContext().getRequestDispatcher("/receivedCSR.jsp")
113: .forward(request, response);
114: }
115: }
|