Source Code Cross Referenced for CertPathBuilderTest.java in  » Security » Bouncy-Castle » org » bouncycastle » jce » provider » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Security » Bouncy Castle » org.bouncycastle.jce.provider.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.jce.provider.test;
002:
003:        import java.io.ByteArrayInputStream;
004:        import java.math.BigInteger;
005:        import java.security.KeyPair;
006:        import java.security.Security;
007:        import java.security.cert.CertPath;
008:        import java.security.cert.CertPathBuilder;
009:        import java.security.cert.CertStore;
010:        import java.security.cert.CertificateFactory;
011:        import java.security.cert.CollectionCertStoreParameters;
012:        import java.security.cert.PKIXBuilderParameters;
013:        import java.security.cert.PKIXCertPathBuilderResult;
014:        import java.security.cert.TrustAnchor;
015:        import java.security.cert.X509CRL;
016:        import java.security.cert.X509CertSelector;
017:        import java.security.cert.X509Certificate;
018:        import java.util.ArrayList;
019:        import java.util.Calendar;
020:        import java.util.Collections;
021:        import java.util.Date;
022:        import java.util.HashSet;
023:        import java.util.List;
024:        import java.util.Set;
025:
026:        import org.bouncycastle.jce.provider.BouncyCastleProvider;
027:        import org.bouncycastle.util.test.SimpleTestResult;
028:        import org.bouncycastle.util.test.Test;
029:        import org.bouncycastle.util.test.TestResult;
030:
031:        public class CertPathBuilderTest implements  Test {
032:
033:            public TestResult baseTest() {
034:                try {
035:                    CertificateFactory cf = CertificateFactory.getInstance(
036:                            "X.509", "BC");
037:
038:                    // initialise CertStore
039:                    X509Certificate rootCert = (X509Certificate) cf
040:                            .generateCertificate(new ByteArrayInputStream(
041:                                    CertPathTest.rootCertBin));
042:                    X509Certificate interCert = (X509Certificate) cf
043:                            .generateCertificate(new ByteArrayInputStream(
044:                                    CertPathTest.interCertBin));
045:                    X509Certificate finalCert = (X509Certificate) cf
046:                            .generateCertificate(new ByteArrayInputStream(
047:                                    CertPathTest.finalCertBin));
048:                    X509CRL rootCrl = (X509CRL) cf
049:                            .generateCRL(new ByteArrayInputStream(
050:                                    CertPathTest.rootCrlBin));
051:                    X509CRL interCrl = (X509CRL) cf
052:                            .generateCRL(new ByteArrayInputStream(
053:                                    CertPathTest.interCrlBin));
054:                    List list = new ArrayList();
055:                    list.add(rootCert);
056:                    list.add(interCert);
057:                    list.add(finalCert);
058:                    list.add(rootCrl);
059:                    list.add(interCrl);
060:                    CollectionCertStoreParameters ccsp = new CollectionCertStoreParameters(
061:                            list);
062:                    CertStore store = CertStore.getInstance("Collection", ccsp,
063:                            "BC");
064:                    Calendar validDate = Calendar.getInstance();
065:                    validDate.set(2002, 2, 21, 2, 21, 10);
066:
067:                    //Searching for rootCert by subjectDN without CRL
068:                    Set trust = new HashSet();
069:                    trust.add(new TrustAnchor(rootCert, null));
070:
071:                    CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX",
072:                            "BC");
073:                    X509CertSelector targetConstraints = new X509CertSelector();
074:                    targetConstraints.setSubject(finalCert
075:                            .getSubjectX500Principal().getEncoded());
076:                    PKIXBuilderParameters params = new PKIXBuilderParameters(
077:                            trust, targetConstraints);
078:                    params.addCertStore(store);
079:                    params.setDate(validDate.getTime());
080:                    PKIXCertPathBuilderResult result = (PKIXCertPathBuilderResult) cpb
081:                            .build(params);
082:                    CertPath path = result.getCertPath();
083:
084:                    if (path.getCertificates().size() != 2) {
085:                        return new SimpleTestResult(false, this .getName()
086:                                + ": wrong number of certs in baseTest path");
087:                    }
088:                } catch (Exception e) {
089:                    return new SimpleTestResult(false, this .getName()
090:                            + ": exception - " + e.toString(), e);
091:                }
092:
093:                return new SimpleTestResult(true, this .getName() + ": Okay");
094:            }
095:
096:            public TestResult v0Test() {
097:                try {
098:                    // create certificates and CRLs
099:                    KeyPair rootPair = TestUtils.generateRSAKeyPair();
100:                    KeyPair interPair = TestUtils.generateRSAKeyPair();
101:                    KeyPair endPair = TestUtils.generateRSAKeyPair();
102:
103:                    X509Certificate rootCert = TestUtils
104:                            .generateRootCert(rootPair);
105:                    X509Certificate interCert = TestUtils
106:                            .generateIntermediateCert(interPair.getPublic(),
107:                                    rootPair.getPrivate(), rootCert);
108:                    X509Certificate endCert = TestUtils.generateEndEntityCert(
109:                            endPair.getPublic(), interPair.getPrivate(),
110:                            interCert);
111:
112:                    BigInteger revokedSerialNumber = BigInteger.valueOf(2);
113:                    X509CRL rootCRL = TestUtils.createCRL(rootCert, rootPair
114:                            .getPrivate(), revokedSerialNumber);
115:                    X509CRL interCRL = TestUtils.createCRL(interCert, interPair
116:                            .getPrivate(), revokedSerialNumber);
117:
118:                    // create CertStore to support path building
119:                    List list = new ArrayList();
120:
121:                    list.add(rootCert);
122:                    list.add(interCert);
123:                    list.add(endCert);
124:                    list.add(rootCRL);
125:                    list.add(interCRL);
126:
127:                    CollectionCertStoreParameters params = new CollectionCertStoreParameters(
128:                            list);
129:                    CertStore store = CertStore.getInstance("Collection",
130:                            params);
131:
132:                    // build the path
133:                    CertPathBuilder builder = CertPathBuilder.getInstance(
134:                            "PKIX", "BC");
135:                    X509CertSelector pathConstraints = new X509CertSelector();
136:
137:                    pathConstraints.setSubject(endCert
138:                            .getSubjectX500Principal().getEncoded());
139:
140:                    PKIXBuilderParameters buildParams = new PKIXBuilderParameters(
141:                            Collections.singleton(new TrustAnchor(rootCert,
142:                                    null)), pathConstraints);
143:
144:                    buildParams.addCertStore(store);
145:                    buildParams.setDate(new Date());
146:
147:                    PKIXCertPathBuilderResult result = (PKIXCertPathBuilderResult) builder
148:                            .build(buildParams);
149:                    CertPath path = result.getCertPath();
150:
151:                    if (path.getCertificates().size() != 2) {
152:                        return new SimpleTestResult(false, this .getName()
153:                                + ": wrong number of certs in v0Test path");
154:                    }
155:                } catch (Exception e) {
156:                    return new SimpleTestResult(false, this .getName()
157:                            + ": exception - " + e.toString(), e);
158:                }
159:
160:                return new SimpleTestResult(true, this .getName() + ": Okay");
161:            }
162:
163:            /* (non-Javadoc)
164:             * @see org.bouncycastle.util.test.Test#perform()
165:             */
166:            public TestResult perform() {
167:                TestResult res = baseTest();
168:                if (!res.isSuccessful()) {
169:                    return res;
170:                }
171:
172:                return v0Test();
173:            }
174:
175:            public String getName() {
176:                return "CertPathBuilder";
177:            }
178:
179:            public static void main(String[] args) {
180:                Security.addProvider(new BouncyCastleProvider());
181:
182:                Test test = new CertPathBuilderTest();
183:                TestResult result = test.perform();
184:
185:                System.out.println(result.toString());
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.