Package org.ejbca.extra.db

Examples of org.ejbca.extra.db.Message


                ScepRequestMessage reqmsg = new ScepRequestMessage(scepmsg, includeCACert);
                String transId = reqmsg.getTransactionId();
                log.debug("Received a message of type: "+reqmsg.getMessageType());
                if(reqmsg.getMessageType() == ScepRequestMessage.SCEP_TYPE_GETCERTINITIAL) {
                  log.info("Received a GetCertInitial message from host: "+remoteAddr);
                  Message msg = null;
                  try {
                    msg = msgHome.findByMessageId(transId);                   
                  } catch (Exception e) {
                    // TODO: internal resources
                    log.info("Error looking for message with transId "+transId+" :", e);
                  }
                  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 {
                      log.debug("Request is not yet processed, status: "+msg.getStatus());
                        reply = createPendingResponseMessage(reqmsg, racert, rapriv, cryptProvider).getResponseMessage();
                        log.debug("Responding with pending response, still pending.");                    
                    }                   
                  }else{
                    // User doesn't exist
View Full Code Here


    SubMessages submessages = new SubMessages(extRaCertificate, extRaKey, racaserviceCert);
    submessages.addSubMessage(subMessage);
    String messageId = GUIDGenerator.generateGUID(this);
    messageHome.create(messageId, submessages);
    // Get response from CA
    Message response = waitForResponse(messageHome, messageId);
    if (response != null) {
      log.debug("Got processed message");
      SubMessages subMessages = response.getSubMessages(extRaKey, caCerts, null);
      if (subMessages.getSubMessages().size() > 0) {
        log.debug("Got submessage message");
        extRAResponse = (ExtRAResponse) subMessages.getSubMessages().get(0);
      } else {
        log.error("No submessages in External RA API response.");
View Full Code Here

   * @return null if CA did not process request before the timeout.
   */
  private Message waitForResponse(MessageHome messageHome, String messageId) {
    long startTime = System.currentTimeMillis();
    long timeOut = ExternalRaGuiConfiguration.getTimeOut()*1000L;
    Message response = null;   
    try {
      while (startTime+timeOut>System.currentTimeMillis() && (response==null || !response.getStatus().equals(Message.STATUS_PROCESSED))) {
        Thread.sleep(1000);
        response = messageHome.findByMessageId(messageId);
      }
    } catch (InterruptedException e) {
    }
    if (response == null) {
      log.error("Message has disappeared from database!?!");
    } else if (!response.getStatus().equals(Message.STATUS_PROCESSED)) {
      log.debug("Status of message is " + response.getStatus());
      messageHome.remove(messageId);
      response = null;
    } else {
      messageHome.remove(messageId);
    }
View Full Code Here

    smgs.addSubMessage(ExtRAMessagesTest.genExtRAPKCS10Request(100,"SimplePKCS10Test1", Constants.pkcs10_1));
    smgs.addSubMessage(ExtRAMessagesTest.genExtRAPKCS10Request(101,"SimplePKCS10Test1", Constants.pkcs10_2));
   
    msghome.create("SimplePKCS10Test1", smgs);
   
        Message msg = waitForUser("SimplePKCS10Test1");
   
    assertNotNull("No response.", msg);
   
    SubMessages submessagesresp = msg.getSubMessages(null,null,null);
   
    assertTrue(submessagesresp.getSubMessages().size() == 2);
   
    Iterator iter =  submessagesresp.getSubMessages().iterator();
    PKCS10Response resp = (PKCS10Response) iter.next();
View Full Code Here

    // First test with a user that does not exist or has status generated, when the user it not created the request will fail
    SubMessages smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(ExtRAMessagesTest.genExtRAPKCS10Request(100,"SimplePKCS10Test1", Constants.pkcs10_1, false));
    msghome.create("SimplePKCS10Test1", smgs);
        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);   
View Full Code Here

    SubMessages smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(ExtRAMessagesTest.genExtRAPKCS12Request(200,"SimplePKCS12Test1", false));
   
    msghome.create("SimplePKCS12Test1", smgs);
   
        Message msg = waitForUser("SimplePKCS12Test1");
    assertNotNull("No response.", msg);
   
    SubMessages submessagesresp = msg.getSubMessages(null,null,null);
   
    assertTrue(submessagesresp.getSubMessages().size() == 1);
   
    PKCS12Response resp = (PKCS12Response) submessagesresp.getSubMessages().iterator().next();
    assertTrue(resp.getRequestId() == 200);
View Full Code Here

    SubMessages smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(ExtRAMessagesTest.genExtRAPKCS12Request(300,"SimplePKCS12Test1", true));
   
    msghome.create("SimplePKCS12Test1", smgs);
   
        Message msg = waitForUser("SimplePKCS12Test1");
    assertNotNull("No response.", msg);
   
    SubMessages submessagesresp = msg.getSubMessages(null,null,null);
   
    assertTrue(submessagesresp.getSubMessages().size() == 1);
   
    PKCS12Response resp = (PKCS12Response) submessagesresp.getSubMessages().iterator().next();
    assertTrue(resp.getRequestId() == 300);
    assertTrue(resp.isSuccessful() == true);
    assertNotNull(resp.getKeyStore("foo123"));
    //KeyStore ks = resp.getKeyStore("foo123");   
   
    X509Certificate orgCert = (X509Certificate) resp.getKeyStore("foo123").getCertificate("PKCS12REQ");
   
    assertTrue(orgCert.getSubjectDN().toString().equals("CN=PKCS12REQ"));
   
    // Generate Key Recovery request with original cert.
   
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(ExtRAMessagesTest.genExtRAKeyRecoveryRequest(301,"SimplePKCS12Test1",true,orgCert));
   
    msghome.create("SimplePKCS12Test1", smgs);
   
        msg = waitForUser("SimplePKCS12Test1");
   
    assertNotNull(msg);
   
    submessagesresp = msg.getSubMessages(null,null,null);
   
    assertTrue(submessagesresp.getSubMessages().size() == 1);
   
    resp = (PKCS12Response) submessagesresp.getSubMessages().iterator().next();
    assertEquals(301, resp.getRequestId());
    assertTrue(resp.isSuccessful());
   
    X509Certificate keyRecCert = (X509Certificate) resp.getKeyStore("foo123").getCertificate("PKCS12REQ");
        assertTrue(keyRecCert.getSerialNumber().equals(orgCert.getSerialNumber()));
       
        // Generate Key Recovery Request with new cert
       
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(ExtRAMessagesTest.genExtRAKeyRecoveryRequest(302,"SimplePKCS12Test1",false,orgCert));
   
    msghome.create("SimplePKCS12Test1", smgs);
   
        msg = waitForUser("SimplePKCS12Test1");
   
    assertNotNull(msg);
   
    submessagesresp = msg.getSubMessages(null,null,null);
   
    assertTrue(submessagesresp.getSubMessages().size() == 1);
   
    resp = (PKCS12Response) submessagesresp.getSubMessages().iterator().next();
    assertTrue(resp.getRequestId() == 302);
View Full Code Here

    assertNotNull("Missing certificate from previous test.", firstCertificate);
    smgs.addSubMessage(new RevocationRequest(10, CertTools.getIssuerDN(firstCertificate), firstCertificate.getSerialNumber(), RevocationRequest.REVOKATION_REASON_UNSPECIFIED));
   
    msghome.create("SimpleRevocationTest", smgs);
   
        Message msg = waitForUser("SimpleRevocationTest");
    assertNotNull("No response.", msg);
   
    SubMessages submessagesresp = msg.getSubMessages(null,null,null);
   
    assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
   
    ExtRAResponse resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertTrue("Wrong Request ID" + resp.getRequestId(), resp.getRequestId() == 10);
    assertTrue(resp.isSuccessful() == true);
 
    // revoke second certificate 
    SubMessages smgs2 = new SubMessages(null,null,null);
    assertNotNull("Missing certificate from previous test.", secondCertificate);
    smgs2.addSubMessage(new RevocationRequest(6, CertTools.getIssuerDN(secondCertificate), secondCertificate.getSerialNumber(), RevocationRequest.REVOKATION_REASON_UNSPECIFIED));
   
    msghome.create("SimpleRevocationTest", smgs2);
   
        Message msg2 = waitForUser("SimpleRevocationTest");
   
    assertNotNull(msg2);
   
    SubMessages submessagesresp2 = msg2.getSubMessages(null,null,null);
   
    assertTrue("Number of submessages " + submessagesresp2.getSubMessages().size() ,  submessagesresp2.getSubMessages().size() == 1);
   
    ExtRAResponse resp2 = (ExtRAResponse) submessagesresp2.getSubMessages().iterator().next();
    assertTrue(resp2.getRequestId() == 6);
    assertTrue(resp2.isSuccessful() == true);
   
    // try to revoke nonexisting certificate 
    SubMessages smgs3 = new SubMessages(null,null,null);
    smgs3.addSubMessage(new RevocationRequest(7, CertTools.getIssuerDN(secondCertificate), new BigInteger("1234"), RevocationRequest.REVOKATION_REASON_UNSPECIFIED));
   
    msghome.create("SimpleRevocationTest", smgs3);
   
        Message msg3 = waitForUser("SimpleRevocationTest");
   
    assertNotNull(msg3);
   
    SubMessages submessagesresp3 = msg3.getSubMessages(null,null,null);
   
    assertTrue(submessagesresp3.getSubMessages().size() == 1);
   
    ExtRAResponse resp3 = (ExtRAResponse) submessagesresp3.getSubMessages().iterator().next();
    assertTrue(resp3.getRequestId() == 7);
    assertTrue(resp3.isSuccessful() == false);
       
    // try to revoke a users all certificates
    SubMessages smgs4 = new SubMessages(null,null,null);
    smgs4.addSubMessage(new RevocationRequest(8, CertTools.getIssuerDN(secondCertificate), secondCertificate.getSerialNumber(), RevocationRequest.REVOKATION_REASON_UNSPECIFIED, false, true));
   
    msghome.create("SimpleRevocationTest", smgs4);
   
        Message msg4 = waitForUser("SimpleRevocationTest");
   
    assertNotNull(msg4);
   
    SubMessages submessagesresp4 = msg4.getSubMessages(null,null,null);
   
    assertTrue(submessagesresp4.getSubMessages().size() == 1);
   
    ExtRAResponse resp4 = (ExtRAResponse) submessagesresp4.getSubMessages().iterator().next();
    assertTrue(resp4.getRequestId() == 8);
    assertTrue(resp4.isSuccessful() == true);
   
    // try to revoke a users all certificates by giving the username
    SubMessages smgs5 = new SubMessages(null,null,null);
    smgs5.addSubMessage(new RevocationRequest(9, "SimplePKCS10Test1", RevocationRequest.REVOKATION_REASON_UNSPECIFIED, false));
   
    msghome.create("SimpleRevocationTest", smgs5);
   
        Message msg5 = waitForUser("SimpleRevocationTest");
   
    assertNotNull(msg5);
   
    SubMessages submessagesresp5 = msg5.getSubMessages(null,null,null);
   
    assertTrue(submessagesresp5.getSubMessages().size() == 1);
   
    ExtRAResponse resp5 = (ExtRAResponse) submessagesresp5.getSubMessages().iterator().next();
    assertTrue(resp5.getRequestId() == 9);
    assertTrue(resp5.isSuccessful() == true);
   
    // Try some error cases
        // First a message with null as parameters
    SubMessages smgs6 = new SubMessages(null,null,null);
    smgs6.addSubMessage(new RevocationRequest(10, null, RevocationRequest.REVOKATION_REASON_UNSPECIFIED, false));   
    msghome.create("SimpleRevocationTest", smgs6);
        Message msg6 = waitForUser("SimpleRevocationTest");
    assertNotNull(msg6);
    SubMessages submessagesresp6 = msg6.getSubMessages(null,null,null);
    assertTrue(submessagesresp6.getSubMessages().size() == 1);
    ExtRAResponse resp6 = (ExtRAResponse) submessagesresp6.getSubMessages().iterator().next();
    assertTrue(resp6.getRequestId() == 10);
    assertTrue(resp6.isSuccessful() == false);
        assertEquals(resp6.getFailInfo(), "Either username or issuer/serno is required");
       
        // Then a message with a suername that does not exist
        SubMessages smgs7 = new SubMessages(null,null,null);
        smgs7.addSubMessage(new RevocationRequest(11, "184hjeyyydvv88q", RevocationRequest.REVOKATION_REASON_UNSPECIFIED, false));    
        msghome.create("SimpleRevocationTest", smgs7);
        Message msg7 = waitForUser("SimpleRevocationTest");
        assertNotNull(msg7);
        SubMessages submessagesresp7 = msg7.getSubMessages(null,null,null);
        assertTrue(submessagesresp7.getSubMessages().size() == 1);
        ExtRAResponse resp7 = (ExtRAResponse) submessagesresp7.getSubMessages().iterator().next();
        assertTrue(resp7.getRequestId() == 11);
        assertTrue(resp7.isSuccessful() == false);
        assertEquals(resp7.getFailInfo(), "User not found from username: username=184hjeyyydvv88q");

        // Then a message with a issuer/serno that does not exist
        SubMessages smgs8 = new SubMessages(null,null,null);
        smgs8.addSubMessage(new RevocationRequest(12, "CN=ffo558444,O=338qqwaa,C=qq", new BigInteger("123"), RevocationRequest.REVOKATION_REASON_UNSPECIFIED, false, false));    
        msghome.create("SimpleRevocationTest", smgs8);
        Message msg8 = waitForUser("SimpleRevocationTest");
        assertNotNull(msg8);
        SubMessages submessagesresp8 = msg8.getSubMessages(null,null,null);
        assertTrue(submessagesresp8.getSubMessages().size() == 1);
        ExtRAResponse resp8 = (ExtRAResponse) submessagesresp8.getSubMessages().iterator().next();
        assertTrue(resp8.getRequestId() == 12);
        assertTrue(resp8.isSuccessful() == false);
        assertEquals(resp8.getFailInfo(), "User not found from issuer/serno: issuer='CN=ffo558444,O=338qqwaa,C=qq', serno=123");
View Full Code Here

    SubMessages smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(ExtRAMessagesTest.genExtRAEditUserRequest(11,"SimpleEditUserTest"));
   
    msghome.create("SimpleEditUserTest", smgs);
   
        Message msg = waitForUser("SimpleEditUserTest");
    assertNotNull("No response.", msg);
   
    SubMessages submessagesresp = msg.getSubMessages(null,null,null);
   
    assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
   
    ExtRAResponse resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertTrue("Wrong Request ID" + resp.getRequestId(), resp.getRequestId() == 11);
View Full Code Here

    smgs.addSubMessage(ExtRAMessagesTest.genExtRAPKCS12Request(2,"SimplePKCS12Test1", false));
    smgs.addSubMessage(ExtRAMessagesTest.genExtRAPKCS12Request(3,"SimplePKCS12Test1", false));
   
    msghome.create("COMPLEXREQ_1", smgs);
   
        Message msg = waitForUser("COMPLEXREQ_1");
    assertNotNull("No response.", msg);
   
    SubMessages submessagesresp = msg.getSubMessages(null,null,null);
   
    assertTrue(submessagesresp.getSubMessages().size() == 3);
   
   
    Iterator iter = submessagesresp.getSubMessages().iterator();
View Full Code Here

TOP

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

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.