Examples of IResponseMessage


Examples of org.ejbca.core.protocol.IResponseMessage

  public IResponseMessage handleMessage(BaseCmpMessage msg) {
    if (LOG.isTraceEnabled()) {
      LOG.trace(">handleMessage");
    }
    int version = msg.getHeader().getPvno().getValue().intValue();
    IResponseMessage resp = null;
    // if version == 1 it is cmp1999 and we should not return a message back
    if (version > 1) {
      // Try to find a HMAC/SHA1 protection key
      String owfAlg = null;
      String macAlg = null;
      int iterationCount = 1024;
      String cmpRaAuthSecret = null
      String keyId = getSenderKeyId(msg.getHeader());
      if (keyId != null) {
        try {
          CmpPbeVerifyer verifyer = new CmpPbeVerifyer(msg.getMessage());
          owfAlg = verifyer.getOwfOid();
          macAlg = verifyer.getMacOid();
          iterationCount = verifyer.getIterationCount();
          // If we use a globally configured shared secret for all CAs we check it right away
          if (raAuthenticationSecret != null) {
            if (!verifyer.verify(raAuthenticationSecret)) {
              String err = "Protection verified false on ConformationMessage";
              LOG.error(err);
              return CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_MESSAGE_CHECK, err);
            }
            cmpRaAuthSecret = raAuthenticationSecret;
          } else {
            // Get the correct profiles' and CA ids based on current configuration.
            CAInfo caInfo;
            try {
              int eeProfileId = getUsedEndEntityProfileId(keyId);
              int caId = getUsedCaId(keyId, eeProfileId);
              caInfo = caAdminSession.getCAInfo(admin, caId);
            } catch (NotFoundException e) {
              LOG.info(INTRES.getLocalizedMessage(CMP_ERRORGENERAL, e.getMessage()), e);
              return CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.INCORRECT_DATA, e.getMessage());
            } catch (EJBException e) {
              final String errMsg = INTRES.getLocalizedMessage(CMP_ERRORADDUSER);
              LOG.error(errMsg, e);     
              return null// Fatal error
            }
            if (caInfo instanceof X509CAInfo) {
              cmpRaAuthSecret = ((X509CAInfo) caInfo).getCmpRaAuthSecret();
            }
            // Now we know which CA the request is for, if we didn't use a global shared secret we can check it now!
            if (cmpRaAuthSecret == null || !verifyer.verify(cmpRaAuthSecret)) {
              String errMsg = INTRES.getLocalizedMessage("cmp.errorauthmessage");
              LOG.info(errMsg); // info because this is something we should expect and we handle it
              if (verifyer.getErrMsg() != null) {
                errMsg = verifyer.getErrMsg();
              }
              return CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_MESSAGE_CHECK, errMsg);
            }
          }
        } catch (NoSuchAlgorithmException e) {
          LOG.error("Exception calculating protection: ", e);
          return CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_MESSAGE_CHECK, e.getMessage());
        } catch (NoSuchProviderException e) {
          LOG.error("Exception calculating protection: ", e);
          return CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_MESSAGE_CHECK, e.getMessage());
        } catch (InvalidKeyException e) {
          LOG.error("Exception calculating protection: ", e);
          return CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_MESSAGE_CHECK, e.getMessage());
        }
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("Creating a PKI confirm message response");
      }
      CmpConfirmResponseMessage cresp = new CmpConfirmResponseMessage();
      cresp.setRecipientNonce(msg.getSenderNonce());
      cresp.setSenderNonce(new String(Base64.encode(CmpMessageHelper.createSenderNonce())));
      cresp.setSender(msg.getRecipient());
      cresp.setRecipient(msg.getSender());
      cresp.setTransactionId(msg.getTransactionId());
      // Set all protection parameters
      if (LOG.isDebugEnabled()) {
        LOG.debug(responseProtection+", "+owfAlg+", "+macAlg+", "+keyId+", "+cmpRaAuthSecret);
      }
      if (StringUtils.equals(responseProtection, "pbe") && (owfAlg != null) && (macAlg != null) && (keyId != null) && (cmpRaAuthSecret != null) ) {
        cresp.setPbeParameters(keyId, cmpRaAuthSecret, owfAlg, macAlg, iterationCount);
      }
      resp = cresp;
      try {
        resp.create();
      } catch (InvalidKeyException e) {
        LOG.error("Exception during CMP processing: ", e);     
      } catch (NoSuchAlgorithmException e) {
        LOG.error("Exception during CMP processing: ", e);     
      } catch (NoSuchProviderException e) {
View Full Code Here

Examples of org.ejbca.core.protocol.IResponseMessage

  public IResponseMessage handleMessage(final BaseCmpMessage msg) {
    if (LOG.isTraceEnabled()) {
      LOG.trace(">handleMessage");
    }
    IResponseMessage resp = null;
    try {
      CrmfRequestMessage crmfreq = null;
      if (msg instanceof CrmfRequestMessage) {
        crmfreq = (CrmfRequestMessage) msg;
        crmfreq.getMessage();
View Full Code Here

Examples of org.ejbca.core.protocol.IResponseMessage

    final String certProfileName;  // The certificate profile to use when adding users in RA mode.
    final int certProfileId;
    // Try to find a HMAC/SHA1 protection key
    final int requestId = crmfreq.getRequestId();
    final int requestType = crmfreq.getRequestType();
    IResponseMessage resp = null; // The CMP response message to be sent back to the client
    final String keyId = getSenderKeyId(crmfreq.getHeader());
    if (keyId == null) {      // No keyId found in message so we can not authenticate it.
      final String errMsg = INTRES.getLocalizedMessage("cmp.errorunauthmessagera");
      LOG.info(errMsg); // info because this is something we should expect and we handle it
      return CmpMessageHelper.createUnprotectedErrorMessage(msg, ResponseStatus.FAILURE, FailInfo.BAD_MESSAGE_CHECK, errMsg);
View Full Code Here

Examples of org.ejbca.core.protocol.IResponseMessage

      if (log.isTraceEnabled()) {
        log.trace(">createCertificate(IRequestMessage)");
      }
        // Get CA that will receive request
        UserDataVO data = null;
        IResponseMessage ret = null;
        CA ca;
        if (suppliedUserData == null) {
          ca = getCAFromRequest(admin, req);
        } else {
          ca = caSession.getCA(admin, suppliedUserData.getCAId()); // Take the CAId from the supplied userdata, if any
        }
        try {
            CATokenContainer catoken = ca.getCAToken();
           
            // See if we need some key material to decrypt request
            if (req.requireKeyInfo()) {
                // You go figure...scep encrypts message with the public CA-cert
                req.setKeyInfo(ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getJCEProvider());
            }
            // Verify the request
            if (req.verify() == false) {
              String msg = intres.getLocalizedMessage("signsession.popverificationfailed");
              logSession.log(admin, ca.getCAId(), LogConstants.MODULE_CA, new java.util.Date(), req.getUsername(), null, LogConstants.EVENT_ERROR_CREATECERTIFICATE, msg);
                throw new SignRequestSignatureException(msg);
            }
           
            if (ca.isUseUserStorage() && req.getUsername() == null) {
              String msg = intres.getLocalizedMessage("signsession.nouserinrequest", req.getRequestDN());
              logSession.log(admin, ca.getCAId(), LogConstants.MODULE_CA, new java.util.Date(), req.getUsername(), null, LogConstants.EVENT_ERROR_CREATECERTIFICATE, msg);
                throw new SignRequestException(msg);
                //ret.setFailInfo(FailInfo.BAD_REQUEST);
                //ret.setStatus(ResponseStatus.FAILURE);
            } else if (ca.isUseUserStorage() && req.getPassword() == null) {
              String msg = intres.getLocalizedMessage("signsession.nopasswordinrequest");
                logSession.log(admin, ca.getCAId(), LogConstants.MODULE_CA, new java.util.Date(), req.getUsername(), null, LogConstants.EVENT_ERROR_CREATECERTIFICATE, msg);
                throw new SignRequestException(msg);
            } else {       
              ResponseStatus status = ResponseStatus.SUCCESS;
              FailInfo failInfo = null;
              String failText = null;
                Certificate cert = null;
              try {
            // If we haven't done so yet, authenticate user. (Only if we store UserData for this CA.)
                if (ca.isUseUserStorage()) {
                    data = authUser(admin, req.getUsername(), req.getPassword());
                } else {
                  data = suppliedUserData;
                }
                    PublicKey reqpk = req.getRequestPublicKey();
                    if (reqpk == null) {
                        logSession.log(admin, ca.getCAId(), LogConstants.MODULE_CA, new java.util.Date(), req.getUsername(), null, LogConstants.EVENT_ERROR_CREATECERTIFICATE, intres.getLocalizedMessage("signsession.nokeyinrequest"));
                        throw new InvalidKeyException("Key is null!");
                    }
                    // We need to make sure we use the users registered CA here
                    if (data.getCAId() != ca.getCAId()) {
                      failText = intres.getLocalizedMessage("signsession.wrongauthority", Integer.valueOf(ca.getCAId()), Integer.valueOf(data.getCAId()));
                        status = ResponseStatus.FAILURE;
                        failInfo = FailInfo.WRONG_AUTHORITY;
                        logSession.log(admin, ca.getCAId(), LogConstants.MODULE_CA, new java.util.Date(), req.getUsername(), null, LogConstants.EVENT_ERROR_CREATECERTIFICATE, failText);
                    }

                    if (status.equals(ResponseStatus.SUCCESS)) {
                      Date notBefore = req.getRequestValidityNotBefore(); // Optionally requested validity
                      Date notAfter = req.getRequestValidityNotAfter(); // Optionally requested validity
                      X509Extensions exts = req.getRequestExtensions(); // Optionally requested extensions
                      int keyusage = -1;
                      if (exts != null) {
                          if (log.isDebugEnabled()) {
                            log.debug("we have extensions, see if we can override KeyUsage by looking for a KeyUsage extension in request");
                          }
                        X509Extension ext = exts.getExtension(X509Extensions.KeyUsage);
                        if (ext != null) {
                          ASN1OctetString os = ext.getValue();
                          ByteArrayInputStream bIs = new ByteArrayInputStream(os.getOctets());
                          ASN1InputStream dIs = new ASN1InputStream(bIs);
                          DERObject dob = dIs.readObject();
                          DERBitString bs = DERBitString.getInstance(dob);
                          keyusage = bs.intValue();                                                           
                          if (log.isDebugEnabled()) {
                            log.debug("We have a key usage request extension: "+keyusage);
                          }
                        }
                      }
              String sequence = null;
              byte[] ki = req.getRequestKeyInfo();
              if ( (ki != null) && (ki.length > 0) ) {
                  sequence = new String(ki);               
              }
                      cert = createCertificate(admin, data, req.getRequestX509Name(), ca, reqpk, keyusage, notBefore, notAfter, exts, sequence);
                    }
              } catch (ObjectNotFoundException oe) {
                // If we didn't find the entity return error message
                log.error("User not found: ", oe);
                  failText = intres.getLocalizedMessage("signsession.nosuchuser", req.getUsername());
                    status = ResponseStatus.FAILURE;
                    failInfo = FailInfo.INCORRECT_DATA;
                    logSession.log(admin, ca.getCAId(), LogConstants.MODULE_CA, new java.util.Date(), req.getUsername(), null, LogConstants.EVENT_ERROR_CREATECERTIFICATE, failText);
              }
               
                //Create the response message with all nonces and checks etc
                ret = req.createResponseMessage(responseClass, req, ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getProvider());
       
        if ( (cert == null) && (status == ResponseStatus.SUCCESS) ) {
          status = ResponseStatus.FAILURE;
          failInfo = FailInfo.BAD_REQUEST;
                } else {
                    ret.setCertificate(cert);
                }
                ret.setStatus(status);
                if (failInfo != null) {
                    ret.setFailInfo(failInfo);
                    ret.setFailText(failText);
                }
            }
            ret.create();
            // Call authentication session and tell that we are finished with this user. (Only if we store UserData for this CA.)
            if (ca.isUseUserStorage() && data!=null) {
            finishUser(ca, data);
            }             
        } catch (NoUniqueCertSerialNumberIndexException e) {
View Full Code Here

Examples of org.ejbca.core.protocol.IResponseMessage

  }

    @Override
    public IResponseMessage createRequestFailedResponse(Admin admin, IRequestMessage req,  Class responseClass) throws  AuthLoginException, AuthStatusException, IllegalKeyException, CADoesntExistsException, SignRequestSignatureException, SignRequestException, CATokenOfflineException {
      log.trace(">createRequestFailedResponse(IRequestMessage)");
        IResponseMessage ret = null;           
        CA ca = getCAFromRequest(admin, req);
        try {
            CATokenContainer catoken = ca.getCAToken();
            // See if we need some key material to decrypt request
            if (req.requireKeyInfo()) {
                // You go figure...scep encrypts message with the public CA-cert
                req.setKeyInfo(ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getProvider());
            }
            // Verify the request
            if (req.verify() == false) {
              String msg = intres.getLocalizedMessage("signsession.popverificationfailed");
              logSession.log(admin, ca.getCAId(), LogConstants.MODULE_CA, new java.util.Date(), req.getUsername(), null, LogConstants.EVENT_ERROR_CREATECERTIFICATE, intres.getLocalizedMessage("signsession.popverificationfailed"));
                throw new SignRequestSignatureException(msg);
            }
            //Create the response message with all nonces and checks etc
            ret = req.createResponseMessage(responseClass, req, ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getProvider());
            ret.setStatus(ResponseStatus.FAILURE);
            ret.setFailInfo(FailInfo.BAD_REQUEST);
            ret.create();
        } catch (IllegalKeyStoreException e) {
            throw new IllegalKeyException(e);
        } catch (NotFoundException e) {
          // This can actually not happen here?
            throw new CADoesntExistsException(e);
View Full Code Here

Examples of org.ejbca.core.protocol.IResponseMessage

    }
   
    @Override
    public IResponseMessage getCRL(Admin admin, IRequestMessage req, Class responseClass) throws AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException, SignRequestException, SignRequestSignatureException, UnsupportedEncodingException {
        log.trace(">getCRL(IRequestMessage)");
        IResponseMessage ret = null;
        // Get CA that will receive request
        CA ca = getCAFromRequest(admin, req);
        try {
            CATokenContainer catoken = ca.getCAToken();
            if (ca.getStatus() != SecConst.CA_ACTIVE) {
              String msg = intres.getLocalizedMessage("signsession.canotactive", ca.getSubjectDN());
              logSession.log(admin, ca.getCAId(), LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_ERROR_GETLASTCRL, msg);
                throw new EJBException(msg);
            }
            // See if we need some key material to decrypt request
            if (req.requireKeyInfo()) {
                // You go figure...scep encrypts message with the public CA-cert
                req.setKeyInfo(ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getProvider());
            }
            //Create the response message with all nonces and checks etc
            ret = req.createResponseMessage(responseClass, req, ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getProvider());
           
            // Get the Full CRL, don't even bother digging into the encrypted CRLIssuerDN...since we already
            // know that we are the CA (SCEP is soooo stupid!)
            final String certSubjectDN = CertTools.getSubjectDN(ca.getCACertificate());
            byte[] crl = crlSession.getLastCRL(admin, certSubjectDN, false);
            if (crl != null) {
                ret.setCrl(CertTools.getCRLfromByteArray(crl));
                ret.setStatus(ResponseStatus.SUCCESS);
            } else {
                ret.setStatus(ResponseStatus.FAILURE);
                ret.setFailInfo(FailInfo.BAD_REQUEST);
            }
            ret.create();
            // TODO: handle returning errors as response message,
            // javax.ejb.ObjectNotFoundException and the others thrown...
        } catch (NotFoundException e) {
          // This actually can not happen here
            throw new CADoesntExistsException(e);
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.