List of usage examples for org.apache.commons.ssl TrustMaterial TrustMaterial
public TrustMaterial(URL urlToPemFile) throws GeneralSecurityException, IOException
From source file:MiGSSLSocketFactory.java
public MiGSSLSocketFactory() throws GeneralSecurityException, IOException { super();//w w w . ja v a 2s .c o m this.loadConf(); super.setTrustMaterial(new TrustMaterial(cacertFile)); super.setCheckHostname(false); super.setCheckExpiry(false); super.setCheckCRL(false); super.setKeyMaterial(new KeyMaterial(certFile, password.toCharArray())); }
From source file:org.fedoraproject.eclipse.packager.FedoraSSL.java
/** * /*from w w w. j a v a 2 s. c o m*/ * @return * @throws GeneralSecurityException * @throws IOException */ private TrustChain getTrustChain() throws GeneralSecurityException, IOException { TrustChain tc = new TrustChain(); tc.addTrustMaterial(new TrustMaterial(fedoraUploadCert)); tc.addTrustMaterial(new TrustMaterial(fedoraServerCert)); return tc; }
From source file:org.opensaml.xml.security.x509.X509Util.java
/** * Decodes X.509 certificates in DER or PEM format. * //from w ww.j a va 2 s. c o m * @param certs encoded certs * * @return decoded certs * * @throws CertificateException thrown if the certificates can not be decoded */ @SuppressWarnings("unchecked") public static Collection<X509Certificate> decodeCertificate(byte[] certs) throws CertificateException { try { TrustMaterial tm = new TrustMaterial(certs); return tm.getCertificates(); } catch (Exception e) { throw new CertificateException("Unable to decode X.509 certificates", e); } }
From source file:org.sipfoundry.commons.sipkeystorebuilder.sipkeystorebuilder.java
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println(//w w w .j a v a 2s .c om "sipkeystorebuilder: creates '[sip or sip-web].keystore' (Java Key Store) and java truststore '[authority].jks"); System.out.println("[alias] will be set to the first CN value of the X509 certificate."); System.out.println("-------------------------------------------------------------------"); System.out.println("Usage: [sipX ssl directory]"); System.out.println("-------------------------------------------------------------------"); System.exit(1); } char[] password = "changeit".toCharArray(); final String auth = "authorities"; final String keySuffix = ".key"; final String certSuffix = ".crt"; final String keystoreSuffix = ".keystore"; final String truststoreSuffix = ".jks"; File ssldir = new File(args[0]); File authdir = new File(args[0] + "/" + auth); FilenameFilter keyFilter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(keySuffix); } }; if (ssldir.isDirectory()) { // Valid directory specified. Now scan for key and cert files to build the KeyStore. File[] keyfiles = ssldir.listFiles(keyFilter); for (int i = 0; i < keyfiles.length; i++) { // get the matching certificate file. String certPath = keyfiles[i].toString().replaceAll(keySuffix, certSuffix); File certFile = new File(certPath); if (certFile.exists()) { FileInputStream fin1 = new FileInputStream(keyfiles[i].toString()); byte[] bytes1 = Util.streamToBytes(fin1); FileInputStream fin2 = new FileInputStream(certFile.toString()); byte[] bytes2 = Util.streamToBytes(fin2); KeyStore SipXKeyStore = KeyStoreBuilder.build(bytes1, bytes2, password); File outks = new File(keyfiles[i].toString().replaceAll(keySuffix, keystoreSuffix)); FileOutputStream fout = new FileOutputStream(outks); SipXKeyStore.store(fout, password); fout.flush(); fout.close(); } } } if (authdir.isDirectory()) { // Valid authority directory specified. Now scan for cert files to build the TrustStore. File[] certFiles = authdir.listFiles(); TrustChain trustChain = new TrustChain(); for (int i = 0; i < certFiles.length; i++) { try { TrustMaterial trustCerts = new TrustMaterial(certFiles[i].toString()); trustChain.addTrustMaterial(trustCerts); } catch (IOException ex) { // skip adding CA. } catch (KeyStoreException ex) { // skip adding CA. } catch (GeneralSecurityException ex) { // skip adding CA. } } File outts = new File(args[0] + "/" + auth + truststoreSuffix); FileOutputStream fout = new FileOutputStream(outts); KeyStore trustKeyStore = trustChain.getUnifiedKeyStore(); trustKeyStore.store(fout, password); fout.flush(); fout.close(); } System.exit(0); }