Home | History | Annotate | Download | only in ssl
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package tests.api.javax.net.ssl;
     19 
     20 import dalvik.annotation.TestTargetClass;
     21 import dalvik.annotation.TestLevel;
     22 import dalvik.annotation.TestTargetNew;
     23 import dalvik.annotation.KnownFailure;
     24 
     25 import java.io.IOException;
     26 import java.security.InvalidAlgorithmParameterException;
     27 import java.security.KeyStore;
     28 import java.security.KeyStoreException;
     29 import java.security.NoSuchAlgorithmException;
     30 import java.security.NoSuchProviderException;
     31 import java.security.Provider;
     32 import java.security.PublicKey;
     33 import java.security.Security;
     34 import java.security.cert.CertificateException;
     35 
     36 import javax.net.ssl.ManagerFactoryParameters;
     37 import javax.net.ssl.TrustManager;
     38 import javax.net.ssl.TrustManagerFactory;
     39 import javax.net.ssl.TrustManagerFactorySpi;
     40 
     41 import org.apache.harmony.security.tests.support.SpiEngUtils;
     42 import org.apache.harmony.security.tests.support.TestKeyPair;
     43 import org.apache.harmony.xnet.tests.support.MyTrustManagerFactorySpi;
     44 import junit.framework.TestCase;
     45 
     46 //
     47 import java.security.cert.TrustAnchor;
     48 import java.security.cert.X509CertSelector;
     49 import java.security.cert.PKIXBuilderParameters;
     50 import javax.net.ssl.CertPathTrustManagerParameters;
     51 
     52 import java.util.HashSet;
     53 import java.util.Set;
     54 
     55 /**
     56  * Tests for <code>TrustManagerFactory</code> class constructors and methods.
     57  *
     58  */
     59 @TestTargetClass(TrustManagerFactory.class)
     60 public class TrustManagerFactory1Test extends TestCase {
     61 
     62     private static final String srvTrustManagerFactory = "TrustManagerFactory";
     63 
     64     private static String defaultAlgorithm = null;
     65 
     66     private static String defaultProviderName = null;
     67 
     68     private static Provider defaultProvider = null;
     69 
     70     private static boolean DEFSupported = false;
     71 
     72     private static final String NotSupportedMsg = "There is no suitable provider for TrustManagerFactory";
     73 
     74     private static final String[] invalidValues = SpiEngUtils.invalidValues;
     75 
     76     private static String[] validValues = new String[3];
     77     static {
     78         defaultAlgorithm = Security
     79                 .getProperty("ssl.TrustManagerFactory.algorithm");
     80         if (defaultAlgorithm != null) {
     81             defaultProvider = SpiEngUtils.isSupport(defaultAlgorithm,
     82                     srvTrustManagerFactory);
     83             DEFSupported = (defaultProvider != null);
     84             defaultProviderName = (DEFSupported ? defaultProvider.getName()
     85                     : null);
     86             validValues[0] = defaultAlgorithm;
     87             validValues[1] = defaultAlgorithm.toUpperCase();
     88             validValues[2] = defaultAlgorithm.toLowerCase();
     89         }
     90     }
     91 
     92     protected TrustManagerFactory[] createTMFac() {
     93         if (!DEFSupported) {
     94             fail(defaultAlgorithm + " algorithm is not supported");
     95             return null;
     96         }
     97         TrustManagerFactory[] tMF = new TrustManagerFactory[3];
     98         try {
     99             tMF[0] = TrustManagerFactory.getInstance(defaultAlgorithm);
    100             tMF[1] = TrustManagerFactory.getInstance(defaultAlgorithm,
    101                     defaultProvider);
    102             tMF[2] = TrustManagerFactory.getInstance(defaultAlgorithm,
    103                     defaultProviderName);
    104             return tMF;
    105         } catch (Exception e) {
    106             e.printStackTrace();
    107             return null;
    108         }
    109     }
    110 
    111     /**
    112      * Test for
    113      * <code>TrustManagerFactory(TrustManagerFactorySpi impl, Provider prov, String algoriyjm) </code>
    114      * constructor
    115      * Assertion: created new TrustManagerFactory object
    116      */
    117     @TestTargetNew(
    118         level = TestLevel.COMPLETE,
    119         notes = "",
    120         method = "TrustManagerFactory",
    121         args = {javax.net.ssl.TrustManagerFactorySpi.class, java.security.Provider.class, java.lang.String.class}
    122     )
    123     public void test_ConstructorLjavax_net_ssl_TrustManagerFactorySpiLjava_security_ProviderLjava_lang_String()
    124         throws NoSuchAlgorithmException {
    125         if (!DEFSupported) {
    126             fail(NotSupportedMsg);
    127             return;
    128         }
    129         TrustManagerFactorySpi spi = new MyTrustManagerFactorySpi();
    130         TrustManagerFactory tmF = new myTrustManagerFactory(spi, defaultProvider,
    131                 defaultAlgorithm);
    132         assertTrue("Not CertStore object", tmF instanceof TrustManagerFactory);
    133         assertEquals("Incorrect algorithm", tmF.getAlgorithm(),
    134                 defaultAlgorithm);
    135         assertEquals("Incorrect provider", tmF.getProvider(), defaultProvider);
    136         assertNull("Incorrect result", tmF.getTrustManagers());
    137 
    138         tmF = new myTrustManagerFactory(null, null, null);
    139         assertTrue("Not CertStore object", tmF instanceof TrustManagerFactory);
    140         assertNull("Provider must be null", tmF.getProvider());
    141         assertNull("Algorithm must be null", tmF.getAlgorithm());
    142         try {
    143             tmF.getTrustManagers();
    144             fail("NullPointerException must be thrown");
    145         } catch (NullPointerException e) {
    146         }
    147     }
    148 
    149     /**
    150      *  Test for <code>getAlgorithm()</code> method
    151      * Assertion: returns the algorithm name of this object
    152      * @throws NoSuchAlgorithmException
    153      * @throws NoSuchProviderException
    154      */
    155     @TestTargetNew(
    156         level = TestLevel.COMPLETE,
    157         notes = "",
    158         method = "getAlgorithm",
    159         args = {}
    160     )
    161     public void test_getAlgorithm()
    162         throws NoSuchAlgorithmException, NoSuchProviderException {
    163         if (!DEFSupported) fail(NotSupportedMsg);
    164         assertEquals("Incorrect algorithm",
    165                 defaultAlgorithm,
    166                 TrustManagerFactory
    167                 .getInstance(defaultAlgorithm).getAlgorithm());
    168         assertEquals("Incorrect algorithm",
    169                 defaultAlgorithm,
    170                 TrustManagerFactory
    171                 .getInstance(defaultAlgorithm, defaultProviderName)
    172                 .getAlgorithm());
    173         assertEquals("Incorrect algorithm",
    174                 defaultAlgorithm,
    175                 TrustManagerFactory.getInstance(defaultAlgorithm, defaultProvider)
    176                 .getAlgorithm());
    177     }
    178 
    179     /**
    180      *  Test for <code>getDefaultAlgorithm()</code> method
    181      * Assertion: returns value which is specifoed in security property
    182      */
    183     @TestTargetNew(
    184         level = TestLevel.COMPLETE,
    185         notes = "",
    186         method = "getDefaultAlgorithm",
    187         args = {}
    188     )
    189     public void test_getDefaultAlgorithm() {
    190         if (!DEFSupported) {
    191             fail(NotSupportedMsg);
    192             return;
    193         }
    194         String def = TrustManagerFactory.getDefaultAlgorithm();
    195         if (defaultAlgorithm == null) {
    196             assertNull("DefaultAlgorithm must be null", def);
    197         } else {
    198             assertEquals("Invalid default algorithm", def, defaultAlgorithm);
    199         }
    200         String defA = "Proba.trustmanagerfactory.defaul.type";
    201         Security.setProperty("ssl.TrustManagerFactory.algorithm", defA);
    202         assertEquals("Incorrect defaultAlgorithm",
    203                 TrustManagerFactory.getDefaultAlgorithm(), defA);
    204         if (def == null) {
    205             def = "";
    206         }
    207         Security.setProperty("ssl.TrustManagerFactory.algorithm", def);
    208         assertEquals("Incorrect defaultAlgorithm",
    209                 TrustManagerFactory.getDefaultAlgorithm(), def);
    210     }
    211 
    212     /**
    213      * Test for <code>getInstance(String algorithm)</code> method
    214      * Assertions: returns security property "ssl.TrustManagerFactory.algorithm";
    215      * returns instance of TrustManagerFactory
    216      */
    217     @TestTargetNew(
    218         level = TestLevel.PARTIAL_COMPLETE,
    219         notes = "",
    220         method = "getInstance",
    221         args = {java.lang.String.class}
    222     )
    223     public void test_getInstanceLjava_lang_String01() throws NoSuchAlgorithmException {
    224         if (!DEFSupported) {
    225             fail(NotSupportedMsg);
    226             return;
    227         }
    228         TrustManagerFactory trustMF;
    229         for (int i = 0; i < validValues.length; i++) {
    230             trustMF = TrustManagerFactory.getInstance(validValues[i]);
    231             assertTrue("Not TrustManagerFactory object",
    232                     trustMF instanceof TrustManagerFactory);
    233             assertEquals("Invalid algorithm", trustMF.getAlgorithm(),
    234                     validValues[i]);
    235         }
    236     }
    237 
    238     /**
    239      * Test for <code>getInstance(String algorithm)</code> method
    240      * Assertion:
    241      * throws NullPointerException when algorithm is null;
    242      * throws NoSuchAlgorithmException when algorithm is not correct;
    243      */
    244     @TestTargetNew(
    245         level = TestLevel.PARTIAL_COMPLETE,
    246         notes = "",
    247         method = "getInstance",
    248         args = {java.lang.String.class}
    249     )
    250     public void test_getInstanceLjava_lang_String02() {
    251         try {
    252             TrustManagerFactory.getInstance(null);
    253             fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
    254         } catch (NoSuchAlgorithmException e) {
    255         } catch (NullPointerException e) {
    256         }
    257         for (int i = 0; i < invalidValues.length; i++) {
    258             try {
    259                 TrustManagerFactory.getInstance(invalidValues[i]);
    260                 fail("NoSuchAlgorithmException was not thrown as expected for algorithm: "
    261                         .concat(invalidValues[i]));
    262             } catch (NoSuchAlgorithmException e) {
    263             }
    264         }
    265     }
    266 
    267     /**
    268      * Test for <code>getInstance(String algorithm, String provider)</code>
    269      * method
    270      * Assertion: throws IllegalArgumentException when provider is null
    271      * or empty
    272      */
    273     @TestTargetNew(
    274         level = TestLevel.PARTIAL_COMPLETE,
    275         notes = "",
    276         method = "getInstance",
    277         args = {java.lang.String.class, java.lang.String.class}
    278     )
    279     public void test_getInstanceLjava_lang_StringLjava_lang_String01() throws NoSuchProviderException,
    280             NoSuchAlgorithmException {
    281         if (!DEFSupported) {
    282             fail(NotSupportedMsg);
    283             return;
    284         }
    285         String provider = null;
    286         for (int i = 0; i < validValues.length; i++) {
    287             try {
    288                 TrustManagerFactory.getInstance(validValues[i], provider);
    289                 fail("IllegalArgumentException must be thrown when provider is null");
    290             } catch (IllegalArgumentException e) {
    291             }
    292             try {
    293                 TrustManagerFactory.getInstance(validValues[i], "");
    294                 fail("IllegalArgumentException must be thrown when provider is empty");
    295             } catch (IllegalArgumentException e) {
    296             }
    297         }
    298     }
    299 
    300     /**
    301      * Test for <code>getInstance(String algorithm, String provider)</code>
    302      * method
    303      * Assertion:
    304      * throws NullPointerException when algorithm is null;
    305      * throws NoSuchAlgorithmException when algorithm is not correct;
    306      */
    307     @TestTargetNew(
    308         level = TestLevel.PARTIAL_COMPLETE,
    309         notes = "",
    310         method = "getInstance",
    311         args = {java.lang.String.class, java.lang.String.class}
    312     )
    313     public void test_getInstanceLjava_lang_StringLjava_lang_String02() throws NoSuchProviderException {
    314         if (!DEFSupported) {
    315             fail(NotSupportedMsg);
    316             return;
    317         }
    318         try {
    319             TrustManagerFactory.getInstance(null, defaultProviderName);
    320             fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
    321         } catch (NoSuchAlgorithmException e) {
    322         } catch (NullPointerException e) {
    323         }
    324         for (int i = 0; i < invalidValues.length; i++) {
    325             try {
    326                 TrustManagerFactory.getInstance(invalidValues[i],
    327                         defaultProviderName);
    328                 fail("NoSuchAlgorithmException must be thrown (algorithm: "
    329                         .concat(invalidValues[i]).concat(")"));
    330             } catch (NoSuchAlgorithmException e) {
    331             }
    332         }
    333     }
    334 
    335     /**
    336      * Test for <code>getInstance(String algorithm, String provider)</code>
    337      * method
    338      * Assertion: throws NoSuchProviderException when provider has
    339      * invalid value
    340      */
    341     @TestTargetNew(
    342         level = TestLevel.PARTIAL_COMPLETE,
    343         notes = "",
    344         method = "getInstance",
    345         args = {java.lang.String.class, java.lang.String.class}
    346     )
    347     public void test_getInstanceLjava_lang_StringLjava_lang_String03() throws NoSuchAlgorithmException {
    348         if (!DEFSupported) {
    349             fail(NotSupportedMsg);
    350             return;
    351         }
    352         for (int i = 1; i < invalidValues.length; i++) {
    353             for (int j = 0; j < validValues.length; j++) {
    354                 try {
    355                     TrustManagerFactory.getInstance(validValues[j],
    356                             invalidValues[i]);
    357                     fail("NuSuchProviderException must be thrown (algorithm: "
    358                             .concat(validValues[j]).concat(" provider: ")
    359                             .concat(invalidValues[i]).concat(")"));
    360                 } catch (NoSuchProviderException e) {
    361                 }
    362             }
    363         }
    364     }
    365 
    366     /**
    367      * Test for <code>getInstance(String algorithm, String provider)</code>
    368      * method
    369      * Assertion: returns instance of TrustManagerFactory
    370      */
    371     @TestTargetNew(
    372         level = TestLevel.PARTIAL_COMPLETE,
    373         notes = "",
    374         method = "getInstance",
    375         args = {java.lang.String.class, java.lang.String.class}
    376     )
    377     public void test_getInstanceLjava_lang_StringLjava_lang_String04() throws NoSuchAlgorithmException,
    378             NoSuchProviderException {
    379         if (!DEFSupported) {
    380             fail(NotSupportedMsg);
    381             return;
    382         }
    383         TrustManagerFactory trustMF;
    384         for (int i = 0; i < validValues.length; i++) {
    385             trustMF = TrustManagerFactory.getInstance(validValues[i],
    386                     defaultProviderName);
    387             assertTrue("Not TrustManagerFactory object",
    388                     trustMF instanceof TrustManagerFactory);
    389             assertEquals("Invalid algorithm", trustMF.getAlgorithm(),
    390                     validValues[i]);
    391             assertEquals("Invalid provider", trustMF.getProvider(),
    392                     defaultProvider);
    393         }
    394     }
    395 
    396     /**
    397      * Test for <code>getInstance(String algorithm, Provider provider)</code>
    398      * method
    399      * Assertion: throws IllegalArgumentException when provider is null
    400      */
    401     @TestTargetNew(
    402         level = TestLevel.PARTIAL_COMPLETE,
    403         notes = "",
    404         method = "getInstance",
    405         args = {java.lang.String.class, java.security.Provider.class}
    406     )
    407     public void test_getInstanceLjava_lang_StringLjava_security_Provider01() throws NoSuchAlgorithmException {
    408         if (!DEFSupported) {
    409             fail(NotSupportedMsg);
    410             return;
    411         }
    412         Provider provider = null;
    413         for (int i = 0; i < validValues.length; i++) {
    414             try {
    415                 TrustManagerFactory.getInstance(validValues[i], provider);
    416                 fail("IllegalArgumentException must be thrown  when provider is null");
    417             } catch (IllegalArgumentException e) {
    418             }
    419         }
    420     }
    421 
    422     /**
    423      * Test for <code>getInstance(String algorithm, Provider provider)</code>
    424      * method
    425      * Assertion:
    426      * throws NullPointerException when algorithm is null;
    427      * throws NoSuchAlgorithmException when algorithm is not correct;
    428      */
    429     @TestTargetNew(
    430         level = TestLevel.PARTIAL_COMPLETE,
    431         notes = "",
    432         method = "getInstance",
    433         args = {java.lang.String.class, java.security.Provider.class}
    434     )
    435     public void test_getInstanceLjava_lang_StringLjava_security_Provider02() {
    436         if (!DEFSupported) {
    437             fail(NotSupportedMsg);
    438             return;
    439         }
    440         try {
    441             TrustManagerFactory.getInstance(null, defaultProvider);
    442             fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
    443         } catch (NoSuchAlgorithmException e) {
    444         } catch (NullPointerException e) {
    445         }
    446         for (int i = 0; i < invalidValues.length; i++) {
    447             try {
    448                 TrustManagerFactory.getInstance(invalidValues[i],
    449                         defaultProvider);
    450                 fail("NoSuchAlgorithmException must be thrown (algorithm: "
    451                         .concat(invalidValues[i]).concat(")"));
    452             } catch (NoSuchAlgorithmException e) {
    453             }
    454         }
    455     }
    456 
    457     /**
    458      * Test for <code>getInstance(String algorithm, Provider provider)</code>
    459      * method
    460      * Assertion: returns instance of TrustManagerFactory
    461      */
    462     @TestTargetNew(
    463         level = TestLevel.PARTIAL_COMPLETE,
    464         notes = "",
    465         method = "getInstance",
    466         args = {java.lang.String.class, java.security.Provider.class}
    467     )
    468     public void test_getInstanceLjava_lang_StringLjava_security_Provider03() throws NoSuchAlgorithmException {
    469         if (!DEFSupported) {
    470             fail(NotSupportedMsg);
    471             return;
    472         }
    473         TrustManagerFactory trustMF;
    474         for (int i = 0; i < validValues.length; i++) {
    475             trustMF = TrustManagerFactory.getInstance(validValues[i],
    476                     defaultProvider);
    477             assertTrue("Not TrustManagerFactory object",
    478                     trustMF instanceof TrustManagerFactory);
    479             assertEquals("Invalid algorithm", trustMF.getAlgorithm(),
    480                     validValues[i]);
    481             assertEquals("Invalid provider", trustMF.getProvider(),
    482                     defaultProvider);
    483         }
    484     }
    485 
    486     /**
    487      * Test for <code>getProvider()</code>
    488      * @throws NoSuchAlgorithmException
    489      * @throws NoSuchProviderException
    490      */
    491     @TestTargetNew(
    492         level = TestLevel.COMPLETE,
    493         notes = "",
    494         method = "getProvider",
    495         args = {}
    496     )
    497     public void test_getProvider()
    498         throws NoSuchAlgorithmException, NoSuchProviderException {
    499         if (!DEFSupported) fail(NotSupportedMsg);
    500         assertEquals("Incorrect provider",
    501                 defaultProvider,
    502                 TrustManagerFactory
    503                 .getInstance(defaultAlgorithm).getProvider());
    504         assertEquals("Incorrect provider",
    505                 defaultProvider,
    506                 TrustManagerFactory
    507                 .getInstance(defaultAlgorithm, defaultProviderName)
    508                 .getProvider());
    509         assertEquals("Incorrect provider",
    510                 defaultProvider,
    511                 TrustManagerFactory.getInstance(defaultAlgorithm, defaultProvider)
    512                 .getProvider());
    513     }
    514 
    515     /**
    516      * Test for <code>geTrustManagers()</code>
    517      * @throws KeyStoreException
    518      * @throws IOException
    519      * @throws CertificateException
    520      * @throws NoSuchAlgorithmException
    521      */
    522     @TestTargetNew(
    523         level = TestLevel.COMPLETE,
    524         notes = "",
    525         method = "getTrustManagers",
    526         args = {}
    527     )
    528     public void test_getTrustManagers() {
    529         try {
    530             TrustManagerFactory trustMF = TrustManagerFactory.getInstance(defaultAlgorithm);
    531             KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
    532             ks.load(null, null);
    533             trustMF.init(ks);
    534             TrustManager[] tm = trustMF.getTrustManagers();
    535             assertNotNull("Result has not be null", tm);
    536             assertTrue("Length of result TrustManager array should not be 0",
    537                     (tm.length > 0));
    538         } catch (Exception ex) {
    539             fail("Unexpected exception " + ex.toString());
    540         }
    541     }
    542 
    543     /**
    544      * Test for <code>init(KeyStore keyStore)</code>
    545      * Assertion: call method with null parameter
    546      */
    547     @TestTargetNew(
    548         level = TestLevel.PARTIAL_COMPLETE,
    549         notes = "",
    550         method = "init",
    551         args = {java.security.KeyStore.class}
    552     )
    553     public void test_initLjava_security_KeyStore_01() {
    554         if (!DEFSupported) {
    555             fail(NotSupportedMsg);
    556             return;
    557         }
    558 
    559         KeyStore ksNull = null;
    560         TrustManagerFactory[] trustMF = createTMFac();
    561         assertNotNull("TrustManagerFactory objects were not created", trustMF);
    562         // null parameter
    563         try {
    564             trustMF[0].init(ksNull);
    565         } catch (Exception ex) {
    566             fail(ex + " unexpected exception was thrown for null parameter");
    567         }
    568     }
    569 
    570     /**
    571      * Test for <code>init(KeyStore keyStore)</code>
    572      * Assertion: call method with not null parameter
    573      */
    574     @TestTargetNew(
    575         level = TestLevel.PARTIAL_COMPLETE,
    576         notes = "",
    577         method = "init",
    578         args = {java.security.KeyStore.class}
    579     )
    580     public void test_initLjava_security_KeyStore_02() throws KeyStoreException {
    581         if (!DEFSupported) {
    582             fail(NotSupportedMsg);
    583             return;
    584         }
    585 
    586         KeyStore ks;
    587         ks = KeyStore.getInstance(KeyStore.getDefaultType());
    588         TrustManagerFactory[] trustMF = createTMFac();
    589         assertNotNull("TrustManagerFactory objects were not created", trustMF);
    590 
    591         // not null parameter
    592         try {
    593             trustMF[0].init(ks);
    594         } catch (Exception ex) {
    595             fail(ex + " unexpected exception was thrown for not null parameter");
    596         }
    597     }
    598 
    599     /**
    600      * Test for <code>init(ManagerFactoryParameters params)</code>
    601      * Assertion:
    602      * throws InvalidAlgorithmParameterException when params is null
    603      */
    604     @TestTargetNew(
    605         level = TestLevel.COMPLETE,
    606         notes = "",
    607         method = "init",
    608         args = {javax.net.ssl.ManagerFactoryParameters.class}
    609     )
    610     @KnownFailure("ManagerFactoryParameters object is not supported " +
    611                   "and InvalidAlgorithmParameterException was thrown.")
    612     public void test_initLjavax_net_ssl_ManagerFactoryParameters() {
    613         if (!DEFSupported) {
    614             fail(NotSupportedMsg);
    615             return;
    616         }
    617         ManagerFactoryParameters par = null;
    618         TrustManagerFactory[] trustMF = createTMFac();
    619         assertNotNull("TrustManagerFactory objects were not created", trustMF);
    620         for (int i = 0; i < trustMF.length; i++) {
    621             try {
    622                 trustMF[i].init(par);
    623                 fail("InvalidAlgorithmParameterException must be thrown");
    624             } catch (InvalidAlgorithmParameterException e) {
    625             }
    626         }
    627 
    628         //
    629         String keyAlg = "DSA";
    630         String validCaNameRfc2253 = "CN=Test CA," +
    631                                     "OU=Testing Division," +
    632                                     "O=Test It All," +
    633                                     "L=Test Town," +
    634                                     "ST=Testifornia," +
    635                                     "C=Testland";
    636 
    637         try {
    638             KeyStore kStore = KeyStore.getInstance(KeyStore.getDefaultType());
    639             kStore.load(null, null);
    640             PublicKey pk = new TestKeyPair(keyAlg).getPublic();
    641             TrustAnchor ta = new TrustAnchor(validCaNameRfc2253, pk, getFullEncoding());
    642             Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
    643             trustAnchors.add(ta);
    644             X509CertSelector xcs = new X509CertSelector();
    645             PKIXBuilderParameters pkixBP = new PKIXBuilderParameters(trustAnchors, xcs);
    646             CertPathTrustManagerParameters cptmp = new CertPathTrustManagerParameters(pkixBP);
    647             TrustManagerFactory tmf = TrustManagerFactory.getInstance(defaultAlgorithm);
    648             try {
    649                 tmf.init(cptmp);
    650             } catch (Exception ex) {
    651                 fail(ex + " was thrown for init(ManagerFactoryParameters spec)");
    652             }
    653         } catch (Exception e) {
    654             fail("Unexpected exception for configuration: " + e);
    655         }
    656 
    657     }
    658 
    659     private static final byte[] getFullEncoding() {
    660         // DO NOT MODIFY!
    661         return new byte[] {
    662                 (byte)0x30,(byte)0x81,(byte)0x8c,(byte)0xa0,
    663                 (byte)0x44,(byte)0x30,(byte)0x16,(byte)0x86,
    664                 (byte)0x0e,(byte)0x66,(byte)0x69,(byte)0x6c,
    665                 (byte)0x65,(byte)0x3a,(byte)0x2f,(byte)0x2f,
    666                 (byte)0x66,(byte)0x6f,(byte)0x6f,(byte)0x2e,
    667                 (byte)0x63,(byte)0x6f,(byte)0x6d,(byte)0x80,
    668                 (byte)0x01,(byte)0x00,(byte)0x81,(byte)0x01,
    669                 (byte)0x01,(byte)0x30,(byte)0x16,(byte)0x86,
    670                 (byte)0x0e,(byte)0x66,(byte)0x69,(byte)0x6c,
    671                 (byte)0x65,(byte)0x3a,(byte)0x2f,(byte)0x2f,
    672                 (byte)0x62,(byte)0x61,(byte)0x72,(byte)0x2e,
    673                 (byte)0x63,(byte)0x6f,(byte)0x6d,(byte)0x80,
    674                 (byte)0x01,(byte)0x00,(byte)0x81,(byte)0x01,
    675                 (byte)0x01,(byte)0x30,(byte)0x12,(byte)0x86,
    676                 (byte)0x0a,(byte)0x66,(byte)0x69,(byte)0x6c,
    677                 (byte)0x65,(byte)0x3a,(byte)0x2f,(byte)0x2f,
    678                 (byte)0x6d,(byte)0x75,(byte)0x75,(byte)0x80,
    679                 (byte)0x01,(byte)0x00,(byte)0x81,(byte)0x01,
    680                 (byte)0x01,(byte)0xa1,(byte)0x44,(byte)0x30,
    681                 (byte)0x16,(byte)0x86,(byte)0x0e,(byte)0x68,
    682                 (byte)0x74,(byte)0x74,(byte)0x70,(byte)0x3a,
    683                 (byte)0x2f,(byte)0x2f,(byte)0x66,(byte)0x6f,
    684                 (byte)0x6f,(byte)0x2e,(byte)0x63,(byte)0x6f,
    685                 (byte)0x6d,(byte)0x80,(byte)0x01,(byte)0x00,
    686                 (byte)0x81,(byte)0x01,(byte)0x01,(byte)0x30,
    687                 (byte)0x16,(byte)0x86,(byte)0x0e,(byte)0x68,
    688                 (byte)0x74,(byte)0x74,(byte)0x70,(byte)0x3a,
    689                 (byte)0x2f,(byte)0x2f,(byte)0x62,(byte)0x61,
    690                 (byte)0x72,(byte)0x2e,(byte)0x63,(byte)0x6f,
    691                 (byte)0x6d,(byte)0x80,(byte)0x01,(byte)0x00,
    692                 (byte)0x81,(byte)0x01,(byte)0x01,(byte)0x30,
    693                 (byte)0x12,(byte)0x86,(byte)0x0a,(byte)0x68,
    694                 (byte)0x74,(byte)0x74,(byte)0x70,(byte)0x3a,
    695                 (byte)0x2f,(byte)0x2f,(byte)0x6d,(byte)0x75,
    696                 (byte)0x75,(byte)0x80,(byte)0x01,(byte)0x00,
    697                 (byte)0x81,(byte)0x01,(byte)0x01
    698         };
    699     }
    700 }
    701 
    702 /**
    703  * Addifional class to verify TrustManagerFactory constructor
    704  */
    705 
    706 class myTrustManagerFactory extends TrustManagerFactory {
    707     public myTrustManagerFactory(TrustManagerFactorySpi spi, Provider prov,
    708             String alg) {
    709         super(spi, prov, alg);
    710     }
    711 }
    712 
    713