Source Code Cross Referenced for X500PrincipalTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » security » auth » x500 » 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 » Apache Harmony Java SE » javax package » javax.security.auth.x500 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:
0018:        /**
0019:         * @author Alexander V. Esin
0020:         * @version $Revision$
0021:         */package javax.security.auth.x500;
0022:
0023:        import java.io.ByteArrayInputStream;
0024:        import java.io.InputStream;
0025:        import java.util.ArrayList;
0026:        import java.util.Arrays;
0027:        import java.util.Locale;
0028:
0029:        import junit.framework.TestCase;
0030:        import tests.support.resource.Support_Resources;
0031:
0032:        /**
0033:         * Tests X500Principal class
0034:         * 
0035:         * Distinguished name(DN) strings follows
0036:         * BNF syntax specified in RFC 2253 and RFC 1779
0037:         *
0038:         * @see http://www.ietf.org/rfc/rfc2253.txt
0039:         * @see http://www.ietf.org/rfc/rfc1779.txt
0040:         * @see http://asn1.elibel.tm.fr/en/standards/index.htm
0041:         */
0042:
0043:        public class X500PrincipalTest extends TestCase {
0044:
0045:            private boolean testing = false;
0046:
0047:            public void testStreamPosition() throws Exception {
0048:                //this encoding is read from the file
0049:                /*byte [] mess = {0x30, 0x30, 
0050:                 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41,
0051:                 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 
0052:                 1, 2, 3//extra bytes
0053:                 };
0054:                 */
0055:
0056:                InputStream is = Support_Resources
0057:                        .getResourceStream("X500PrincipalTest.0.dat");
0058:                X500Principal principal = new X500Principal(is);
0059:                String s = principal.toString();
0060:                assertEquals("CN=A, CN=B, CN=A, CN=B", s);
0061:                byte[] restBytes = new byte[] { 0, 0, 0 };
0062:                is.read(restBytes);
0063:                assertEquals(restBytes[0], 1);
0064:                assertEquals(restBytes[1], 2);
0065:                assertEquals(restBytes[2], 3);
0066:                is.close();
0067:            }
0068:
0069:            public void testStreamPosition_0() throws Exception {
0070:                //this encoding is read from the file
0071:                /*byte [] mess = {0x30, 0x30, 
0072:                 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41,
0073:                 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 
0074:                 };
0075:                 */
0076:
0077:                InputStream is = Support_Resources
0078:                        .getResourceStream("X500PrincipalTest.1.dat");
0079:                X500Principal principal = new X500Principal(is);
0080:                String s = principal.toString();
0081:                assertEquals("CN=A, CN=B, CN=A, CN=B", s);
0082:                assertEquals(0, is.available());
0083:                is.close();
0084:            }
0085:
0086:            public void testStreamPosition_1() throws Exception {
0087:                byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A,
0088:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01,
0089:                        0x5A, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0090:                        0x0B, 0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06,
0091:                        0x03, 0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A,
0092:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01,
0093:                        0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0094:                        0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06,
0095:                        0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09,
0096:                        0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41,
0097:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B,
0098:                        0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0099:                        0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30,
0100:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01, 0x43,
0101:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0A,
0102:                        0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06, 0x03,
0103:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 0x06,
0104:                        0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 2, 3, 4 };
0105:
0106:                ByteArrayInputStream is = new ByteArrayInputStream(mess);
0107:                X500Principal principal = new X500Principal(is);
0108:
0109:                String s = principal.getName(X500Principal.RFC1779);
0110:                assertEquals(
0111:                        "CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=Z",
0112:                        s);
0113:                assertEquals(3, is.available());
0114:                assertEquals(2, is.read());
0115:                assertEquals(3, is.read());
0116:                assertEquals(4, is.read());
0117:            }
0118:
0119:            public void testStreamPosition_2() throws Exception {
0120:                byte[] mess = { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0121:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 2 };
0122:                ByteArrayInputStream is = new ByteArrayInputStream(mess);
0123:                X500Principal principal = new X500Principal(is);
0124:                String s = principal.getName(X500Principal.RFC1779);
0125:                assertEquals("CN=A", s);
0126:                assertEquals(1, is.available());
0127:                assertEquals(2, is.read());
0128:            }
0129:
0130:            public void testEncodingFromFile() throws Exception {
0131:                //this encoding is read from the file
0132:                /*byte [] mess = {0x30, 0x30, 
0133:                 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41,
0134:                 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41
0135:                 };
0136:                 */
0137:                InputStream is = Support_Resources
0138:                        .getResourceStream("X500PrincipalTest.1.dat");
0139:                X500Principal principal = new X500Principal(is);
0140:                String s = principal.toString();
0141:                assertEquals("CN=A, CN=B, CN=A, CN=B", s);
0142:                is.close();
0143:            }
0144:
0145:            public void testEncodingFromEncoding() {
0146:                byte[] arr1 = new X500Principal("O=Org.").getEncoded();
0147:                byte[] arr2 = new X500Principal(new X500Principal("O=Org.")
0148:                        .getEncoded()).getEncoded();
0149:                assertTrue(Arrays.equals(arr1, arr2));
0150:            }
0151:
0152:            /**
0153:             * tests if the encoding is backed
0154:             */
0155:            public void testSafeEncoding() {
0156:                byte[] mess = { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0157:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x41 };
0158:                X500Principal principal = new X500Principal(mess);
0159:                mess[mess.length - 1] = (byte) 0xFF;
0160:                byte[] enc = principal.getEncoded();
0161:                assertEquals(enc[mess.length - 1], 0x41);
0162:            }
0163:
0164:            /**
0165:             * Inits X500Principal with byte array
0166:             * gets toString
0167:             * checks the result
0168:             */
0169:            public void testToString() throws Exception {
0170:                byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0171:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30,
0172:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 };
0173:                X500Principal principal = new X500Principal(mess);
0174:                String s = principal.toString();
0175:                assertNotNull(s);
0176:            }
0177:
0178:            /**
0179:             * Inits X500Principal with byte array
0180:             * gets hashCode
0181:             * compares with expected value 
0182:             */
0183:            public void testHashCode() throws Exception {
0184:                byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0185:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30,
0186:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 };
0187:                X500Principal principal = new X500Principal(mess);
0188:                int hash = principal.hashCode();
0189:                assertEquals(principal.getName(X500Principal.CANONICAL)
0190:                        .hashCode(), hash);
0191:            }
0192:
0193:            /**
0194:             * Inits X500Principal with byte array
0195:             * Inits other X500Principal with equivalent string
0196:             * checks if <code>equals</code> returns true for first against second one 
0197:             */
0198:            public void testEquals() throws Exception {
0199:                byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0200:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30,
0201:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 };
0202:                X500Principal principal = new X500Principal(mess);
0203:                X500Principal principal2 = new X500Principal("CN=A, CN=B");
0204:                assertTrue(principal.equals(principal2));
0205:            }
0206:
0207:            /**
0208:             * @tests javax.security.auth.x500.X500Principal#equals(Object)
0209:             */
0210:            public void test_equalsLjava_lang_Object() {
0211:                X500Principal xp1 = new X500Principal(
0212:                        "C=US, ST=California, L=San Diego, O=Apache, OU=Project Harmony, CN=Test cert");
0213:                assertEquals(
0214:                        "C=US,ST=California,L=San Diego,O=Apache,OU=Project Harmony,CN=Test cert",
0215:                        xp1.getName());
0216:            }
0217:
0218:            /**
0219:             * Inits X500Principal with byte array, where Oid does fall into any keyword, but not given as a keyword
0220:             * Value is given as hex value
0221:             * (extra spaces are given)
0222:             * gets Name in RFC1779 format
0223:             * compares with expected value of name 
0224:             */
0225:            public void testKWAsOid_RFC1779() throws Exception {
0226:                String dn = "CN=A, OID.2.5.4.3  =    #130142";
0227:                X500Principal principal = new X500Principal(dn);
0228:
0229:                String s = principal.getName(X500Principal.RFC1779);
0230:                assertEquals("CN=A, CN=B", s);
0231:            }
0232:
0233:            /**
0234:             * Inits X500Principal with byte array, where Oid does fall into any keyword, but not given as a keyword
0235:             * Value is given as hex value
0236:             * (extra spaces are given)
0237:             * gets Name in RFC2253 format
0238:             * compares with expected value of name 
0239:             */
0240:            public void testKWAsOid_RFC2253() throws Exception {
0241:                String dn = "CN=A, OID.2.5.4.3 =  #130142";
0242:                X500Principal principal = new X500Principal(dn);
0243:
0244:                String s = principal.getName(X500Principal.RFC2253);
0245:                assertEquals("CN=A,CN=B", s);
0246:            }
0247:
0248:            /**
0249:             * Inits X500Principal with byte array, where Oid does fall into any keyword, but not given as a keyword
0250:             * Value is given as hex value
0251:             * (extra spaces are given)
0252:             * gets Name in CANONICAL format
0253:             * compares with expected value of name 
0254:             */
0255:            public void testKWAsOid_CANONICAL() throws Exception {
0256:                String dn = "CN=A, OID.2.5.4.3 =  #130142";
0257:                X500Principal principal = new X500Principal(dn);
0258:
0259:                String s = principal.getName(X500Principal.CANONICAL);
0260:                assertEquals("cn=a,cn=b", s);
0261:            }
0262:
0263:            /**
0264:             * Inits X500Principal with byte array, where Oid does not fall into any keyword
0265:             * gets Name in RFC1779 format
0266:             * compares with expected value of name 
0267:             */
0268:            public void testOid_RFC1779() throws Exception {
0269:                byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0270:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30,
0271:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 };
0272:                mess[8] = 0x60;
0273:                X500Principal principal = new X500Principal(mess);
0274:
0275:                String s = principal.getName(X500Principal.RFC1779);
0276:                assertEquals("CN=A, OID.2.16.4.3=B", s);
0277:            }
0278:
0279:            /**
0280:             * Inits X500Principal with byte array, where Oid does not fall into any keyword
0281:             * gets Name in RFC2253 format
0282:             * compares with expected value of name 
0283:             */
0284:            public void testOid_RFC2253() throws Exception {
0285:                byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0286:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x4F, 0x31, 0x0A, 0x30,
0287:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 };
0288:                mess[8] = 0x60;
0289:                X500Principal principal = new X500Principal(mess);
0290:
0291:                String s = principal.getName(X500Principal.RFC2253);
0292:                assertEquals("CN=A,2.16.4.3=#13014f", s);
0293:            }
0294:
0295:            /**
0296:             * Inits X500Principal with byte array, where Oid does not fall into any keyword
0297:             * gets Name in CANONICAL format
0298:             * compares with expected value of name 
0299:             */
0300:            public void testOid_CANONICAL() throws Exception {
0301:                byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0302:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x4F, 0x31, 0x0A, 0x30,
0303:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 };
0304:                mess[8] = 0x60;
0305:                X500Principal principal = new X500Principal(mess);
0306:
0307:                String s = principal.getName(X500Principal.CANONICAL);
0308:                assertEquals("cn=a,2.16.4.3=#13014f", s);
0309:            }
0310:
0311:            /**
0312:             * Inits X500Principal with a string
0313:             * gets encoded form
0314:             * compares with expected byte array 
0315:             */
0316:            public void testNameGetEncoding() throws Exception {
0317:                byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A,
0318:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01,
0319:                        0x5A, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0320:                        0x0B, 0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06,
0321:                        0x03, 0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A,
0322:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01,
0323:                        0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0324:                        0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06,
0325:                        0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09,
0326:                        0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41,
0327:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B,
0328:                        0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0329:                        0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30,
0330:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01, 0x43,
0331:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0A,
0332:                        0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06, 0x03,
0333:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 0x06,
0334:                        0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 };
0335:                String dn = "CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=Z";
0336:                X500Principal principal = new X500Principal(dn);
0337:                byte[] s = principal.getEncoded();
0338:
0339:                assertTrue(Arrays.equals(mess, s));
0340:            }
0341:
0342:            /**
0343:             * Inits X500Principal with a string
0344:             * gets encoded form
0345:             * compares with expected byte array 
0346:             */
0347:            public void testNameGetEncoding_01() throws Exception {
0348:                byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0349:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30,
0350:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 };
0351:                String dn = "CN=A,CN=B";
0352:                X500Principal principal = new X500Principal(dn);
0353:                byte[] s = principal.getEncoded();
0354:
0355:                assertTrue(Arrays.equals(mess, s));
0356:            }
0357:
0358:            /**
0359:             * Inits X500Principal with byte array
0360:             * gets Name in RFC1779 format
0361:             * compares with expected value of name 
0362:             */
0363:            public void testGetName_RFC1779() throws Exception {
0364:                byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A,
0365:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01,
0366:                        0x5A, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0367:                        0x0B, 0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06,
0368:                        0x03, 0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A,
0369:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01,
0370:                        0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0371:                        0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06,
0372:                        0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09,
0373:                        0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41,
0374:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B,
0375:                        0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0376:                        0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30,
0377:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01, 0x43,
0378:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0A,
0379:                        0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06, 0x03,
0380:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 0x06,
0381:                        0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 };
0382:                X500Principal principal = new X500Principal(mess);
0383:
0384:                String s = principal.getName(X500Principal.RFC1779);
0385:                assertEquals(
0386:                        "CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=Z",
0387:                        s);
0388:
0389:            }
0390:
0391:            /**
0392:             * Inits X500Principal with byte array
0393:             * gets Name in RFC2253 format
0394:             * compares with expected value of name 
0395:             */
0396:            public void testGetName_RFC2253() throws Exception {
0397:                byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A,
0398:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01,
0399:                        0x5A, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0400:                        0x0B, 0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06,
0401:                        0x03, 0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A,
0402:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01,
0403:                        0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0404:                        0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06,
0405:                        0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09,
0406:                        0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41,
0407:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B,
0408:                        0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0409:                        0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30,
0410:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01, 0x43,
0411:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0A,
0412:                        0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06, 0x03,
0413:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 0x06,
0414:                        0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 };
0415:                X500Principal principal = new X500Principal(mess);
0416:
0417:                String s = principal.getName(X500Principal.RFC2253);
0418:                assertEquals(
0419:                        "CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=Z",
0420:                        s);
0421:            }
0422:
0423:            /**
0424:             * Inits X500Principal with byte array
0425:             * gets Name in CANONICAL format
0426:             * compares with expected value of name 
0427:             */
0428:            public void testGetName_CANONICAL() throws Exception {
0429:                byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A,
0430:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01,
0431:                        0x5A, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0432:                        0x0B, 0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06,
0433:                        0x03, 0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A,
0434:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01,
0435:                        0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0436:                        0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06,
0437:                        0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09,
0438:                        0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41,
0439:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B,
0440:                        0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0441:                        0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30,
0442:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01, 0x43,
0443:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0A,
0444:                        0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06, 0x03,
0445:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 0x06,
0446:                        0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 };
0447:                X500Principal principal = new X500Principal(mess);
0448:
0449:                String s = principal.getName(X500Principal.CANONICAL);
0450:                assertEquals(
0451:                        "CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=Z"
0452:                                .toLowerCase(Locale.US), s);
0453:            }
0454:
0455:            /**
0456:             * Inits X500Principal with byte array
0457:             * gets Name in RFC1779 format
0458:             * compares with expected value of name 
0459:             */
0460:            public void testStreamGetName_RFC1779() throws Exception {
0461:                byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A,
0462:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01,
0463:                        0x5A, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0464:                        0x0B, 0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06,
0465:                        0x03, 0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A,
0466:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01,
0467:                        0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0468:                        0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06,
0469:                        0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09,
0470:                        0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41,
0471:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B,
0472:                        0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0473:                        0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30,
0474:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01, 0x43,
0475:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0A,
0476:                        0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06, 0x03,
0477:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 0x06,
0478:                        0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 };
0479:                ByteArrayInputStream is = new ByteArrayInputStream(mess);
0480:                X500Principal principal = new X500Principal(is);
0481:
0482:                String s = principal.getName(X500Principal.RFC1779);
0483:                assertEquals(
0484:                        "CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=Z",
0485:                        s);
0486:            }
0487:
0488:            /**
0489:             * Inits X500Principal with byte array
0490:             * gets Name in RFC2253 format
0491:             * compares with expected value of name 
0492:             */
0493:            public void testStreamGetName_RFC2253() throws Exception {
0494:                byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A,
0495:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01,
0496:                        0x5A, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0497:                        0x0B, 0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06,
0498:                        0x03, 0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A,
0499:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01,
0500:                        0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0501:                        0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06,
0502:                        0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09,
0503:                        0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41,
0504:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B,
0505:                        0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0506:                        0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30,
0507:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01, 0x43,
0508:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0A,
0509:                        0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06, 0x03,
0510:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 0x06,
0511:                        0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 };
0512:                ByteArrayInputStream is = new ByteArrayInputStream(mess);
0513:                X500Principal principal = new X500Principal(is);
0514:
0515:                String s = principal.getName(X500Principal.RFC2253);
0516:                assertEquals(
0517:                        "CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=Z",
0518:                        s);
0519:            }
0520:
0521:            /**
0522:             * Inits X500Principal with byte array
0523:             * gets Name in CANONICAL format
0524:             * compares with expected value of name 
0525:             */
0526:            public void testStreamGetName_CANONICAL() throws Exception {
0527:                byte[] mess = { 0x30, (byte) 0x81, (byte) 0x9A, 0x31, 0x0A,
0528:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01,
0529:                        0x5A, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0530:                        0x0B, 0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06,
0531:                        0x03, 0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A,
0532:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01,
0533:                        0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
0534:                        0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06,
0535:                        0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09,
0536:                        0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41,
0537:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B,
0538:                        0x13, 0x01, 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0539:                        0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30,
0540:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01, 0x43,
0541:                        0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0A,
0542:                        0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08, 0x06, 0x03,
0543:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09, 0x06,
0544:                        0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 };
0545:                ByteArrayInputStream is = new ByteArrayInputStream(mess);
0546:                X500Principal principal = new X500Principal(is);
0547:
0548:                String s = principal.getName(X500Principal.CANONICAL);
0549:                assertEquals(
0550:                        "CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=A+ST=CA,O=B,L=C,C=D,OU=E,CN=Z"
0551:                                .toLowerCase(Locale.US), s);
0552:            }
0553:
0554:            /**
0555:             * Inits X500Principal with a string, where OID does not fall into any keyword 
0556:             * gets encoded form
0557:             * inits new X500Principal with the encoding
0558:             * gets string in RFC1779 format
0559:             * compares with expected value 
0560:             */
0561:            public void testGetName_EncodingWithWrongOidButGoodName_SeveralRDNs_RFC1779()
0562:                    throws Exception {
0563:                String dn = "OID.2.16.4.3=B; CN=A";
0564:                X500Principal principal = new X500Principal(dn);
0565:                byte[] enc = principal.getEncoded();
0566:                X500Principal principal2 = new X500Principal(enc);
0567:                String s = principal2.getName(X500Principal.RFC1779);
0568:                assertEquals("OID.2.16.4.3=B, CN=A", s);
0569:
0570:            }
0571:
0572:            /**
0573:             * Inits X500Principal with a string, where OID does not fall into any keyword 
0574:             * gets encoded form
0575:             * inits new X500Principal with the encoding
0576:             * gets string in RFC2253 format
0577:             * compares with expected value 
0578:             */
0579:            public void testGetName_EncodingWithWrongOidButGoodName_SeveralRDNs_RFC2253()
0580:                    throws Exception {
0581:                String dn = "OID.2.16.4.3=B; CN=A";
0582:                X500Principal principal = new X500Principal(dn);
0583:                byte[] enc = principal.getEncoded();
0584:                X500Principal principal2 = new X500Principal(enc);
0585:                String s = principal2.getName(X500Principal.RFC2253);
0586:                assertEquals("2.16.4.3=#130142,CN=A", s);
0587:
0588:            }
0589:
0590:            /**
0591:             * Inits X500Principal with a string, where OID does not fall into any keyword 
0592:             * gets encoded form
0593:             * inits new X500Principal with the encoding
0594:             * gets string in CANONICAL format
0595:             * compares with expected value 
0596:             */
0597:            public void testGetName_EncodingWithWrongOidButGoodName_SeveralRDNs_CANONICAL()
0598:                    throws Exception {
0599:                String dn = "OID.2.16.4.3=B; CN=A";
0600:                X500Principal principal = new X500Principal(dn);
0601:                byte[] enc = principal.getEncoded();
0602:                X500Principal principal2 = new X500Principal(enc);
0603:                String s = principal2.getName(X500Principal.CANONICAL);
0604:                assertEquals("2.16.4.3=#130142,cn=a", s);
0605:
0606:            }
0607:
0608:            /**
0609:             * Inits X500Principal with a string, where OID does not fall into any keyword 
0610:             * gets string in RFC1779 format
0611:             * compares with expected value 
0612:             */
0613:            public void testGetName_wrongOidButGoodName_RFC1779()
0614:                    throws Exception {
0615:                String dn = "OID.2.16.4.3=B + CN=A";
0616:                X500Principal principal = new X500Principal(dn);
0617:
0618:                String s = principal.getName(X500Principal.RFC1779);
0619:                assertEquals("OID.2.16.4.3=B + CN=A", s);
0620:            }
0621:
0622:            /**
0623:             * Inits X500Principal with a string, where OID does not fall into any keyword 
0624:             * gets string in RFC2253 format
0625:             * compares with expected value 
0626:             */
0627:            public void testGetName_wrongOidButGoodName_RFC2253()
0628:                    throws Exception {
0629:                String dn = "OID.2.16.4.3=B + CN=A";
0630:                X500Principal principal = new X500Principal(dn);
0631:
0632:                String s = principal.getName(X500Principal.RFC2253);
0633:                assertEquals("2.16.4.3=#130142+CN=A", s);
0634:            }
0635:
0636:            /**
0637:             * Inits X500Principal with a string, there are multiple AVAs
0638:             * gets string in CANONICAL format
0639:             * compares with expected value paying attention on sorting order of AVAs
0640:             */
0641:            public void testGetName_CANONICAL_SortOrder() throws Exception {
0642:                String dn = "ST=C + CN=A; OU=B + CN=D";
0643:                X500Principal principal = new X500Principal(dn);
0644:
0645:                String s = principal.getName(X500Principal.CANONICAL);
0646:                assertEquals("cn=a+st=c,cn=d+ou=b", s);
0647:
0648:            }
0649:
0650:            /**
0651:             * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword
0652:             * gets string in CANONICAL format
0653:             * compares with expected value paying attention on sorting order of AVAs
0654:             */
0655:            public void testGetName_CANONICAL_SortOrder_01() throws Exception {
0656:                String dn = "OID.2.16.4.3=B + CN=A";
0657:                X500Principal principal = new X500Principal(dn);
0658:
0659:                String s = principal.getName(X500Principal.CANONICAL);
0660:                assertEquals("cn=a+2.16.4.3=#130142", s);
0661:
0662:            }
0663:
0664:            /**
0665:             * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword, and value given in hex format
0666:             * gets string in CANONICAL format
0667:             * compares with expected value paying attention on sorting order of AVAs
0668:             */
0669:            public void testGetName_CANONICAL_SortOrder_02() throws Exception {
0670:                String dn = "OID.2.16.4.3=#13024220+ CN=A";
0671:                X500Principal principal = new X500Principal(dn);
0672:
0673:                String s = principal.getName(X500Principal.CANONICAL);
0674:                assertEquals("cn=a+2.16.4.3=#13024220", s);
0675:
0676:            }
0677:
0678:            /**
0679:             * Inits X500Principal with a string, there are multiple AVAs and 2 Oids which do not fall into any keyword
0680:             * gets string in CANONICAL format
0681:             * compares with expected value paying attention on sorting order of AVAs
0682:             */
0683:            public void testGetName_CANONICAL_SortOrder_03() throws Exception {
0684:                String dn = "OID.2.16.4.9=A + OID.2.16.4.3=B";
0685:                X500Principal principal = new X500Principal(dn);
0686:
0687:                String s = principal.getName(X500Principal.CANONICAL);
0688:                assertEquals("2.16.4.3=#130142+2.16.4.9=#130141", s);
0689:
0690:            }
0691:
0692:            /**
0693:             * Inits X500Principal with a string, there are multiple AVAs and 2 Oids which do not fall into any keyword
0694:             * gets string in CANONICAL format
0695:             * compares with expected value paying attention on sorting order of AVAs
0696:             */
0697:            public void testGetName_CANONICAL_SortOrder_04() throws Exception {
0698:                String dn = "OID.2.2.2.2=A + OID.1.1.1.1=B";
0699:                X500Principal principal = new X500Principal(dn);
0700:
0701:                String s = principal.getName(X500Principal.CANONICAL);
0702:                assertEquals("1.1.1.1=#130142+2.2.2.2=#130141", s);
0703:
0704:            }
0705:
0706:            /**
0707:             * Inits X500Principal with a string, there are multiple AVAs and 2 Oids which do not fall into any keyword
0708:             * gets string in CANONICAL format
0709:             * compares with expected value paying attention on sorting order of AVAs
0710:             */
0711:            public void testGetName_CANONICAL_SortOrder_05() throws Exception {
0712:                String dn = "OID.2.16.4.9=A + OID.2.16.4=B";
0713:                X500Principal principal = new X500Principal(dn);
0714:
0715:                String s = principal.getName(X500Principal.CANONICAL);
0716:                assertEquals("2.16.4=#130142+2.16.4.9=#130141", s);
0717:
0718:            }
0719:
0720:            /**
0721:             * Inits X500Principal with a string, there are multiple AVAs and 2 Oids which do not fall into any keyword
0722:             * gets string in CANONICAL format
0723:             * compares with expected value paying attention on sorting order of AVAs
0724:             */
0725:            public void testGetName_CANONICAL_SortOrder_06() throws Exception {
0726:                String dn = "OID.1.1.2=A + OID.1.2=B";
0727:                X500Principal principal = new X500Principal(dn);
0728:
0729:                String s = principal.getName(X500Principal.CANONICAL);
0730:                assertEquals("1.1.2=#130141+1.2=#130142", s);
0731:
0732:            }
0733:
0734:            /**
0735:             * Inits X500Principal with a string, there are multiple AVAs and 2 Oids which do not fall into any keyword
0736:             * gets string in CANONICAL format
0737:             * compares with expected value paying attention on sorting order of AVAs
0738:             */
0739:            public void testGetName_CANONICAL_SortOrder_07() throws Exception {
0740:                String dn = "OID.1.1.1=A + OID.1.1=B";
0741:                X500Principal principal = new X500Principal(dn);
0742:
0743:                String s = principal.getName(X500Principal.CANONICAL);
0744:                assertEquals("1.1=#130142+1.1.1=#130141", s);
0745:
0746:            }
0747:
0748:            /**
0749:             * FIXME test is failed - implement unicode normalization
0750:             * @throws Exception
0751:             */
0752:            public void testGetNameUnicodeNormalized() throws Exception {
0753:                String unicodeStr = "CN= \u0401\u0410";
0754:                X500Principal principal = new X500Principal(unicodeStr);
0755:                principal.getName(X500Principal.CANONICAL);
0756:            }
0757:
0758:            /**
0759:             * Inits X500Principal with empty string
0760:             * gets encoding
0761:             * compares with expected encoding
0762:             */
0763:            public void testEmptyInputName() {
0764:                String dn = "CN=\"\"";
0765:                byte[] mess = { 0x30, 0x0B, 0x31, 0x09, 0x30, 0x07, 0x06, 0x03,
0766:                        0x55, 0x04, 0x03, 0x13, 0x00 };
0767:                X500Principal principal = new X500Principal(dn);
0768:                assertTrue(Arrays.equals(mess, principal.getEncoded()));
0769:            }
0770:
0771:            /**
0772:             * Inits X500Principal with string as single escaped space
0773:             * gets encoding
0774:             * compares with expected encoding
0775:             */
0776:            public void testNameSingleEscapedSpace() {
0777:                String dn = "CN=\\ ";
0778:                byte[] mess = { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
0779:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x20 };
0780:                X500Principal principal = new X500Principal(dn);
0781:                assertTrue(Arrays.equals(mess, principal.getEncoded()));
0782:            }
0783:
0784:            /**
0785:             * Inits X500Principal with string with spaces
0786:             * gets Name in RFC2253 format
0787:             * compares with expected value of name 
0788:             */
0789:            public void testNameOnlySpaces_RFC1779() {
0790:                String dn = "CN=\"  \"";
0791:                X500Principal principal = new X500Principal(dn);
0792:                assertEquals("CN=\"  \"", principal
0793:                        .getName(X500Principal.RFC1779));
0794:            }
0795:
0796:            /**
0797:             * Inits X500Principal with string with spaces
0798:             * gets Name in RFC2253 format
0799:             * compares with expected value of name 
0800:             */
0801:            public void testNameOnlySpaces_RFC2253() {
0802:                String dn = "CN=\"  \"";
0803:                X500Principal principal = new X500Principal(dn);
0804:                assertEquals("CN=\\ \\ ", principal
0805:                        .getName(X500Principal.RFC2253));
0806:            }
0807:
0808:            /**
0809:             * Inits X500Principal with string with only spaces,
0810:             * gets Name in CANONICAL format:leading and trailing white space
0811:             * chars are removed even string doesn't have other chars (bug???)
0812:             */
0813:            public void testNameOnlySpaces_CANONICAL() {
0814:                String dn = "CN=\"  \"";
0815:                X500Principal principal = new X500Principal(dn);
0816:                assertEquals("cn=", principal.getName(X500Principal.CANONICAL));
0817:            }
0818:
0819:            ///*** Negative Tests ***///
0820:            /**
0821:             * Inits X500Principal with string, where DN name is improper "CNN"
0822:             * checks if proper exception is thrown
0823:             */
0824:            public void testIllegalInputName() {
0825:                try {
0826:                    String dn = "CNN=A";
0827:                    new X500Principal(dn);
0828:                    fail("No IllegalArgumentException on improper input name \"CNN\"");
0829:                } catch (IllegalArgumentException e) {
0830:                }
0831:            }
0832:
0833:            /**
0834:             * Inits X500Principal with string, where there is leading ';'
0835:             * checks if proper exception is thrown
0836:             */
0837:            public void testIllegalInputName_01() {
0838:                try {
0839:                    String dn = ";CN=A";
0840:                    new X500Principal(dn);
0841:                    fail("No IllegalArgumentException on leading ';' in input name");
0842:                } catch (IllegalArgumentException e) {
0843:                }
0844:            }
0845:
0846:            /**
0847:             * Inits X500Principal with string, where there is leading '='
0848:             * checks if proper exception is thrown
0849:             */
0850:            public void testIllegalInputName_02() {
0851:                try {
0852:                    String dn = "=CN=A";
0853:                    new X500Principal(dn);
0854:                    fail("No IllegalArgumentException on leading '=' in input name");
0855:                } catch (IllegalArgumentException e) {
0856:                }
0857:            }
0858:
0859:            /**
0860:             * Inits X500Principal with string, where there is no value
0861:             * checks if proper exception is thrown
0862:             */
0863:            public void testEmptyInputName_0() {
0864:                String dn = "CN=";
0865:                byte[] mess = { 0x30, 0x0B, 0x31, 0x09, 0x30, 0x07, 0x06, 0x03,
0866:                        0x55, 0x04, 0x03, 0x13, 0x00 };
0867:                X500Principal principal = new X500Principal(dn);
0868:                assertTrue(Arrays.equals(mess, principal.getEncoded()));
0869:            }
0870:
0871:            public void testEmptyInputName_1() {
0872:                String dn = "CN=\"\", C=\"\"";
0873:                X500Principal principal = new X500Principal(dn);
0874:                dn = "CN=, C=";
0875:                X500Principal principal2 = new X500Principal(dn);
0876:                assertTrue(Arrays.equals(principal.getEncoded(), principal2
0877:                        .getEncoded()));
0878:
0879:            }
0880:
0881:            public void testEmptyInputName_2() {
0882:                String dn = "CN=\"\" + OU=A, C=\"\"";
0883:                X500Principal principal = new X500Principal(dn);
0884:                dn = "CN=+OU=A, C=";
0885:                X500Principal principal2 = new X500Principal(dn);
0886:                assertTrue(Arrays.equals(principal.getEncoded(), principal2
0887:                        .getEncoded()));
0888:
0889:            }
0890:
0891:            public void testIllegalInputName_15() {
0892:                try {
0893:                    String dn = "CN=,C";
0894:                    new X500Principal(dn);
0895:                    fail("No IllegalArgumentException on improper attribute value");
0896:                } catch (IllegalArgumentException e) {
0897:                }
0898:            }
0899:
0900:            public void testIllegalInputName_16() {
0901:                try {
0902:                    String dn = "CN=,C=+";
0903:                    new X500Principal(dn);
0904:                    fail("No IllegalArgumentException on improper attribute value");
0905:                } catch (IllegalArgumentException e) {
0906:                }
0907:            }
0908:
0909:            /**
0910:             * Inits X500Principal with string, where value is given in wrong hex format
0911:             * checks if proper exception is thrown
0912:             */
0913:            public void testIllegalInputName_04() {
0914:                try {
0915:                    String dn = "CN=#XYZ";
0916:                    new X500Principal(dn);
0917:                    fail("No IllegalArgumentException on improper hex value");
0918:                } catch (IllegalArgumentException e) {
0919:                }
0920:            }
0921:
0922:            /**
0923:             * Inits X500Principal with string, where value is given with special chars
0924:             * checks if proper exception is thrown
0925:             */
0926:            public void testIllegalInputName_05() {
0927:                try {
0928:                    String dn = "CN=X+YZ";
0929:                    new X500Principal(dn);
0930:                    fail("No IllegalArgumentException on improper attribute value");
0931:                } catch (IllegalArgumentException e) {
0932:                }
0933:            }
0934:
0935:            /**
0936:             * Inits X500Principal with string, where value is given with special chars
0937:             * Compatibility issue: according RFC 2253 such string is invalid
0938:             * but we accept it, not string char is escaped
0939:             */
0940:            public void testIllegalInputName_06() {
0941:                String dn = "CN=X=YZ";
0942:                X500Principal p = new X500Principal(dn);
0943:                assertEquals("CN=X\\=YZ", p.getName(X500Principal.RFC2253));
0944:            }
0945:
0946:            /**
0947:             * Inits X500Principal with string, where value is given with not string chars
0948:             * Compatibility issue: according RFC 2253 such string is invalid
0949:             * but we accept it, not string char is escaped
0950:             */
0951:            public void testIllegalInputName_07() {
0952:                String dn = "CN=X\"YZ";
0953:                X500Principal p = new X500Principal(dn);
0954:                assertEquals("CN=X\\\"YZ", p.getName(X500Principal.RFC2253));
0955:            }
0956:
0957:            /**
0958:             * Inits X500Principal with string, where value is given with special chars
0959:             * Compatibility issue: according RFC 2253 such string is invalid
0960:             * but we accept it, special char is escaped
0961:             */
0962:            public void testIllegalInputName_08() {
0963:                String dn = "CN=X<YZ";
0964:                X500Principal p = new X500Principal(dn);
0965:                assertEquals("CN=X\\<YZ", p.getName(X500Principal.RFC2253));
0966:            }
0967:
0968:            /**
0969:             * Inits X500Principal with string, where value is given with special chars
0970:             * checks if proper exception is thrown
0971:             */
0972:            public void testIllegalInputName_09() {
0973:                try {
0974:                    String dn = "CN=#";
0975:                    new X500Principal(dn);
0976:                    fail("No IllegalArgumentException on improper attribute hex value");
0977:                } catch (IllegalArgumentException e) {
0978:                    //ignore
0979:                }
0980:
0981:            }
0982:
0983:            /**
0984:             * Inits X500Principal with string, where value is given with special chars
0985:             * checks if proper exception is thrown
0986:             */
0987:            public void testIllegalInputName_10() {
0988:                try {
0989:                    String dn = "CN=#13";
0990:                    new X500Principal(dn);
0991:                    fail("No IllegalArgumentException on improper attribute hex value");
0992:                } catch (IllegalArgumentException e) {
0993:                    //ignore
0994:                }
0995:
0996:            }
0997:
0998:            /**
0999:             * Inits X500Principal with string, where value is given with special chars
1000:             * checks if proper exception is thrown
1001:             */
1002:            public void testIllegalInputName_11() {
1003:                try {
1004:                    String dn = "CN=#1301";
1005:                    new X500Principal(dn);
1006:                    fail("No IllegalArgumentException on improper attribute hex value");
1007:                } catch (IllegalArgumentException e) {
1008:                    //ignore
1009:                }
1010:
1011:            }
1012:
1013:            /**
1014:             * Inits X500Principal with string, where value is given with special chars
1015:             * checks if proper exception is thrown
1016:             */
1017:            public void testIllegalInputName_12() {
1018:                try {
1019:                    String dn = "CN=#13010101";
1020:                    new X500Principal(dn);
1021:                    fail("No IllegalArgumentException on improper attribute hex value");
1022:                } catch (IllegalArgumentException e) {
1023:                }
1024:            }
1025:
1026:            /**
1027:             * Inits X500Principal with string, where value is given with special chars
1028:             * checks if proper exception is thrown
1029:             */
1030:            public void testIllegalInputName_13() {
1031:                try {
1032:                    String dn = "CN=# 0";
1033:                    new X500Principal(dn);
1034:                    fail("No IllegalArgumentException on improper attribute hex value");
1035:                } catch (IllegalArgumentException e) {
1036:                }
1037:            }
1038:
1039:            /**
1040:             * Inits X500Principal with string, where value is given in hex format, but improper tag
1041:             * checks if it is ignored
1042:             */
1043:            public void testSemiIllegalInputName_14() {
1044:                String dn = "CN=#7E0142";
1045:                new X500Principal(dn);
1046:            }
1047:
1048:            public void testInitClause() {
1049:                try {
1050:                    byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06,
1051:                            0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31,
1052:                            0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
1053:                            0x13, 0x01, 0x41 };
1054:                    mess[3] = 0x12;//length field
1055:                    new X500Principal(mess);
1056:
1057:                    fail("No IllegalArgumentException on input array with improper length field");
1058:                } catch (IllegalArgumentException e) {
1059:                }
1060:            }
1061:
1062:            /**
1063:             * Inits X500Principal with byte array = null
1064:             * checks if proper exception is thrown
1065:             */
1066:            public void testIllegalInputArray_0() {
1067:                try {
1068:                    byte[] mess = null;
1069:                    new X500Principal(mess);
1070:                    fail("No IllegalArgumentException on input array with improper length field");
1071:                } catch (IllegalArgumentException e) {
1072:                }
1073:            }
1074:
1075:            /**
1076:             * Inits X500Principal with byte array with wrong length field
1077:             * checks if proper exception is thrown
1078:             */
1079:            public void testIllegalInputArray() {
1080:                try {
1081:                    byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06,
1082:                            0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31,
1083:                            0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
1084:                            0x13, 0x01, 0x41 };
1085:                    mess[3] = 0x12;//length field
1086:                    new X500Principal(mess);
1087:
1088:                    fail("No IllegalArgumentException on input array with improper length field");
1089:                } catch (IllegalArgumentException e) {
1090:                }
1091:            }
1092:
1093:            /**
1094:             * Inits X500Principal with input stream with wrong length field
1095:             * checks if proper exception is thrown
1096:             */
1097:            public void testIllegalInputArray_is() {
1098:                try {
1099:                    byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06,
1100:                            0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31,
1101:                            0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
1102:                            0x13, 0x01, 0x41 };
1103:                    mess[3] = 0x12;//length field
1104:                    ByteArrayInputStream is = new ByteArrayInputStream(mess);
1105:                    new X500Principal(is);
1106:
1107:                    fail("No IllegalArgumentException on input array with improper length field");
1108:                } catch (IllegalArgumentException e) {
1109:                }
1110:            }
1111:
1112:            /**
1113:             * Inits X500Principal with byte array with wrong inner Sequence tag field
1114:             * checks if proper exception is thrown
1115:             */
1116:            public void testIllegalInputArray_01() {
1117:                try {
1118:                    byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06,
1119:                            0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31,
1120:                            0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
1121:                            0x13, 0x01, 0x41 };
1122:                    mess[4] = 0x12;//inner Sequence tag field
1123:                    new X500Principal(mess);
1124:
1125:                    fail("No IllegalArgumentException on input array with improper inner Sequence tag field");
1126:                } catch (IllegalArgumentException e) {
1127:                }
1128:            }
1129:
1130:            /**
1131:             * Inits X500Principal with byte array with wrong last byte of OID
1132:             * checks if proper exception is thrown
1133:             */
1134:            public void testIllegalInputArray_02() {
1135:                try {
1136:                    byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06,
1137:                            0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31,
1138:                            0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
1139:                            0x13, 0x01, 0x41 };
1140:                    mess[10] = (byte) 0xFE;//last byte of OID
1141:                    new X500Principal(mess);
1142:
1143:                    fail("No IllegalArgumentException on input array with improper last byte of OID");
1144:                } catch (IllegalArgumentException e) {
1145:                }
1146:            }
1147:
1148:            /**
1149:             * Inits X500Principal with byte array with wrong length of OID
1150:             * checks if proper exception is thrown
1151:             */
1152:            public void testIllegalInputArray_03() {
1153:                try {
1154:                    byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06,
1155:                            0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31,
1156:                            0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
1157:                            0x13, 0x01, 0x41 };
1158:                    mess[7] = 2;//length of OID
1159:                    new X500Principal(mess);
1160:
1161:                    fail("No IllegalArgumentException on input array with improper length of OID");
1162:                } catch (IllegalArgumentException e) {
1163:                }
1164:            }
1165:
1166:            /**
1167:             * Inits X500Principal with byte array with wrong tag of value
1168:             * checks if it is ignored
1169:             */
1170:            public void testSemiIllegalInputArray_04() {
1171:                byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
1172:                        0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31, 0x0A, 0x30,
1173:                        0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41 };
1174:                mess[11] = (byte) 0x0F;//tag of value
1175:                new X500Principal(mess);
1176:            }
1177:
1178:            /**
1179:             * Inits X500Principal with byte array with wrong length of value
1180:             * checks if proper exception is thrown
1181:             */
1182:            public void testIllegalInputArray_05() {
1183:                try {
1184:                    byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06,
1185:                            0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31,
1186:                            0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
1187:                            0x13, 0x01, 0x41 };
1188:                    mess[12] = 2;//length of value
1189:                    new X500Principal(mess);
1190:
1191:                    fail("No IllegalArgumentException on input array with improper length of value");
1192:                } catch (IllegalArgumentException e) {
1193:                }
1194:            }
1195:
1196:            /**
1197:             * Inits X500Principal with input stream with wrong length of value
1198:             * checks if proper exception is thrown
1199:             */
1200:            public void testIllegalInputArray_05_is() {
1201:                try {
1202:                    byte[] mess = { 0x30, 0x18, 0x31, 0x0A, 0x30, 0x08, 0x06,
1203:                            0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x42, 0x31,
1204:                            0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
1205:                            0x13, 0x01, 0x41 };
1206:                    mess[12] = 2;//length of value
1207:                    ByteArrayInputStream is = new ByteArrayInputStream(mess);
1208:                    new X500Principal(is);
1209:
1210:                    fail("No IllegalArgumentException on input array with improper length of value");
1211:                } catch (IllegalArgumentException e) {
1212:                }
1213:            }
1214:
1215:            /**
1216:             * Inits X500Principal with string
1217:             * Calls getName with improper parameter as format
1218:             * checks if proper exception is thrown
1219:             */
1220:            public void testIllegalFormat() {
1221:                try {
1222:                    String dn = "CN=A";
1223:                    X500Principal principal = new X500Principal(dn);
1224:                    principal.getName("WRONG FORMAT");
1225:                    fail("No IllegalArgumentException on improper parameter as format");
1226:                } catch (IllegalArgumentException e) {
1227:                }
1228:            }
1229:
1230:            /**
1231:             * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword
1232:             * Gets encoding
1233:             * Inits other X500Principal with the encoding
1234:             * gets string in RFC1779 format
1235:             * compares with expected value paying attention on sorting order of AVAs
1236:             */
1237:            public void testGetName_EncodingWithWrongOidButGoodName_MultAVA_RFC1779()
1238:                    throws Exception {
1239:                String dn = "OID.2.16.4.3=B + CN=A";
1240:                X500Principal principal = new X500Principal(dn);
1241:                byte[] enc = principal.getEncoded();
1242:                X500Principal principal2 = new X500Principal(enc);
1243:                String s = principal2.getName(X500Principal.RFC1779);
1244:                assertEquals("OID.2.16.4.3=B + CN=A", s);
1245:
1246:            }
1247:
1248:            /**
1249:             * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword
1250:             * Gets encoding
1251:             * Inits other X500Principal with the encoding
1252:             * gets string in RFC2253 format
1253:             * compares with expected value paying attention on sorting order of AVAs
1254:             */
1255:            public void testGetName_EncodingWithWrongOidButGoodName_MultAVA_RFC2253()
1256:                    throws Exception {
1257:                String dn = "OID.2.16.4.3=B + CN=A";
1258:                X500Principal principal = new X500Principal(dn);
1259:                byte[] enc = principal.getEncoded();
1260:                X500Principal principal2 = new X500Principal(enc);
1261:                String s = principal2.getName(X500Principal.RFC2253);
1262:                assertEquals("2.16.4.3=#130142+CN=A", s);
1263:
1264:            }
1265:
1266:            /**
1267:             * Inits X500Principal with a string, there are multiple AVAs and Oid which does not fall into any keyword
1268:             * Gets encoding
1269:             * Inits other X500Principal with the encoding
1270:             * gets string in CANONICAL format
1271:             * compares with expected value paying attention on sorting order of AVAs
1272:             */
1273:            public void testGetName_EncodingWithWrongOidButGoodName_MultAVA_CANONICAL()
1274:                    throws Exception {
1275:                String dn = "OID.2.16.4.3=B + CN=A";
1276:                X500Principal principal = new X500Principal(dn);
1277:                byte[] enc = principal.getEncoded();
1278:                X500Principal principal2 = new X500Principal(enc);
1279:                String s = principal2.getName(X500Principal.CANONICAL);
1280:                assertEquals("cn=a+2.16.4.3=#130142", s);
1281:
1282:            }
1283:
1284:            /**
1285:             * Inits X500Principal with byte array, where there are leading and tailing spaces
1286:             * gets Name in RFC1779 format
1287:             * compares with expected value of name 
1288:             */
1289:            public void testNameSpaceFromEncoding_RFC1779() throws Exception {
1290:                byte[] mess = { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03,
1291:                        0x55, 0x04, 0x03, 0x13, 0x03, 0x20, 0x41, 0x20, };
1292:                X500Principal principal = new X500Principal(mess);
1293:                String s = principal.getName(X500Principal.RFC1779);
1294:                assertEquals("CN=\" A \"", s);
1295:
1296:            }
1297:
1298:            /**
1299:             * Inits X500Principal with byte array, where there are leading and tailing spaces
1300:             * gets Name in RFC2253 format
1301:             * compares with expected value of name 
1302:             */
1303:            public void testNameSpaceFromEncoding_RFC2253() throws Exception {
1304:                byte[] mess = { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03,
1305:                        0x55, 0x04, 0x03, 0x13, 0x03, 0x20, 0x41, 0x20, };
1306:                X500Principal principal = new X500Principal(mess);
1307:                String s = principal.getName(X500Principal.RFC2253);
1308:                assertEquals("CN=\\ A\\ ", s);
1309:
1310:            }
1311:
1312:            /**
1313:             * Inits X500Principal with byte array, where there are leading and tailing spaces
1314:             * gets Name in CANONICAL format
1315:             * compares with expected value of name 
1316:             */
1317:            public void testNameSpaceFromEncoding_CANONICAL() throws Exception {
1318:                byte[] mess = { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03,
1319:                        0x55, 0x04, 0x03, 0x13, 0x03, 0x20, 0x41, 0x20, };
1320:                X500Principal principal = new X500Principal(mess);
1321:                String s = principal.getName(X500Principal.CANONICAL);
1322:                assertEquals("cn=a", s);
1323:
1324:            }
1325:
1326:            /**
1327:             * Inits X500Principal with byte array, where there are special characters
1328:             * gets Name in RFC1779 format
1329:             * compares with expected value of name, checks if the string is in quotes 
1330:             */
1331:            public void testNameSpecialCharsFromEncoding_RFC1779()
1332:                    throws Exception {
1333:                byte[] mess = { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03,
1334:                        0x55, 0x04, 0x03, 0x0C, 0x02, 0x3B, 0x2C };
1335:                X500Principal principal = new X500Principal(mess);
1336:                String s = principal.getName(X500Principal.RFC1779);
1337:                assertEquals("CN=\";,\"", s);
1338:
1339:            }
1340:
1341:            /**
1342:             * Inits X500Principal with byte array, where there are special characters
1343:             * gets Name in RFC1779 format
1344:             * compares with expected value of name, checks if the characters are escaped 
1345:             */
1346:            public void testNameSpecialCharsFromEncoding_RFC2253()
1347:                    throws Exception {
1348:                byte[] mess = { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03,
1349:                        0x55, 0x04, 0x03, 0x0C, 0x02, 0x3B, 0x2C };
1350:                X500Principal principal = new X500Principal(mess);
1351:                String s = principal.getName(X500Principal.RFC2253);
1352:                assertEquals("CN=\\;\\,", s);
1353:
1354:            }
1355:
1356:            /**
1357:             * Inits X500Principal with byte array, where there are special characters
1358:             * gets Name in CANONICAL format
1359:             * compares with expected value of name, checks if the characters are escaped 
1360:             */
1361:            public void testNameSpecialCharsFromEncoding_CANONICAL()
1362:                    throws Exception {
1363:                byte[] mess = { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03,
1364:                        0x55, 0x04, 0x03, 0x0C, 0x02, 0x3B, 0x2C };
1365:                X500Principal principal = new X500Principal(mess);
1366:                String s = principal.getName(X500Principal.CANONICAL);
1367:                assertEquals("cn=\\;\\,", s);
1368:
1369:            }
1370:
1371:            /**
1372:             * Inits X500Principal with the string with special characters - \"B
1373:             * gets Name in RFC1779 format
1374:             * compares with expected value of name - "\B"
1375:             */
1376:            public void testNameSpecialChars_RFC1779() throws Exception {
1377:                String dn = "CN=A,CN=\\\"B";
1378:                X500Principal principal = new X500Principal(dn);
1379:                String s = principal.getName(X500Principal.RFC1779);
1380:                assertEquals("CN=A, CN=\"\\\"B\"", s);
1381:
1382:            }
1383:
1384:            /**
1385:             * Inits X500Principal with the string with special characters - \"B
1386:             * gets Name in RFC2253 format
1387:             * compares with expected value of name - "\B"
1388:             */
1389:            public void testNameSpecialChars_RFC2253() throws Exception {
1390:                String dn = "CN=A,CN=\\\"B";
1391:                X500Principal principal = new X500Principal(dn);
1392:                String s = principal.getName(X500Principal.RFC2253);
1393:                assertEquals("CN=A,CN=\\\"B", s);
1394:
1395:            }
1396:
1397:            /**
1398:             * Inits X500Principal with the string with special characters - \"B
1399:             * gets Name in CANONICAL format
1400:             * compares with expected value of name - "\b"
1401:             */
1402:            public void testNameSpecialChars_CANONICAL() throws Exception {
1403:                String dn = "CN=A,CN=\\\"B";
1404:                X500Principal principal = new X500Principal(dn);
1405:                String s = principal.getName(X500Principal.CANONICAL);
1406:                assertEquals("cn=a,cn=\\\"b", s);
1407:
1408:            }
1409:
1410:            /**
1411:             * Inits X500Principal with the string with special characters - \\nB
1412:             * gets Name in RFC1779 format
1413:             * compares with expected value of name - "\nB"
1414:             */
1415:            public void testNameSpecialChars_RFC1779_01() throws Exception {
1416:                //FIXME see testNameSpecialChars_RFC2253_01
1417:                //        String dn = "CN=\\\nB";
1418:                //        X500Principal principal = new X500Principal(dn);
1419:                //        String s = principal.getName(X500Principal.RFC1779);
1420:                //        assertEquals("CN=\"\nB\"", s);
1421:
1422:            }
1423:
1424:            /**
1425:             * Inits X500Principal with the string with special characters - \\nB
1426:             * gets Name in RFC2253 format
1427:             * compares with expected value of name - \\nB
1428:             */
1429:            public void testNameSpecialChars_RFC2253_01() throws Exception {
1430:
1431:                try {
1432:                    // compatibility issue:
1433:                    // don't accept escaped \n because it is not a special char
1434:                    new X500Principal("CN=\\\nB");
1435:                    fail("No expected IllegalArgumentException");
1436:                } catch (IllegalArgumentException e) {
1437:                }
1438:            }
1439:
1440:            /**
1441:             * Inits X500Principal with the string with special characters - \\nB
1442:             * gets Name in CANONICAL format
1443:             * compares with expected value of name - \\nb
1444:             */
1445:            public void testNameSpecialChars_CANONICAL_01() throws Exception {
1446:                //FIXME testNameSpecialChars_RFC2253_01
1447:                //        String dn = "CN=\\\nB";
1448:                //        X500Principal principal = new X500Principal(dn);
1449:                //        String s = principal.getName(X500Principal.CANONICAL);
1450:                //        assertEquals("cn=b", s);
1451:
1452:            }
1453:
1454:            /**
1455:             * Inits X500Principal with the string with special characters - \\B
1456:             * gets Name in RFC1779 format
1457:             * compares with expected value of name - "\B"
1458:             */
1459:            public void testNameSpecialChars_RFC1779_02() throws Exception {
1460:                String dn = "CN=\\\\B";
1461:                X500Principal principal = new X500Principal(dn);
1462:                String s = principal.getName(X500Principal.RFC1779);
1463:                assertEquals("CN=\"\\\\B\"", s);
1464:
1465:            }
1466:
1467:            /**
1468:             * Inits X500Principal with the string with special characters - \\B
1469:             * gets Name in RFC2253 format
1470:             * compares with expected value of name - \\B
1471:             */
1472:            public void testNameSpecialChars_RFC2253_02() throws Exception {
1473:                String dn = "CN=\\\\B";
1474:                X500Principal principal = new X500Principal(dn);
1475:                String s = principal.getName(X500Principal.RFC2253);
1476:                assertEquals("CN=\\\\B", s);
1477:
1478:            }
1479:
1480:            /**
1481:             * Inits X500Principal with the string with special characters - \\B
1482:             * gets Name in CANONICAL format
1483:             * compares with expected value of name - \\b
1484:             */
1485:            public void testNameSpecialChars_CANONICAL_02() throws Exception {
1486:                String dn = "CN=\\\\B";
1487:                X500Principal principal = new X500Principal(dn);
1488:                String s = principal.getName(X500Principal.CANONICAL);
1489:                assertEquals("cn=\\\\b", s);
1490:
1491:            }
1492:
1493:            /**
1494:             * Inits X500Principal with the string with special characters - ABC"DEF"
1495:             * gets encoding
1496:             * compares with expected encoding
1497:             */
1498:            public void testNameWithQuotation() throws Exception {
1499:                String dn = "CN=\"ABCDEF\"";
1500:
1501:                X500Principal principal = new X500Principal(dn);
1502:                byte[] enc = principal.getEncoded();
1503:                assertTrue(Arrays.equals(new byte[] { 0x30, 0x11, 0x31, 0x0F,
1504:                        0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x06,
1505:                        0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }, enc));
1506:
1507:            }
1508:
1509:            /**
1510:             * Inits X500Principal with the string with special characters - "ABCDEF
1511:             * checks if the proper exception is thrown
1512:             */
1513:            public void testNameWithQuotation_01() throws Exception {
1514:                String dn = "CN=\"ABCDEF";
1515:                try {
1516:                    new X500Principal(dn);
1517:                    fail("No IllegalArgumentException on string with no closing quotations");
1518:                } catch (IllegalArgumentException e) {
1519:                }
1520:            }
1521:
1522:            /**
1523:             * Inits X500Principal with the string with special characters - ABC"D#EF"
1524:             * gets encoding
1525:             * compares with expected encoding
1526:             */
1527:            public void testNameWithQuotation_02() throws Exception {
1528:                String dn = "CN=\"ABCD#EF\"";
1529:                X500Principal principal = new X500Principal(dn);
1530:                byte[] enc = principal.getEncoded();
1531:                assertTrue(Arrays.equals(new byte[] { 0x30, 0x12, 0x31, 0x10,
1532:                        0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x07,
1533:                        0x41, 0x42, 0x43, 0x44, 0x23, 0x45, 0x46 }, enc));
1534:            }
1535:
1536:            /**
1537:             * Inits X500Principal with the string with special characters - ABC"DEF"
1538:             * Compatibility issue: according RFC 2253 such string is invalid
1539:             * but we accept it, not string char is escaped
1540:             */
1541:            public void testNameWithQuotation_03() throws Exception {
1542:                String dn = "CN=ABC\"DEF\"";
1543:                X500Principal principal = new X500Principal(dn);
1544:                assertEquals("CN=ABC\\\"DEF\\\"", principal
1545:                        .getName(X500Principal.RFC2253));
1546:            }
1547:
1548:            /**
1549:             * Inits X500Principal with the string with special characters - ABC"DEF"
1550:             * gets Name in RFC1779 format
1551:             * compares with expected value of name - "ABCDEF"
1552:             */
1553:            public void testNameSpecialChars_RFC1779_03() throws Exception {
1554:                String dn = "CN=\"ABCDEF\"";
1555:                X500Principal principal = new X500Principal(dn);
1556:                String s = principal.getName(X500Principal.RFC1779);
1557:                assertEquals("CN=ABCDEF", s);
1558:
1559:            }
1560:
1561:            /**
1562:             * Inits X500Principal with the string with special characters - ABC"DEF"
1563:             * gets Name in RFC2253 format
1564:             * compares with expected value of name - ABC"DEF"
1565:             */
1566:            public void testNameSpecialChars_RFC2253_03() throws Exception {
1567:                String dn = "CN=\"ABCDEF\"";
1568:                X500Principal principal = new X500Principal(dn);
1569:                String s = principal.getName(X500Principal.RFC2253);
1570:                assertEquals("CN=ABCDEF", s);
1571:
1572:            }
1573:
1574:            /**
1575:             * Inits X500Principal with the string with special characters - ABC"DEF"
1576:             * gets Name in CANONICAL format
1577:             * compares with expected value of name - abc"def"
1578:             */
1579:            public void testNameSpecialChars_CANONICAL_03() throws Exception {
1580:                String dn = "CN=\"ABCDEF\"";
1581:                X500Principal principal = new X500Principal(dn);
1582:                String s = principal.getName(X500Principal.CANONICAL);
1583:                assertEquals("cn=abcdef", s);
1584:
1585:            }
1586:
1587:            /**
1588:             * Inits X500Principal with the string with special characters - ABC"D#EF"
1589:             * gets Name in RFC1779 format
1590:             * compares with expected value of name - "ABCD#EF"
1591:             */
1592:            public void testNameSpecialChars_RFC1779_04() throws Exception {
1593:                String dn = "CN=\"ABCD#EF\"";
1594:                X500Principal principal = new X500Principal(dn);
1595:                String s = principal.getName(X500Principal.RFC1779);
1596:                assertEquals("CN=\"ABCD#EF\"", s);
1597:
1598:            }
1599:
1600:            /**
1601:             * Inits X500Principal with the string with special characters - ABC"D#EF"
1602:             * gets Name in RFC1779 format
1603:             * compares with expected value of name - ABCD\#EF
1604:             */
1605:            public void testNameSpecialChars_RFC2253_04() throws Exception {
1606:                String dn = "CN=\"ABCD#EF\"";
1607:                X500Principal principal = new X500Principal(dn);
1608:                String s = principal.getName(X500Principal.RFC2253);
1609:                assertEquals("CN=ABCD\\#EF", s);
1610:
1611:            }
1612:
1613:            /**
1614:             * Inits X500Principal with the string with special characters - ABC"D#EF"
1615:             * gets Name in RFC1779 format
1616:             * compares with expected value of name - abc"d#ef"
1617:             */
1618:            public void testNameSpecialChars_CANONICAL_04() throws Exception {
1619:                String dn = "CN=\"ABCD#EF\"";
1620:                X500Principal principal = new X500Principal(dn);
1621:                String s = principal.getName(X500Principal.CANONICAL);
1622:                assertEquals("cn=abcd#ef", s);
1623:
1624:            }
1625:
1626:            /**
1627:             * Inits X500Principal with the string with special characters - X#YZ
1628:             * gets Name in RFC1779 format
1629:             * compares with expected value of name - "X#YZ"
1630:             */
1631:            public void testNameSpecialChars_RFC1779_05() {
1632:                String dn = "CN=X#YZ";
1633:                X500Principal principal = new X500Principal(dn);
1634:
1635:                String s = principal.getName(X500Principal.RFC1779);
1636:                assertEquals("CN=\"X#YZ\"", s);
1637:
1638:            }
1639:
1640:            /**
1641:             * Inits X500Principal with the string with special characters - X#YZ
1642:             * gets Name in RFC2253 format
1643:             * compares with expected value of name - X\#YZ
1644:             */
1645:            public void testNameSpecialChars_RFC2253_05() {
1646:                String dn = "CN=X#YZ";
1647:                X500Principal principal = new X500Principal(dn);
1648:
1649:                String s = principal.getName(X500Principal.RFC2253);
1650:
1651:                assertEquals("CN=X\\#YZ", s);
1652:
1653:            }
1654:
1655:            /**
1656:             * Inits X500Principal with the string with special characters - X#YZ
1657:             * gets Name in CANONICAL format
1658:             * compares with expected value of name - x#yz
1659:             */
1660:            public void testNameSpecialChars_CANONICAL_05() {
1661:                String dn = "CN=X#YZ";
1662:                X500Principal principal = new X500Principal(dn);
1663:
1664:                String s = principal.getName(X500Principal.CANONICAL);
1665:                assertEquals("cn=x#yz", s);
1666:
1667:            }
1668:
1669:            /**
1670:             * Inits X500Principal with the string with special characters - CN=\#XYZ
1671:             * gets Name in RFC1779 format
1672:             * compares with expected value of name - CN="#XYZ"
1673:             */
1674:            public void testNameSpecialChars_RFC1779_6() throws Exception {
1675:                String dn = "CN=\\#XYZ";
1676:                X500Principal principal = new X500Principal(dn);
1677:                String s = principal.getName(X500Principal.RFC1779);
1678:                assertEquals("CN=\"#XYZ\"", s);
1679:
1680:            }
1681:
1682:            /**
1683:             * Inits X500Principal with the string with special characters - CN=\#XYZ
1684:             * gets Name in RFC2253 format
1685:             * compares with expected value of name - CN=\#XYZ
1686:             */
1687:            public void testNameSpecialChars_RFC2253_6() throws Exception {
1688:                String dn = "CN=\\#XYZ";
1689:                X500Principal principal = new X500Principal(dn);
1690:                String s = principal.getName(X500Principal.RFC2253);
1691:                assertEquals("CN=\\#XYZ", s);
1692:            }
1693:
1694:            /**
1695:             * Inits X500Principal with the string with special characters - CN=\#XYZ
1696:             * gets Name in CANONICAL format
1697:             * compares with expected value of name - cn=\#xyz
1698:             */
1699:            public void testNameSpecialChars_CANONICAL_6() throws Exception {
1700:                String dn = "CN=\\#XYZ";
1701:                X500Principal principal = new X500Principal(dn);
1702:                String s = principal.getName(X500Principal.CANONICAL);
1703:                assertEquals("cn=\\#xyz", s);
1704:            }
1705:
1706:            /**
1707:             * Inits X500Principal with the string with special characters - B\'space'
1708:             * gets Name in RFC1779 format
1709:             * compares with expected value of name - "B "
1710:             */
1711:            public void testNameSpaces_RFC1779() throws Exception {
1712:                String dn = "CN=A,CN=B\\ ";
1713:                X500Principal principal = new X500Principal(dn);
1714:                String s = principal.getName(X500Principal.RFC1779);
1715:                assertEquals("CN=A, CN=\"B \"", s);
1716:
1717:            }
1718:
1719:            /**
1720:             * Inits X500Principal with the string with special characters - B\'space'
1721:             * gets Name in RFC2253 format
1722:             * compares with expected value of name - B\'space'
1723:             */
1724:            public void testNameSpaces_RFC2253() throws Exception {
1725:                String dn = "CN=A,CN=B\\ ";
1726:                X500Principal principal = new X500Principal(dn);
1727:                String s = principal.getName(X500Principal.RFC2253);
1728:                assertEquals("CN=A,CN=B\\ ", s);
1729:
1730:            }
1731:
1732:            /**
1733:             * Inits X500Principal with the string with special characters - B\'space'
1734:             * gets Name in CANONICAL format
1735:             * compares with expected value of name - B\
1736:             */
1737:            public void testNameSpaces_CANONICAL() throws Exception {
1738:                String dn = "CN=A,CN=B\\ ";
1739:                X500Principal principal = new X500Principal(dn);
1740:                String s = principal.getName(X500Principal.CANONICAL);
1741:                assertEquals("cn=a,cn=b", s);
1742:
1743:            }
1744:
1745:            /**
1746:             * Inits X500Principal with the string with special characters - "B'space''space''space'A"
1747:             * gets Name in RFC1779 format
1748:             * compares with expected value of name - "B   A"
1749:             */
1750:            public void testNameSpaces_RFC1779_01() throws Exception {
1751:                String dn = "CN=\"B   A\"";
1752:                X500Principal principal = new X500Principal(dn);
1753:                String s = principal.getName(X500Principal.RFC1779);
1754:                assertEquals("CN=B   A", s);
1755:
1756:            }
1757:
1758:            /**
1759:             * Inits X500Principal with the string with special characters - "B'space''space''space'A"
1760:             * gets Name in 2253 format
1761:             * compares with expected value of name - B'space''space''space'A
1762:             */
1763:            public void testNameSpaces_RFC2253_01() throws Exception {
1764:                String dn = "CN=\"B   A\"";
1765:                X500Principal principal = new X500Principal(dn);
1766:                String s = principal.getName(X500Principal.RFC2253);
1767:                assertEquals("CN=B   A", s);
1768:
1769:            }
1770:
1771:            /**
1772:             * Inits X500Principal with the string with special characters - "B'space''space''space'A"
1773:             * gets Name in CANONICAL format
1774:             * compares with expected value of name - b'space'a
1775:             */
1776:            public void testNameSpaces_CANONICAL_01() throws Exception {
1777:                String dn = "CN=\"B   A\"";
1778:                X500Principal principal = new X500Principal(dn);
1779:                String s = principal.getName(X500Principal.CANONICAL);
1780:                assertEquals("cn=b a", s);
1781:
1782:            }
1783:
1784:            /**
1785:             * Inits X500Principal with the string with special characters - \\'space''space'B
1786:             * gets Name in RFC1779 format
1787:             * compares with expected value of name - "  B"
1788:             */
1789:            public void testNameSpaces_RFC1779_02() throws Exception {
1790:                String dn = "CN=\\  B";
1791:                X500Principal principal = new X500Principal(dn);
1792:                String s = principal.getName(X500Principal.RFC1779);
1793:                assertEquals("CN=\"  B\"", s);
1794:
1795:            }
1796:
1797:            /**
1798:             * Inits X500Principal with the string with special characters - \\'space''space'B
1799:             * gets Name in RFC1779 format
1800:             * compares with expected value of name - \'space''space'B
1801:             */
1802:            public void testNameSpaces_RFC2253_02() throws Exception {
1803:                String dn = "CN=\\  B";
1804:                X500Principal principal = new X500Principal(dn);
1805:                String s = principal.getName(X500Principal.RFC2253);
1806:                assertEquals("CN=\\  B", s);
1807:
1808:            }
1809:
1810:            /**
1811:             * Inits X500Principal with the string with special characters - \\'space''space'B
1812:             * gets Name in CANONICAL format
1813:             * compares with expected value of name - \'space''space'b
1814:             */
1815:            public void testNameSpaces_CANONICAL_02() throws Exception {
1816:                String dn = "CN=\\  B";
1817:                X500Principal principal = new X500Principal(dn);
1818:                String s = principal.getName(X500Principal.CANONICAL);
1819:                assertEquals("cn=b", s);
1820:
1821:            }
1822:
1823:            /**
1824:             * Inits X500Principal with the string with special characters - ""B
1825:             * checks if the proper exception is thrown
1826:             */
1827:            public void testNameQu() throws Exception {
1828:                String dn = "CN=\"\"B";
1829:                try {
1830:                    new X500Principal(dn);
1831:                    fail("No IllegalArgumentException on improper string");
1832:                } catch (IllegalArgumentException e) {
1833:                }
1834:            }
1835:
1836:            /**
1837:             * Inits X500Principal with the string with special characters - "A\"B"
1838:             * gets Name in RFC1779 format
1839:             * compares with expected value of name - "A\"B"
1840:             */
1841:            public void testNameQu_RFC1779_2() throws Exception {
1842:                String dn = "CN=\"A\\\"B\"";
1843:                X500Principal principal = new X500Principal(dn);
1844:                String s = principal.getName(X500Principal.RFC1779);
1845:                assertEquals("CN=\"A\\\"B\"", s);
1846:            }
1847:
1848:            /**
1849:             * Inits X500Principal with the string with special characters - "A\"B"
1850:             * gets Name in RFC2253 format
1851:             * compares with expected value of name - A\"B
1852:             */
1853:            public void testNameQu_RFC2253_2() throws Exception {
1854:                String dn = "CN=\"A\\\"B\"";
1855:                X500Principal principal = new X500Principal(dn);
1856:                String s = principal.getName(X500Principal.RFC2253);
1857:                assertEquals("CN=A\\\"B", s);
1858:            }
1859:
1860:            /**
1861:             * Inits X500Principal with the string with special characters - "A\"B"
1862:             * gets Name in CANONICAL format
1863:             * compares with expected value of name - a\"b
1864:             */
1865:            public void testNameQu_CANONICAL_2() throws Exception {
1866:                String dn = "CN=\"A\\\"B\"";
1867:                X500Principal principal = new X500Principal(dn);
1868:                String s = principal.getName(X500Principal.CANONICAL);
1869:                assertEquals("cn=a\\\"b", s);
1870:
1871:            }
1872:
1873:            /**
1874:             * Inits X500Principal with the string with special characters - "A\""
1875:             * gets Name in RFC1779 format
1876:             * compares with expected value of name - "A\""
1877:             */
1878:            public void testNameQu_RFC1779_3() throws Exception {
1879:                String dn = "CN=\"A\\\"\"";
1880:                X500Principal principal = new X500Principal(dn);
1881:                String s = principal.getName(X500Principal.RFC1779);
1882:                assertEquals("CN=\"A\\\"\"", s);
1883:            }
1884:
1885:            /**
1886:             * Inits X500Principal with the string with special characters - "A\""
1887:             * gets Name in RFC2253 format
1888:             * compares with expected value of name - A\"
1889:             */
1890:            public void testNameQu_RFC2253_3() throws Exception {
1891:                String dn = "CN=\"A\\\"\"";
1892:                X500Principal principal = new X500Principal(dn);
1893:                String s = principal.getName(X500Principal.RFC2253);
1894:                assertEquals("CN=A\\\"", s);
1895:            }
1896:
1897:            /**
1898:             * Inits X500Principal with the string with special characters - "A\""
1899:             * gets Name in CANONICAL format
1900:             * compares with expected value of name - A\"
1901:             */
1902:            public void testNameQu_CANONICAL_3() throws Exception {
1903:                String dn = "CN=\"A\\\"\"";
1904:                X500Principal principal = new X500Principal(dn);
1905:                String s = principal.getName(X500Principal.CANONICAL);
1906:                assertEquals("cn=a\\\"", s);
1907:
1908:            }
1909:
1910:            /**
1911:             * Inits X500Principal with the string with special characters - "A\", C=B"
1912:             * gets Name in RFC1779 format
1913:             * compares with expected value of name - "A\", C=B"
1914:             */
1915:            public void testNameQu_4() throws Exception {
1916:                String dn = "CN=\"A\\\", C=B\"";
1917:                X500Principal principal = new X500Principal(dn);
1918:                String s = principal.getName(X500Principal.RFC1779);
1919:                assertEquals("CN=\"A\\\", C=B\"", s);
1920:
1921:            }
1922:
1923:            /**
1924:             * Inits X500Principal with the string with special characters - CN="A\\", C=B
1925:             * gets Name in RFC1779 format
1926:             * compares with expected value of name - CN="A\\", C=B
1927:             */
1928:            public void testNameQu_5() throws Exception {
1929:                String dn = "CN=\"A\\\\\", C=B";
1930:                X500Principal principal = new X500Principal(dn);
1931:                String s = principal.getName(X500Principal.RFC1779);
1932:                assertEquals("CN=\"A\\\\\", C=B", s);
1933:
1934:            }
1935:
1936:            /**
1937:             * Inits X500Principal with the string with special characters - CN=A\nB
1938:             * gets Name in RFC1779 format
1939:             * compares with expected value of name - CN="A\nB"
1940:             */
1941:            public void testNameCR_RFC1779() throws Exception {
1942:                String dn = "CN=A\nB";
1943:                X500Principal principal = new X500Principal(dn);
1944:                String s = principal.getName(X500Principal.RFC1779);
1945:                assertEquals("CN=A\nB", s);
1946:            }
1947:
1948:            /**
1949:             * Inits X500Principal with the string with special characters - CN=A\nB
1950:             * gets Name in RFC2253 format
1951:             * compares with expected value of name - CN=A\nB
1952:             */
1953:            public void testNameCR_RFC2253() throws Exception {
1954:                String dn = "CN=A\nB";
1955:                X500Principal principal = new X500Principal(dn);
1956:                String s = principal.getName(X500Principal.RFC2253);
1957:                assertEquals("CN=A\nB", s);
1958:            }
1959:
1960:            /**
1961:             * Inits X500Principal with the string with special characters - CN=A\nB
1962:             * gets Name in CANONICAL format
1963:             * compares with expected value of name - cn=a\nb
1964:             */
1965:            public void testNameCR_CANONICAL() throws Exception {
1966:                String dn = "CN=A\nB";
1967:                X500Principal principal = new X500Principal(dn);
1968:                String s = principal.getName(X500Principal.CANONICAL);
1969:                assertEquals("cn=a\nb", s);
1970:            }
1971:
1972:            public static final String[] RFC2253_SPECIAL = new String[] { ",",
1973:                    "=", "+", "<", ">", "#", ";" };
1974:
1975:            public void testValidDN() throws Exception {
1976:
1977:                TestList list = new TestList();
1978:
1979:                list.add("", "", "", "", new byte[] { 0x30, 0x00 }); // empty RDN sequence
1980:
1981:                // sequence of RDN: RDN *("," RDN)
1982:                list.add("CN=A,C=B", "CN=A,C=B", "CN=A, C=B", "cn=a,c=b");
1983:                list.add("C=B,CN=A", "C=B,CN=A", "C=B, CN=A", "c=b,cn=a");
1984:                list.add("CN=A,CN=A", "CN=A,CN=A", "CN=A, CN=A", "cn=a,cn=a"); // duplicate RDNs
1985:
1986:                // sequence of RDN: RFC 1779 compatibility
1987:                list.add("CN=A , C=B", "CN=A,C=B", "CN=A, C=B");
1988:                list.add("CN=A  ,  C=B", "CN=A,C=B", "CN=A, C=B");
1989:                list.add("CN=A;C=B", "CN=A,C=B", "CN=A, C=B");
1990:                list.add("CN=A ; C=B", "CN=A,C=B", "CN=A, C=B");
1991:                //FIXME list.add("CN=A\r,\rC=B", "CN=A,C=B"); // <CR> & comma => comma
1992:                list.add("  CN=A,C=B  ", "CN=A,C=B", "CN=A, C=B"); // spaces at beg&end
1993:                list.add("  CN=A,C=\"B\"  ", "CN=A,C=B", "CN=A, C=B"); // spaces at beg&end
1994:
1995:                // set of ATAV: ATAV *("+" ATAV)
1996:                list.add("CN=A+ST=CA", "CN=A+ST=CA", "CN=A + ST=CA",
1997:                        "cn=a+st=ca");
1998:                list.add("CN=A+CN=A", "CN=A+CN=A", "CN=A + CN=A", "cn=a+cn=a"); // duplicate AT
1999:                list.add("2.5.4.3=A+2.5.4.3=A", "CN=A+CN=A", "CN=A + CN=A",
2000:                        "cn=a+cn=a"); // duplicate AT
2001:
2002:                // set of ATAV: RFC 1779 compatibility
2003:                list.add("CN=A + ST=CA", "CN=A+ST=CA", "CN=A + ST=CA");
2004:                list.add("CN=A  +  ST=CA", "CN=A+ST=CA", "CN=A + ST=CA");
2005:                //FIXME list.add("CN=A\r+\rST=CA", "CN=A+ST=CA"); // <CR> & '+' => '+'
2006:
2007:                // ATAV = AttributeType "=" AttributeValue
2008:                list.add("CN=A", "CN=A", "CN=A");
2009:                list.add("cn=A", "CN=A", "CN=A"); // AT case insensitive
2010:                list.add("cN=A", "CN=A", "CN=A"); // AT case insensitive
2011:                list.add("cn=a", "CN=a", "CN=a"); // AT case insensitive
2012:
2013:                // ATAV : RFC 1779 compatibility
2014:                list.add("CN = A", "CN=A", "CN=A");
2015:                list.add("CN  =  A", "CN=A", "CN=A");
2016:                // FIXME list.add("CN\r=\rA", "CN=A"); // <CR> & '=' => '='
2017:
2018:                // AttributeType = <name string> | <OID>
2019:                // testing OID case :  OID => <name string>
2020:                // tested all OIDs from RFC 2253 (2.3) and RFC 1779 (Table 1)
2021:
2022:                // different variants of 2.5.4.3 (CN) OID
2023:                list.add("OID.2.5.4.3=A", "CN=A", "CN=A");
2024:                list.add("oid.2.5.4.3=A", "CN=A", "CN=A");
2025:                list.add("2.5.4.3=A", "CN=A", "CN=A");
2026:                list.add("02.5.4.3=A", "CN=A", "CN=A"); // first: 02 => 2
2027:                list.add("2.5.4.0003=A", "CN=A", "CN=A"); // last: 0003 => 3
2028:
2029:                // the rest of OIDs
2030:                list.add("2.5.4.7=A", "L=A", "L=A", "l=a");
2031:                list.add("2.5.4.8=A", "ST=A", "ST=A", "st=a");
2032:                list.add("2.5.4.10=A", "O=A", "O=A", "o=a");
2033:                list.add("2.5.4.11=A", "OU=A", "OU=A", "ou=a");
2034:                list.add("2.5.4.6=A", "C=A", "C=A", "c=a");
2035:                list.add("2.5.4.9=A", "STREET=A", "STREET=A", "street=a");
2036:                list.add("0.9.2342.19200300.100.1.25=A", "DC=A",
2037:                        "OID.0.9.2342.19200300.100.1.25=A", "dc=a");
2038:                list.add("0.9.2342.19200300.100.1.1=A", "UID=A",
2039:                        "OID.0.9.2342.19200300.100.1.1=A", "uid=a");
2040:
2041:                // attribute types from RFC 2459 (see Appendix A)
2042:                // keywords are from the API spec
2043:                list.add("T=A", "2.5.4.12=#130141", "OID.2.5.4.12=A",
2044:                        "2.5.4.12=#130141");
2045:                list.add("DNQ=A", "2.5.4.46=#130141", "OID.2.5.4.46=A",
2046:                        "2.5.4.46=#130141");
2047:                list.add("DNQUALIFIER=A", "2.5.4.46=#130141", "OID.2.5.4.46=A",
2048:                        "2.5.4.46=#130141");
2049:                list.add("SURNAME=A", "2.5.4.4=#130141", "OID.2.5.4.4=A",
2050:                        "2.5.4.4=#130141");
2051:                list.add("GIVENNAME=A", "2.5.4.42=#130141", "OID.2.5.4.42=A",
2052:                        "2.5.4.42=#130141");
2053:                list.add("INITIALS=A", "2.5.4.43=#130141", "OID.2.5.4.43=A",
2054:                        "2.5.4.43=#130141");
2055:                list.add("GENERATION=A", "2.5.4.44=#130141", "OID.2.5.4.44=A",
2056:                        "2.5.4.44=#130141");
2057:                list.add("EMAILADDRESS=A", "1.2.840.113549.1.9.1=#130141",
2058:                        "OID.1.2.840.113549.1.9.1=A",
2059:                        "1.2.840.113549.1.9.1=#130141", null, (byte) 0x05); //FIXME bug???
2060:                list.add("SERIALNUMBER=A", "2.5.4.5=#130141", "OID.2.5.4.5=A",
2061:                        "2.5.4.5=#130141");
2062:
2063:                // AttributeValue => BER encoding (if OID in dotted-decimal form)
2064:                // see RFC 2253 (2.4)
2065:                list
2066:                        .add("OID.2.5.4.12=A", "2.5.4.12=#130141",
2067:                                "OID.2.5.4.12=A");
2068:                list
2069:                        .add("oid.2.5.4.12=A", "2.5.4.12=#130141",
2070:                                "OID.2.5.4.12=A");
2071:                list.add("2.5.4.12=A", "2.5.4.12=#130141", "OID.2.5.4.12=A");
2072:                list.add("1.1=A", "1.1=#130141", "OID.1.1=A");
2073:
2074:                //
2075:                // AttributeValue first alternative : *( stringchar / pair )
2076:                // testing pair characters.
2077:                //
2078:                // Note: for RFC1779 quoted string is returned (unspecified)
2079:                //
2080:                list.add("CN=", "CN=", "CN="); // zero string chars
2081:                list.add("CN= ", "CN=", "CN="); // zero string chars
2082:                list.add("CN=A+ST=", "CN=A+ST=", "CN=A + ST="); // zero string chars
2083:                list.add("CN=+ST=A", "CN=+ST=A", "CN= + ST=A"); // empty value for 1 RDN
2084:                list.add("CN=A+ST= ", "CN=A+ST=", "CN=A + ST="); // empty value for 1 RDN
2085:                list.add("CN=+ST=", "CN=+ST=", "CN= + ST="); // empty value for both RDNs
2086:                list.add("CN=,ST=B", "CN=,ST=B", "CN=, ST=B"); // empty value for 1 RDN
2087:                list.add("CN=,ST=", "CN=,ST=", "CN=, ST="); // empty value for both RDNs
2088:                list.add("CN=;ST=B", "CN=,ST=B", "CN=, ST=B"); // empty value for 1 RDN
2089:                list.add("CN=;ST=", "CN=,ST=", "CN=, ST="); // empty value for both RDNs
2090:                for (String element : RFC2253_SPECIAL) {
2091:                    // \special
2092:                    list.add("CN=\\" + element, "CN=\\" + element, "CN=\""
2093:                            + element + "\"");
2094:
2095:                    // A + \special + B
2096:                    list.add("CN=A\\" + element + "B",
2097:                            "CN=A\\" + element + "B", "CN=\"A" + element
2098:                                    + "B\"");
2099:                }
2100:
2101:                // pair = \" 
2102:                list
2103:                        .add("CN=\\\"", "CN=\\\"", "CN=\"\\\"\"", null,
2104:                                (byte) 0x02);
2105:                list.add("CN=\\\"A", "CN=\\\"A", "CN=\"\\\"A\"", null,
2106:                        (byte) 0x02);
2107:                list.add("CN=\\\",C=\\\"", "CN=\\\",C=\\\"",
2108:                        "CN=\"\\\"\", C=\"\\\"\"", null, (byte) 0x02); // 2 RDN
2109:                list.add("CN=A\\\"B", "CN=A\\\"B", "CN=\"A\\\"B\"", null,
2110:                        (byte) 0x02); // A\"B
2111:                list.add("CN=A ST=B", "CN=A ST\\=B", "CN=\"A ST=B\""); // no RDN separator
2112:
2113:                // pair = \space 
2114:                list.add("CN=\\ ", "CN=\\ ", "CN=\" \"", "cn=");
2115:
2116:                // pair = \hexpair
2117:                list.add("CN=\\41", "CN=A", "CN=A"); // 0x41=='A'
2118:                list.add("CN=\\41\\2C", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2C=','
2119:                list.add("CN=\\41\\2c", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2c=','
2120:                list.add("CN=\\D0\\AF", "CN=" + ((char) 1071), "CN="
2121:                        + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B,
2122:                        0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03,
2123:                        // UTF8 String
2124:                        0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // 0xD0AF == the last letter(capital) of Russian alphabet
2125:                list.add("CN=\\D0\\AFA\\41", "CN=" + ((char) 1071) + "AA",
2126:                        "CN=" + ((char) 1071) + "AA", new byte[] { 0x30, 0x0F,
2127:                                0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55, 0x04,
2128:                                0x03,
2129:                                // UTF8 String
2130:                                0x0C, 0x04, (byte) 0xD0, (byte) 0xAF, 0x41,
2131:                                0x41 }); // 0xD0AF == the last letter(capital) of Russian alphabet
2132:                // UTF-8(0xE090AF) is non-shortest form of UTF-8(0xD0AF)
2133:                //FIXME list.add("CN=\\E0\\90\\AF", "CN=" + ((char) 1071), "CN="
2134:                //        + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30,
2135:                //        0x09, 0x06, 0x03, 0x55, 0x04, 0x03,
2136:                //        // UTF8 String
2137:                //        0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); 
2138:                // UTF-8(0xF08090AF) is non-shortest form of UTF-8(0xD0AF)
2139:                //FIXME list.add("CN=\\F0\\80\\90\\AF", "CN=" + ((char) 1071), "CN="
2140:                //        + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30,
2141:                //        0x09, 0x06, 0x03, 0x55, 0x04, 0x03,
2142:                //        // UTF8 String
2143:                //        0x0C, 0x02, (byte) 0xD0, (byte) 0xAF });
2144:                //FIXME        list.add("CN=\\D0", "CN=" + ((char) 65533), "CN=" + ((char) 65533),
2145:                //                new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
2146:                //                        0x55, 0x04, 0x03,
2147:                //                        // UTF8 String
2148:                //                        0x0C, 0x01, 0x3F }); // 0xD0 is not correct UTF8 char => '?'
2149:                list.add("CN=\\41+ST=A", "CN=A+ST=A", "CN=A + ST=A"); // 0x41=='A'
2150:                list
2151:                        .add("CN=\\41\\2C+ST=A", "CN=A\\,+ST=A",
2152:                                "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2C=','
2153:                list
2154:                        .add("CN=\\41\\2c+ST=A", "CN=A\\,+ST=A",
2155:                                "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2c=','
2156:
2157:                // stringchar '=' or not leading '#'
2158:                //FIXME RFC 2253 grammar violation: '=' and '#' is a special char 
2159:                list.add("CN==", "CN=\\=", "CN=\"=\"");
2160:                list.add("CN=A=", "CN=A\\=", "CN=\"A=\"");
2161:                list.add("CN=A#", "CN=A\\#", "CN=\"A#\"");
2162:
2163:                // not leading or trailing spaces
2164:                list.add("CN=A B", "CN=A B", "CN=A B", "cn=a b");
2165:                list.add("CN=A\\ B", "CN=A B", "CN=A B", "cn=a b");
2166:                list.add("CN=A \\,B", "CN=A \\,B", "CN=\"A ,B\"", "cn=a \\,b");
2167:
2168:                //not alphabet chars
2169:                list.add("CN=$", "CN=$", "CN=$", new byte[] { 0x30, 0x0C, 0x31,
2170:                        0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
2171:                        //UTF-8 String: "$"
2172:                        0x0C, 0x01, 0x24 });
2173:                list.add("CN=(", "CN=(", "CN=(", new byte[] { 0x30, 0x0C, 0x31,
2174:                        0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
2175:                        //PrintableString: "("
2176:                        0x13, 0x01, 0x28 });
2177:
2178:                //
2179:                //
2180:                // AttributeValue second alternative : "#" hexstring
2181:                //
2182:                //
2183:                list.add("CN=#130141", "CN=A", "CN=A", "cn=a"); // ASN1 Printable hex string = 'A'
2184:                list.add("CN=#140141", "CN=A", "CN=A", "cn=#140141",
2185:                        new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06,
2186:                                0x03, 0x55, 0x04, 0x03, 0x14, 0x01, 0x41 }); // ASN1 Teletex hex string = 'A'
2187:
2188:                list
2189:                        .add("CN=#010100", "CN=#010100", "CN=#010100",
2190:                                "cn=#010100"); // ASN1 Boolean = FALSE
2191:                list
2192:                        .add("CN=#0101fF", "CN=#0101ff", "CN=#0101FF",
2193:                                "cn=#0101ff"); // ASN1 Boolean = TRUE
2194:                //FIXME list.add("CN=#3000", "CN=#3000", "CN=#3000"); // ASN1 Sequence
2195:                //FIXME list.add("CN=#0500", "CN=A", "CN=A"); // ASN1 Null
2196:                list
2197:                        .add("CN= #0101fF", "CN=#0101ff", "CN=#0101FF", // space at beginning 
2198:                                new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30,
2199:                                        0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
2200:                                        0x01, 0x01, (byte) 0xFF } // ASN.1 Boolean = TRUE
2201:                        );
2202:                list.add("CN= #0101fF+ST=A", "CN=#0101ff+ST=A",
2203:                        "CN=#0101FF + ST=A", "cn=#0101ff+st=a"); //space
2204:                list
2205:                        .add("CN= #0101fF ", "CN=#0101ff", "CN=#0101FF", // space at the end
2206:                                new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30,
2207:                                        0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
2208:                                        0x01, 0x01, (byte) 0xFF } // ASN.1 Boolean = TRUE
2209:                                , (byte) 0x00);
2210:
2211:                //FIXME unspecified output for RFC1779
2212:                //FIXME list.add("CN=#1C0141", "CN=A", "CN=A"); // ASN1 Universal hex string = 'A'
2213:                //FIXME list.add("CN=#1E0141", "CN=A", "CN=A"); // ASN1 Bmp hex string = 'A'
2214:
2215:                //
2216:                // AttributeValue third alternative : " *( quotechar / pair ) "
2217:                // quotechar = <any character except '\' or '"' >
2218:                // 
2219:                // Note:
2220:                // RFC2253: passed quoted AV string is unquoted, special chars are escaped
2221:                // RFC1779: escaped quoted chars are unescaped 
2222:                //
2223:                list.add("CN=\"\"", "CN=", "CN="); // empty quoted string
2224:                list.add("CN=\"A\"", "CN=A", "CN=A"); // "A"
2225:                for (String element : RFC2253_SPECIAL) {
2226:                    // "special" => \special
2227:                    list.add("CN=\"" + element + "\"", "CN=\\" + element,
2228:                            "CN=\"" + element + "\"");
2229:
2230:                    // "A + special + B" => A + \special + B
2231:                    list.add("CN=\"A" + element + "B\"", "CN=A\\" + element
2232:                            + "B", "CN=\"A" + element + "B\"");
2233:                }
2234:                for (String element : RFC2253_SPECIAL) {
2235:                    // "\special" => \special
2236:                    list.add("CN=\"\\" + element + "\"", "CN=\\" + element,
2237:                            "CN=\"" + element + "\"");
2238:
2239:                    // "A + \special + B" => A + \special + B
2240:                    list.add("CN=\"A\\" + element + "B\"", "CN=A\\" + element
2241:                            + "B", "CN=\"A" + element + "B\"");
2242:                }
2243:                list.add("CN=\"\\\"\"", "CN=\\\"", "CN=\"\\\"\"", null,
2244:                        (byte) 0x02); // "\""
2245:                list.add("CN=\"A\\\"B\"", "CN=A\\\"B", "CN=\"A\\\"B\"", null,
2246:                        (byte) 0x02); // "A\"B"
2247:
2248:                // pair = \hexpair (test cases are the same as for the first alternative)
2249:                list.add("CN=\"\\41\"", "CN=A", "CN=A"); // 0x41=='A'
2250:                list.add("CN=\"\\41\\2C\"", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2C=','
2251:                list.add("CN=\"\\41\\2c\"", "CN=A\\,", "CN=\"A,\""); // 0x41=='A', 0x2c=','
2252:                list.add("CN=\"\\D0\\AF\"", "CN=" + ((char) 1071), "CN="
2253:                        + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B,
2254:                        0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03,
2255:                        // UTF8 String
2256:                        0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // 0xD0AF == the last letter(capital) of Russian alphabet
2257:                list.add("CN=\"\\D0\\AFA\\41\"", "CN=" + ((char) 1071) + "AA",
2258:                        "CN=" + ((char) 1071) + "AA", new byte[] { 0x30, 0x0F,
2259:                                0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55, 0x04,
2260:                                0x03,
2261:                                // UTF8 String
2262:                                0x0C, 0x04, (byte) 0xD0, (byte) 0xAF, 0x41,
2263:                                0x41 }); // 0xD0AF == the last letter(capital) of Russian alphabet
2264:                list.add("CN=\"\\E0\\90\\AF\"", "CN=" + ((char) 1071), "CN="
2265:                        + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31, 0x0B,
2266:                        0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03,
2267:                        // UTF8 String
2268:                        0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // UTF8(0xE090AF that is not quite correct)== UTF8(0xD0AF) == the last letter(capital) of Russian alphabet
2269:                list.add("CN=\"\\F0\\80\\90\\AF\"", "CN=" + ((char) 1071),
2270:                        "CN=" + ((char) 1071), new byte[] { 0x30, 0x0D, 0x31,
2271:                                0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03,
2272:                                // UTF8 String
2273:                                0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }); // UTF8(0xF08090AF that is not quite correct)== UTF8(0xD0AF) == the last letter(capital) of Russian alphabet
2274:
2275:                list.add("CN=\"\\41\"+ST=A", "CN=A+ST=A", "CN=A + ST=A"); // 0x41=='A'
2276:                list.add("CN=\"\\41\\2C\"+ST=A", "CN=A\\,+ST=A",
2277:                        "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2C=','
2278:                list.add("CN=\"\\41\\2c\"+ST=A", "CN=A\\,+ST=A",
2279:                        "CN=\"A,\" + ST=A"); // 0x41=='A', 0x2c=','
2280:
2281:                // AttributeValue third alternative : RFC 1779 compatibility
2282:                //FIXME list.add("CN=\"\r\"", "CN=\"\r\""); // "<CR>" 
2283:                //FIXME list.add("CN=\"\\\r\"", "CN=\"\\\r\""); // "\<CR>" 
2284:
2285:                // AttributeValue : RFC 1779 compatibility
2286:                list.add("CN=  A  ", "CN=A", "CN=A", "cn=a"); // leading & trailing spaces
2287:                list.add("CN=\\  A  ", "CN=\\  A", "CN=\"  A\"", "cn=a", null,
2288:                        (byte) 0x01); // escaped leading space
2289:                list.add("CN=  A \\ ", "CN=A \\ ", "CN=\"A  \"", "cn=a", null,
2290:                        (byte) 0x01); // escaped trailing space
2291:
2292:                list.add("CN=  \"A\"  ", "CN=A", "CN=A", "cn=a"); // leading & trailing spaces
2293:
2294:                StringBuffer errorMsg = new StringBuffer();
2295:                for (int i = 0; i < list.size(); i++) {
2296:
2297:                    Object[] obj = list.get(i);
2298:
2299:                    String dn = (String) obj[0];
2300:                    String rfc2253 = (String) obj[1];
2301:                    String rfc1779 = (String) obj[2];
2302:                    String canonical = (String) obj[3];
2303:                    byte[] encoded = (byte[]) obj[4];
2304:                    byte mask = ((byte[]) obj[5])[0];
2305:
2306:                    try {
2307:                        X500Principal p = new X500Principal(dn);
2308:                        if (!rfc2253.equals(p.getName(X500Principal.RFC2253))) {
2309:                            if (!testing || ((mask & 0x01) == 0)) {
2310:
2311:                                errorMsg.append("RFC2253: " + i);
2312:                                errorMsg.append("\tparm: '" + dn + "'");
2313:                                errorMsg.append("\t\texpected: '" + rfc2253
2314:                                        + "'");
2315:                                errorMsg.append("\treturned: '"
2316:                                        + p.getName(X500Principal.RFC2253)
2317:                                        + "'\n");
2318:                            }
2319:                        }
2320:
2321:                        if (!rfc1779.equals(p.getName(X500Principal.RFC1779))) {
2322:                            if (!testing || ((mask & 0x02) == 0)) {
2323:
2324:                                errorMsg.append("RFC1779: " + i);
2325:                                errorMsg.append("\tparm: '" + dn + "'");
2326:                                errorMsg.append("\t\texpected: " + rfc1779
2327:                                        + "'");
2328:                                errorMsg.append("\treturned: '"
2329:                                        + p.getName(X500Principal.RFC1779)
2330:                                        + "'\n");
2331:                            }
2332:                        }
2333:
2334:                        if (canonical != null) {
2335:                            if (!canonical.equals(p
2336:                                    .getName(X500Principal.CANONICAL))) {
2337:                                if (!testing || ((mask & 0x04) == 0)) {
2338:
2339:                                    errorMsg.append("CANONICAL: " + i);
2340:                                    errorMsg.append("\tparm: '" + dn + "'");
2341:                                    errorMsg.append("\t\texpected: "
2342:                                            + canonical + "'");
2343:                                    errorMsg
2344:                                            .append("\treturned: '"
2345:                                                    + p
2346:                                                            .getName(X500Principal.CANONICAL)
2347:                                                    + "'\n");
2348:                                }
2349:                            }
2350:                        }
2351:
2352:                        if (encoded != null) {
2353:                            if (!Arrays.equals(encoded, p.getEncoded())) {
2354:                                if (!testing || ((mask & 0x08) == 0)) {
2355:
2356:                                    errorMsg.append("Unexpected encoding for: "
2357:                                            + i + ", dn= '" + dn + "'\n");
2358:
2359:                                    System.out.println("\nI " + i);
2360:                                    byte[] enc = p.getEncoded();
2361:                                    for (byte element : enc) {
2362:                                        System.out.print(", 0x"
2363:                                                + Integer.toHexString(element));
2364:                                    }
2365:                                }
2366:                            }
2367:                        }
2368:                    } catch (IllegalArgumentException e) {
2369:                        errorMsg.append("IllegalArgumentException: " + i);
2370:                        errorMsg.append("\tparm: '" + dn + "'\n");
2371:                    } catch (Exception e) {
2372:                        errorMsg.append("Exception: " + i);
2373:                        errorMsg.append("\tparm: '" + dn + "'");
2374:                        errorMsg.append("\texcep: " + e.getClass().getName()
2375:                                + "\n");
2376:                    }
2377:                }
2378:
2379:                if (errorMsg.length() != 0) {
2380:                    fail(errorMsg.toString());
2381:                }
2382:
2383:            }
2384:
2385:            public void testInvalidDN() {
2386:                String[] illegalDN = new String[] {
2387:                // RDN
2388:                        //FIXME " ", // space only
2389:                        "CN", // attribute type only
2390:                        "CN=A;", // RFC 1779: BNF allows this, but ...
2391:                        "CN=A,", // RFC 1779: BNF allows this, but ...
2392:                        ",CN=A", // no AttributeType for first RDN
2393:                        "CN=,A", // no AttributeType for second RDN
2394:                        "CN=A+", // no AttributeTypeAndValue for second RDN
2395:                        "CN=#130141 ST=B", // no RDN separator
2396:
2397:                        // AttributeType = <name string> | <OID>
2398:                        "AAA=A", // no such <name string> 
2399:                        "1..1=A", // wrong OID
2400:                        ".1.1=A", // wrong OID
2401:                        "11=A", // wrong OID
2402:                        "1=A", // wrong OID
2403:                        "AID.1.1=A", // wrong OID
2404:                        "1.50=A", // wrong OID
2405:                        "5.1.0=A", // wrong OID
2406:                        "2.-5.4.3=A", // wrong OID
2407:                        "2.5.-4.3=A", // wrong OID
2408:                        "2.5.4-.3=A", // wrong OID
2409:                        //FIXME "2.5.4.-3=A", // wrong OID
2410:
2411:                        // AttributeValue first alternative : *( stringchar / pair )
2412:                        "CN=,", // stringchar = ','
2413:                        //FIXME "CN==",
2414:                        "CN=+", // stringchar = '+'
2415:                        //FIXME "CN=<", // stringchar = '<'
2416:                        //FIXME "CN=>", // stringchar = '>'
2417:                        "CN=#", // stringchar = '#'
2418:                        //FIXME "CN=Z#", // stringchar = '#'
2419:                        "CN=;", // stringchar = ';'
2420:                        "CN=\"", // stringchar = "
2421:                        //FIXME "CN=A\"B", // stringchar = "
2422:                        "CN=\\", // stringchar = \
2423:                        "CN=A\\", // stringchar = \
2424:                        "CN=A\\B", // stringchar = \
2425:                        "CN=\\z", // invalid pair = \z
2426:                        "CN=\\4", // invalid pair = \4
2427:                        "CN=\\4Z", // invalid pair = \4Z
2428:                        "CN=\\4\\2c", // invalid pair = \4\2c
2429:
2430:                        // AttributeValue second alternative : "#" hexstring
2431:                        "CN=#", // no hex string
2432:                        "CN=#2", // no hex pair
2433:                        "CN=#22", // hexpair is not BER encoding
2434:                        "CN=#0001", // invalid BER encoding (missed content)
2435:                        "CN=#000201", // invalid BER encoding (wrong length)
2436:                        "CN=#0002010101", // invalid BER encoding (wrong length)
2437:                        "CN=#00FF", // invalid BER encoding (wrong length)
2438:                        "CN=#ZZ", // not hex pair
2439:
2440:                        // FIXME boolean with indefinite length
2441:                        //"CN=#0100010000", // invalid BER encoding (wrong length)
2442:
2443:                        // AttributeValue third alternative : " *( quotechar / pair ) "
2444:                        "CN=\"A\" B", // TODO comment me
2445:                        "CN=\"A\\", // TODO comment me
2446:                        "CN=\"\\4\"", // invalid pair = \4
2447:                        "CN=\"\\4Z\"", // invalid pair = \4Z
2448:                        "CN=\"\\4\\2c\"", // invalid pair = \4\2c
2449:                };
2450:
2451:                StringBuffer errorMsg = new StringBuffer();
2452:                for (String element : illegalDN) {
2453:
2454:                    try {
2455:                        new X500Principal(element);
2456:                        errorMsg.append("No IllegalArgumentException: '"
2457:                                + element + "'\n");
2458:                    } catch (IllegalArgumentException e) {
2459:                    }
2460:                }
2461:
2462:                if (errorMsg.length() != 0) {
2463:                    fail(errorMsg.toString());
2464:                }
2465:            }
2466:
2467:            public void testValidEncoding() {
2468:                TestList list = new TestList();
2469:
2470:                //
2471:                // Empty
2472:                //
2473:                list.add(new byte[] { 0x30, 0x00 }, "", "", "");
2474:                list.add(new byte[] { 0x30, 0x02, 0x31, 0x00 }, "", "", ""); //??? invalid size constraints
2475:
2476:                //
2477:                // Known OID + string with different tags(all string) 
2478:                //
2479:                list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06,
2480:                        0x03, 0x55, 0x04, 0x03,
2481:                        // PrintableString
2482:                        0x13, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z");
2483:                list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06,
2484:                        0x03, 0x55, 0x04, 0x03,
2485:                        // TeletexString
2486:                        0x14, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=#14015a");
2487:                //FIXME:compatibility        list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
2488:                //                0x55, 0x04, 0x03,
2489:                //                // UniversalString
2490:                //                0x1C, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z");
2491:                list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06,
2492:                        0x03, 0x55, 0x04, 0x03,
2493:                        // UTF8String
2494:                        0x0C, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z");
2495:                //FIXME:compatibility        list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
2496:                //                0x55, 0x04, 0x03,
2497:                //                // BMPString
2498:                //                0x1E, 0x01, 0x5A }, "CN=Z", "CN=Z", "cn=z");
2499:
2500:                //
2501:                // Unknown OID + string with different tags(all string) 
2502:                //
2503:                list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06,
2504:                        0x01, 0x00,
2505:                        // PrintableString
2506:                        0x13, 0x01, 0x5A }, "0.0=#13015a", "OID.0.0=Z",
2507:                        "0.0=#13015a");
2508:                list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06,
2509:                        0x01, 0x00,
2510:                        // TeletexString
2511:                        0x14, 0x01, 0x5A }, "0.0=#14015a", "OID.0.0=Z",
2512:                        "0.0=#14015a");
2513:                //FIXME:compatibility        list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01,
2514:                //                0x00,
2515:                //                // UniversalString
2516:                //                0x1C, 0x01, 0x5A }, "0.0=#1c015a", "OID.0.0=Z", "cn=z");
2517:                list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06,
2518:                        0x01, 0x00,
2519:                        // UTF8String
2520:                        0x0C, 0x01, 0x5A }, "0.0=#0c015a", "OID.0.0=Z",
2521:                        "0.0=#0c015a");
2522:                //FIXME:compatibility        list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06, 0x01,
2523:                //                0x00,
2524:                //                // BMPString
2525:                //                0x1E, 0x01, 0x5A }, "0.0=#1e015a", "OID.0.0=Z", "cn=z");
2526:
2527:                //
2528:                // Known OID + not a string value
2529:                //
2530:                list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06,
2531:                        0x03, 0x55, 0x04, 0x03,
2532:                        // Boolean
2533:                        0x01, 0x01, (byte) 0xFF }, "CN=#0101ff", "CN=#0101FF",
2534:                        "cn=#0101ff");
2535:                list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06,
2536:                        0x03, 0x55, 0x04, 0x03,
2537:                        // Integer
2538:                        0x02, 0x01, 0x0F }, "CN=#02010f", "CN=#02010F",
2539:                        "cn=#02010f");
2540:                list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06,
2541:                        0x03, 0x55, 0x04, 0x03,
2542:                        // BitString
2543:                        0x03, 0x01, 0x00 }, "CN=#030100", "CN=#030100",
2544:                        "cn=#030100");
2545:                list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06,
2546:                        0x03, 0x55, 0x04, 0x03,
2547:                        // SEQUENCE
2548:                        0x30, 0x01, 0x0A }, "CN=#30010a", "CN=#30010A",
2549:                        "cn=#30010a");
2550:
2551:                //
2552:                // unknown OID + not a string value
2553:                //
2554:                list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06,
2555:                        0x01, 0x00,
2556:                        // Boolean
2557:                        0x01, 0x01, (byte) 0xFF }, "0.0=#0101ff",
2558:                        "OID.0.0=#0101FF", "0.0=#0101ff");
2559:                list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06,
2560:                        0x01, 0x00,
2561:                        // Integer
2562:                        0x02, 0x01, 0x0F }, "0.0=#02010f", "OID.0.0=#02010F",
2563:                        "0.0=#02010f");
2564:                list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06,
2565:                        0x01, 0x00,
2566:                        // BitString
2567:                        0x03, 0x01, 0x00 }, "0.0=#030100", "OID.0.0=#030100",
2568:                        "0.0=#030100");
2569:                list.add(new byte[] { 0x30, 0x0A, 0x31, 0x08, 0x30, 0x06, 0x06,
2570:                        0x01, 0x00,
2571:                        // SEQUENCE
2572:                        0x30, 0x01, 0x0A }, "0.0=#30010a", "OID.0.0=#30010A",
2573:                        "0.0=#30010a");
2574:
2575:                //
2576:                // Known OID + UTF-8 string with chars to be escaped 
2577:                //
2578:
2579:                // spaces
2580:                list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06,
2581:                        0x03, 0x55, 0x04, 0x03,
2582:                        // UTF8String: a single space char 
2583:                        0x0C, 0x01, 0x20 }, "CN=\\ ", "CN=\" \"", "cn=");
2584:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2585:                        0x03, 0x55, 0x04, 0x03,
2586:                        // UTF8String: a space char at the beginning 
2587:                        0x0C, 0x02, 0x20, 0x5A }, "CN=\\ Z", "CN=\" Z\"",
2588:                        "cn=z");
2589:                list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06,
2590:                        0x03, 0x55, 0x04, 0x03,
2591:                        // UTF8String: two space chars at the beginning 
2592:                        0x0C, 0x03, 0x20, 0x20, 0x5A }, "CN=\\  Z",
2593:                        "CN=\"  Z\"", "cn=z", (byte) 0x01);
2594:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2595:                        0x03, 0x55, 0x04, 0x03,
2596:                        // UTF8String: a space char at the end 
2597:                        0x0C, 0x02, 0x5A, 0x20 }, "CN=Z\\ ", "CN=\"Z \"",
2598:                        "cn=z");
2599:                list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06,
2600:                        0x03, 0x55, 0x04, 0x03,
2601:                        // UTF8String: two space chars at the end 
2602:                        0x0C, 0x03, 0x5A, 0x20, 0x20 }, "CN=Z \\ ",
2603:                        "CN=\"Z  \"", "cn=z", (byte) 0x01);
2604:
2605:                // special chars
2606:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2607:                        0x03, 0x55, 0x04, 0x03,
2608:                        // UTF8String: a '#' char at the beginning 
2609:                        0x0C, 0x02, 0x23, 0x5A }, "CN=\\#Z", "CN=\"#Z\"",
2610:                        "cn=\\#z");
2611:                list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06,
2612:                        0x03, 0x55, 0x04, 0x03,
2613:                        // UTF8String: two '#' chars 
2614:                        0x0C, 0x03, 0x23, 0x5A, 0x23 }, "CN=\\#Z\\#",
2615:                        "CN=\"#Z#\"", "cn=\\#z#");
2616:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2617:                        0x03, 0x55, 0x04, 0x03,
2618:                        // UTF8String: ','
2619:                        0x0C, 0x02, 0x5A, 0x2C }, "CN=Z\\,", "CN=\"Z,\"",
2620:                        "cn=z\\,");
2621:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2622:                        0x03, 0x55, 0x04, 0x03,
2623:                        // UTF8String: '+'
2624:                        0x0C, 0x02, 0x5A, 0x2B }, "CN=Z\\+", "CN=\"Z+\"",
2625:                        "cn=z\\+");
2626:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2627:                        0x03, 0x55, 0x04, 0x03,
2628:                        // UTF8String: '"'
2629:                        0x0C, 0x02, 0x5A, 0x22 }, "CN=Z\\\"", "CN=\"Z\\\"\"",
2630:                        "cn=z\\\"", (byte) 0x02);
2631:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2632:                        0x03, 0x55, 0x04, 0x03,
2633:                        // UTF8String: '\'
2634:                        0x0C, 0x02, 0x5A, 0x5C }, "CN=Z\\\\", "CN=\"Z\\\\\"",
2635:                        "cn=z\\\\", (byte) 0x02);
2636:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2637:                        0x03, 0x55, 0x04, 0x03,
2638:                        // UTF8String: '<'
2639:                        0x0C, 0x02, 0x5A, 0x3C }, "CN=Z\\<", "CN=\"Z<\"",
2640:                        "cn=z\\<");
2641:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2642:                        0x03, 0x55, 0x04, 0x03,
2643:                        // UTF8String: '>'
2644:                        0x0C, 0x02, 0x5A, 0x3E }, "CN=Z\\>", "CN=\"Z>\"",
2645:                        "cn=z\\>");
2646:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2647:                        0x03, 0x55, 0x04, 0x03,
2648:                        // UTF8String: ';'
2649:                        0x0C, 0x02, 0x5A, 0x3B }, "CN=Z\\;", "CN=\"Z;\"",
2650:                        "cn=z\\;");
2651:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2652:                        0x03, 0x55, 0x04, 0x03,
2653:                        // UTF8String: '='
2654:                        0x0C, 0x02, 0x5A, 0x3D }, "CN=Z\\=", "CN=\"Z=\"",
2655:                        "cn=z=");
2656:                //FIXME        list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03,
2657:                //                0x55, 0x04, 0x03,
2658:                //                // UTF8String: ';'
2659:                //                0x0C, 0x02, 0x5A, 0x0D }, "CN=Z\\\r", "CN=\"Z\r\"", "cn=z");
2660:
2661:                // combinations
2662:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2663:                        0x03, 0x55, 0x04, 0x03,
2664:                        // UTF8String: '\ '
2665:                        0x0C, 0x02, 0x5C, 0x20 }, "CN=\\\\\\ ", "CN=\"\\\\ \"",
2666:                        "cn=\\\\", (byte) 0x02);
2667:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2668:                        0x03, 0x55, 0x04, 0x03,
2669:                        // UTF8String: ' \'
2670:                        0x0C, 0x02, 0x20, 0x5C }, "CN=\\ \\\\", "CN=\" \\\\\"",
2671:                        "cn=\\\\", (byte) 0x02);
2672:                list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06,
2673:                        0x03, 0x55, 0x04, 0x03,
2674:                        // UTF8String: ' \ '
2675:                        0x0C, 0x03, 0x20, 0x5C, 0x20 }, "CN=\\ \\\\\\ ",
2676:                        "CN=\" \\\\ \"", "cn=\\\\", (byte) 0x02);
2677:                list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06,
2678:                        0x03, 0x55, 0x04, 0x03,
2679:                        // UTF8String: 'Z Z' no escaping
2680:                        0x0C, 0x03, 0x5A, 0x20, 0x5A }, "CN=Z Z", "CN=Z Z",
2681:                        "cn=z z");
2682:                list.add(new byte[] { 0x30, 0x0F, 0x31, 0x0D, 0x30, 0x0B, 0x06,
2683:                        0x03, 0x55, 0x04, 0x03,
2684:                        // UTF8String: 'Z  Z' no escaping
2685:                        0x0C, 0x04, 0x5A, 0x20, 0x20, 0x5A }, "CN=Z  Z",
2686:                        "CN=Z  Z", "cn=z z", (byte) 0x02);
2687:                list.add(new byte[] { 0x30, 0x0F, 0x31, 0x0D, 0x30, 0x0B, 0x06,
2688:                        0x03, 0x55, 0x04, 0x03,
2689:                        // UTF8String: ' #Z ' no escaping
2690:                        0x0C, 0x04, 0x20, 0x23, 0x5A, 0x20 }, "CN=\\ \\#Z\\ ",
2691:                        "CN=\" #Z \"", "cn=#z");
2692:
2693:                //
2694:                // Special cases
2695:                //
2696:                //        list.add(new byte[] {
2697:                //        // Name
2698:                //                0x30, 0x13, 0x31, 0x11, 0x30, 0x0F,
2699:                //                // OID
2700:                //                0x06, 0x0A, 0x09, (byte) 0x92, 0x26, (byte) 0x89, (byte) 0x93,
2701:                //                (byte) 0xF2, 0x2C, 0x64, 0x01, 0x01,
2702:                //                // ANY
2703:                //                0x13, 0x01, 0x41 }, "UID=A", "OID.0.9.2342.19200300.100.1.1=A",
2704:                //                "uid=a");
2705:                //
2706:                //        list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
2707:                //                0x55, 0x04, 0x03, 0x1E, 0x01, 0x5A }, "CN=Z", "CN=Z",
2708:                //                "cn=#1e015a");
2709:
2710:                //
2711:                // Multi-valued DN
2712:                //
2713:                list.add(new byte[] { 0x30, 0x14, 0x31, 0x12,
2714:                // 1
2715:                        0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03,
2716:                        // UTF8String: 'Z'
2717:                        0x0C, 0x01, 0x5A,
2718:                        //2
2719:                        0x30, 0x06, 0x06, 0x01, 0x01,
2720:                        // UTF8String: 'A'
2721:                        0x0C, 0x01, 0x41 }, "CN=Z+0.1=#0c0141",
2722:                        "CN=Z + OID.0.1=A", "cn=z+0.1=#0c0141");
2723:
2724:                //
2725:                //
2726:                //
2727:                list.add(new byte[] { 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09, 0x06,
2728:                        0x03, 0x55, 0x04, 0x03,
2729:                        // UTF8String: the last letter(capital) of Russian alphabet
2730:                        0x0C, 0x02, (byte) 0xD0, (byte) 0xAF }, "CN="
2731:                        + ((char) 1071), "CN=" + ((char) 1071), "cn="
2732:                        + ((char) 1103));
2733:                // FIXME list.add(new byte[] { 0x30, 0x0E, 0x31, 0x0C, 0x30, 0x0A, 0x06, 0x03,
2734:                //        0x55, 0x04, 0x03,
2735:                //        // UTF8String: the last letter(capital) of Russian alphabet
2736:                //        0x0C, 0x03, (byte) 0xE0, (byte) 0x90, (byte) 0xAF }, "CN="
2737:                //        + ((char) 1071), "CN=" + ((char) 1071), "cn=" + ((char) 1103));
2738:                // FIXME list.add(
2739:                //        new byte[] { 0x30, 0x0F, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03,
2740:                //                0x55, 0x04, 0x03,
2741:                //                // UTF8String: the last letter(capital) of Russian alphabet
2742:                //                0x0C, 0x04, (byte) 0xF0, (byte) 0x80, (byte) 0x90,
2743:                //                (byte) 0xAF }, "CN=" + ((char) 1071), "CN="
2744:                //                + ((char) 1071), "cn=" + ((char) 1103));
2745:                list.add(new byte[] { 0x30, 0x0C, 0x31, 0x0A, 0x30, 0x08, 0x06,
2746:                        0x03, 0x55, 0x04, 0x03,
2747:                        // PrintableString: char '$' is not in table 8 (X.680)
2748:                        0x13, 0x01, 0x24 }, "CN=$", "CN=$", "cn=$");
2749:
2750:                StringBuffer errorMsg = new StringBuffer();
2751:                for (int i = 0; i < list.size(); i++) {
2752:
2753:                    Object[] values = list.get(i);
2754:                    byte[] encoded = (byte[]) values[0];
2755:                    String rfc2253 = (String) values[1];
2756:                    String rfc1179 = (String) values[2];
2757:                    String canonical = (String) values[3];
2758:                    byte mask = ((byte[]) values[4])[0];
2759:
2760:                    X500Principal p;
2761:                    try {
2762:                        p = new X500Principal(encoded);
2763:
2764:                        if (!rfc2253.equals(p.getName(X500Principal.RFC2253))) {
2765:                            if (!testing || ((mask & 0x01) == 0)) {
2766:                                errorMsg.append("RFC2253: " + i);
2767:                                errorMsg.append("\t\texpected: '" + rfc2253
2768:                                        + "'");
2769:                                errorMsg.append("\treturned: '"
2770:                                        + p.getName(X500Principal.RFC2253)
2771:                                        + "'\n");
2772:                            }
2773:                        }
2774:
2775:                        if (!rfc1179.equals(p.getName(X500Principal.RFC1779))) {
2776:                            if (!testing || ((mask & 0x02) == 0)) {
2777:                                errorMsg.append("RFC1779: " + i);
2778:                                errorMsg.append("\t\texpected: '" + rfc1179
2779:                                        + "'");
2780:                                errorMsg.append("\treturned: '"
2781:                                        + p.getName(X500Principal.RFC1779)
2782:                                        + "'\n");
2783:                            }
2784:                        }
2785:
2786:                        if (!canonical.equals(p
2787:                                .getName(X500Principal.CANONICAL))) {
2788:                            if (!testing || ((mask & 0x04) == 0)) {
2789:                                errorMsg.append("CANONICAL: " + i);
2790:                                errorMsg.append("\t\texpected: " + canonical
2791:                                        + "'");
2792:                                errorMsg.append("\treturned: '"
2793:                                        + p.getName(X500Principal.CANONICAL)
2794:                                        + "'\n");
2795:                            }
2796:                        }
2797:
2798:                    } catch (IllegalArgumentException e) {
2799:                        errorMsg.append("\nIllegalArgumentException: " + i
2800:                                + ", for " + rfc2253);
2801:                        continue;
2802:                    } catch (Exception e) {
2803:                        errorMsg.append("Exception: " + i + ", for " + rfc2253);
2804:                        errorMsg.append("\texcep: " + e.getClass().getName()
2805:                                + "\n");
2806:                        continue;
2807:                    }
2808:
2809:                }
2810:
2811:                if (errorMsg.length() != 0) {
2812:                    fail(errorMsg.toString());
2813:                }
2814:            }
2815:
2816:            @SuppressWarnings("serial")
2817:            public static class TestList extends ArrayList<Object[]> {
2818:                //
2819:                // TODO comment me
2820:                //
2821:                public void add(String param, String rfc2253, String rfc1779) {
2822:                    add(param, rfc2253, rfc1779, (byte[]) null);
2823:                }
2824:
2825:                public void add(String param, String rfc2253, String rfc1779,
2826:                        String canonical) {
2827:                    add(param, rfc2253, rfc1779, canonical, null);
2828:                }
2829:
2830:                public void add(String param, String rfc2253, String rfc1779,
2831:                        byte[] encoded) {
2832:                    add(new Object[] { param, rfc2253, rfc1779, null, encoded,
2833:                            emptyMask });
2834:                }
2835:
2836:                public void add(String param, String rfc2253, String rfc1779,
2837:                        byte[] encoded, byte mask) {
2838:                    add(new Object[] { param, rfc2253, rfc1779, null, encoded,
2839:                            new byte[] { mask } });
2840:                }
2841:
2842:                public void add(String param, String rfc2253, String rfc1779,
2843:                        String canonical, byte[] encoded) {
2844:                    add(new Object[] { param, rfc2253, rfc1779, canonical,
2845:                            encoded, emptyMask });
2846:                }
2847:
2848:                public void add(String param, String rfc2253, String rfc1779,
2849:                        String canonical, byte[] encoded, byte mask) {
2850:                    add(new Object[] { param, rfc2253, rfc1779, canonical,
2851:                            encoded, new byte[] { mask } });
2852:                }
2853:
2854:                //
2855:                // TODO comment me
2856:                //
2857:
2858:                private static final byte[] emptyMask = new byte[] { 0x00 };
2859:
2860:                public void add(byte[] encoding, String rfc2253,
2861:                        String rfc1779, String canonical) {
2862:                    add(new Object[] { encoding, rfc2253, rfc1779, canonical,
2863:                            emptyMask });
2864:                }
2865:
2866:                public void add(byte[] encoding, String rfc2253,
2867:                        String rfc1779, String canonical, byte mask) {
2868:                    add(new Object[] { encoding, rfc2253, rfc1779, canonical,
2869:                            new byte[] { mask } });
2870:                }
2871:            }
2872:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.