Package java.security.cert

Examples of java.security.cert.X509CRL


        // Get number of last Delta CRL
        int number = createCrlSession.getLastCRLNumber(admin, ca.getSubjectDN(), true);
        log.debug("Last CRLNumber = " + number);
        byte[] crl = createCrlSession.getLastCRL(admin, ca.getSubjectDN(), true);
        assertNotNull("Could not get CRL", crl);
        X509CRL x509crl = CertTools.getCRLfromByteArray(crl);
        BigInteger num = CrlExtensions.getCrlNumber(x509crl);
        assertEquals(number, num.intValue());
        // Create a new CRL again to see that the number increases
        crlStoreSession.runDeltaCRL(admin, ca, -1, -1);
        int number1 = createCrlSession.getLastCRLNumber(admin, ca.getSubjectDN(), true);
        assertEquals(number + 1, number1);
        byte[] crl1 = createCrlSession.getLastCRL(admin, ca.getSubjectDN(), true);
        X509CRL x509crl1 = CertTools.getCRLfromByteArray(crl1);
        BigInteger num1 = CrlExtensions.getCrlNumber(x509crl1);
        assertEquals(number + 1, num1.intValue());
        // Now create a normal CRL and a deltaCRL again. CRLNUmber should now be
        // increased by two
        crlStoreSession.run(admin, ca);
        crlStoreSession.runDeltaCRL(admin, ca, -1, -1);
        int number2 = createCrlSession.getLastCRLNumber(admin, ca.getSubjectDN(), true);
        assertEquals(number1 + 2, number2);
        byte[] crl2 = createCrlSession.getLastCRL(admin, ca.getSubjectDN(), true);
        X509CRL x509crl2 = CertTools.getCRLfromByteArray(crl2);
        BigInteger num2 = CrlExtensions.getCrlNumber(x509crl2);
        assertEquals(number1 + 2, num2.intValue());
        log.trace("<test02LastDeltaCRL()");
    }
View Full Code Here


    public void test03CheckNumberofRevokedCerts() throws Exception {
        // check revoked certificates
        log.trace(">test03CheckNumberofRevokedCerts()");

        byte[] crl = createCrlSession.getLastCRL(admin, ca.getSubjectDN(), false);
        X509CRL x509crl = CertTools.getCRLfromByteArray(crl);
        // Get number of last CRL
        Collection<RevokedCertInfo> revfp = certificateStoreSession.listRevokedCertInfo(admin, ca.getSubjectDN(), x509crl.getThisUpdate().getTime());
        log.debug("Number of revoked certificates=" + revfp.size());
        crl = createCrlSession.getLastCRL(admin, ca.getSubjectDN(), true);
        assertNotNull("Could not get CRL", crl);

        x509crl = CertTools.getCRLfromByteArray(crl);
        Set<? extends X509CRLEntry> revset = x509crl.getRevokedCertificates();
        int revsize = 0;
        // This is probably 0
        if (revset != null) {
            revsize = revset.size();
            assertEquals(revfp.size(), revsize);
        }

        // Do some revoke
        X509Certificate cert = createUserAndCert();
        certificateStoreSession.revokeCertificate(admin, cert, null, RevokedCertInfo.REVOCATION_REASON_CERTIFICATEHOLD, null);
        // Sleep 1 second so we don't issue the next CRL at the exact same time
        // as the revocation
        Thread.sleep(1000);
        // Create a new CRL again...
        crl = crlStoreSession.runDeltaCRL(admin, ca, -1, -1);
        // Check that our newly signed certificate is present in a new CRL
        // crl = storeremote.getLastCRL(admin, cadn, true);
        assertNotNull("Could not get CRL", crl);
        x509crl = CertTools.getCRLfromByteArray(crl);
        revset = x509crl.getRevokedCertificates();
        assertNotNull("revset can not be null", revset);
        assertEquals(revsize + 1, revset.size());

        log.trace("<test03CheckNumberofRevokedCerts()");
    }
View Full Code Here

        // Create a new CRL again...
        crlStoreSession.run(admin, ca);
        // Check that our newly signed certificate is not present in a new CRL
        byte[] crl = createCrlSession.getLastCRL(admin, ca.getSubjectDN(), false);
        assertNotNull("Could not get CRL", crl);
        X509CRL x509crl = CertTools.getCRLfromByteArray(crl);
        Set<? extends X509CRLEntry> revset = x509crl.getRevokedCertificates();
        if (revset != null) {
            Iterator<? extends X509CRLEntry> iter = revset.iterator();
            while (iter.hasNext()) {
                X509CRLEntry ce = iter.next();
                assertTrue(ce.getSerialNumber().compareTo(cert.getSerialNumber()) != 0);
            }
        } // If no revoked certificates exist at all, this test passed...

        certificateStoreSession.revokeCertificate(admin, cert, null, RevokedCertInfo.REVOCATION_REASON_CERTIFICATEHOLD, null);
        // Sleep 1 second so we don't issue the next CRL at the exact same time
        // as the revocation
        Thread.sleep(1000);
        // Create a new delta CRL again...
        crl = crlStoreSession.runDeltaCRL(admin, ca, -1, -1);
        // Check that our newly signed certificate IS present in a new Delta CRL
        // crl = storeremote.getLastCRL(admin, cadn, true);
        assertNotNull("Could not get CRL", crl);
        x509crl = CertTools.getCRLfromByteArray(crl);
        revset = x509crl.getRevokedCertificates();
        assertNotNull("revset can not be null", revset);
        Iterator<? extends X509CRLEntry> iter = revset.iterator();
        boolean found = false;
        while (iter.hasNext()) {
            X509CRLEntry ce = iter.next();
            if (ce.getSerialNumber().compareTo(cert.getSerialNumber()) == 0) {
                found = true;
                // TODO: verify the reason code
            }
        }
        assertTrue(found);

        // Unrevoke the certificate that we just revoked
        certificateStoreSession.revokeCertificate(admin, cert, null, RevokedCertInfo.NOT_REVOKED, null);
        // Create a new Delta CRL again...
        crlStoreSession.runDeltaCRL(admin, ca, -1, -1);
        // Check that our newly signed certificate IS NOT present in the new
        // CRL.
        crl = createCrlSession.getLastCRL(admin, ca.getSubjectDN(), true);
        assertNotNull("Could not get CRL", crl);
        x509crl = CertTools.getCRLfromByteArray(crl);
        revset = x509crl.getRevokedCertificates();
        if (revset != null) {
            iter = revset.iterator();
            found = false;
            while (iter.hasNext()) {
                X509CRLEntry ce = (X509CRLEntry) iter.next();
                if (ce.getSerialNumber().compareTo(cert.getSerialNumber()) == 0) {
                    found = true;
                }
            }
            assertFalse(found);
        } // If no revoked certificates exist at all, this test passed...

        // Check that when we revoke a certificate it will be present on the
        // delta CRL
        // When we create a new full CRL it will be present there, and not on
        // the next delta CRL
        certificateStoreSession.revokeCertificate(admin, cert, null, RevokedCertInfo.REVOCATION_REASON_CACOMPROMISE, null);
        // Sleep 1 second so we don't issue the next CRL at the exact same time
        // as the revocation
        Thread.sleep(1000);
        // Create a new delta CRL again...
        crl = crlStoreSession.runDeltaCRL(admin, ca, -1, -1);
        // Check that our newly signed certificate IS present in a new Delta CRL
        // crl = storeremote.getLastCRL(admin, cadn, true);
        assertNotNull("Could not get CRL", crl);
        x509crl = CertTools.getCRLfromByteArray(crl);
        revset = x509crl.getRevokedCertificates();
        assertNotNull(revset);
        iter = revset.iterator();
        found = false;
        // log.debug(x509crl.getThisUpdate());
        while (iter.hasNext()) {
            X509CRLEntry ce = (X509CRLEntry) iter.next();
            // log.debug(ce);
            if (ce.getSerialNumber().compareTo(cert.getSerialNumber()) == 0) {
                found = true;
                // TODO: verify the reason code
            }
        }
        assertTrue(found);

        // Sleep 1 second so we don't issue the next CRL at the exact same time
        // as the revocation
        Thread.sleep(1000);
        // Create a new Full CRL
        crlStoreSession.run(admin, ca);
        // Check that our newly signed certificate IS present in a new Full CRL
        crl = createCrlSession.getLastCRL(admin, ca.getSubjectDN(), false);
        assertNotNull("Could not get CRL", crl);
        x509crl = CertTools.getCRLfromByteArray(crl);
        revset = x509crl.getRevokedCertificates();
        assertNotNull(revset);
        iter = revset.iterator();
        found = false;
        // log.debug(x509crl.getThisUpdate());
        // log.debug(x509crl.getThisUpdate().getTime());
        while (iter.hasNext()) {
            X509CRLEntry ce = (X509CRLEntry) iter.next();
            // log.debug(ce);
            if (ce.getSerialNumber().compareTo(cert.getSerialNumber()) == 0) {
                found = true;
                // TODO: verify the reason code
            }
        }
        assertTrue(found);

        // Sleep 1 second so we don't issue the next CRL at the exact same time
        // as the revocation
        Thread.sleep(1000);
        // Create a new Delta CRL again...
        crlStoreSession.runDeltaCRL(admin, ca, -1, -1);
        // Check that our newly signed certificate IS NOT present in the new
        // Delta CRL.
        crl = createCrlSession.getLastCRL(admin, ca.getSubjectDN(), true);
        assertNotNull("Could not get CRL", crl);
        x509crl = CertTools.getCRLfromByteArray(crl);
        revset = x509crl.getRevokedCertificates();
        // log.debug(x509crl.getThisUpdate());
        if (revset != null) {
            iter = revset.iterator();
            found = false;
            while (iter.hasNext()) {
View Full Code Here

        }
        if (command.equalsIgnoreCase(COMMAND_CRL) && issuerdn != null) {
            try {
                Admin admin = ejbcawebbean.getAdminObject();
                byte[] crl = crlSession.getLastCRL(admin, issuerdn, false);
                X509CRL x509crl = CertTools.getCRLfromByteArray(crl);
                String dn = CertTools.getIssuerDN(x509crl);
            String basename = getBaseFileName(dn);
                String filename = basename+".crl";
                // We must remove cache headers for IE
                ServletUtils.removeCacheHeaders(res);
                res.setHeader("Content-disposition", "attachment; filename=" +  filename);
                res.setContentType("application/pkix-crl");
                res.setContentLength(crl.length);
                res.getOutputStream().write(crl);
                String iMsg = intres.getLocalizedMessage("certreq.sentlatestcrl", remoteAddr);
                log.info(iMsg);
            } catch (Exception e) {
                String errMsg = intres.getLocalizedMessage("certreq.errorsendcrl", remoteAddr, e.getMessage());
                log.error(errMsg, e);
                res.sendError(HttpServletResponse.SC_NOT_FOUND, errMsg);
                return;
            }
        }
        if (command.equalsIgnoreCase(COMMAND_DELTACRL) && issuerdn != null) {
          try {
            Admin admin = ejbcawebbean.getAdminObject();
            byte[] crl = crlSession.getLastCRL(admin, issuerdn, true);
            X509CRL x509crl = CertTools.getCRLfromByteArray(crl);
            String dn = CertTools.getIssuerDN(x509crl);
            String basename = getBaseFileName(dn);
            String filename = basename+"_delta.crl";
            // We must remove cache headers for IE
            ServletUtils.removeCacheHeaders(res);
View Full Code Here

                  StressTest.this.performanceTest.getLog().error("CRLS should be 1: "+crls.size());
                  return false;
                }
                final Iterator<?> it = crls.iterator();
                // CRL is first (and only)
                final X509CRL retCrl = (X509CRL)it.next();
                //System.out.println("Got CRL with DN: "+ retCrl.getIssuerDN().getName());
                //                        try {
                //                            FileOutputStream fos = new FileOutputStream("sceptest.der");
                //                            fos.write(retCrl.getEncoded());
                //                            fos.close();
                //                        } catch (Exception e) {}
                // check the returned CRL
                if ( !StringUtils.equals(this.sessionData.certchain[1].getSubjectDN().getName(), retCrl.getIssuerDN().getName()) ) {
                  StressTest.this.performanceTest.getLog().error("CRL issuerDN should be "+this.sessionData.certchain[1].getSubjectDN().getName()+" but was: "+retCrl.getIssuerDN().getName());
                  return false;
                }
                retCrl.verify(this.sessionData.certchain[1].getPublicKey());
                return true;
              }
              // We got a reply with a requested certificate
              final Collection<?> certs = certstore.getCertificates(null);
              //System.out.println("Got certificate reply with certchain of length: "+certs.size());
View Full Code Here

                // We got a reply with a requested CRL
                final Collection<X509CRL> crls = (Collection<X509CRL>) certstore.getCRLs(null);
                assertEquals(crls.size(), 1);
                final Iterator<X509CRL> it = crls.iterator();
                // CRL is first (and only)
                final X509CRL retCrl = it.next();
                log.info("Got CRL with DN: " + retCrl.getIssuerDN().getName());

                // check the returned CRL
                assertEquals(cacert.getSubjectDN().getName(), retCrl.getIssuerDN().getName());
                retCrl.verify(cacert.getPublicKey());
            } else {
                // We got a reply with a requested certificate
                final Collection<X509Certificate> certs = (Collection<X509Certificate>) certstore.getCertificates(null);
                // EJBCA returns the issued cert and the CA cert (cisco vpn
                // client requires that the ca cert is included)
View Full Code Here

            if (crlRep) {
                // We got a reply with a requested CRL
                Collection crls = certstore.getCRLs(null);
                assertEquals(crls.size(), 1);
                it = crls.iterator();
                X509CRL retCrl = null;
                // CRL is first (and only)
                retCrl = (X509CRL)it.next();
                log.info("Got CRL with DN: "+ retCrl.getIssuerDN().getName());
//                try {
//                    FileOutputStream fos = new FileOutputStream("sceptest.der");
//                    fos.write(retCrl.getEncoded());
//                    fos.close();
//                } catch (Exception e) {}
                // check the returned CRL
                assertEquals(cacert.getSubjectDN().getName(), retCrl.getIssuerDN().getName());
                retCrl.verify(cacert.getPublicKey());
            } else {
                // We got a reply with a requested certificate
                Collection certs = certstore.getCertificates(null);
                log.info("Got certificate reply with certchain of length: "+certs.size());
                // EJBCA returns the issued cert and the CA cert (cisco vpn client requires that the ca cert is included)
View Full Code Here

        try {
            crls = new ArrayList<CRL>();
            for (int k = 0; k < seq.size(); ++k) {
                ByteArrayInputStream ar = new ByteArrayInputStream(seq.getObjectAt(k).getDERObject().getDEREncoded());
                CertificateFactory cf = CertificateFactory.getInstance("X.509");
                X509CRL crl = (X509CRL)cf.generateCRL(ar);
                crls.add(crl);
            }
        }
        catch (Exception ex) {
            // ignore
View Full Code Here

    final String dn;
    final String crldn;
    final boolean isDeltaCRL;
    try {
      // Extract the users DN from the crl. Use the least number of encodings...
      final X509CRL crl = CertTools.getCRLfromByteArray(incrl);
      crldn = CertTools.stringToBCDNString(crl.getIssuerDN().toString());
      // Is it a delta CRL?
      if (crl.getExtensionValue(X509Extensions.DeltaCRLIndicator.getId()) != null) {
        isDeltaCRL = true;
      } else {
        isDeltaCRL = false;
      }
      // Construct the DN used for the LDAP object entry
View Full Code Here

   * Method to lazy create the fake CRL.
   */
  protected byte[] getFakeCRL(){
    byte[] fakecrl = null;
    try {
      X509CRL crl = CertTools.getCRLfromByteArray(fakecrlbytes);
      fakecrl = crl.getEncoded();
    } catch (CRLException e) {}
    return fakecrl;
  }
View Full Code Here

TOP

Related Classes of java.security.cert.X509CRL

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.