Source Code Cross Referenced for CertStoreTest.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 org.bouncycastle.jce.provider.BouncyCastleProvider;
004:        import org.bouncycastle.util.test.SimpleTest;
005:
006:        import java.io.ByteArrayInputStream;
007:        import java.security.Security;
008:        import java.security.cert.CertStore;
009:        import java.security.cert.CertificateFactory;
010:        import java.security.cert.CollectionCertStoreParameters;
011:        import java.security.cert.X509CRL;
012:        import java.security.cert.X509CRLSelector;
013:        import java.security.cert.X509CertSelector;
014:        import java.security.cert.X509Certificate;
015:        import java.util.ArrayList;
016:        import java.util.Collection;
017:        import java.util.Iterator;
018:        import java.util.List;
019:
020:        public class CertStoreTest extends SimpleTest {
021:
022:            public void performTest() throws Exception {
023:                basicTest();
024:                orderTest();
025:            }
026:
027:            private void basicTest() throws Exception {
028:                CertificateFactory cf = CertificateFactory.getInstance("X.509",
029:                        "BC");
030:
031:                X509Certificate rootCert = (X509Certificate) cf
032:                        .generateCertificate(new ByteArrayInputStream(
033:                                CertPathTest.rootCertBin));
034:                X509Certificate interCert = (X509Certificate) cf
035:                        .generateCertificate(new ByteArrayInputStream(
036:                                CertPathTest.interCertBin));
037:                X509Certificate finalCert = (X509Certificate) cf
038:                        .generateCertificate(new ByteArrayInputStream(
039:                                CertPathTest.finalCertBin));
040:                X509CRL rootCrl = (X509CRL) cf
041:                        .generateCRL(new ByteArrayInputStream(
042:                                CertPathTest.rootCrlBin));
043:                X509CRL interCrl = (X509CRL) cf
044:                        .generateCRL(new ByteArrayInputStream(
045:                                CertPathTest.interCrlBin));
046:
047:                // Testing CollectionCertStore generation from List
048:                List list = new ArrayList();
049:                list.add(rootCert);
050:                list.add(interCert);
051:                list.add(finalCert);
052:                list.add(rootCrl);
053:                list.add(interCrl);
054:                CollectionCertStoreParameters ccsp = new CollectionCertStoreParameters(
055:                        list);
056:                CertStore store = CertStore.getInstance("Collection", ccsp,
057:                        "BC");
058:
059:                // Searching for rootCert by subjectDN
060:                X509CertSelector targetConstraints = new X509CertSelector();
061:                targetConstraints.setSubject(rootCert.getSubjectX500Principal()
062:                        .getName());
063:                Collection certs = store.getCertificates(targetConstraints);
064:                if (certs.size() != 1 || !certs.contains(rootCert)) {
065:                    fail("rootCert not found by subjectDN");
066:                }
067:
068:                // Searching for rootCert by subjectDN encoded as byte
069:                targetConstraints = new X509CertSelector();
070:                targetConstraints.setSubject(rootCert.getSubjectX500Principal()
071:                        .getEncoded());
072:                certs = store.getCertificates(targetConstraints);
073:                if (certs.size() != 1 || !certs.contains(rootCert)) {
074:                    fail("rootCert not found by encoded subjectDN");
075:                }
076:
077:                // Searching for rootCert by public key encoded as byte
078:                targetConstraints = new X509CertSelector();
079:                targetConstraints.setSubjectPublicKey(rootCert.getPublicKey()
080:                        .getEncoded());
081:                certs = store.getCertificates(targetConstraints);
082:                if (certs.size() != 1 || !certs.contains(rootCert)) {
083:                    fail("rootCert not found by encoded public key");
084:                }
085:
086:                // Searching for interCert by issuerDN
087:                targetConstraints = new X509CertSelector();
088:                targetConstraints.setIssuer(rootCert.getSubjectX500Principal()
089:                        .getEncoded());
090:                certs = store.getCertificates(targetConstraints);
091:                if (certs.size() != 2) {
092:                    fail("did not found 2 certs");
093:                }
094:                if (!certs.contains(rootCert)) {
095:                    fail("rootCert not found");
096:                }
097:                if (!certs.contains(interCert)) {
098:                    fail("interCert not found");
099:                }
100:
101:                // Searching for rootCrl by issuerDN
102:                X509CRLSelector targetConstraintsCRL = new X509CRLSelector();
103:                targetConstraintsCRL.addIssuerName(rootCrl
104:                        .getIssuerX500Principal().getEncoded());
105:                Collection crls = store.getCRLs(targetConstraintsCRL);
106:                if (crls.size() != 1 || !crls.contains(rootCrl)) {
107:                    fail("rootCrl not found");
108:                }
109:            }
110:
111:            private void orderTest() throws Exception {
112:                CertificateFactory cf = CertificateFactory.getInstance("X.509",
113:                        "BC");
114:
115:                X509Certificate rootCert = (X509Certificate) cf
116:                        .generateCertificate(new ByteArrayInputStream(
117:                                CertPathTest.rootCertBin));
118:                X509Certificate interCert = (X509Certificate) cf
119:                        .generateCertificate(new ByteArrayInputStream(
120:                                CertPathTest.interCertBin));
121:                X509Certificate finalCert = (X509Certificate) cf
122:                        .generateCertificate(new ByteArrayInputStream(
123:                                CertPathTest.finalCertBin));
124:
125:                List list = new ArrayList();
126:                list.add(rootCert);
127:                list.add(interCert);
128:                list.add(finalCert);
129:                CollectionCertStoreParameters ccsp = new CollectionCertStoreParameters(
130:                        list);
131:                CertStore store = CertStore.getInstance("Collection", ccsp,
132:                        "BC");
133:
134:                Iterator certs = store.getCertificates(null).iterator();
135:
136:                if (!certs.next().equals(rootCert)) {
137:                    fail("root ordering wrong");
138:                }
139:                if (!certs.next().equals(interCert)) {
140:                    fail("mid ordering wrong");
141:                }
142:                if (!certs.next().equals(finalCert)) {
143:                    fail("final ordering wrong");
144:                }
145:
146:                list = new ArrayList();
147:                list.add(finalCert);
148:                list.add(interCert);
149:                list.add(rootCert);
150:                ccsp = new CollectionCertStoreParameters(list);
151:                store = CertStore.getInstance("Collection", ccsp, "BC");
152:
153:                certs = store.getCertificates(null).iterator();
154:
155:                if (!certs.next().equals(finalCert)) {
156:                    fail("reverse final ordering wrong");
157:                }
158:                if (!certs.next().equals(interCert)) {
159:                    fail("reverse mid ordering wrong");
160:                }
161:                if (!certs.next().equals(rootCert)) {
162:                    fail("reverse root ordering wrong");
163:                }
164:
165:                X509CRL rootCrl = (X509CRL) cf
166:                        .generateCRL(new ByteArrayInputStream(
167:                                CertPathTest.rootCrlBin));
168:                X509CRL interCrl = (X509CRL) cf
169:                        .generateCRL(new ByteArrayInputStream(
170:                                CertPathTest.interCrlBin));
171:
172:                list = new ArrayList();
173:                list.add(finalCert);
174:                list.add(rootCrl);
175:                list.add(interCrl);
176:
177:                ccsp = new CollectionCertStoreParameters(list);
178:                store = CertStore.getInstance("Collection", ccsp, "BC");
179:
180:                Iterator crls = store.getCRLs(null).iterator();
181:
182:                if (!crls.next().equals(rootCrl)) {
183:                    fail("root crl ordering wrong");
184:                }
185:                if (!crls.next().equals(interCrl)) {
186:                    fail("mid crl ordering wrong");
187:                }
188:
189:                list = new ArrayList();
190:                list.add(finalCert);
191:                list.add(interCrl);
192:                list.add(rootCrl);
193:                ccsp = new CollectionCertStoreParameters(list);
194:                store = CertStore.getInstance("Collection", ccsp, "BC");
195:
196:                crls = store.getCRLs(null).iterator();
197:
198:                if (!crls.next().equals(interCrl)) {
199:                    fail("reverse mid crl ordering wrong");
200:                }
201:                if (!crls.next().equals(rootCrl)) {
202:                    fail("reverse root crl ordering wrong");
203:                }
204:            }
205:
206:            public String getName() {
207:                return "CertStore";
208:            }
209:
210:            public static void main(String[] args) {
211:                Security.addProvider(new BouncyCastleProvider());
212:
213:                runTest(new CertStoreTest());
214:            }
215:
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.