當前位置: 首頁>>代碼示例>>Java>>正文


Java TrustManagerFactory類代碼示例

本文整理匯總了Java中javax.net.ssl.TrustManagerFactory的典型用法代碼示例。如果您正苦於以下問題:Java TrustManagerFactory類的具體用法?Java TrustManagerFactory怎麽用?Java TrustManagerFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TrustManagerFactory類屬於javax.net.ssl包,在下文中一共展示了TrustManagerFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: newSSLContext

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
public static SSLContext newSSLContext(final KeyStore ks, final String password,
    final String ksAlgorithm) throws InvalidSSLConfig {
    try {
        // Get a KeyManager and initialize it
        final KeyManagerFactory kmf = KeyManagerFactory.getInstance(ksAlgorithm);
        kmf.init(ks, password.toCharArray());

        // Get a TrustManagerFactory with the DEFAULT KEYSTORE, so we have all the certificates in cacerts trusted
        final TrustManagerFactory tmf = TrustManagerFactory.getInstance(ksAlgorithm);
        tmf.init((KeyStore) null);

        // Get the SSLContext to help create SSLSocketFactory
        final SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
        return sslContext;
    } catch (final GeneralSecurityException e) {
        throw new InvalidSSLConfig(e);
    }
}
 
開發者ID:aerogear,項目名稱:push-network-proxies,代碼行數:20,代碼來源:SSLHelper.java

示例2: getSSLSocketFactory

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
/**
 * 獲得SSLSocektFactory
 * 
 * @param password 密碼
 * @param keyStorePath 密鑰庫路徑
 * @param trustStorePath 信任庫路徑
 * @return SSLSocketFactory
 * @throws Exception
 */
private static SSLSocketFactory getSSLSocketFactory(String password, String keyStorePath, String trustStorePath)
		throws Exception {
	// 實例化密鑰庫
	KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
	// 獲得密鑰庫
	KeyStore keyStore = getKeyStore(keyStorePath, password);
	// 初始化密鑰工廠
	keyManagerFactory.init(keyStore, password.toCharArray());
	// 實例化信任庫
	TrustManagerFactory trustManagerFactory = TrustManagerFactory
			.getInstance(TrustManagerFactory.getDefaultAlgorithm());
	// 獲得信任庫
	KeyStore trustStore = getKeyStore(trustStorePath, password);
	// 初始化信任庫
	trustManagerFactory.init(trustStore);
	// 實例化SSL上下文
	SSLContext ctx = SSLContext.getInstance(PROTOCOL);
	// 初始化SSL上下文
	ctx.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
	// 獲得SSLSocketFactory
	return ctx.getSocketFactory();

}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:33,代碼來源:HTTPSCoder.java

示例3: SslHandlerFactory

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
public SslHandlerFactory(AmqpServerConfiguration configuration) throws KeyStoreException, IOException,
        CertificateException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyManagementException {
    KeyStore keyStore = getKeyStore(configuration.getSsl().getKeyStore().getType(),
                                    configuration.getSsl().getKeyStore().getLocation(),
                                    configuration.getSsl().getKeyStore().getPassword());
    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(configuration.getSsl()
                                                                                     .getKeyStore()
                                                                                     .getCertType());
    keyManagerFactory.init(keyStore, configuration.getSsl().getKeyStore().getPassword().toCharArray());

    KeyStore trustStore = getKeyStore(configuration.getSsl().getTrustStore().getType(),
                                      configuration.getSsl().getTrustStore().getLocation(),
                                      configuration.getSsl().getTrustStore().getPassword());
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(configuration.getSsl()
                                                                           .getTrustStore()
                                                                           .getCertType());
    trustManagerFactory.init(trustStore);

    sslContext = SSLContext.getInstance(configuration.getSsl().getProtocol());
    sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:22,代碼來源:SslHandlerFactory.java

示例4: LocalTrustManager

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
LocalTrustManager(KeyStore localKeyStore) {
    try {
        TrustManagerFactory tmf = TrustManagerFactory
                .getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init((KeyStore) null);

        defaultTrustManager = findX509TrustManager(tmf);
        if (defaultTrustManager == null) {
            throw new IllegalStateException("Couldn't find X509TrustManager");
        }

        localTrustManager = new LocalStoreX509TrustManager(localKeyStore);

        List<X509Certificate> allIssuers = new ArrayList<>();
        allIssuers.addAll(Arrays.asList(defaultTrustManager.getAcceptedIssuers()));
        allIssuers.addAll(Arrays.asList(localTrustManager.getAcceptedIssuers()));
        acceptedIssuers = allIssuers.toArray(new X509Certificate[allIssuers.size()]);
    } catch (GeneralSecurityException e) {
        throw new RuntimeException(e);
    }


}
 
開發者ID:vbier,項目名稱:habpanelviewer,代碼行數:24,代碼來源:LocalTrustManager.java

示例5: getTrustManagers

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
@Override
public TrustManager[] getTrustManagers() throws Exception {
	String truststoreType = endpoint.getTruststoreType();
	if (truststoreType == null) {
		truststoreType = System.getProperty("javax.net.ssl.trustStoreType");
	}
	if (truststoreType == null) {
		truststoreType = endpoint.getKeystoreType();
	}
	if (truststoreType == null) {
		truststoreType = defaultKeystoreType;
	}

	String algorithm = endpoint.getTruststoreAlgorithm();
	if (algorithm == null) {
		algorithm = TrustManagerFactory.getDefaultAlgorithm();
	}

	return getTrustManagers(truststoreType, endpoint.getKeystoreProvider(), algorithm);
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:21,代碼來源:JSSESocketFactory.java

示例6: EventWebSocketSecureServer

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
public EventWebSocketSecureServer(int port, String keystorepath, String keystorepassword, InetAddress ip) {
    super(port, ip);

    try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        char ksPassword[] = keystorepassword.toCharArray();
        if (!keystorepath.equals("")) {
            KeyStore ks = KeyStore.getInstance("JKS");
            ks.load(new FileInputStream(new File(keystorepath)), ksPassword);

            KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
            kmf.init(ks, ksPassword);
            TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
            tmf.init(ks);

            sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
        } else {
            sslContext.init(null, null, null);
        }
        this.setWebSocketFactory(new DefaultSSLWebSocketServerFactory(sslContext));
    } catch (Exception e) {
        com.gmt2001.Console.out.println("Secure EventSocketServer failed: " + e);
        e.printStackTrace();
    }
}
 
開發者ID:GloriousEggroll,項目名稱:quorrabot,代碼行數:26,代碼來源:EventWebSocketSecureServer.java

示例7: EdgeXSecurityManager

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
public EdgeXSecurityManager() throws IllegalStateException {
	super();
	
	try {
		keystore = KeyStore.getInstance("JKS");
		InputStream jksInputStream = EdgeXSecurityManager.class.getClassLoader().getResourceAsStream("/mqttkeystore.jks"); 
		keystore.load(jksInputStream, "storepassword".toCharArray()); 

		keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
		keyManagerFactory.init(keystore, "keypassword".toCharArray()); 

		trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 
           trustManagerFactory.init(this.keystore);

	} catch (Exception e) {
		failedInitializationCause = e;
		keystore = null;
		keyManagerFactory = null;
		trustManagerFactory = null;
		throw new IllegalStateException("SecurityManager failed to initialize.", failedInitializationCause);
	}
}
 
開發者ID:edgexfoundry,項目名稱:export-distro,代碼行數:23,代碼來源:EdgeXSecurityManager.java

示例8: dumpTrustedCerts

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
public void dumpTrustedCerts() {
	try {
		TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory
				.getDefaultAlgorithm());
		tmf.init((KeyStore) null);
		X509TrustManager xtm = (X509TrustManager) tmf.getTrustManagers()[0];
		StringBuffer buff = new StringBuffer();
		for (X509Certificate cert : xtm.getAcceptedIssuers()) {
			String certStr = "S:" + cert.getSubjectDN().getName() + "\nI:"
					+ cert.getIssuerDN().getName();
			Log.d(TAG, certStr);
			buff.append(certStr + "\n\n");
		}
	} catch (GeneralSecurityException e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:CactusSoft,項目名稱:zabbkit-android,代碼行數:18,代碼來源:SSLManager.java

示例9: createSSLContext

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
private SSLContext createSSLContext() throws GeneralSecurityException, IOException  {
    SSLContext sslContext;
    if (provider != null)
        sslContext = SSLContext.getInstance(protocol, provider);
    else
        sslContext = SSLContext.getInstance(protocol);

    KeyManager[] keyManagers = null;
    if (keystore != null) {
        String kmfAlgorithm = this.kmfAlgorithm != null ? this.kmfAlgorithm : KeyManagerFactory.getDefaultAlgorithm();
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(kmfAlgorithm);
        KeyStore ks = keystore.load();
        Password keyPassword = this.keyPassword != null ? this.keyPassword : keystore.password;
        kmf.init(ks, keyPassword.value().toCharArray());
        keyManagers = kmf.getKeyManagers();
    }

    String tmfAlgorithm = this.tmfAlgorithm != null ? this.tmfAlgorithm : TrustManagerFactory.getDefaultAlgorithm();
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
    KeyStore ts = truststore == null ? null : truststore.load();
    tmf.init(ts);

    sslContext.init(keyManagers, tmf.getTrustManagers(), this.secureRandomImplementation);
    return sslContext;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:26,代碼來源:SslFactory.java

示例10: getSocketFactory

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
private SSLSocketFactory getSocketFactory() {
    try {
        Security.addProvider(new BouncyCastleProvider());

        TrustManagerFactory trustManagerFactory = createAndInitTrustManagerFactory();
        KeyManagerFactory keyManagerFactory = createAndInitKeyManagerFactory();

        SSLContext context = SSLContext.getInstance(TLS_VERSION);
        context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);

        return context.getSocketFactory();
    } catch (Exception e) {
        log.error("[{}:{}:{}:{}] Creating TLS factory failed!", caCert, cert, privateKey, password, e);
        throw new RuntimeException("Creating TLS factory failed!", e);
    }
}
 
開發者ID:thingsboard,項目名稱:thingsboard-gateway,代碼行數:17,代碼來源:CertPemClientCredentials.java

示例11: createAndInitTrustManagerFactory

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
private TrustManagerFactory createAndInitTrustManagerFactory() throws Exception {
    X509Certificate caCertHolder;
    if (caCertFileName != null) {
        caCertHolder = readCertFile(caCert);
    } else {
        caCertHolder = certificateConverter.getCertificate((X509CertificateHolder) readPEMFile(caCert));
    }

    KeyStore caKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    caKeyStore.load(null, null);
    caKeyStore.setCertificateEntry("caCert-cert", caCertHolder);

    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(caKeyStore);
    return trustManagerFactory;
}
 
開發者ID:thingsboard,項目名稱:thingsboard-gateway,代碼行數:17,代碼來源:CertPemClientCredentials.java

示例12: initialize

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
private void initialize() throws CertificateException {
    String passwd =
        System.getProperty("javax.net.ssl.trustStorePassword");
    char [] password = passwd.toCharArray();
    String trustFilename =
        System.getProperty("javax.net.ssl.trustStore");

    try {
        KeyStore ks = KeyStore.getInstance("JKS");
        ks.load(new FileInputStream(trustFilename), password);

        TrustManagerFactory tmf =
                TrustManagerFactory.getInstance("PKIX");
        tmf.init(ks);
        tm = (X509TrustManager)tmf.getTrustManagers()[0];
    } catch (Exception e) {
        throw new CertificateException("Unable to initialize TM");
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:EmptyCertificateAuthorities.java

示例13: BouncrSSLSocketFactory

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
public BouncrSSLSocketFactory() {
    try {
        SSLContext ctx = SSLContext.getInstance("TLSv1.2");
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        KeyStore trustStore = KeyStore.getInstance("JKS");

        try (InputStream in = new FileInputStream(keyStoreInfo.get().getTruststorePath())) {
            trustStore.load(in, keyStoreInfo.get().getTruststorePassword().toCharArray());
        }
        tmf.init(trustStore);
        ctx.init(null, tmf.getTrustManagers(), SecureRandom.getInstance("SHA1PRNG"));
        delegate = ctx.getSocketFactory();
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
 
開發者ID:kawasima,項目名稱:bouncr,代碼行數:17,代碼來源:BouncrSSLSocketFactory.java

示例14: createSslContext

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
private static SSLContext createSslContext(ApacheThriftClientConfig config)
{
    try {
        KeyStore trustStore = loadTrustStore(config.getTrustCertificate());
        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init(trustStore);

        KeyManager[] keyManagers = null;
        if (config.getKey() != null) {
            Optional<String> keyPassword = Optional.ofNullable(config.getKeyPassword());
            KeyStore keyStore = loadKeyStore(config.getTrustCertificate(), config.getKey(), keyPassword);
            KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            keyManagerFactory.init(keyStore, new char[0]);
            keyManagers = keyManagerFactory.getKeyManagers();
        }

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(keyManagers, trustManagerFactory.getTrustManagers(), null);
        return sslContext;
    }
    catch (IOException | GeneralSecurityException e) {
        throw new IllegalArgumentException("Unable to load SSL keys", e);
    }
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:25,代碼來源:ApacheThriftMethodInvokerFactory.java

示例15: makeSSLSocketFactory

import javax.net.ssl.TrustManagerFactory; //導入依賴的package包/類
public static SSLServerSocketFactory makeSSLSocketFactory(KeyStore loadedKeyStore, KeyManager[] keyManagers)
{
    SSLServerSocketFactory res = null;
    try {
        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init(loadedKeyStore);
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(keyManagers, trustManagerFactory.getTrustManagers(), null);
        res = ctx.getServerSocketFactory();
    } 
    catch (Exception e) 
    {
    	System.out.println(e.toString());
        //throw new IOException(e.getMessage());
    }
    return res;
}
 
開發者ID:johndavidbustard,項目名稱:RoughWorld,代碼行數:18,代碼來源:WebInterfaceSSL.java


注:本文中的javax.net.ssl.TrustManagerFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。