Package org.ejbca.core.model.ca.caadmin

Examples of org.ejbca.core.model.ca.caadmin.CAInfo


    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    @Override
    public boolean runNewTransactionConditioned(Admin admin, CA ca, long addtocrloverlaptime) throws CATokenOfflineException {
        boolean ret = false;
        Date currenttime = new Date();
        CAInfo cainfo = ca.getCAInfo();
        try {
                if (cainfo.getStatus() == SecConst.CA_EXTERNAL) {
                                if (log.isDebugEnabled()) {
                                        log.debug("Not trying to generate CRL for external CA "+cainfo.getName());
                                }
                } else if (cainfo.getStatus() == SecConst.CA_WAITING_CERTIFICATE_RESPONSE) {
                                if (log.isDebugEnabled()) {
                                        log.debug("Not trying to generate CRL for CA "+cainfo.getName() +" awaiting certificate response.");
                                }
                } else {
                        if (cainfo instanceof X509CAInfo) {
                                Collection<Certificate> certs = cainfo.getCertificateChain();
                                final Certificate cacert;
                                if (!certs.isEmpty()) {
                                        cacert = certs.iterator().next();  
                                } else {
                                        cacert = null;
                                }
                                // Don't create CRLs if the CA has expired
                                if ( (cacert != null) && (CertTools.getNotAfter(cacert).after(new Date())) ) {
                                        if (cainfo.getStatus() == SecConst.CA_OFFLINE )  {
                                                String msg = intres.getLocalizedMessage("createcrl.caoffline", cainfo.getName(), Integer.valueOf(cainfo.getCAId()));                                                  
                                                log.info(msg);
                                                logSession.log(admin, cainfo.getCAId(), LogConstants.MODULE_CA, new java.util.Date(),null, null, LogConstants.EVENT_INFO_CREATECRL, msg);
                                        } else {
                                                try {
                                                        if (log.isDebugEnabled()) {
                                                                log.debug("Checking to see if CA '"+cainfo.getName()+"' ("+cainfo.getCAId()+") needs CRL generation.");
                                                        }
                                                        final String certSubjectDN = CertTools.getSubjectDN(cacert);
                                                        CRLInfo crlinfo = crlSession.getLastCRLInfo(admin,certSubjectDN,false);
                                                        if (log.isDebugEnabled()) {
                                                                if (crlinfo == null) {
                                                                        log.debug("Crlinfo was null");
                                                                } else {
                                                                        log.debug("Read crlinfo for CA: "+cainfo.getName()+", lastNumber="+crlinfo.getLastCRLNumber()+", expireDate="+crlinfo.getExpireDate());
                                                                }                                         
                                                        }
                                                        long crlissueinterval = cainfo.getCRLIssueInterval();
                                                        if (log.isDebugEnabled()) {
                                                                log.debug("crlissueinterval="+crlissueinterval);
                                                                log.debug("crloverlaptime="+cainfo.getCRLOverlapTime());                                  
                                                        }
                                                        long overlap = cainfo.getCRLOverlapTime() + addtocrloverlaptime; // Overlaptime is in minutes, default if crlissueinterval == 0
                                                        long nextUpdate = 0; // if crlinfo == 0, we will issue a crl now
                                                        if (crlinfo != null) {
                                                                // CRL issueinterval in hours. If this is 0, we should only issue a CRL when
                                                                // the old one is about to expire, i.e. when currenttime + overlaptime > expiredate
                                                                // if isseuinterval is > 0 we will issue a new CRL when currenttime > createtime + issueinterval
                                                                nextUpdate = crlinfo.getExpireDate().getTime(); // Default if crlissueinterval == 0
                                                                if (crlissueinterval > 0) {
                                                                        long u = crlinfo.getCreateDate().getTime() + crlissueinterval;
                                                                        // If this period for some reason (we missed to issue some?) is larger than when the CRL expires,
                                                                        // we need to issue one when the CRL expires
                                                                        if ((u + overlap) < nextUpdate) {
                                                                                nextUpdate = u;
                                                                                // When we issue CRLs before the real expiration date we don't use overlap
                                                                                overlap = 0;
                                                                        }
                                                                }                                  
                                                                if (log.isDebugEnabled()) {
                                                                        log.debug("Calculated nextUpdate to "+nextUpdate);
                                                                }
                                                        } else {
                                                                String msg = intres.getLocalizedMessage("createcrl.crlinfonull", cainfo.getName());                                               
                                                                log.info(msg);
                                                        }
                                                        if ((currenttime.getTime() + overlap) >= nextUpdate) {
                                                                if (log.isDebugEnabled()) {
                                                                        log.debug("Creating CRL for CA, because:"+currenttime.getTime()+overlap+" >= "+nextUpdate);                                               
                                                                }
                                                                run(admin, ca);
                                                                //this.runNewTransaction(admin, cainfo.getSubjectDN());
                                                                ret = true;
                                                                //createdcrls++;
                                                        }

                                                } catch (CATokenOfflineException e) {
                                                        String msg = intres.getLocalizedMessage("createcrl.caoffline", cainfo.getName(), Integer.valueOf(cainfo.getCAId()));                                                  
                                                        log.error(msg);
                                                        logSession.log(admin, cainfo.getCAId(), LogConstants.MODULE_CA, new java.util.Date(),null, null, LogConstants.EVENT_ERROR_CREATECRL, msg);
                                                }
                                        }
                                } else if (cacert != null) {
                                        if (log.isDebugEnabled()) {
                                                log.debug("Not creating CRL for expired CA "+cainfo.getName()+". CA subjectDN='"+CertTools.getSubjectDN(cacert)+"', expired: "+CertTools.getNotAfter(cacert));
                                        }
                                } else {
                                        if (log.isDebugEnabled()) {
                                                log.debug("Not creating CRL for CA without CA certificate: "+cainfo.getName());
                                        }
                                }
                        }                                                         
                }
        } catch(Exception e) {
                String msg = intres.getLocalizedMessage("createcrl.generalerror", Integer.valueOf(cainfo.getCAId()));                                                 
                log.error(msg, e);
                logSession.log(admin, cainfo.getCAId(), LogConstants.MODULE_CA, new java.util.Date(),null, null, LogConstants.EVENT_ERROR_CREATECRL,msg,e);
                if (e instanceof EJBException) {
                        throw (EJBException)e;
                }
                throw new EJBException(e);
        }
View Full Code Here


    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    @Override
    public boolean runDeltaCRLnewTransactionConditioned(Admin admin, CA ca, long crloverlaptime) throws CATokenOfflineException {
        boolean ret = false;
                Date currenttime = new Date();
                CAInfo cainfo = ca.getCAInfo();
                try{
                        if (cainfo.getStatus() == SecConst.CA_EXTERNAL) {
                                if (log.isDebugEnabled()) {
                                        log.debug("Not trying to generate delta CRL for external CA "+cainfo.getName());
                                }
                        } else if (cainfo.getStatus() == SecConst.CA_WAITING_CERTIFICATE_RESPONSE) {
                                if (log.isDebugEnabled()) {
                                        log.debug("Not trying to generate delta CRL for CA "+cainfo.getName() +" awaiting certificate response.");
                                }
                        } else {
                                if (cainfo instanceof X509CAInfo) {
                                        Collection<Certificate> certs = cainfo.getCertificateChain();
                                        final Certificate cacert;
                                        if (!certs.isEmpty()) {
                                                cacert = certs.iterator().next();  
                                        } else {
                                            cacert = null;
                                        }
                                        // Don't create CRLs if the CA has expired
                                        if ( (cacert != null) && (CertTools.getNotAfter(cacert).after(new Date())) ) {
                                        if(cainfo.getDeltaCRLPeriod() > 0) {
                                                if (cainfo.getStatus() == SecConst.CA_OFFLINE) {
                                                        String msg = intres.getLocalizedMessage("createcrl.caoffline", cainfo.getName(), Integer.valueOf(cainfo.getCAId()));                                                  
                                                        log.error(msg);
                                                        logSession.log(admin, cainfo.getCAId(), LogConstants.MODULE_CA, new java.util.Date(),null, null, LogConstants.EVENT_ERROR_CREATECRL, msg);
                                                } else {
                                                        if (log.isDebugEnabled()) {
                                                                log.debug("Checking to see if CA '"+cainfo.getName()+"' needs Delta CRL generation.");
                                                        }
                                                        final String certSubjectDN = CertTools.getSubjectDN(cacert);
                                                        CRLInfo deltacrlinfo = crlSession.getLastCRLInfo(admin, certSubjectDN, true);
                                                        if (log.isDebugEnabled()) {
                                                                if (deltacrlinfo == null) {
                                                                        log.debug("DeltaCrlinfo was null");
                                                                } else {
                                                                        log.debug("Read deltacrlinfo for CA: "+cainfo.getName()+", lastNumber="+deltacrlinfo.getLastCRLNumber()+", expireDate="+deltacrlinfo.getExpireDate());
                                                                }                                         
                                                        }
                                                        if((deltacrlinfo == null) || ((currenttime.getTime() + crloverlaptime) >= deltacrlinfo.getExpireDate().getTime())){
                                                                runDeltaCRL(admin, ca, -1, -1);
                                                                ret = true;
                                                        }
                                                }
                                        }
                                        } else if (cacert != null) {
                                                if (log.isDebugEnabled()) {
                                                        log.debug("Not creating delta CRL for expired CA "+cainfo.getName()+". CA subjectDN='"+CertTools.getSubjectDN(cacert)+"', expired: "+CertTools.getNotAfter(cacert));
                                                }
                                        } else {
                                                if (log.isDebugEnabled()) {
                                                        log.debug("Not creating delta CRL for CA without CA certificate: "+cainfo.getName());
                                                }
                                        }
                                }                                      
                   }
        } catch (CATokenOfflineException e) {
            throw e;           
                }catch(Exception e) {
                String msg = intres.getLocalizedMessage("createcrl.generalerror", Integer.valueOf(cainfo.getCAId()));                                                 
                log.error(msg, e);
                logSession.log(admin, cainfo.getCAId(), LogConstants.MODULE_CA, new java.util.Date(),null, null, LogConstants.EVENT_ERROR_CREATECRL,msg,e);
                if (e instanceof EJBException) {
                        throw (EJBException)e;
                }
                throw new EJBException(e);
                }
View Full Code Here

                return;
            }
            String inpath = args[1];
            Integer caid = null;
            if (args.length > 2) {
              CAInfo ca = ejb.getCAAdminSession().getCAInfo(getAdmin(), args[2]);
              if (ca != null) {
                caid = ca.getCAId();
              } else {
                getLogger().error("CA '"+args[2]+"' does not exist.");
                    return;
              }
            }
View Full Code Here

          !usernameFilter.equalsIgnoreCase ("CN") &&
          !usernameFilter.equalsIgnoreCase("FILE")) {
        throw new Exception(usernameFilter + "is not a valid option. Currently only \"DN\", \"CN\" and \"FILE\" username-source are implemented");
      }
      // Fetch CA info
      final CAInfo caInfo = getCAInfo(caName);
      final X509Certificate cacert = (X509Certificate) caInfo.getCertificateChain().iterator().next();
      final String issuer = CertTools.stringToBCDNString(cacert.getSubjectDN().toString());
      getLogger().info("CA: " + issuer);
      // Fetch End Entity Profile info
      getLogger().debug("Searching for End Entity Profile " + eeProfile);
      final int endEntityProfileId = ejb.getEndEntityProfileSession().getEndEntityProfileId(getAdmin(), eeProfile);
View Full Code Here

        }
        try {
          CryptoProviderTools.installBCProvider();
            String caname = args[1];
            ArrayList chain = new ArrayList(getCertChain(caname));
            CAInfo cainfo = getCAInfo(caname);
                                   
            getLogger().info("CA name: " + caname);
            getLogger().info("CA type: "+cainfo.getCAType());
            getLogger().info("CA ID: " + cainfo.getCAId());
            getLogger().info("CA CRL Expiration Period: " + cainfo.getCRLPeriod());
            getLogger().info("CA CRL Issue Interval: " + cainfo.getCRLIssueInterval());
            getLogger().info("CA Description: " + cainfo.getDescription());
           
            if (chain.size() < 2) {
              getLogger().info("This is a Root CA.");
            } else {
              getLogger().info("This is a subordinate CA.");
View Full Code Here

     */
    protected Collection<Certificate> getCertChain(String caname) throws Exception {
        getLogger().trace(">getCertChain()");
        Collection<Certificate> returnval = new ArrayList<Certificate>();
        try {
            CAInfo cainfo = ejb.getCAAdminSession().getCAInfo(getAdmin(), caname);
            if (cainfo != null) {
                returnval = cainfo.getCertificateChain();
            }
        } catch (Exception e) {
            getLogger().error("Error while getting certfificate chain from CA.", e);
        }
        getLogger().trace("<getCertChain()");
View Full Code Here

        }
        getLogger().trace(">createCRL()");
    }

    protected String getIssuerDN(String caname) throws Exception {
        CAInfo cainfo = ejb.getCAAdminSession().getCAInfo(getAdmin(), caname);
        return cainfo != null ? cainfo.getSubjectDN() : null;
    }
View Full Code Here

        CAInfo cainfo = ejb.getCAAdminSession().getCAInfo(getAdmin(), caname);
        return cainfo != null ? cainfo.getSubjectDN() : null;
    }

    protected CAInfo getCAInfo(String caname) throws Exception {
        CAInfo result;
        try {
            result = ejb.getCAAdminSession().getCAInfo(getAdmin(), caname);
        } catch (Exception e) {
            getLogger().debug("Error retriving CA " + caname + " info.", e);
            throw new Exception("Error retriving CA " + caname + " info.");
View Full Code Here

          CryptoProviderTools.installBCProvider();
            Collection<Integer> caids = ejb.getCaSession().getAvailableCAs(getAdmin());
            Iterator<Integer> iter = caids.iterator();
            while (iter.hasNext()) {
                int caid = ((Integer)iter.next()).intValue();
                CAInfo ca = ejb.getCAAdminSession().getCAInfo(getAdmin(),caid);
                Collection<Certificate> certs = ca.getCertificateChain();
                Iterator<Certificate> ci = certs.iterator();
                Certificate cacert = null;
                if (ci.hasNext()) {
                    cacert = (Certificate)ci.next();                 
                }
                getLogger().info("CA Name: "+ca.getName());
                getLogger().info(" Id: "+ca.getCAId());
                if (cacert != null) {
                  getLogger().info(" Issuer DN: "+CertTools.getIssuerDN(cacert));                 
                }
                getLogger().info(" Subject DN: "+ca.getSubjectDN());
                getLogger().info(" Type: "+ca.getCAType());
                getLogger().info(" Expire time: "+ca.getExpireTime());
                getLogger().info(" Signed by: "+ca.getSignedBy());
            }
        } catch (Exception e) {
            throw new ErrorAdminCommandException(e);
        }
    }
View Full Code Here

                return;
            }
            String caname = args[1];
            CryptoProviderTools.installBCProvider();
            // Get the CAs info and id
            CAInfo cainfo = ejb.getCAAdminSession().getCAInfo(getAdmin(), caname);
            if (cainfo == null) {
                getLogger().info("CA with name '" + caname + "' does not exist.");
                return;
            }
            // Publish the CAs certificate and CRL
            Collection<Certificate> cachain = cainfo.getCertificateChain();
            Iterator<Certificate> caiter = cachain.iterator();
            if (caiter.hasNext()) {
                final X509Certificate cacert = (X509Certificate) caiter.next();
                final byte[] crlbytes = ejb.getCrlSession().getLastCRL(getAdmin(), cainfo.getSubjectDN(), false);
                // Get the CRLnumber
                X509CRL crl = CertTools.getCRLfromByteArray(crlbytes);
                int crlNumber = CrlExtensions.getCrlNumber(crl).intValue();
                final Collection<Integer> capublishers = cainfo.getCRLPublishers();
                // Store cert and CRL in ca publishers.
                if (capublishers != null) {
                    String fingerprint = CertTools.getFingerprintAsString(cacert);
                    String username = ejb.getCertStoreSession().findUsernameByCertSerno(getAdmin(), cacert.getSerialNumber(), cacert.getIssuerDN().getName());
                    CertificateInfo certinfo = ejb.getCertStoreSession().getCertificateInfo(getAdmin(), fingerprint);
                    ejb.getPublisherSession().storeCertificate(getAdmin(), capublishers, cacert, username, null, cainfo.getSubjectDN(), fingerprint, certinfo
                            .getStatus(), certinfo.getType(), certinfo.getRevocationDate().getTime(), certinfo.getRevocationReason(), certinfo.getTag(),
                            certinfo.getCertificateProfileId(), certinfo.getUpdateTime().getTime(), null);
                    getLogger().info("Certificate published for " + caname);
                    if ( crlbytes!=null && crlbytes.length>0 && crlNumber>0 ) {
                        ejb.getPublisherSession().storeCRL(getAdmin(), capublishers, crlbytes, fingerprint, crlNumber, cainfo.getSubjectDN());
                        getLogger().info("CRL with number "+crlNumber+" published for " + caname);
                    } else {
                        getLogger().info("CRL not published, no CRL createed for CA?");
                    }
                } else {
                    getLogger().info("No publishers configured for the CA, no CA certificate or CRL published.");
                }
            } else {
                getLogger().info("CA does not have a certificate, no certificate or CRL published!");
            }

            // Get all users for this CA
            Collection<UserDataVO> coll = ejb.getUserAdminSession().findAllUsersByCaId(getAdmin(), cainfo.getCAId());
            Iterator<UserDataVO> iter = coll.iterator();
            while (iter.hasNext()) {
                UserDataVO data = iter.next();
                getLogger().info(
                        "User: " + data.getUsername() + ", \"" + data.getDN() + "\", \"" + data.getSubjectAltName() + "\", " + data.getEmail() + ", "
View Full Code Here

TOP

Related Classes of org.ejbca.core.model.ca.caadmin.CAInfo

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.