Package java.security.cert

Examples of java.security.cert.CertStore


        // Verify that the response is of the right type
        assertTrue(pkcs7Response.getResponseType().equals(CertificateHelper.RESPONSETYPE_PKCS7));
        // Verify that the PKCS#7 response contains a certificate
        CMSSignedData cmsSignedData = new CMSSignedData(CertificateHelper.getPKCS7(pkcs7Response.getData()));
        assertNotNull(cmsSignedData);
        CertStore certStore = cmsSignedData.getCertificatesAndCRLs("Collection", "BC");
        assertTrue(certStore.getCertificates(null).size() == 1);
        return null;
    }
View Full Code Here


                .pkcs10Request(CA1_WSTESTUSER1, "foo123", new String(Base64.encode(pkcs10.getEncoded())), null, CertificateHelper.RESPONSETYPE_PKCS7);
        assertTrue(certenv.getResponseType().equals(CertificateHelper.RESPONSETYPE_PKCS7));
        CMSSignedData cmsSignedData = new CMSSignedData(CertificateHelper.getPKCS7(certenv.getData()));
        assertTrue(cmsSignedData != null);

        CertStore certStore = cmsSignedData.getCertificatesAndCRLs("Collection", "BC");
        assertTrue(certStore.getCertificates(null).size() == 1);

    }
View Full Code Here

        Iterator siter = col.iterator();
        SignerInformation signerInfo = (SignerInformation)siter.next();
        SignerId sinfo = signerInfo.getSID();
        // Check that the signer is the expected CA
        assertEquals(CertTools.stringToBCDNString(firstCertificate.getIssuerDN().getName()), CertTools.stringToBCDNString(sinfo.getIssuerAsString()));
        CertStore certstore = s.getCertificatesAndCRLs("Collection","BC");
        Collection certs = certstore.getCertificates(null);
        assertEquals(certs.size(), 2);                 
        Iterator it = certs.iterator();
        boolean found = false;
        while (it.hasNext()) {
            X509Certificate retcert = (X509Certificate)it.next();
View Full Code Here

        Iterator siter = col.iterator();
        SignerInformation signerInfo = (SignerInformation)siter.next();
        SignerId sinfo = signerInfo.getSID();
        // Check that the signer is the expected CA
        assertEquals(CertTools.stringToBCDNString(firstCertificate.getIssuerDN().getName()), CertTools.stringToBCDNString(sinfo.getIssuerAsString()));
        CertStore certstore = s.getCertificatesAndCRLs("Collection","BC");
        Collection certs = certstore.getCertificates(null);
        assertEquals(certs.size(), 2);                 
        Iterator it = certs.iterator();
        boolean found = false;
        while (it.hasNext()) {
            X509Certificate retcert = (X509Certificate)it.next();
View Full Code Here

    assertFalse("AutoEnrollment has to be enabled for this test to work.", response.contains("Not allowed."));
    response = response.replaceFirst("-----BEGIN PKCS7-----", "").replaceFirst("-----END PKCS7-----", "");
    byte[] responseData = Base64.decode(response.getBytes());
    X509Certificate returnCertificate= null;
    CMSSignedData p7b = new CMSSignedData(responseData);
    CertStore certStore = p7b.getCertificatesAndCRLs("Collection", "BC");
    SignerInformationStore  signers = p7b.getSignerInfos();
    Iterator<SignerInformation> iter = signers.getSigners().iterator();
    while (iter.hasNext())
    {
      SignerInformation signer = iter.next();
      X509Certificate caCert = (X509Certificate) certStore.getCertificates(signer.getSID()).iterator().next();
      Iterator<? extends Certificate> iter2 = certStore.getCertificates(null).iterator();
      if (iter2.hasNext()) {
        X509Certificate cert = (X509Certificate)iter2.next();
        if (!caCert.getSubjectDN().getName().equals(cert.getSubjectDN().getName())) {
          returnCertificate = cert;
        }
View Full Code Here

  public static byte[] signData(PrivateKey signKey, X509Certificate signCert, byte[] data){
    byte[] retdata = null;
    try{
          ArrayList certList = new ArrayList();
          certList.add(signCert);
          CertStore certs = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certList), provider);         
      CMSSignedDataGenerator    gen = new CMSSignedDataGenerator();
      gen.addCertificatesAndCRLs(certs);
      gen.addSigner(signKey, signCert, signAlg);       
      CMSSignedData           signedData = gen.generate(new CMSProcessableByteArray(data), true, provider);
      retdata = signedData.getEncoded();
View Full Code Here

       
        try{
          // First verify the signature
          CMSSignedData     sp = new CMSSignedData(signedData);                                 
         
          CertStore               certs = sp.getCertificatesAndCRLs("Collection", "BC");
          SignerInformationStore  signers = sp.getSignerInfos();
         
          ByteArrayOutputStream baos = new ByteArrayOutputStream();         
          ((CMSProcessableByteArray) sp.getSignedContent()).write(baos);
          content = baos.toByteArray();
          baos.close();
         
          Collection              c = signers.getSigners();
          Iterator                it = c.iterator();
         
          while (it.hasNext())
          {
            SignerInformation   signer = (SignerInformation)it.next();
            Collection          certCollection = certs.getCertificates(signer.getSID());
           
            Iterator        certIt = certCollection.iterator();
            usercert = (X509Certificate)certIt.next();  
           
            boolean validalg = signer.getDigestAlgOID().equals(signAlg);
           
           
            verifies = validalg && signer.verify(usercert.getPublicKey(), "BC");
           
          }
         
          // Second validate the certificate          
          X509Certificate rootCert = null;
          Iterator iter = cACertChain.iterator();
          while(iter.hasNext()){
            X509Certificate cert = (X509Certificate) iter.next();
            if(cert.getIssuerDN().equals(cert.getSubjectDN())){
              rootCert = cert;
              break;
            }
          }
         
          if(rootCert == null){
            throw new CertPathValidatorException("Error Root CA cert not found in cACertChain");
          }
         
          List list = new ArrayList();
          list.add(usercert);
          list.add(cACertChain);
          if(trustedCRLs != null){
            list.add(trustedCRLs);
          }
         
          CollectionCertStoreParameters ccsp = new CollectionCertStoreParameters(list);
          CertStore store = CertStore.getInstance("Collection", ccsp);
         
          //validating path
          List certchain = new ArrayList();
          certchain.addAll(cACertChain);
          certchain.add(usercert);
View Full Code Here

                if ( !StringUtils.equals(con.getContentType(), mimetype) ) {
                    StressTest.this.performanceTest.getLog().error("Content type not "+mimetype+": "+con.getContentType());
                    return false;
                }
                final CMSSignedData s = new CMSSignedData(con.getInputStream());
                final CertStore certstore = s.getCertificatesAndCRLs("Collection","BC");
                final Collection<?> certs = certstore.getCertificates(null);
                // Length two if the Scep RA server is signed directly by a Root CA
                // Length three if the Scep RA server is signed by a CA which is signed by a Root CA
                final Iterator<?> it = certs.iterator();
                if ( this.sessionData.certchain!=null && this.sessionData.certchain.length!=certs.size() ) {
                    StressTest.this.performanceTest.getLog().error("Length of received certificate chain "+certs.size()+" but should be "+this.sessionData.certchain.length);
View Full Code Here

              }
              final byte decBytes[] = recipient.getContent(StressTest.this.keyPair.getPrivate(), "BC");
              // This is yet another CMS signed data
              final CMSSignedData sd = new CMSSignedData(decBytes);
              // Get certificates from the signed data
              final CertStore certstore = sd.getCertificatesAndCRLs("Collection","BC");
              if (crlRep) {
                // We got a reply with a requested CRL
                final Collection<?> crls = certstore.getCRLs(null);
                if ( crls.size() != 1 ) {
                  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());
              // EJBCA returns the issued cert and the CA cert (cisco vpn client requires that the ca cert is included)
              final X509Certificate usercert;
              final X509Certificate cacert;
              if (noca) {
View Full Code Here

            // within the CMS signed data
            final CMSProcessable sp = s.getSignedContent();
            final byte[] content = (byte[]) sp.getContent();
            final CMSEnvelopedData ed = new CMSEnvelopedData(content);
            final RecipientInformationStore recipients = ed.getRecipientInfos();
            CertStore certstore;
            {
                Collection<RecipientInformation> c = recipients.getRecipients();
                assertEquals(c.size(), 1);
                Iterator<RecipientInformation> it = c.iterator();
                byte[] decBytes = null;
                RecipientInformation recipient = it.next();
                decBytes = recipient.getContent(key1.getPrivate(), "BC");
                // This is yet another CMS signed data
                CMSSignedData sd = new CMSSignedData(decBytes);
                // Get certificates from the signed data
                certstore = sd.getCertificatesAndCRLs("Collection", "BC");
            }
            if (crlRep) {
                // 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)
                if (noca) {
                    assertEquals(certs.size(), 1);
                } else {
View Full Code Here

TOP

Related Classes of java.security.cert.CertStore

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.