Examples of KeyStoreRetrievalResponse


Examples of org.ejbca.extra.db.KeyStoreRetrievalResponse

  /**
   * @see org.ejbca.externalra.gui.IRequestDispatcher#getKeyStoreResponse(java.lang.String, java.lang.String)
   */
  public ResponseData getKeyStoreResponse(String username, String password) {
    ResponseData keyStoreResponse = null;
    KeyStoreRetrievalResponse responseSub = (KeyStoreRetrievalResponse) getResponseFromCA(new KeyStoreRetrievalRequest(random.nextLong(), username, password));
    if (responseSub != null) {
      if (responseSub.isSuccessful()) {
        keyStoreResponse = new ResponseData(responseSub.getKeyStoreData(), responseSub.getKeyStoreType(), null);
      } else {
        keyStoreResponse = new ResponseData(null, 0, responseSub.getFailInfo());
      }
    }
    return keyStoreResponse;
  }
View Full Code Here

Examples of org.ejbca.extra.db.KeyStoreRetrievalResponse

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

Examples of org.ejbca.extra.db.KeyStoreRetrievalResponse

        data = userAdminSession.findUser(admin, submessage.getUsername());
      } catch (AuthorizationDeniedException e) {
        log.info("External RA admin was denied access to a user: " + e.getMessage());
      }
      if (data == null) {
        return new KeyStoreRetrievalResponse(((ExtRARequest) submessage).getRequestId(), false, "No such user.", null, null);
      }
      // Find out if are doing key recovery
      int endEntityProfileId = data.getEndEntityProfileId()// TODO should probably also be used to get keysize and algorithm in the future..
      boolean usekeyrecovery = globalConfigurationSession.getCachedGlobalConfiguration(admin).getEnableKeyRecovery();
      boolean savekeys = data.getKeyRecoverable() && usekeyrecovery &&  (data.getStatus() != UserDataConstants.STATUS_KEYRECOVERY);
      boolean loadkeys = (data.getStatus() == UserDataConstants.STATUS_KEYRECOVERY) && usekeyrecovery;
      boolean reusecertificate = endEntityProfileSession.getEndEntityProfile(admin, endEntityProfileId).getReUseKeyRecoveredCertificate();
      // Generate or recover keystore and save it in the configured format
      GenerateToken tgen = new GenerateToken(authenticationSession, userAdminSession, caAdminSession, keyRecoverySession, signSession);
      byte[] buf = null;
      int tokentype = data.getTokenType();
      boolean createJKS = (tokentype == SecConst.TOKEN_SOFT_JKS);
      KeyStore ks = tgen.generateOrKeyRecoverToken(admin, submessage.getUsername(), submessage.getPassword(), data.getCAId(), "2048", AlgorithmConstants.KEYALGORITHM_RSA,
          createJKS, loadkeys, savekeys, reusecertificate, endEntityProfileId);
      if (tokentype == SecConst.TOKEN_SOFT_PEM) {
        buf = KeyTools.getSinglePemFromKeyStore(ks, submessage.getPassword().toCharArray());
      } else if (tokentype == SecConst.TOKEN_SOFT_P12 || tokentype == SecConst.TOKEN_SOFT_JKS) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ks.store(baos, submessage.getPassword().toCharArray());
        buf = baos.toByteArray();
      } else {
        return new KeyStoreRetrievalResponse(submessage.getRequestId(), false, "Unknown token type.", null, null);
      }
      return new KeyStoreRetrievalResponse(submessage.getRequestId(), true, null, tokentype, buf);
    } catch (Exception e) {
      log.debug("External RA request generated an error: " + e.getMessage());
      return new KeyStoreRetrievalResponse(submessage.getRequestId(), false, "Error " + e.getMessage(), null, null);
    }
  }
View Full Code Here

Examples of org.ejbca.extra.db.KeyStoreRetrievalResponse

    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);
    KeyStore ks = KeyStore.getInstance("PKCS12", "BC");
    try {
      ks.load(new ByteArrayInputStream(ksResp.getKeyStoreData()), password.toCharArray());
    } catch (Exception e) {
      assertTrue("Could not recreate keystore from response.", false);
    }
  } 
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.