private void clear() throws LoginException { LoginModuleUtils.clearPassword(keyStorePassword); keyStorePassword = null; LoginModuleUtils.clearPassword(privateKeyPassword); privateKeyPassword = null; if (keyStoreProvider instanceof AuthProvider) { ((AuthProvider) (keyStoreProvider)).logout(); } if (principal != null) { subject.getPrincipals().remove(principal); principal = null; } if (certPath != null) { subject.getPublicCredentials().remove(certPath); certPath = null; } if (privateCredential != null) { subject.getPrivateCredentials().remove(privateCredential); privateCredential.destroy(); privateCredential = null; } status.logouted(); }
private static void list() throws Exception { int testnum = 1; ks = KeyStore.getInstance(KS_TYPE, provider); // check instance if (ks.getProvider() instanceof java.security.AuthProvider) { System.out.println("keystore provider instance of AuthProvider"); System.out.println("test " + testnum++ + " passed"); } else { throw new SecurityException("did not get AuthProvider KeyStore"); } // load ks.load(null, tokenPwd); System.out.println("test " + testnum++ + " passed"); // aliases Enumeration enu = ks.aliases(); int count = 0; while (enu.hasMoreElements()) { count++; System.out.println("alias " + count + " = " + (String)enu.nextElement()); } }
/** * Do action. */ @Override protected void doAction() { try { DOpenPkcs11KeyStore dOpenPkcs11KeyStore = new DOpenPkcs11KeyStore(frame); dOpenPkcs11KeyStore.setLocationRelativeTo(frame); dOpenPkcs11KeyStore.setVisible(true); Provider selectedProvider = dOpenPkcs11KeyStore.getSelectedProvider(); if (selectedProvider == null) { return; } KeyStore keyStore = KeyStore.getInstance(PKCS11.jce(), selectedProvider); // register password handler AuthProvider authProvider = (AuthProvider) selectedProvider; authProvider.setCallbackHandler(new PasswordCallbackHandler(frame)); keyStore.load(null, null); kseFrame.addKeyStore(keyStore, selectedProvider.getName(), null, selectedProvider); } catch (Exception ex) { DError.displayError(frame, ex); } }
/** * Efetua logout do SmartCard * @throws LoginException */ public static void logoutSmart () throws LoginException{ if (pkcs11Provider != null){ AuthProvider ap = (AuthProvider) pkcs11Provider; ap.logout(); pkcs11Provider = null; } if (providerName != null){ Security.removeProvider(providerName); providerName = null; } }