Package org.ejbca.extra.db

Examples of org.ejbca.extra.db.SubMessages


  }
 
  public void test09GenerateSimpleCardRenewalRequest() throws Exception {
   
    // First fail message
    SubMessages smgs = new SubMessages(null,null,null);
    assertNotNull("Missing certificate from previous test.", firstCertificate);
    String cert1 = new String(Base64.encode(firstCertificate.getEncoded()));
    assertNotNull("Missing certificate from previous test.", secondCertificate);
        String cert2 = new String(Base64.encode(secondCertificate.getEncoded()));
    smgs.addSubMessage(new CardRenewalRequest(10, cert1, cert1, null, null));
    msghome.create("SimpleCardRenewalTest", smgs);
        Message msg = waitForUser("SimpleCardRenewalTest");
    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() == false);
        assertEquals(resp.getFailInfo(), "An authentication cert, a signature cert, an authentication request and a signature request are required");

        // Second fail message
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(new CardRenewalRequest(11, null, null, Constants.pkcs10_1, Constants.pkcs10_2));
    msghome.create("SimpleCardRenewalTest", smgs);
        msg = waitForUser("SimpleCardRenewalTest");
    assertNotNull(msg);
    submessagesresp = msg.getSubMessages(null,null,null);
    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() == 11);
    assertTrue(resp.isSuccessful() == false);
        assertEquals(resp.getFailInfo(), "An authentication cert, a signature cert, an authentication request and a signature request are required");

        // Third fail message
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(new CardRenewalRequest(12, cert1, cert1, Constants.pkcs10_1, Constants.pkcs10_2));
    msghome.create("SimpleCardRenewalTest", smgs);
        msg = waitForUser("SimpleCardRenewalTest");
    assertNotNull(msg);
    submessagesresp = msg.getSubMessages(null,null,null);
    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() == 12);
        assertTrue(resp.isSuccessful() == false);
        assertEquals(resp.getFailInfo(), "Verify failed for signature request");
       
        // Fourth fail message
        smgs = new SubMessages(null,null,null);
        smgs.addSubMessage(new CardRenewalRequest(12, cert1, cert2, Constants.pkcs10_1, Constants.pkcs10_2));
        msghome.create("SimpleCardRenewalTest", smgs);
        msg = waitForUser("SimpleCardRenewalTest");
        assertNotNull(msg);
        submessagesresp = msg.getSubMessages(null,null,null);
        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() == 12);
        assertTrue(resp.isSuccessful() == false);
        log.debug("resp.getFailInfo: " + resp.getFailInfo());
        assertEquals("Wrong error message.", resp.getFailInfo(), "User status must be new for SimplePKCS10Test1");
       
View Full Code Here


    String username = "ExtRA-ksret-" + random.nextInt();
    String password = "foo123";
    // Add a new user
    EditUserRequest editUserRequest = new EditUserRequest(requestId, username, "CN=" + username, null, null, null, "EMPTY", "ENDUSER",
                   "AdminCA1", password, 10, 1, EditUserRequest.SOFTTOKENNAME_P12, null);
    SubMessages smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(editUserRequest);
    msghome.create(username, smgs);
        Message msg = waitForUser(username);
    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() == requestId);
    assertTrue("Edit user failed", resp.isSuccessful() == true);
    // Try to retrieve keystore
    requestId = random.nextLong();
    KeyStoreRetrievalRequest keyStoreRetrievalRequest = new KeyStoreRetrievalRequest(requestId, username, password);
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(keyStoreRetrievalRequest);
    msghome.create(username+"ks", smgs);
        msg = waitForUser(username+"ks");
    assertNotNull("No response.", msg);
    submessagesresp = msg.getSubMessages(null,null,null);
    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 KeyStoreRetrievalResponse);
    KeyStoreRetrievalResponse ksResp = (KeyStoreRetrievalResponse) resp;
    assertTrue("Wrong keystore type.", ksResp.getKeyStoreType() == SecConst.TOKEN_SOFT_P12);
View Full Code Here

    String username = "ExtRA-ksret-" + random.nextInt();
    String password = "foo123";
    // Add a new user
    EditUserRequest editUserRequest = new EditUserRequest(requestId, username, "CN=" + username, null, null, null, "EMPTY", "ENDUSER",
                   "AdminCA1", password, 10, 1, EditUserRequest.SOFTTOKENNAME_USERGENERATED, null);
    SubMessages smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(editUserRequest);
    msghome.create(username, smgs);
        Message msg = waitForUser(username);
    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() == requestId);
    assertTrue("Edit user failed", resp.isSuccessful() == true);
    // Try to retrieve keystore
    requestId = random.nextLong();
    byte[] requestData = NonEjbTestTools.generatePKCS10Req("CN=dummyname", password);
    CertificateRequestRequest certificateRequestRequest = new CertificateRequestRequest(requestId, username, password, CertificateRequestRequest.REQUEST_TYPE_PKCS10, requestData, CertificateRequestRequest.RESPONSE_TYPE_ENCODED);
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(certificateRequestRequest);
    msghome.create(username+"csr", smgs);
        msg = waitForUser(username+"csr");
    assertNotNull("No response.", msg);
    submessagesresp = msg.getSubMessages(null,null,null);
    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);
View Full Code Here

        null,
        password,
        CertificateRequestRequest.REQUEST_TYPE_PKCS10, requestData, CertificateRequestRequest.RESPONSE_TYPE_CERTIFICATE);
    request.setCreateOrEditUser(true);
   
    final SubMessages smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(request);
    msghome.create(username + "csr", smgs);
       
    final Message msg = waitForUser(username + "csr");
        assertNotNull("No response.", msg);
    final SubMessages submessagesresp = msg.getSubMessages(null,null,null);
    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());
View Full Code Here

      // Generate request
      String username = "TEST_" + threadName + "_REQ-" + serialNumber;
      long pkcs10RequestId = 0;
      long pkcs12RequestId = 0;
      long starttime = new Date().getTime();
      SubMessages submgs = generateSubMessage();
      pkcs10RequestId = createPKCS10Request(username,submgs);
      if (requestKeyStore) {
        pkcs12RequestId = createPKCS12Request(username,submgs);
      }
      createUser(username, submgs);     

      run=true;
      // Wait for response
      boolean processed = false;
      Message msg = null;
      int wait = waitTime;
      while (wait >= 0 && run) {
        msg = findByUser(username);
        if (msg != null && msg.getStatus().equals(Message.STATUS_PROCESSED)) {
          processed = true;
          break;
        }
        try {
          sleep(1000);
        } catch (InterruptedException e) {
        }
        wait--;
      }
      if (!processed) {
        println("Error : Couldn't get processed response within the specified waitTime : Username :" + username + ", WaitTime : " + waitTime);

      } else {
        SubMessages respmsgs = null;
        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) {
View Full Code Here

      return requestId;
    }
   
    private SubMessages generateSubMessage() {
      if(securitylevel.equalsIgnoreCase(SECURITY_SIGNEDENCRYPTED)){
        return new SubMessages(raCert,raKey, encCert);                         
      }
      if(securitylevel.equalsIgnoreCase(SECURITY_SIGNED)){
        return new SubMessages(raCert,raKey,null);                 
      }
      if(securitylevel.equalsIgnoreCase(SECURITY_ENCRYPTED)){
        return new SubMessages(null,null,encCert);                         
      }
      return new SubMessages(null,null,null);
    }
View Full Code Here

          msg.setStatus(Message.STATUS_WAITING);
          msgHome.update(msg);             
          msg = null;
        } else {
          String errormessage = null;
          SubMessages submgs = null;
          try {
            log.info("Started processing message with messageId: " + msg.getMessageid()+", and uniqueId: "+msg.getUniqueId());

            if (serviceKeyStore != null) {
              submgs = msg.getSubMessages(
                  (PrivateKey) serviceKeyStore.getKeyStore().getKey(serviceKeyStore.getAlias(), keystorePwd.toCharArray()),
                  cACertChain,null);
            } else {
              submgs =  msg.getSubMessages(null,null,null);
            }
            if (submgs.isSigned()) {
              log.debug("Message from : " + msg.getMessageid() + " was signed");
            }
            if (signatureRequired && !submgs.isSigned()) {
              errormessage = "Error: Message from : " + msg.getMessageid() + " wasn't signed which is a requirement";
              log.error(errormessage);

            }
            if (submgs.isEncrypted()) {
              log.debug("Message from : " + msg.getMessageid() + " was encrypted");
            }
            if (encryptionRequired && !submgs.isEncrypted()) {
              errormessage = "Error: Message from : " + msg.getMessageid() + " wasn't encrypted which is a requirement";
              log.error(errormessage);
            }
          } catch (Exception e) {
            errormessage = "Error processing waiting message with Messageid : " + msg.getMessageid() + " : "+ e.getMessage();
            log.error("Error processing waiting message with Messageid : " + msg.getMessageid(), e);
          }

          if (submgs != null) {
            SubMessages respSubMsg;
            try {
              respSubMsg = generateResponseSubMessage(submgs.getSignerCert());
              Iterator<ISubMessage> iter = submgs.getSubMessages().iterator();
              boolean somethingprocessed = false;
              while(iter.hasNext()){
                ISubMessage reqMsg = iter.next();
                if (!checkWhiteList(reqMsg)) {
                  errormessage = "Sub message of type " + reqMsg.getClass().getName() + " is not listed in white list. Message id: " + msg.getMessageid();
                }
                ISubMessage respMsg = MessageProcessor.processSubMessage(getAdmin(submgs), reqMsg, errormessage, ejbs);
                if (respMsg != null) {
                  // if the response message is null here, we will ignore this message,
                  // it means that we should not do anything with it this round
                  respSubMsg.addSubMessage(respMsg);
                  somethingprocessed = true;
                }
              }
              if (somethingprocessed) {
                msg.setStatus(Message.STATUS_PROCESSED);
View Full Code Here

   * @throws KeyStoreException
   */ 
  private SubMessages generateResponseSubMessage(X509Certificate reqCert) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
   
    if(encryptionRequired && signatureRequired){
      return new SubMessages((X509Certificate) serviceKeyStore.getKeyStore().getCertificate(serviceKeyStore.getAlias()),
                         (PrivateKey) serviceKeyStore.getKeyStore().getKey(serviceKeyStore.getAlias(), keystorePwd.toCharArray()),
                         reqCert);                         
    }
    if(signatureRequired){
      return new SubMessages((X509Certificate) serviceKeyStore.getKeyStore().getCertificate(serviceKeyStore.getAlias()),
                         (PrivateKey) serviceKeyStore.getKeyStore().getKey(serviceKeyStore.getAlias(), keystorePwd.toCharArray()),
                         null);                         
    }
    if(encryptionRequired){
      return new SubMessages(null,
                         null,
                         reqCert);                         
    }
   
    return new SubMessages(null,null,null);
  }
View Full Code Here

TOP

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

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.