List of usage examples for java.security KeyStoreException KeyStoreException
public KeyStoreException(Throwable cause)
From source file:org.globus.security.stores.PEMKeyStore.java
@SuppressWarnings("unchecked") private CredentialWrapper createProxyCredential(String s, X509Credential credential) throws KeyStoreException { CredentialWrapper wrapper;// ww w. j ava 2 s . co m CredentialWrapper proxyCredential = getKeyEntry(s); File file; if (proxyCredential != null && proxyCredential instanceof AbstractResourceSecurityWrapper) { AbstractResourceSecurityWrapper proxyWrapper = (AbstractResourceSecurityWrapper) proxyCredential; file = proxyWrapper.getFile(); } else { // FIXME: should alias be file name? or generate? file = new File(defaultDirectory, s + "-key.pem"); } try { wrapper = new ResourceProxyCredential(new FileSystemResource(file), credential); } catch (ResourceStoreException e) { throw new KeyStoreException(e); } return wrapper; }
From source file:org.globus.security.stores.PEMKeyStore.java
private CredentialWrapper createCertKeyCredential(String s, X509Credential credential) throws KeyStoreException { Resource certResource;//ww w. ja va2 s . co m Resource keyResource; CredentialWrapper wrapper; CredentialWrapper credentialWrapper = getKeyEntry(s); if (credentialWrapper != null && credentialWrapper instanceof CertKeyCredential) { CertKeyCredential certKeyCred = (CertKeyCredential) credentialWrapper; certResource = certKeyCred.getCertificateFile(); keyResource = certKeyCred.getKeyFile(); } else { certResource = new FileSystemResource(new File(defaultDirectory, s + ".0")); keyResource = new FileSystemResource(new File(defaultDirectory, s + "-key.pem")); } try { wrapper = new CertKeyCredential(certResource, keyResource, credential); } catch (ResourceStoreException e) { throw new KeyStoreException(e); } return wrapper; }
From source file:org.globus.gsi.stores.PEMKeyStore.java
@SuppressWarnings("rawtypes") private CredentialWrapper createProxyCredential(String s, X509Credential credential) throws KeyStoreException { CredentialWrapper wrapper;/* www.java 2 s . c o m*/ CredentialWrapper proxyCredential = getKeyEntry(s); File file; if (proxyCredential != null && proxyCredential instanceof AbstractResourceSecurityWrapper) { AbstractResourceSecurityWrapper proxyWrapper = (AbstractResourceSecurityWrapper) proxyCredential; file = proxyWrapper.getFile(); } else { // JGLOBUS-91 : should alias be file name? or generate? file = new File(defaultDirectory, s + "-key.pem"); } try { wrapper = new ResourceProxyCredential(inMemoryOnly, new GlobusResource(file.getAbsolutePath()), credential); } catch (ResourceStoreException e) { throw new KeyStoreException(e); } return wrapper; }
From source file:org.globus.security.stores.PEMKeyStore.java
/** * Add a certificate to the keystore.//from w w w . j a v a2 s. c o m * * @param alias * The certificate alias. * @param certificate * The certificate to store. * @throws KeyStoreException */ @Override public void engineSetCertificateEntry(String alias, Certificate certificate) throws KeyStoreException { if (!(certificate instanceof X509Certificate)) { throw new KeyStoreException("Certificate must be instance of X509Certificate"); } File file; ResourceTrustAnchor trustAnchor = getCertificateEntry(alias); if (trustAnchor != null) { file = trustAnchor.getFile(); } else { file = new File(defaultDirectory, alias); } X509Certificate x509Cert = (X509Certificate) certificate; try { writeCertificate(x509Cert, file); ResourceTrustAnchor anchor = new ResourceTrustAnchor(new FileSystemResource(file), new TrustAnchor(x509Cert, null)); this.aliasObjectMap.put(alias, anchor); this.certFilenameMap.put(x509Cert, alias); } catch (ResourceStoreException e) { throw new KeyStoreException(e); } catch (IOException e) { throw new KeyStoreException(e); } catch (CertificateEncodingException e) { throw new KeyStoreException(e); } }
From source file:org.globus.gsi.stores.PEMKeyStore.java
private CredentialWrapper createCertKeyCredential(String s, X509Credential credential) throws KeyStoreException { GlobusResource certResource;// w ww. jav a2s . c o m GlobusResource keyResource; CredentialWrapper wrapper; CredentialWrapper credentialWrapper = getKeyEntry(s); if (credentialWrapper != null && credentialWrapper instanceof CertKeyCredential) { CertKeyCredential certKeyCred = (CertKeyCredential) credentialWrapper; certResource = certKeyCred.getCertificateFile(); keyResource = certKeyCred.getKeyFile(); } else { certResource = new GlobusResource(new File(defaultDirectory, s + ".0").getAbsolutePath()); keyResource = new GlobusResource(new File(defaultDirectory, s + "-key.pem").getAbsolutePath()); } try { wrapper = new CertKeyCredential(certResource, keyResource, credential); } catch (ResourceStoreException e) { throw new KeyStoreException(e); } return wrapper; }
From source file:ca.uhn.hl7v2.testpanel.model.conn.AbstractConnection.java
public KeyStore getTlsKeystore() throws KeyStoreException { if (isBlank(myTlsKeystoreLocation) || isTls() == false) { return null; }/*from www . j av a2 s.c o m*/ if (myTlsKeystore != null) { return myTlsKeystore; } File jksFile = new File(myTlsKeystoreLocation); if (!jksFile.exists() || !jksFile.canRead()) { throw new KeyStoreException("File does not exist or can not be read: " + jksFile.getAbsolutePath()); } char[] password = null; if (isNotBlank(myTlsKeystorePassword)) { password = myTlsKeystorePassword.toCharArray(); } KeyStore keystore; try { keystore = KeystoreUtils.loadKeystore(jksFile, password); } catch (NoSuchAlgorithmException e) { ourLog.error("Failed to load keystore!", e); throw new KeyStoreException("Failed to load keystore: " + e.getMessage()); } catch (CertificateException e) { ourLog.error("Failed to load keystore!", e); throw new KeyStoreException("Failed to load keystore: " + e.getMessage()); } catch (IOException e) { ourLog.error("Failed to load keystore!", e); if (e.getCause() instanceof UnrecoverableKeyException) { throw new KeyStoreException("Keystore password appears to be incorrect"); } throw new KeyStoreException("Failed to load keystore: " + e.getMessage()); } if (this instanceof InboundConnection) { if (!KeystoreUtils.validateKeystoreForTlsReceiving(keystore)) { throw new KeyStoreException("Keystore contains no keys appropriate for receiving data"); } } else if (this instanceof OutboundConnection) { if (!KeystoreUtils.validateKeystoreForTlsSending(keystore)) { throw new KeyStoreException("Keystore contains no keys appropriate for receiving data"); } } myTlsKeystore = keystore; return myTlsKeystore; }
From source file:org.globus.gsi.stores.PEMKeyStore.java
/** * Add a certificate to the keystore.//from w w w. j a v a 2 s .c o m * * @param alias * The certificate alias. * @param certificate * The certificate to store. * @throws KeyStoreException */ @Override public void engineSetCertificateEntry(String alias, Certificate certificate) throws KeyStoreException { if (!(certificate instanceof X509Certificate)) { throw new KeyStoreException("Certificate must be instance of X509Certificate"); } File file; ResourceTrustAnchor trustAnchor = getCertificateEntry(alias); if (trustAnchor != null) { file = trustAnchor.getFile(); } else { file = new File(defaultDirectory, alias); } X509Certificate x509Cert = (X509Certificate) certificate; try { if (!inMemoryOnly) { writeCertificate(x509Cert, file); } ResourceTrustAnchor anchor = new ResourceTrustAnchor(inMemoryOnly, new GlobusResource(file.getAbsolutePath()), new TrustAnchor(x509Cert, null)); this.aliasObjectMap.put(alias, anchor); this.certFilenameMap.put(x509Cert, alias); } catch (ResourceStoreException e) { throw new KeyStoreException(e); } catch (IOException e) { throw new KeyStoreException(e); } catch (CertificateEncodingException e) { throw new KeyStoreException(e); } }
From source file:org.signserver.server.cryptotokens.KeystoreCryptoToken.java
private KeyStore getKeystore(final String type, final String path, final char[] authCode) throws KeyStoreException, CertificateException, NoSuchProviderException, NoSuchAlgorithmException, FileNotFoundException, IOException { final KeyStore result; if (TYPE_PKCS12.equalsIgnoreCase(type) || TYPE_INTERNAL.equalsIgnoreCase(type)) { result = KeyStore.getInstance("PKCS12", "BC"); } else {//from w w w .j a va2 s . co m result = KeyStore.getInstance("JKS"); } InputStream in = null; try { if (!TYPE_INTERNAL.equalsIgnoreCase(type)) { if (path == null) { throw new FileNotFoundException("Missing property " + KeystoreCryptoToken.KEYSTOREPATH + "."); } in = new FileInputStream(path); } else { // load data from internal worker data... final byte[] keystoreData = getWorkerSession() .getKeystoreData(new AdminInfo("Internal", null, null), this.workerId); if (keystoreData != null) { in = new ByteArrayInputStream(keystoreData); } } result.load(in, authCode); } catch (NamingException e) { throw new KeyStoreException("Failed to get worker session: " + e.getMessage()); } finally { if (in != null) { try { in.close(); } catch (IOException ex) { LOG.error("Error closing file", ex); } } } return result; }