List of usage examples for java.security KeyStoreException getLocalizedMessage
public String getLocalizedMessage()
From source file:SigningProcess.java
public static HashMap returnCertificates() { HashMap map = new HashMap(); try {/*from ww w .ja v a2 s.c o m*/ providerMSCAPI = new SunMSCAPI(); Security.addProvider(providerMSCAPI); ks = KeyStore.getInstance("Windows-MY"); ks.load(null, null); Field spiField = KeyStore.class.getDeclaredField("keyStoreSpi"); spiField.setAccessible(true); KeyStoreSpi spi = (KeyStoreSpi) spiField.get(ks); Field entriesField = spi.getClass().getSuperclass().getDeclaredField("entries"); entriesField.setAccessible(true); Collection entries = (Collection) entriesField.get(spi); for (Object entry : entries) { alias = (String) invokeGetter(entry, "getAlias"); // System.out.println("alias :" + alias); privateKey = (Key) invokeGetter(entry, "getPrivateKey"); certificateChain = (X509Certificate[]) invokeGetter(entry, "getCertificateChain"); // System.out.println(alias + ": " + privateKey + "CERTIFICATES -----------"+Arrays.toString(certificateChain)); } map.put("privateKey", privateKey); map.put("certificateChain", certificateChain); } catch (KeyStoreException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (IOException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (NoSuchAlgorithmException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (CertificateException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (NoSuchFieldException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (SecurityException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (IllegalArgumentException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (IllegalAccessException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (NoSuchMethodException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } catch (InvocationTargetException ex) { System.out.println("Exception :" + ex.getLocalizedMessage()); } return map; }
From source file:org.owasp.proxy.Main.java
private static SSLContextSelector getClientSSLContextSelector(Configuration config) { String type = config.keystoreType; char[] password = config.keyStorePassword == null ? null : config.keyStorePassword.toCharArray(); File location = config.keyStoreLocation == null ? null : new File(config.keyStoreLocation); if (type != null) { KeyStore ks = null;/*www.j a va 2s . co m*/ if (type.equals("PKCS11")) { try { int slot = config.pkcs11SlotLocation; ks = KeystoreUtils.getPKCS11Keystore("PKCS11", location, slot, password); } catch (Exception e) { System.err.println(e.getLocalizedMessage()); System.exit(2); } } else { try { FileInputStream in = new FileInputStream(location); ks = KeyStore.getInstance(type); ks.load(in, password); } catch (Exception e) { System.err.println(e.getLocalizedMessage()); System.exit(2); } } String alias = config.keyStoreAlias; if (alias == null) { try { Map<String, String> aliases = KeystoreUtils.getAliases(ks); if (aliases.size() > 0) { System.err.println("Keystore contains the following aliases: \n"); for (String a : aliases.keySet()) { System.err.println("Alias \"" + a + "\"" + " : " + aliases.get(a)); } alias = aliases.keySet().iterator().next(); System.err.println("Using " + alias + " : " + aliases.get(alias)); } else { System.err.println("Keystore contains no aliases!"); System.exit(3); } } catch (KeyStoreException kse) { System.err.println(kse.getLocalizedMessage()); System.exit(4); } } try { final X509KeyManager km = KeystoreUtils.getKeyManagerForAlias(ks, alias, password); return new DefaultClientContextSelector(km); } catch (GeneralSecurityException gse) { System.err.println(gse.getLocalizedMessage()); System.exit(5); } } return new DefaultClientContextSelector(); }
From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java
public void addPublicKey(KeyStore ks, KeyPair keyPair, String keyPairName, String keyPairSubjectDN) throws CryptoException { try {//from ww w. jav a 2s .c o m X509Certificate cert = generateV3Certificate(keyPair, keyPairSubjectDN); ks.setCertificateEntry(keyPairName, cert); } catch (KeyStoreException e) { this.logger.error("KeyStoreException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } }
From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java
/** * * @param ks/*w w w .j a v a 2 s .c o m*/ * @param keyPair * @param keyPairName * @param keyPairSubjectDN * @param before * @param expiry * @throws CryptoException */ public void addPublicKey(KeyStore ks, KeyPair keyPair, String keyPairName, String keyPairSubjectDN, Calendar before, Calendar expiry) throws CryptoException { try { X509Certificate cert = generateV3Certificate(keyPair, keyPairSubjectDN, before, expiry); ks.setCertificateEntry(keyPairName, cert); } catch (KeyStoreException e) { this.logger.error("KeyStoreException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } }
From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java
public byte[] convertKeystoreByteArray(KeyStore keyStore, String keyStorePassphrase) throws CryptoException { byte[] keyStoreBytes; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try {//from w ww. ja v a 2 s .c o m keyStore.store(outputStream, keyStorePassphrase.toCharArray()); keyStoreBytes = outputStream.toByteArray(); return keyStoreBytes; } catch (KeyStoreException e) { this.logger.error("KeyStoreException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (NoSuchAlgorithmException e) { this.logger.error("NoSuchAlgorithmException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (CertificateException e) { this.logger.error("CertificateException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (IOException e) { this.logger.error("IOException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } finally { try { outputStream.close(); } catch (IOException e) { this.logger.error("IOException thrown in finally, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); } } }
From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java
public KeyStore generateKeyStore() throws CryptoException { try {//www . ja v a2 s . c om logger.debug("Generating a new key store."); /* Add BC to the jdk security manager to be able to use it as a provider */ Security.addProvider(new BouncyCastleProvider()); /* Create and init an empty key store */ KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(null, null); /* * Populate all new key stores with the key data of the local resolver, generally this is for metadata * purposes to ensure that all systems in the authentication network can correctly validate the signed * metadata document */ X509Certificate localCertificate = (X509Certificate) localResolver.getLocalCertificate(); Calendar before = new GregorianCalendar(); Calendar expiry = new GregorianCalendar(); before.setTime(localCertificate.getNotBefore()); expiry.setTime(localCertificate.getNotAfter()); addPublicKey(keyStore, new KeyPair(this.localResolver.getLocalPublicKey(), this.localResolver.getLocalPrivateKey()), this.localResolver.getLocalKeyAlias(), this.certIssuerDN, before, expiry); return keyStore; } catch (KeyStoreException e) { this.logger.error("KeyStoreException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (NoSuchAlgorithmException e) { this.logger.error("NoSuchAlgorithmException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (CertificateException e) { this.logger.error("CertificateException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (IOException e) { this.logger.error("IOException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } }