d96c1777242f1593e6467a4313ec1e71d3c9e0ad
[java-idp.git] / tests / edu / internet2 / middleware / shibboleth / common / CredentialsTests.java
1 /*
2  * The Shibboleth License, Version 1. Copyright (c) 2002 University Corporation for Advanced Internet Development, Inc.
3  * All rights reserved
4  * 
5  * 
6  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 
9  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
10  * disclaimer.
11  * 
12  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials provided with the distribution, if any, must include the
14  * following acknowledgment: "This product includes software developed by the University Corporation for Advanced
15  * Internet Development <http://www.ucaid.edu> Internet2 Project. Alternately, this acknowledegement may appear in the
16  * software itself, if and wherever such third-party acknowledgments normally appear.
17  * 
18  * Neither the name of Shibboleth nor the names of its contributors, nor Internet2, nor the University Corporation for
19  * Advanced Internet Development, Inc., nor UCAID may be used to endorse or promote products derived from this software
20  * without specific prior written permission. For written permission, please contact shibboleth@shibboleth.org
21  * 
22  * Products derived from this software may not be called Shibboleth, Internet2, UCAID, or the University Corporation
23  * for Advanced Internet Development, nor may Shibboleth appear in their name, without prior written permission of the
24  * University Corporation for Advanced Internet Development.
25  * 
26  * 
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND WITH ALL FAULTS. ANY EXPRESS OR
28  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
29  * PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED AND THE ENTIRE RISK OF SATISFACTORY QUALITY, PERFORMANCE,
30  * ACCURACY, AND EFFORT IS WITH LICENSEE. IN NO EVENT SHALL THE COPYRIGHT OWNER, CONTRIBUTORS OR THE UNIVERSITY
31  * CORPORATION FOR ADVANCED INTERNET DEVELOPMENT, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37
38 package edu.internet2.middleware.shibboleth.common;
39
40 import java.io.FileInputStream;
41 import java.io.InputStream;
42
43 import junit.framework.TestCase;
44
45 import org.apache.log4j.BasicConfigurator;
46 import org.apache.log4j.Level;
47 import org.apache.log4j.Logger;
48 import org.xml.sax.InputSource;
49 import edu.internet2.middleware.shibboleth.xml.Parser;
50
51 /**
52  * Validation suite for the <code>Credentials</code> interface.
53  * 
54  * @author Walter Hoehn
55  */
56
57 public class CredentialsTests extends TestCase {
58
59         private Parser.DOMParser parser = new Parser.DOMParser(true);
60
61         public CredentialsTests(String name) {
62                 super(name);
63                 BasicConfigurator.resetConfiguration();
64                 BasicConfigurator.configure();
65                 Logger.getRootLogger().setLevel(Level.OFF);
66         }
67
68         public static void main(String[] args) {
69                 junit.textui.TestRunner.run(CredentialsTests.class);
70                 BasicConfigurator.configure();
71                 Logger.getRootLogger().setLevel(Level.OFF);
72         }
73
74         /**
75          * @see junit.framework.TestCase#setUp()
76          */
77         protected void setUp() throws Exception {
78                 super.setUp();
79         }
80
81         public void testKeyStoreX509CompleteChain() {
82
83                 try {
84                         InputStream inStream = new FileInputStream("data/credentials1.xml");
85                         parser.parse(new InputSource(inStream));
86                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
87
88                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
89                         Credential credential = credentials.getCredential("test");
90
91                         assertTrue(
92                                 "Credential was loaded with an incorrect type.",
93                                 credential.getCredentialType() == Credential.RSA);
94                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
95                         assertEquals(
96                                 "Unexpected X509 certificate found.",
97                                 credential.getX509Certificate().getSubjectDN().getName(),
98                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
99                         assertEquals(
100                                 "Unexpected certificate chain length.",
101                                 new Integer(credential.getX509CertificateChain().length),
102                                 new Integer(3));
103                         assertEquals(
104                                 "Unexpected X509 certificate found.",
105                                 credential.getX509CertificateChain()[1].getSubjectDN().getName(),
106                                 "CN=HEPKI Server CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
107                         assertEquals(
108                                 "Unexpected X509 certificate found.",
109                                 credential.getX509CertificateChain()[2].getSubjectDN().getName(),
110                                 "CN=HEPKI Master CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
111                 } catch (Exception e) {
112                         fail("Failed to load credentials: " + e);
113                 }
114         }
115
116         public void testFileX509EndOnly() {
117
118                 try {
119                         InputStream inStream = new FileInputStream("data/credentials16.xml");
120                         parser.parse(new InputSource(inStream));
121                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
122
123                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
124                         Credential credential = credentials.getCredential("test");
125
126                         assertTrue(
127                                 "Credential was loaded with an incorrect type.",
128                                 credential.getCredentialType() == Credential.RSA);
129                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
130                         assertEquals(
131                                 "Unexpected X509 certificate found.",
132                                 credential.getX509Certificate().getSubjectDN().getName(),
133                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
134                         assertEquals(
135                                 "Unexpected certificate chain length.",
136                                 new Integer(credential.getX509CertificateChain().length),
137                                 new Integer(1));
138                 } catch (Exception e) {
139                         fail("Failed to load credentials: " + e);
140                 }
141         }
142
143         public void testFileX509IncompleteChain() {
144
145                 try {
146                         InputStream inStream = new FileInputStream("data/credentials17.xml");
147                         parser.parse(new InputSource(inStream));
148                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
149
150                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
151                         Credential credential = credentials.getCredential("test");
152
153                         assertTrue(
154                                 "Credential was loaded with an incorrect type.",
155                                 credential.getCredentialType() == Credential.RSA);
156                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
157                         assertEquals(
158                                 "Unexpected X509 certificate found.",
159                                 credential.getX509Certificate().getSubjectDN().getName(),
160                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
161                         assertEquals(
162                                 "Unexpected certificate chain length.",
163                                 new Integer(credential.getX509CertificateChain().length),
164                                 new Integer(2));
165                         assertEquals(
166                                 "Unexpected X509 certificate found.",
167                                 credential.getX509CertificateChain()[1].getSubjectDN().getName(),
168                                 "CN=HEPKI Server CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
169                 } catch (Exception e) {
170                         fail("Failed to load credentials: " + e);
171                 }
172         }
173         
174         public void testFileX509RSANoCert() {
175
176                 try {
177                         InputStream inStream = new FileInputStream("data/credentials18.xml");
178                         parser.parse(new InputSource(inStream));
179                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
180
181                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
182                         Credential credential = credentials.getCredential("test");
183
184                         assertTrue(
185                                 "Credential was loaded with an incorrect type.",
186                                 credential.getCredentialType() == Credential.RSA);
187                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
188                         assertEquals(
189                                 "Unexpected X509 certificate found.",
190                                 credential.hasX509Certificate(),
191                                 false);
192                         assertEquals(
193                                 "Unexpected certificate chain length.",
194                                 new Integer(credential.getX509CertificateChain().length),
195                                 new Integer(0));
196                 } catch (Exception e) {
197                         fail("Failed to load credentials: " + e);
198                 }
199         }
200
201         public void testKeyStoreX509AliasDefaulting() {
202
203                 try {
204                         InputStream inStream = new FileInputStream("data/credentials3.xml");
205                         parser.parse(new InputSource(inStream));
206                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
207
208                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
209                         Credential credential = credentials.getCredential("test");
210
211                         assertTrue(
212                                 "Credential was loaded with an incorrect type.",
213                                 credential.getCredentialType() == Credential.RSA);
214                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
215                         assertEquals(
216                                 "Unexpected X509 certificate found.",
217                                 credential.getX509Certificate().getSubjectDN().getName(),
218                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
219                         assertEquals(
220                                 "Unexpected certificate chain length.",
221                                 new Integer(credential.getX509CertificateChain().length),
222                                 new Integer(3));
223                         assertEquals(
224                                 "Unexpected X509 certificate found.",
225                                 credential.getX509CertificateChain()[2].getSubjectDN().getName(),
226                                 "CN=HEPKI Master CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
227                 } catch (Exception e) {
228                         fail("Failed to load credentials: " + e);
229                 }
230         }
231
232         public void testFileX509NoPassword() {
233
234                 try {
235                         InputStream inStream = new FileInputStream("data/credentials2.xml");
236                         parser.parse(new InputSource(inStream));
237                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
238
239                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
240                         Credential credential = credentials.getCredential("test");
241
242                         assertTrue(
243                                 "Credential was loaded with an incorrect type.",
244                                 credential.getCredentialType() == Credential.RSA);
245                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
246                         assertEquals(
247                                 "Unexpected X509 certificate found.",
248                                 credential.getX509Certificate().getSubjectDN().getName(),
249                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
250                         assertEquals(
251                                 "Unexpected certificate chain length.",
252                                 new Integer(credential.getX509CertificateChain().length),
253                                 new Integer(3));
254                         assertEquals(
255                                 "Unexpected X509 certificate found.",
256                                 credential.getX509CertificateChain()[2].getSubjectDN().getName(),
257                                 "CN=HEPKI Master CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
258                 } catch (Exception e) {
259                         fail("Failed to load credentials: " + e);
260                 }
261         }
262
263         public void testFileX509withCABundles() {
264
265                 try {
266                         InputStream inStream = new FileInputStream("data/credentials4.xml");
267                         parser.parse(new InputSource(inStream));
268                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
269
270                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
271                         Credential credential = credentials.getCredential("test");
272
273                         assertTrue(
274                                 "Credential was loaded with an incorrect type.",
275                                 credential.getCredentialType() == Credential.RSA);
276                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
277                         assertEquals(
278                                 "Unexpected X509 certificate found.",
279                                 credential.getX509Certificate().getSubjectDN().getName(),
280                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
281                         assertEquals(
282                                 "Unexpected certificate chain length.",
283                                 new Integer(credential.getX509CertificateChain().length),
284                                 new Integer(3));
285                         assertEquals(
286                                 "Unexpected X509 certificate found.",
287                                 credential.getX509CertificateChain()[2].getSubjectDN().getName(),
288                                 "CN=HEPKI Master CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
289                 } catch (Exception e) {
290                         fail("Failed to load credentials: " + e);
291                 }
292         }
293
294         public void testFileX509_PEM_PKCS8Key() {
295
296                 try {
297                         InputStream inStream = new FileInputStream("data/credentials5.xml");
298                         parser.parse(new InputSource(inStream));
299                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
300
301                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
302                         Credential credential = credentials.getCredential("test");
303
304                         assertTrue(
305                                 "Credential was loaded with an incorrect type.",
306                                 credential.getCredentialType() == Credential.RSA);
307                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
308                         assertEquals(
309                                 "Unexpected X509 certificate found.",
310                                 credential.getX509Certificate().getSubjectDN().getName(),
311                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
312                         assertEquals(
313                                 "Unexpected certificate chain length.",
314                                 new Integer(credential.getX509CertificateChain().length),
315                                 new Integer(3));
316                         assertEquals(
317                                 "Unexpected X509 certificate found.",
318                                 credential.getX509CertificateChain()[2].getSubjectDN().getName(),
319                                 "CN=HEPKI Master CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
320                 } catch (Exception e) {
321                         fail("Failed to load credentials: " + e);
322                 }
323         }
324
325         public void testFileX509_DER_RSA_Key() {
326
327                 try {
328                         InputStream inStream = new FileInputStream("data/credentials6.xml");
329                         parser.parse(new InputSource(inStream));
330                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
331
332                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
333                         Credential credential = credentials.getCredential("test");
334
335                         assertTrue(
336                                 "Credential was loaded with an incorrect type.",
337                                 credential.getCredentialType() == Credential.RSA);
338                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
339                         assertEquals(
340                                 "Unexpected X509 certificate found.",
341                                 credential.getX509Certificate().getSubjectDN().getName(),
342                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
343                         assertEquals(
344                                 "Unexpected certificate chain length.",
345                                 new Integer(credential.getX509CertificateChain().length),
346                                 new Integer(3));
347                         assertEquals(
348                                 "Unexpected X509 certificate found.",
349                                 credential.getX509CertificateChain()[2].getSubjectDN().getName(),
350                                 "CN=HEPKI Master CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
351                 } catch (Exception e) {
352                         fail("Failed to load credentials: " + e);
353                 }
354         }
355
356         public void testFileX509_PEM_RSA_Key() {
357
358                 try {
359                         InputStream inStream = new FileInputStream("data/credentials7.xml");
360                         parser.parse(new InputSource(inStream));
361                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
362
363                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
364                         Credential credential = credentials.getCredential("test");
365
366                         assertTrue(
367                                 "Credential was loaded with an incorrect type.",
368                                 credential.getCredentialType() == Credential.RSA);
369                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
370                         assertEquals(
371                                 "Unexpected X509 certificate found.",
372                                 credential.getX509Certificate().getSubjectDN().getName(),
373                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
374                         assertEquals(
375                                 "Unexpected certificate chain length.",
376                                 new Integer(credential.getX509CertificateChain().length),
377                                 new Integer(3));
378                         assertEquals(
379                                 "Unexpected X509 certificate found.",
380                                 credential.getX509CertificateChain()[2].getSubjectDN().getName(),
381                                 "CN=HEPKI Master CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
382                 } catch (Exception e) {
383                         fail("Failed to load credentials: " + e);
384                 }
385         }
386
387         public void testFileX509_DER_DSA_Key() {
388
389                 try {
390                         InputStream inStream = new FileInputStream("data/credentials8.xml");
391                         parser.parse(new InputSource(inStream));
392                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
393
394                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
395                         Credential credential = credentials.getCredential("test");
396
397                         assertTrue(
398                                 "Credential was loaded with an incorrect type.",
399                                 credential.getCredentialType() == Credential.DSA);
400                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
401                         assertEquals(
402                                 "Unexpected X509 certificate found.",
403                                 credential.getX509Certificate().getSubjectDN().getName(),
404                                 "CN=test.columbia.edu, OU=ACIS, O=Columbia University, L=New York, ST=NY, C=US");
405                         assertEquals(
406                                 "Unexpected certificate chain length.",
407                                 new Integer(credential.getX509CertificateChain().length),
408                                 new Integer(1));
409                 } catch (Exception e) {
410                         fail("Failed to load credentials: " + e);
411                 }
412         }
413
414         public void testFileX509_PEM_DSA_Key() {
415
416                 try {
417                         InputStream inStream = new FileInputStream("data/credentials9.xml");
418                         parser.parse(new InputSource(inStream));
419                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
420
421                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
422                         Credential credential = credentials.getCredential("test");
423
424                         assertTrue(
425                                 "Credential was loaded with an incorrect type.",
426                                 credential.getCredentialType() == Credential.DSA);
427                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
428                         assertEquals(
429                                 "Unexpected X509 certificate found.",
430                                 credential.getX509Certificate().getSubjectDN().getName(),
431                                 "CN=test.columbia.edu, OU=ACIS, O=Columbia University, L=New York, ST=NY, C=US");
432                         assertEquals(
433                                 "Unexpected certificate chain length.",
434                                 new Integer(credential.getX509CertificateChain().length),
435                                 new Integer(1));
436                 } catch (Exception e) {
437                         fail("Failed to load credentials: " + e);
438                 }
439         }
440
441         public void testFileX509_PEM_PKCS8_DSA_Key() {
442
443                 try {
444                         InputStream inStream = new FileInputStream("data/credentials10.xml");
445                         parser.parse(new InputSource(inStream));
446                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
447
448                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
449                         Credential credential = credentials.getCredential("test");
450
451                         assertTrue(
452                                 "Credential was loaded with an incorrect type.",
453                                 credential.getCredentialType() == Credential.DSA);
454                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
455                         assertEquals(
456                                 "Unexpected X509 certificate found.",
457                                 credential.getX509Certificate().getSubjectDN().getName(),
458                                 "CN=test.columbia.edu, OU=ACIS, O=Columbia University, L=New York, ST=NY, C=US");
459                         assertEquals(
460                                 "Unexpected certificate chain length.",
461                                 new Integer(credential.getX509CertificateChain().length),
462                                 new Integer(1));
463                 } catch (Exception e) {
464                         fail("Failed to load credentials: " + e);
465                 }
466         }
467
468         public void testFileX509_DER_PKCS8_Encrypted_RSA_Key() {
469
470                 try {
471                         InputStream inStream = new FileInputStream("data/credentials11.xml");
472                         parser.parse(new InputSource(inStream));
473                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
474
475                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
476                         Credential credential = credentials.getCredential("test");
477
478                         assertTrue(
479                                 "Credential was loaded with an incorrect type.",
480                                 credential.getCredentialType() == Credential.RSA);
481                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
482                         assertEquals(
483                                 "Unexpected X509 certificate found.",
484                                 credential.getX509Certificate().getSubjectDN().getName(),
485                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
486                         assertEquals(
487                                 "Unexpected certificate chain length.",
488                                 new Integer(credential.getX509CertificateChain().length),
489                                 new Integer(3));
490                         assertEquals(
491                                 "Unexpected X509 certificate found.",
492                                 credential.getX509CertificateChain()[2].getSubjectDN().getName(),
493                                 "CN=HEPKI Master CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
494                 } catch (Exception e) {
495                         fail("Failed to load credentials: " + e);
496                 }
497         }
498
499         public void testFileX509_PEM_PKCS8_Encrypted_RSA_Key() {
500
501                 try {
502                         InputStream inStream = new FileInputStream("data/credentials12.xml");
503                         parser.parse(new InputSource(inStream));
504                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
505
506                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
507                         Credential credential = credentials.getCredential("test");
508
509                         assertTrue(
510                                 "Credential was loaded with an incorrect type.",
511                                 credential.getCredentialType() == Credential.RSA);
512                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
513                         assertEquals(
514                                 "Unexpected X509 certificate found.",
515                                 credential.getX509Certificate().getSubjectDN().getName(),
516                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
517                         assertEquals(
518                                 "Unexpected certificate chain length.",
519                                 new Integer(credential.getX509CertificateChain().length),
520                                 new Integer(3));
521                         assertEquals(
522                                 "Unexpected X509 certificate found.",
523                                 credential.getX509CertificateChain()[2].getSubjectDN().getName(),
524                                 "CN=HEPKI Master CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
525                 } catch (Exception e) {
526                         fail("Failed to load credentials: " + e);
527                 }
528         }
529
530         public void testFileX509_PEM_Encrypted_DES_RSA_Key() {
531
532                 try {
533                         InputStream inStream = new FileInputStream("data/credentials14.xml");
534                         parser.parse(new InputSource(inStream));
535                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
536
537                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
538                         Credential credential = credentials.getCredential("test");
539
540                         assertTrue(
541                                 "Credential was loaded with an incorrect type.",
542                                 credential.getCredentialType() == Credential.RSA);
543                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
544                         assertEquals(
545                                 "Unexpected X509 certificate found.",
546                                 credential.getX509Certificate().getSubjectDN().getName(),
547                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
548                         assertEquals(
549                                 "Unexpected certificate chain length.",
550                                 new Integer(credential.getX509CertificateChain().length),
551                                 new Integer(3));
552                         assertEquals(
553                                 "Unexpected X509 certificate found.",
554                                 credential.getX509CertificateChain()[2].getSubjectDN().getName(),
555                                 "CN=HEPKI Master CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
556                 } catch (Exception e) {
557                         fail("Failed to load credentials: " + e);
558                 }
559         }
560
561         public void testFileX509_PEM_Encrypted_TripeDES_RSA_Key() {
562
563                 try {
564                         InputStream inStream = new FileInputStream("data/credentials13.xml");
565                         parser.parse(new InputSource(inStream));
566                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
567
568                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
569                         Credential credential = credentials.getCredential("test");
570
571                         assertTrue(
572                                 "Credential was loaded with an incorrect type.",
573                                 credential.getCredentialType() == Credential.RSA);
574                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
575                         assertEquals(
576                                 "Unexpected X509 certificate found.",
577                                 credential.getX509Certificate().getSubjectDN().getName(),
578                                 "CN=shib2.internet2.edu, OU=Unknown, O=Unknown, ST=Unknown, C=Unknown");
579                         assertEquals(
580                                 "Unexpected certificate chain length.",
581                                 new Integer(credential.getX509CertificateChain().length),
582                                 new Integer(3));
583                         assertEquals(
584                                 "Unexpected X509 certificate found.",
585                                 credential.getX509CertificateChain()[2].getSubjectDN().getName(),
586                                 "CN=HEPKI Master CA -- 20020701A, OU=Division of Information Technology, O=University of Wisconsin, L=Madison, ST=Wisconsin, C=US");
587                 } catch (Exception e) {
588                         fail("Failed to load credentials: " + e);
589                 }
590         }
591
592         public void testFileX509_PEM_Encrypted_TripeDES_DSA_Key() {
593
594                 try {
595                         InputStream inStream = new FileInputStream("data/credentials15.xml");
596                         parser.parse(new InputSource(inStream));
597                         Credentials credentials = new Credentials(parser.getDocument().getDocumentElement());
598
599                         assertTrue("Credential could not be found.", credentials.containsCredential("test"));
600                         Credential credential = credentials.getCredential("test");
601
602                         assertTrue(
603                                 "Credential was loaded with an incorrect type.",
604                                 credential.getCredentialType() == Credential.DSA);
605                         assertNotNull("Private key was not loaded correctly.", credential.getPrivateKey());
606                         assertEquals(
607                                 "Unexpected X509 certificate found.",
608                                 credential.getX509Certificate().getSubjectDN().getName(),
609                                 "CN=test.columbia.edu, OU=ACIS, O=Columbia University, L=New York, ST=NY, C=US");
610                         assertEquals(
611                                 "Unexpected certificate chain length.",
612                                 new Integer(credential.getX509CertificateChain().length),
613                                 new Integer(1));
614                 } catch (Exception e) {
615                         fail("Failed to load credentials: " + e);
616                 }
617         }
618
619 }