当前位置: 首页>>代码示例>>Java>>正文


Java KeyManagerFactory.getDefaultAlgorithm方法代码示例

本文整理汇总了Java中javax.net.ssl.KeyManagerFactory.getDefaultAlgorithm方法的典型用法代码示例。如果您正苦于以下问题:Java KeyManagerFactory.getDefaultAlgorithm方法的具体用法?Java KeyManagerFactory.getDefaultAlgorithm怎么用?Java KeyManagerFactory.getDefaultAlgorithm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.net.ssl.KeyManagerFactory的用法示例。


在下文中一共展示了KeyManagerFactory.getDefaultAlgorithm方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: upgradeToTls

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的package包/类
private void upgradeToTls(Socket socket) throws KeyStoreException, IOException, NoSuchAlgorithmException,
        CertificateException, UnrecoverableKeyException, KeyManagementException {

    KeyStore keyStore = keyStoreProvider.getKeyStore();

    String defaultAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(defaultAlgorithm);
    keyManagerFactory.init(keyStore, keyStoreProvider.getPassword());

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
    SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();

    SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
            socket, socket.getInetAddress().getHostAddress(), socket.getPort(), true);
    sslSocket.setUseClientMode(false);
    sslSocket.startHandshake();

    input = Okio.buffer(Okio.source(sslSocket.getInputStream()));
    output = Okio.buffer(Okio.sink(sslSocket.getOutputStream()));
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:22,代码来源:MockSmtpServer.java

示例2: getTrustedSslContext

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的package包/类
/**
 * Gets the trusted ssl context.
 *
 * @param trustStoreFile the trust store file
 * @param trustStorePassword the trust store password
 * @param trustStoreType the trust store type
 * @return the trusted ssl context
 */
private static SSLContext getTrustedSslContext(final File trustStoreFile, final String trustStorePassword,
                                        final String trustStoreType) {
    try {

        if (!trustStoreFile.exists() || !trustStoreFile.canRead()) {
            throw new FileNotFoundException("Truststore file cannot be located at "
                + trustStoreFile.getCanonicalPath());
        }

        final KeyStore casTrustStore = KeyStore.getInstance(trustStoreType);
        final char[] trustStorePasswordCharArray = trustStorePassword.toCharArray();

        try (final FileInputStream casStream = new FileInputStream(trustStoreFile)) {
            casTrustStore.load(casStream, trustStorePasswordCharArray);
        }

        final String defaultAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
        final X509KeyManager customKeyManager = getKeyManager("PKIX", casTrustStore, trustStorePasswordCharArray);
        final X509KeyManager jvmKeyManager = getKeyManager(defaultAlgorithm, null, null);
        final X509TrustManager customTrustManager = getTrustManager("PKIX", casTrustStore);
        final X509TrustManager jvmTrustManager = getTrustManager(defaultAlgorithm, null);

        final KeyManager[] keyManagers = {
                new CompositeX509KeyManager(Arrays.asList(jvmKeyManager, customKeyManager))
        };
        final TrustManager[] trustManagers = {
                new CompositeX509TrustManager(Arrays.asList(jvmTrustManager, customTrustManager))
        };

        final SSLContext context = SSLContexts.custom().useSSL().build();
        context.init(keyManagers, trustManagers, null);
        return context;

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:47,代码来源:FileTrustStoreSslSocketFactory.java

示例3: createSSLContext

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的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

示例4: getTrustedSslContext

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的package包/类
/**
 * Gets the trusted ssl context.
 *
 * @param trustStoreFile the trust store file
 * @param trustStorePassword the trust store password
 * @param trustStoreType the trust store type
 * @return the trusted ssl context
 */
private static SSLContext getTrustedSslContext(final File trustStoreFile, final String trustStorePassword,
                                        final String trustStoreType) {
    try {

        if (!trustStoreFile.exists() || !trustStoreFile.canRead()) {
            throw new FileNotFoundException("Truststore file cannot be located at "
                + trustStoreFile.getCanonicalPath());
        }

        final KeyStore casTrustStore = KeyStore.getInstance(trustStoreType);
        final char[] trustStorePasswordCharArray = trustStorePassword.toCharArray();

        try (FileInputStream casStream = new FileInputStream(trustStoreFile)) {
            casTrustStore.load(casStream, trustStorePasswordCharArray);
        }

        final String defaultAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
        final X509KeyManager customKeyManager = getKeyManager("PKIX", casTrustStore, trustStorePasswordCharArray);
        final X509KeyManager jvmKeyManager = getKeyManager(defaultAlgorithm, null, null);
        final X509TrustManager customTrustManager = getTrustManager("PKIX", casTrustStore);
        final X509TrustManager jvmTrustManager = getTrustManager(defaultAlgorithm, null);

        final KeyManager[] keyManagers = {
                new CompositeX509KeyManager(Arrays.asList(jvmKeyManager, customKeyManager))
        };
        final TrustManager[] trustManagers = {
                new CompositeX509TrustManager(Arrays.asList(jvmTrustManager, customTrustManager))
        };

        final SSLContext context = SSLContexts.custom().useSSL().build();
        context.init(keyManagers, trustManagers, null);
        return context;

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:47,代码来源:FileTrustStoreSslSocketFactory.java

示例5: getTrustedSslContext

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的package包/类
/**
 * Gets the trusted ssl context.
 *
 * @param trustStoreFile the trust store file
 * @param trustStorePassword the trust store password
 * @param trustStoreType the trust store type
 * @return the trusted ssl context
 */
private static SSLContext getTrustedSslContext(final File trustStoreFile, final String trustStorePassword,
                                        final String trustStoreType) {
    try {

        if (!trustStoreFile.exists() || !trustStoreFile.canRead()) {
            throw new FileNotFoundException("Truststore file cannot be located at " + trustStoreFile.getCanonicalPath());
        }

        final KeyStore casTrustStore = KeyStore.getInstance(trustStoreType);
        final char[] trustStorePasswordCharArray = trustStorePassword.toCharArray();

        try (final FileInputStream casStream = new FileInputStream(trustStoreFile)) {
            casTrustStore.load(casStream, trustStorePasswordCharArray);
        }

        final String defaultAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
        final X509KeyManager customKeyManager = getKeyManager("PKIX", casTrustStore, trustStorePasswordCharArray);
        final X509KeyManager jvmKeyManager = getKeyManager(defaultAlgorithm, null, null);
        final X509TrustManager customTrustManager = getTrustManager("PKIX", casTrustStore);
        final X509TrustManager jvmTrustManager = getTrustManager(defaultAlgorithm, null);

        final KeyManager[] keyManagers = {
                new CompositeX509KeyManager(Arrays.asList(jvmKeyManager, customKeyManager))
        };
        final TrustManager[] trustManagers = {
                new CompositeX509TrustManager(Arrays.asList(jvmTrustManager, customTrustManager))
        };

        final SSLContext context = SSLContexts.custom().useSSL().build();
        context.init(keyManagers, trustManagers, null);
        return context;

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:46,代码来源:FileTrustStoreSslSocketFactory.java

示例6: getTrustedSslContext

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的package包/类
/**
 * Gets the trusted ssl context.
 *
 * @param trustStoreFile     the trust store file
 * @param trustStorePassword the trust store password
 * @param trustStoreType     the trust store type
 * @return the trusted ssl context
 */
private static SSLContext getTrustedSslContext(final Resource trustStoreFile, final String trustStorePassword,
                                               final String trustStoreType) {
    try {

        final KeyStore casTrustStore = KeyStore.getInstance(trustStoreType);
        final char[] trustStorePasswordCharArray = trustStorePassword.toCharArray();

        try (InputStream casStream = trustStoreFile.getInputStream()) {
            casTrustStore.load(casStream, trustStorePasswordCharArray);
        }

        final String defaultAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
        final X509KeyManager customKeyManager = getKeyManager(ALG_NAME_PKIX, casTrustStore, trustStorePasswordCharArray);
        final X509KeyManager jvmKeyManager = getKeyManager(defaultAlgorithm, null, null);
        final X509TrustManager customTrustManager = getTrustManager(ALG_NAME_PKIX, casTrustStore);
        final X509TrustManager jvmTrustManager = getTrustManager(defaultAlgorithm, null);

        final KeyManager[] keyManagers = {
                new CompositeX509KeyManager(Arrays.asList(jvmKeyManager, customKeyManager))
        };
        final TrustManager[] trustManagers = {
                new CompositeX509TrustManager(Arrays.asList(jvmTrustManager, customTrustManager))
        };

        final SSLContext context = SSLContexts.custom().useProtocol("SSL").build();
        context.init(keyManagers, trustManagers, null);
        return context;

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:42,代码来源:FileTrustStoreSslSocketFactory.java

示例7: getKeyManagers

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的package包/类
@Override
public KeyManager[] getKeyManagers() throws Exception {
    String keystoreType = endpoint.getKeystoreType();
    if (keystoreType == null) {
        keystoreType = defaultKeystoreType;
    }

    String algorithm = endpoint.getAlgorithm();
    if (algorithm == null) {
        algorithm = KeyManagerFactory.getDefaultAlgorithm();
    }

    return getKeyManagers(keystoreType, endpoint.getKeystoreProvider(),
            algorithm, endpoint.getKeyAlias());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:JSSESocketFactory.java

示例8: SslNetworkLayer

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的package包/类
public SslNetworkLayer(
		SipStackImpl sipStack,
        String trustStoreFile,
        String keyStoreFile,
        char[] keyStorePassword,
        char[] trustStorePassword,
        String keyStoreType, String trustStoreType) throws GeneralSecurityException, FileNotFoundException, IOException
{
    SSLContext sslContext;
    sslContext = SSLContext.getInstance("TLS");
    String algorithm = KeyManagerFactory.getDefaultAlgorithm();
    TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(algorithm);
    KeyManagerFactory kmFactory = KeyManagerFactory.getInstance(algorithm);
    SecureRandom secureRandom   = new SecureRandom();
    secureRandom.nextInt();
    KeyStore keyStore = KeyStore.getInstance(
         keyStoreType != null ? keyStoreType : KeyStore.getDefaultType());
    KeyStore trustStore = KeyStore.getInstance(
    		trustStoreType != null ? trustStoreType : KeyStore.getDefaultType());
    keyStore.load(new FileInputStream(keyStoreFile), keyStorePassword);
    trustStore.load(new FileInputStream(trustStoreFile), trustStorePassword);
    tmFactory.init(trustStore);
    kmFactory.init(keyStore, keyStorePassword);
    if(sipStack.getClientAuth() == ClientAuthType.DisabledAll) {
    	if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
            logger.logDebug(
                    "ClientAuth " + sipStack.getClientAuth()  +  " bypassing all cert validations");
        }
    	sslContext.init(null, trustAllCerts, secureRandom);
    } else {
    	if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
            logger.logDebug(
                    "ClientAuth " + sipStack.getClientAuth());
        }
    	sslContext.init(kmFactory.getKeyManagers(), tmFactory.getTrustManagers(), secureRandom);
    }
    sslServerSocketFactory = sslContext.getServerSocketFactory();        
    sslSocketFactory = sslContext.getSocketFactory();
}
 
开发者ID:YunlongYang,项目名称:LightSIP,代码行数:40,代码来源:SslNetworkLayer.java

示例9: getkeyManagerAlgorithm

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的package包/类
private String getkeyManagerAlgorithm() {
  String algorithm = Security.getProperty(
          "ssl.KeyManagerFactory.algorithm");
  return (algorithm != null) ?
          algorithm : KeyManagerFactory.getDefaultAlgorithm();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:7,代码来源:ThriftSource.java

示例10: testSslProcess

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的package包/类
@Test
public void testSslProcess() throws Exception {
  Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
  src = new ThriftTestingSource(ThriftTestingSource.HandlerType.OK.name(), port,
          ThriftRpcClient.COMPACT_PROTOCOL, "src/test/resources/keystorefile.jks",
          "password", KeyManagerFactory.getDefaultAlgorithm(), "JKS");
  Context context = new Context();
  context.put("hostname", hostname);
  context.put("port", String.valueOf(port));
  context.put("ssl", String.valueOf(true));
  context.put("batch-size", String.valueOf(2));
  context.put("connect-timeout", String.valueOf(2000L));
  context.put("request-timeout", String.valueOf(3000L));
  context.put("truststore", "src/test/resources/truststorefile.jks");
  context.put("truststore-password", "password");
  context.put("trustmanager-type", TrustManagerFactory.getDefaultAlgorithm());

  Configurables.configure(sink, context);
  channel.start();
  sink.start();
  Transaction transaction = channel.getTransaction();
  transaction.begin();
  for (int i = 0; i < 11; i++) {
    channel.put(event);
  }
  transaction.commit();
  transaction.close();
  for (int i = 0; i < 6; i++) {
    Sink.Status status = sink.process();
    Assert.assertEquals(Sink.Status.READY, status);
  }
  Assert.assertEquals(Sink.Status.BACKOFF, sink.process());

  sink.stop();
  Assert.assertEquals(11, src.flumeEvents.size());
  Assert.assertEquals(6, src.batchCount);
  Assert.assertEquals(0, src.individualCount);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:39,代码来源:TestThriftSink.java

示例11: getKeyManagers

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的package包/类
@Override
public KeyManager[] getKeyManagers() throws Exception {
	String keystoreType = endpoint.getKeystoreType();
	if (keystoreType == null) {
		keystoreType = defaultKeystoreType;
	}

	String algorithm = endpoint.getAlgorithm();
	if (algorithm == null) {
		algorithm = KeyManagerFactory.getDefaultAlgorithm();
	}

	return getKeyManagers(keystoreType, endpoint.getKeystoreProvider(), algorithm, endpoint.getKeyAlias());
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:15,代码来源:JSSESocketFactory.java

示例12: testSslSinkWithNonTrustedCert

import javax.net.ssl.KeyManagerFactory; //导入方法依赖的package包/类
@Test
public void testSslSinkWithNonTrustedCert() throws Exception {
  Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
  src = new ThriftTestingSource(ThriftTestingSource.HandlerType.OK.name(), port,
          ThriftRpcClient.COMPACT_PROTOCOL, "src/test/resources/keystorefile.jks",
          "password", KeyManagerFactory.getDefaultAlgorithm(), "JKS");

  Context context = new Context();
  context.put("hostname", hostname);
  context.put("port", String.valueOf(port));
  context.put("ssl", String.valueOf(true));
  context.put("batch-size", String.valueOf(2));
  context.put("connect-timeout", String.valueOf(2000L));
  context.put("request-timeout", String.valueOf(3000L));

  Configurables.configure(sink, context);
  channel.start();
  sink.start();
  Assert.assertTrue(LifecycleController.waitForOneOf(sink,
          LifecycleState.START_OR_ERROR, 5000));
  Transaction transaction = channel.getTransaction();
  transaction.begin();
  for (int i = 0; i < 11; i++) {
    channel.put(event);
  }
  transaction.commit();
  transaction.close();

  boolean failed = false;
  try {
    for (int i = 0; i < 6; i++) {
      Sink.Status status = sink.process();
      failed = true;
    }
  } catch (EventDeliveryException ex) {
    // This is correct
  }

  sink.stop();
  Assert.assertTrue(LifecycleController.waitForOneOf(sink,
          LifecycleState.STOP_OR_ERROR, 5000));
  if (failed) {
    Assert.fail("SSL-enabled sink successfully connected to a server with an " +
                "untrusted certificate when it should have failed");
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:47,代码来源:TestThriftSink.java


注:本文中的javax.net.ssl.KeyManagerFactory.getDefaultAlgorithm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。