test/sun/security/pkcs11/KeyStore/Basic.java

Print this page
7191662: JCE providers should be located via ServiceLoader


 351 
 352         // load
 353         ks.load(null, tokenPwd);
 354         System.out.println("test " + testnum++ + " passed");
 355 
 356         // aliases
 357         Enumeration enu = ks.aliases();
 358         int count = 0;
 359         while (enu.hasMoreElements()) {
 360             count++;
 361             System.out.println("alias " +
 362                                 count +
 363                                 " = " +
 364                                 (String)enu.nextElement());
 365         }
 366     }
 367 
 368     private static void module() throws Exception {
 369 
 370         // perform Security.addProvider of P11 provider
 371         ProviderLoader.go(System.getProperty("CUSTOM_P11_CONFIG"));





 372 
 373         String KS_PROVIDER = "SunPKCS11-" + System.getProperty("TOKEN");
 374 
 375         KeyStoreLoginModule m = new KeyStoreLoginModule();
 376         Subject s = new Subject();
 377         Map options = new HashMap();
 378         options.put("keyStoreURL", "NONE");
 379         options.put("keyStoreType", KS_TYPE);
 380         options.put("keyStoreProvider", KS_PROVIDER);
 381         options.put("debug", "true");
 382         m.initialize(s, new TextCallbackHandler(), new HashMap(), options);
 383         m.login();
 384         m.commit();
 385         System.out.println("authenticated subject = " + s);
 386         m.logout();
 387         System.out.println("authenticated subject = " + s);
 388     }
 389 
 390     /**
 391      * SCA1000 does not handle extended secret key tests




 351 
 352         // load
 353         ks.load(null, tokenPwd);
 354         System.out.println("test " + testnum++ + " passed");
 355 
 356         // aliases
 357         Enumeration enu = ks.aliases();
 358         int count = 0;
 359         while (enu.hasMoreElements()) {
 360             count++;
 361             System.out.println("alias " +
 362                                 count +
 363                                 " = " +
 364                                 (String)enu.nextElement());
 365         }
 366     }
 367 
 368     private static void module() throws Exception {
 369 
 370         // perform Security.addProvider of P11 provider
 371         Provider p = getSunPKCS11(System.getProperty("CUSTOM_P11_CONFIG"));
 372         if (p != null) {
 373             Security.addProvider(p);
 374         } else {
 375             throw new Exception("Error: PKCS11 provider configuration failed");
 376         }
 377 
 378         String KS_PROVIDER = "SunPKCS11-" + System.getProperty("TOKEN");
 379 
 380         KeyStoreLoginModule m = new KeyStoreLoginModule();
 381         Subject s = new Subject();
 382         Map options = new HashMap();
 383         options.put("keyStoreURL", "NONE");
 384         options.put("keyStoreType", KS_TYPE);
 385         options.put("keyStoreProvider", KS_PROVIDER);
 386         options.put("debug", "true");
 387         m.initialize(s, new TextCallbackHandler(), new HashMap(), options);
 388         m.login();
 389         m.commit();
 390         System.out.println("authenticated subject = " + s);
 391         m.logout();
 392         System.out.println("authenticated subject = " + s);
 393     }
 394 
 395     /**
 396      * SCA1000 does not handle extended secret key tests