Package org.ejbca.extra.db

Examples of org.ejbca.extra.db.CertificateRequestResponse


  /**
   * @see org.ejbca.externalra.gui.IRequestDispatcher#getCertificateSigningRequestResponse(java.lang.String, java.lang.String, java.lang.String, int)
   */
  public ResponseData getCertificateSigningRequestResponse(String username, String password, String certificateRequest, int responseType) {
    ResponseData csrResponse = null;
    CertificateRequestResponse responseSub = (CertificateRequestResponse) getResponseFromCA(new CertificateRequestRequest(
        random.nextLong(), username, password, CertificateRequestRequest.REQUEST_TYPE_PKCS10, certificateRequest.getBytes(), responseType));
    if (responseSub != null) {
      if (responseSub.isSuccessful()) {
        csrResponse = new ResponseData(responseSub.getResponseData(), responseSub.getResponseType(), null);
      } else {
        csrResponse = new ResponseData(null, 0, responseSub.getFailInfo());
      }
    }
    return csrResponse;
  }
View Full Code Here


  /**
   * @see org.ejbca.externalra.gui.IRequestDispatcher#getCertificateResponse(java.lang.String, java.lang.String, int, byte[], int)
   */
  public ResponseData getCertificateResponse(String username, String password, int requestType, byte[] buf, int responseType) {
    ResponseData certificateResponse = null;
    CertificateRequestResponse responseSub = (CertificateRequestResponse) getResponseFromCA(new CertificateRequestRequest(
        random.nextLong(), username, password, requestType, buf, responseType));
    if (responseSub != null) {
      if (responseSub.isSuccessful()) {
        certificateResponse = new ResponseData(responseSub.getResponseData(), responseSub.getResponseType(), null);
      } else {
        certificateResponse = new ResponseData(null, 0, responseSub.getFailInfo());
      }
    }
    return certificateResponse;
  }
View Full Code Here

  /** @see ISubMessageProcessor#process(Admin, ISubMessage, String) */
  public ISubMessage process(Admin admin, ISubMessage submessage, String errormessage) {
    if (errormessage == null) {
      return processCertificateRequestRequest(admin, (CertificateRequestRequest) submessage);
    } else {
      return new CertificateRequestResponse(((ExtRARequest) submessage).getRequestId(), false, errormessage, null, null);
    }
  }
View Full Code Here

                      // Create large certificate-only PKCS7
                      CertificateFactory cf = CertificateFactory.getInstance("X.509");
                      CertPath certPath = cf.generateCertPath(new ByteArrayInputStream(CertTools.getPEMFromCerts(certList)));
                      result = certPath.getEncoded("PKCS7");
              } else
              return new CertificateRequestResponse(submessage.getRequestId(), false, MSG_UNSUPPORTED_RESPONSE_TYPE, null, null);
              }
              break;
            case CertificateRequestRequest.REQUEST_TYPE_CRMF:
              // Extract request in a format that EJBCA can process
          CertReqMessages certReqMessages = CertReqMessages.getInstance(new ASN1InputStream(submessage.getRequestData()).readObject());
          PKIMessage msg = new PKIMessage(new PKIHeader(
              new DERInteger(2), new GeneralName(new X509Name("CN=unused")), new GeneralName(new X509Name("CN=unused"))),
              new PKIBody(certReqMessages, 2)); // [2] CertReqMessages --Certification Request
              CrmfRequestMessage crmfReq = new CrmfRequestMessage(msg, null, true, null);
              crmfReq.setUsername(submessage.getUsername());
              crmfReq.setPassword(submessage.getPassword());
              // Request and extract certificate from response
              IResponseMessage response = signSession.createCertificate(admin, crmfReq, org.ejbca.core.protocol.cmp.CmpResponseMessage.class, null);
              ASN1InputStream ais = new ASN1InputStream(new ByteArrayInputStream(response.getResponseMessage()));
              CertRepMessage certRepMessage = PKIMessage.getInstance(ais.readObject()).getBody().getCp();
          InputStream inStream = new ByteArrayInputStream(certRepMessage.getResponse(0).getCertifiedKeyPair().getCertOrEncCert().getCertificate().getEncoded());
          cert = CertificateFactory.getInstance("X.509").generateCertificate(inStream);
          inStream.close();
          // Convert to the right response type
              if (submessage.getResponseType() == CertificateRequestRequest.RESPONSE_TYPE_CERTIFICATE) {
                result = cert.getEncoded();
              } else if (submessage.getResponseType() == CertificateRequestRequest.RESPONSE_TYPE_PKCS7) { 
                result = signSession.createPKCS7(admin, cert, false);
              } else if (submessage.getResponseType() == CertificateRequestRequest.RESPONSE_TYPE_PKCS7WITHCHAIN) {
                // Read certificate chain
                    ArrayList<Certificate> certList = new ArrayList<Certificate>();
                      certList.add(cert);
                      certList.addAll(caSession.getCA(Admin.getInternalAdmin(), CertTools.getIssuerDN(cert).hashCode()).getCertificateChain());
                      // Create large certificate-only PKCS7
                      CertificateFactory cf = CertificateFactory.getInstance("X.509");
                      CertPath certPath = cf.generateCertPath(new ByteArrayInputStream(CertTools.getPEMFromCerts(certList)));
                      result = certPath.getEncoded("PKCS7");
              } else {
              return new CertificateRequestResponse(submessage.getRequestId(), false, MSG_UNSUPPORTED_RESPONSE_TYPE, null, null);
              }
              break;
            default:
            return new CertificateRequestResponse(submessage.getRequestId(), false, MSG_UNSUPPORTED_REQUEST_TYPE, null, null);
            }
          }
         
          // Return the response when we have response data (byte[])
          return new CertificateRequestResponse(submessage.getRequestId(), true, null, submessage.getResponseType(), result);
    } catch (Exception e) {
      if (log.isDebugEnabled()) {
        log.debug("External RA request generated an error: " + e.getMessage());
      }
      return new CertificateRequestResponse(submessage.getRequestId(), false, "Error " + e.getMessage(), null, null);
    }
  }
View Full Code Here

    assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
    resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertTrue("Wrong Request ID" + resp.getRequestId(), resp.getRequestId() == requestId);
    assertTrue("KeyStoreRetrieval failed", resp.isSuccessful() == true);
    assertTrue("Wrong response type.", resp instanceof CertificateRequestResponse);
    CertificateRequestResponse certResp = (CertificateRequestResponse) resp;
    assertTrue("Wrong keystore type.", certResp.getResponseType() == CertificateRequestRequest.RESPONSE_TYPE_ENCODED);
    assertTrue("Wrong certificate in response", CertTools.getSubjectDN(CertTools.getCertfromByteArray(certResp.getResponseData())).equals("CN="+username));
  }
View Full Code Here

    assertEquals("Number of submessages " + submessagesresp.getSubMessages().size(), 1, submessagesresp.getSubMessages().size());
    final ExtRAResponse resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertEquals("Wrong Request ID" + resp.getRequestId(), requestId, resp.getRequestId());
    assertTrue("KeyStoreRetrieval failed: " + resp.getFailInfo(), resp.isSuccessful());
    assertTrue("Wrong response type.", resp instanceof CertificateRequestResponse);
    final CertificateRequestResponse certResp = (CertificateRequestResponse) resp;
    assertEquals("Wrong keystore type.", CertificateRequestRequest.RESPONSE_TYPE_CERTIFICATE, certResp.getResponseType());
    assertEquals("Wrong certificate in response", "CN=" + username, CertTools.getSubjectDN(CertTools.getCertfromByteArray(certResp.getResponseData())));
  }
View Full Code Here

TOP

Related Classes of org.ejbca.extra.db.CertificateRequestResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.