Package org.ejbca.extra.db

Examples of org.ejbca.extra.db.PKCS10Response


                  if(msg != null) {
                    if(msg.getStatus().equals(Message.STATUS_PROCESSED)) {
                      log.debug("Request is processed with status: "+msg.getStatus());
                      SubMessages submessagesresp = msg.getSubMessages(null,null,null);
                      Iterator<ISubMessage> iter =  submessagesresp.getSubMessages().iterator();
                      PKCS10Response resp = (PKCS10Response)iter.next();
                      // create proper ScepResponseMessage
                      IResponseMessage ret = reqmsg.createResponseMessage(org.ejbca.core.protocol.scep.ScepResponseMessage.class, reqmsg, racert, rapriv, cryptProvider);
                      ret.setCACert(cacert);
                    X509Certificate respCert = resp.getCertificate();
                      if ( resp.isSuccessful() && (respCert != null) ) {
                        ret.setCertificate(respCert);                         
                      } else {
                        ret.setStatus(ResponseStatus.FAILURE);
                        ret.setFailInfo(FailInfo.BAD_REQUEST);
                        String failText = resp.getFailInfo();
                        ret.setFailText(failText);
                      }
                      ret.create();
                      reply = ret.getResponseMessage();                       
                    } else {
View Full Code Here


    public ISubMessage process(Admin admin, ISubMessage submessage, String errormessage) {
    if(errormessage == null){
      return processExtRAPKCS10Request(admin, (PKCS10Request) submessage);
    }else{
      return new PKCS10Response(((ExtRARequest) submessage).getRequestId(), false, errormessage, null, null);
    }
    }
View Full Code Here

    }
    }
   
    private ISubMessage processExtRAPKCS10Request(Admin admin, PKCS10Request submessage) {
    log.debug("Processing PKCS10Request");
    PKCS10Response retval = null;
    try {
        // Create a PKCS10
        PKCS10RequestMessage pkcs10 = RequestMessageUtils.genPKCS10RequestMessage(submessage.getPKCS10().getBytes());
        String password = pkcs10.getPassword();
       
        if (submessage.createOrEditUser()) {
          // If we did not provide a password, set a default one
          if (StringUtils.isEmpty(password)) {
            log.debug("Empty password received, createOrEditUser=true so setting default password.");
            password = "foo123";
          }
            UserDataVO userdata = generateUserDataVO(admin, submessage);
            userdata.setPassword(password);
            log.info("Creating/editing user: "+userdata.getUsername()+", with dn: "+userdata.getDN());
          // See if the user already exists, if it exists and have status NEW or INPROCESS we will not try to change it
          // This way we can use approvals. When a request first comes in, it is put for approval. When it is approved,
          // we will not try to change it again, because it is ready to be processed
            storeUserData(admin, userdata,false,UserDataConstants.STATUS_INPROCESS );           
        }
        if (StringUtils.isNotEmpty(password)) {
          X509Certificate cert = (X509Certificate) signSession.createCertificate(admin,submessage.getUsername(),password, pkcs10.getRequestPublicKey());
          byte[] pkcs7 = signSession.createPKCS7(admin, cert, true);
          retval = new PKCS10Response(submessage.getRequestId(),true,null,cert,pkcs7);         
        } else {
          // Will be caught below and a fail response created
          throw new Exception("No challenge password received, can not use empty password for enrollment. Nothing processed.");
        }
    } catch (ApprovalException ae) {
      // there might be an already saved approval for this user or a new approval will be created,
      // so catch the exception thrown when this is the case and let the method return null to leave the message in the queue to be tried the next round.
      log.info("ApprovalException: "+ae.getMessage());
    } catch (WaitingForApprovalException wae) {
      // there might be an already saved approval for this user or a new approval will be created,
      // so catch the exception thrown when this is the case and let the method return null to leave the message in the queue to be tried the next round.
      log.info("WaitingForApprovalException: "+wae.getMessage());
    }catch(Exception e){
      // We should end up here if an approval is rejected, or some other error occur. We will then send back a failed message
      log.error("Error processing PKCS10Request: ", e);
      retval = new PKCS10Response(submessage.getRequestId(),false,e.getMessage(),null,null);
    }
   
    return retval;
  }
View Full Code Here

    SubMessages submessagesresp = msg.getSubMessages(null,null,null);
   
    assertTrue(submessagesresp.getSubMessages().size() == 2);
   
    Iterator iter =  submessagesresp.getSubMessages().iterator();
    PKCS10Response resp = (PKCS10Response) iter.next();
    assertTrue(resp.getRequestId() == 100);
    assertTrue(resp.isSuccessful() == true);   
    assertTrue(resp.getCertificate().getSubjectDN().toString().equals("CN=PKCS10REQ"));
    firstCertificate = resp.getCertificate();
    assertNotNull(firstCertificate);
    // Check the pkcs7 response
    byte[] pkcs7 = resp.getCertificateAsPKCS7();
    assertNotNull(pkcs7);
        CMSSignedData s = new CMSSignedData(pkcs7);
        // The signer, i.e. the CA, check it's the right CA
        SignerInformationStore signers = s.getSignerInfos();
        Collection col = signers.getSigners();
        assertTrue(col.size() > 0);
        Iterator siter = col.iterator();
        SignerInformation signerInfo = (SignerInformation)siter.next();
        SignerId sinfo = signerInfo.getSID();
        // Check that the signer is the expected CA
        assertEquals(CertTools.stringToBCDNString(firstCertificate.getIssuerDN().getName()), CertTools.stringToBCDNString(sinfo.getIssuerAsString()));
        CertStore certstore = s.getCertificatesAndCRLs("Collection","BC");
        Collection certs = certstore.getCertificates(null);
        assertEquals(certs.size(), 2);                 
        Iterator it = certs.iterator();
        boolean found = false;
        while (it.hasNext()) {
            X509Certificate retcert = (X509Certificate)it.next();
            if (retcert.getSubjectDN().equals(firstCertificate.getSubjectDN())) {
              found = true;
            }
        }
        assertTrue(found);

      resp = (PKCS10Response) iter.next();
    assertTrue(resp.getRequestId() == 101);
    assertTrue(resp.isSuccessful() == true);   
    assertTrue(resp.getCertificate().getSubjectDN().toString().equals("CN=PKCS10REQ"));
    secondCertificate = resp.getCertificate();
    assertNotNull(secondCertificate);
    pkcs7 = resp.getCertificateAsPKCS7();
    assertNotNull(pkcs7);
   
    // TODO: test with createUser = false
 
  }
View Full Code Here

        Message msg = waitForUser("SimplePKCS10Test1");
    assertNotNull("No response", msg);
    SubMessages submessagesresp = msg.getSubMessages(null,null,null);
    assertTrue(submessagesresp.getSubMessages().size() == 1);   
    Iterator iter =  submessagesresp.getSubMessages().iterator();
    PKCS10Response resp = (PKCS10Response) iter.next();
    assertTrue(resp.getRequestId() == 100);
    assertTrue(resp.isSuccessful() == false);
   
    // if we create the user first, with correct status, the request should be ok
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(ExtRAMessagesTest.genExtRAPKCS10UserRequest(101,"SimplePKCS10Test1", "foo123"));
    msghome.create("SimplePKCS10Test1", smgs);   
        msg = waitForUser("SimplePKCS10Test1");
    assertNotNull(msg);
    submessagesresp = msg.getSubMessages(null,null,null);
    assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
    ExtRAResponse editresp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertTrue("Wrong Request ID" + editresp.getRequestId(), editresp.getRequestId() == 101);
    assertTrue("External RA CA Service was not successful.", editresp.isSuccessful() == true);

    // Create a new request, now it should be ok
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(ExtRAMessagesTest.genExtRAPKCS10Request(102,"SimplePKCS10Test1", Constants.pkcs10_1, false));
    msghome.create("SimplePKCS10Test1", smgs);   
        msg = waitForUser("SimplePKCS10Test1");
    assertNotNull(msg);
    submessagesresp = msg.getSubMessages(null,null,null);
    assertTrue(submessagesresp.getSubMessages().size() == 1);
    iter =  submessagesresp.getSubMessages().iterator();
    resp = (PKCS10Response) iter.next();
    assertTrue(resp.getRequestId() == 102);
    assertTrue(resp.isSuccessful() == true);   
    assertTrue(resp.getCertificate().getSubjectDN().toString().equals("CN=PKCS10REQ"));
    firstCertificate = resp.getCertificate();
    assertNotNull(firstCertificate);
    // Check the pkcs7 response
    byte[] pkcs7 = resp.getCertificateAsPKCS7();
    assertNotNull(pkcs7);
        CMSSignedData s = new CMSSignedData(pkcs7);
        // The signer, i.e. the CA, check it's the right CA
        SignerInformationStore signers = s.getSignerInfos();
        Collection col = signers.getSigners();
View Full Code Here

   
    assertTrue(submessagesresp.getSubMessages().size() == 3);
   
   
    Iterator iter = submessagesresp.getSubMessages().iterator();
    PKCS10Response resp1 = (PKCS10Response) iter.next();
    PKCS12Response resp2 = (PKCS12Response) iter.next();
    PKCS12Response resp3 = (PKCS12Response) iter.next();
    assertTrue(resp1.getRequestId() == 1);
    assertTrue(resp1.isSuccessful() == true);
    assertTrue(resp2.getRequestId() == 2);
    assertTrue(resp2.isSuccessful() == true);
    assertTrue(resp3.getRequestId() == 3);
    assertTrue(resp3.isSuccessful() == true);
  }
View Full Code Here

    Message[] resps = new Message[numberOfRequests];
    for(int i=0; i < numberOfRequests; i++){
      resps[i] = waitForUser("LotsOfReq"+i);
      assertNotNull("No response.", resps[i]);
      SubMessages submessagesresp = resps[i].getSubMessages(null,null,null);
      PKCS10Response resp = (PKCS10Response) submessagesresp.getSubMessages().iterator().next();
      assertTrue(resp.isSuccessful() == true);
    }               
  }
View Full Code Here

        if (raKey != null) {         
          respmsgs = msg.getSubMessages(raKey,cAChain,null);
        } else {
          respmsgs = msg.getSubMessages(null,null,null);
        }
        PKCS10Response pkcs10resp = (PKCS10Response) respmsgs.getSubMessages().get(0);
        PKCS12Response pkcs12resp = null;
        if (requestKeyStore) {
          pkcs12resp = (PKCS12Response) respmsgs.getSubMessages().get(1);
        }
        if (pkcs10resp.getRequestId() !=  pkcs10RequestId) {
          println("Error in PKCS10 Request requestId doesn't match responseId for user : " + username + ", request Id : " + pkcs10RequestId + " = " +  pkcs10resp.getRequestId());
        }
        if (requestKeyStore && pkcs12resp.getRequestId() !=  pkcs12RequestId) {
          println("Error in PKCS12 Request requestId doesn't match responseId for user : " + username + ", request Id : " + pkcs12RequestId + " = " +  pkcs12resp.getRequestId());
        }
        if (!pkcs10resp.isSuccessful()) {
          println("Error in PKCS10 Request for user : " + username + ", message : " + pkcs10resp.getFailInfo());
        }
        if (requestKeyStore && !pkcs12resp.isSuccessful()) {
          println("Error in PKCS12 Request for user : " + username + ", message : " + pkcs12resp.getFailInfo());                   
        }
        long endtime = new Date().getTime();
        float processtime = ((float) (endtime - starttime)) / 1000;
        if (pkcs10resp.isSuccessful() && !requestKeyStore) {          
          println("  " + username + " Generated Sucessfully in " + processtime + " seconds, Total Requests " + ++generateUserRequests);
        }
        if (requestKeyStore && pkcs10resp.isSuccessful() && pkcs12resp.isSuccessful()) {
          println("  " + username + " Generated Sucessfully in " + processtime + " seconds, Total Requests " + ++generateUserRequests);
        }
      }

    }
View Full Code Here

TOP

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

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.