forked from bcgit/bc-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added cap on size of subject alt name extension reviewer will accept.
- Loading branch information
Showing
3 changed files
with
131 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
pkix/src/test/java/org/bouncycastle/pkix/test/CheckNameConstraintsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package org.bouncycastle.pkix.test; | ||
|
||
import java.security.Security; | ||
import java.security.cert.CertPath; | ||
import java.security.cert.CertPathBuilder; | ||
import java.security.cert.CertPathValidator; | ||
import java.security.cert.CertStore; | ||
import java.security.cert.CertificateFactory; | ||
import java.security.cert.CollectionCertStoreParameters; | ||
import java.security.cert.PKIXBuilderParameters; | ||
import java.security.cert.PKIXCertPathBuilderResult; | ||
import java.security.cert.PKIXParameters; | ||
import java.security.cert.TrustAnchor; | ||
import java.security.cert.X509CertSelector; | ||
import java.security.cert.X509Certificate; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Date; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import junit.framework.TestCase; | ||
import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
import org.bouncycastle.pkix.jcajce.PKIXCertPathReviewer; | ||
import org.bouncycastle.test.TestResourceFinder; | ||
|
||
public class CheckNameConstraintsTest | ||
extends TestCase | ||
{ | ||
public void testPKIXCertPathReviewer() | ||
throws Exception | ||
{ | ||
Security.addProvider(new BouncyCastleProvider()); | ||
|
||
CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC"); | ||
|
||
X509Certificate root = (X509Certificate) cf.generateCertificate(TestResourceFinder.findTestResource("pkix", "mal-root.crt")); | ||
X509Certificate ca1 = (X509Certificate) cf.generateCertificate(TestResourceFinder.findTestResource("pkix", "mal-ca1.crt")); | ||
X509Certificate ca2 = (X509Certificate) cf.generateCertificate(TestResourceFinder.findTestResource("pkix", "mal-ca2.crt")); | ||
X509Certificate leaf = (X509Certificate) cf.generateCertificate(TestResourceFinder.findTestResource("pkix", "mal-leaf.crt")); | ||
|
||
List certchain = new ArrayList(); | ||
certchain.add(root); | ||
certchain.add(ca1); | ||
certchain.add(ca2); | ||
certchain.add(leaf); | ||
|
||
CertPath cp = cf.generateCertPath(certchain); | ||
|
||
Set trust = new HashSet(); | ||
trust.add(new TrustAnchor(root, null)); | ||
PKIXParameters param = new PKIXParameters(trust); | ||
|
||
PKIXCertPathReviewer certPathReviewer = new PKIXCertPathReviewer(); | ||
certPathReviewer.init(cp, param); | ||
|
||
assertFalse(certPathReviewer.isValidCertPath()); // hit | ||
} | ||
|
||
public void testPKIXCertPathBuilder() | ||
throws Exception | ||
{ | ||
Security.addProvider(new BouncyCastleProvider()); | ||
|
||
CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC"); | ||
X509Certificate rootCert = (X509Certificate) cf.generateCertificate(TestResourceFinder.findTestResource("pkix", "mal-root.crt")); | ||
X509Certificate endCert = (X509Certificate) cf.generateCertificate(TestResourceFinder.findTestResource("pkix", "mal-ca1.crt")); | ||
|
||
// create CertStore to support path building | ||
List list = new ArrayList(); | ||
list.add(endCert); | ||
|
||
CollectionCertStoreParameters params = new CollectionCertStoreParameters(list); | ||
CertStore store = CertStore.getInstance("Collection", params, "BC"); | ||
|
||
// build the path | ||
CertPathBuilder builder = CertPathBuilder.getInstance("PKIX", "BC"); | ||
X509CertSelector pathConstraints = new X509CertSelector(); | ||
|
||
pathConstraints.setCertificate(endCert); | ||
|
||
PKIXBuilderParameters buildParams = new PKIXBuilderParameters(Collections.singleton(new TrustAnchor(rootCert, null)), pathConstraints); | ||
|
||
buildParams.addCertStore(store); | ||
buildParams.setDate(new Date()); | ||
buildParams.setRevocationEnabled(false); | ||
|
||
PKIXCertPathBuilderResult result = (PKIXCertPathBuilderResult)builder.build(buildParams); | ||
CertPath path = result.getCertPath(); | ||
|
||
if (path.getCertificates().size() != 1) | ||
{ | ||
fail("wrong number of certs in testPKIXCertPathBuilder path"); | ||
} | ||
} | ||
|
||
public void testPKIXCertPathValidator() | ||
throws Exception | ||
{ | ||
Security.addProvider(new BouncyCastleProvider()); | ||
|
||
CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC"); | ||
|
||
X509Certificate rootCert = (X509Certificate) cf.generateCertificate(TestResourceFinder.findTestResource("pkix", "mal-root.crt")); | ||
X509Certificate endCert = (X509Certificate) cf.generateCertificate(TestResourceFinder.findTestResource("pkix", "mal-ca1.crt")); | ||
|
||
List list = new ArrayList(); | ||
list.add(endCert); | ||
|
||
CertPath certPath = cf.generateCertPath(list); | ||
|
||
Set trust = new HashSet(); | ||
trust.add(new TrustAnchor(rootCert, null)); | ||
|
||
CertPathValidator cpv = CertPathValidator.getInstance("PKIX", "BC"); | ||
PKIXParameters param = new PKIXParameters(trust); | ||
param.setRevocationEnabled(false); | ||
|
||
cpv.validate(certPath, param); | ||
} | ||
} |