当前位置: 首页>>代码示例>>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;未经允许,请勿转载。