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


Java KeyManagementException类代码示例

本文整理汇总了Java中java.security.KeyManagementException的典型用法代码示例。如果您正苦于以下问题:Java KeyManagementException类的具体用法?Java KeyManagementException怎么用?Java KeyManagementException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createSocketFactory

import java.security.KeyManagementException; //导入依赖的package包/类
public SocketFactory createSocketFactory() {
    try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, new TrustManager[] { this }, null);
        return sslContext.getSocketFactory();
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        throw new RuntimeException("Failed to create a SSL socket factory");
    }
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:10,代码来源:UserOverrideTrustManager.java

示例2: getConnctionManager

import java.security.KeyManagementException; //导入依赖的package包/类
public static PoolingHttpClientConnectionManager getConnctionManager(){

        Registry<ConnectionSocketFactory> socketFactoryRegistry = null;
        try {
            SSLConnectionSocketFactory trustSelfSignedSocketFactory = new SSLConnectionSocketFactory(
                        new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
                        new TrustAllHostNameVerifier());
            socketFactoryRegistry = RegistryBuilder
                    .<ConnectionSocketFactory> create()
                    .register("http", new PlainConnectionSocketFactory())
                    .register("https", trustSelfSignedSocketFactory)
                    .build();
        } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
            Data.logger.warn("", e);
        }
        
        PoolingHttpClientConnectionManager cm = (socketFactoryRegistry != null) ? 
                new PoolingHttpClientConnectionManager(socketFactoryRegistry):
                new PoolingHttpClientConnectionManager();
        
        // twitter specific options
        cm.setMaxTotal(2000);
        cm.setDefaultMaxPerRoute(200);
        
        return cm;
    }
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:27,代码来源:ClientConnection.java

示例3: restTemplate

import java.security.KeyManagementException; //导入依赖的package包/类
@Bean
public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {

    SSLContext sslContext = SSLContexts.custom()
            .loadTrustMaterial(null, new TrustSelfSignedStrategy())
            .build();

    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
    CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLSocketFactory(sslConnectionSocketFactory)
            .build();

    HttpComponentsClientHttpRequestFactory requestFactory =
            new HttpComponentsClientHttpRequestFactory();

    requestFactory.setHttpClient(httpClient);

    return new RestTemplate(requestFactory);
}
 
开发者ID:borysfan,项目名称:websocket-poc,代码行数:20,代码来源:App.java

示例4: buildCertificateIgnoringSslContext

import java.security.KeyManagementException; //导入依赖的package包/类
/**
 * Will create a certificate-ignoring {@link SSLContext}. Please use with utmost caution as it undermines security,
 * but may be useful in certain testing or development scenarios.
 *
 * @return The SSLContext
 */
public static SSLContext buildCertificateIgnoringSslContext() {
	try {
		return SSLContexts
			.custom()
			.loadTrustMaterial(new TrustStrategy() {
				@Override
				public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
					return true;
				}
			})
			.build();
	}
	catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
		throw new IllegalStateException("Unexpected exception while building the certificate-ignoring SSLContext.", e);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:23,代码来源:HttpClientUtils.java

示例5: prepare

import java.security.KeyManagementException; //导入依赖的package包/类
/**
		 * Prepare.
		 *
		 * @param requestURL the request URL
		 * @return the URL processor
		 * @throws IOException Signals that an I/O exception has occurred.
		 * @throws KeyStoreException 
		 * @throws CertificateException 
		 * @throws NoSuchAlgorithmException 
		 * @throws KeyManagementException 
		 */
		public URLProcessor prepare(URL requestURL) throws IOException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
//			System.out.println("requestURL=");
//			System.out.println(requestURL);

			connection = (HttpsURLConnection) requestURL.openConnection();
			connection.setInstanceFollowRedirects(false);
			Trust.trustSpecific(connection, truststoreFile);

			connection.setRequestMethod("GET");
			if (accessToken != null) {
				connection.setRequestProperty("Authorization", "Bearer " + accessToken);
			}

			if (uploadFile != null) {
				injectUpload();
			}

			return this;
		}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:31,代码来源:OIDCAuthorization.java

示例6: createSslContext

import java.security.KeyManagementException; //导入依赖的package包/类
/**
 * Creates a SSLContext instance using the given information.
 *
 * @param keystore the full path to the keystore
 * @param keystorePasswd the keystore password
 * @param keystoreType the type of keystore (e.g., PKCS12, JKS)
 * @param protocol the protocol to use for the SSL connection
 *
 * @return a SSLContext instance
 * @throws KeyStoreException if any issues accessing the keystore
 * @throws IOException for any problems loading the keystores
 * @throws NoSuchAlgorithmException if an algorithm is found to be used but is unknown
 * @throws CertificateException if there is an issue with the certificate
 * @throws UnrecoverableKeyException if the key is insufficient
 * @throws KeyManagementException if unable to manage the key
 */
public static SSLContext createSslContext(
    final String keystore, final char[] keystorePasswd, final char[] keyPasswd, final String keystoreType, final String protocol)
        throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException,
        UnrecoverableKeyException, KeyManagementException {

    // prepare the keystore
    final KeyStore keyStore = KeyStoreUtils.getKeyStore(keystoreType);
    try (final InputStream keyStoreStream = new FileInputStream(keystore)) {
        keyStore.load(keyStoreStream, keystorePasswd);
    }
    final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    if (keyPasswd == null) {
        keyManagerFactory.init(keyStore, keystorePasswd);
    } else {
        keyManagerFactory.init(keyStore, keyPasswd);
    }

    // initialize the ssl context
    final SSLContext ctx = SSLContext.getInstance(protocol);
    ctx.init(keyManagerFactory.getKeyManagers(), new TrustManager[0], new SecureRandom());

    return ctx;

}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:41,代码来源:SslContextFactory.java

示例7: getHttpClient

import java.security.KeyManagementException; //导入依赖的package包/类
public QMailHttpClient getHttpClient() throws MessagingException {
    if (httpClient == null) {
        httpClient = httpClientFactory.create();
        // Disable automatic redirects on the http client.
        httpClient.getParams().setBooleanParameter("http.protocol.handle-redirects", false);

        // Setup a cookie store for forms-based authentication.
        httpContext = new BasicHttpContext();
        authCookies = new BasicCookieStore();
        httpContext.setAttribute(ClientContext.COOKIE_STORE, authCookies);

        SchemeRegistry reg = httpClient.getConnectionManager().getSchemeRegistry();
        try {
            Scheme s = new Scheme("https", new WebDavSocketFactory(hostname, 443), 443);
            reg.register(s);
        } catch (NoSuchAlgorithmException nsa) {
            Timber.e(nsa, "NoSuchAlgorithmException in getHttpClient");
            throw new MessagingException("NoSuchAlgorithmException in getHttpClient: ", nsa);
        } catch (KeyManagementException kme) {
            Timber.e(kme, "KeyManagementException in getHttpClient");
            throw new MessagingException("KeyManagementException in getHttpClient: ", kme);
        }
    }
    return httpClient;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:26,代码来源:WebDavStore.java

示例8: handleInteractions

import java.security.KeyManagementException; //导入依赖的package包/类
private void handleInteractions(Socket socket) throws IOException, KeyStoreException,
        NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException, KeyManagementException,
        UnexpectedCommandException {

    ImapInteraction interaction = interactions.pop();
    if (interaction instanceof ExpectedCommand) {
        readExpectedCommand((ExpectedCommand) interaction);
    } else if (interaction instanceof CannedResponse) {
        writeCannedResponse((CannedResponse) interaction);
    } else if (interaction instanceof CloseConnection) {
        clientSocket.close();
    } else if (interaction instanceof EnableCompression) {
        enableCompression(socket);
    } else if (interaction instanceof UpgradeToTls) {
        upgradeToTls(socket);
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:18,代码来源:MockImapServer.java

示例9: upgradeToTls

import java.security.KeyManagementException; //导入依赖的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,代码来源:MockImapServer.java

示例10: OkHttpUtils

import java.security.KeyManagementException; //导入依赖的package包/类
private OkHttpUtils(long connectTimeOut, long readTimeOut, long writeTimeOut, int retrys) {
    OkHttpClient.Builder builder = getBuilder(connectTimeOut, readTimeOut, writeTimeOut, retrys);

    this.connectTimeOut = connectTimeOut;
    this.readTimeOut = readTimeOut;
    this.writeTimeOut = writeTimeOut;
    this.retrys = retrys;

    okHttpClient = builder.build();
    try {
        ssl(builder);
        okHttpsClient = builder.build();
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage());
    }
}
 
开发者ID:HujiangTechnology,项目名称:Juice,代码行数:18,代码来源:OkHttpUtils.java

示例11: retrieveProviderMetadata

import java.security.KeyManagementException; //导入依赖的package包/类
/**
	 * Retrieve provider metadata.
	 * Provider configuration information
	 * Obtaining the provider configuration information can be done either out-of-band or using the optional discovery process:
	 *
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @throws ParseException the parse exception
	 * @throws KeyStoreException
	 * @throws CertificateException
	 * @throws NoSuchAlgorithmException
	 * @throws KeyManagementException
	 */
	public void retrieveProviderMetadata() throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
		
		URL providerConfigurationURL = issuerURI.resolve(URLPATH_WELL_KNOWN_OPENID).toURL();
//		System.out.println(providerConfigurationURL);
		URLConnection conn = providerConfigurationURL.openConnection();

		if (trustStoreFile != null) {
			Trust.trustSpecific((HttpsURLConnection) conn, trustStoreFile);
		}
		InputStream stream = conn.getInputStream();
		// Read all data from URL
		String providerInfo = null;
		try (java.util.Scanner s = new java.util.Scanner(stream)) {
			providerInfo = s.useDelimiter("\\A").hasNext() ? s.next() : "";
		}
		setProviderMetadata(OIDCProviderMetadata.parse(providerInfo));
	}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:30,代码来源:SimpleOIDCClient.java

示例12: getSSLSocketFactory

import java.security.KeyManagementException; //导入依赖的package包/类
/**
 * 获取LayeredConnectionSocketFactory 使用ssl单向认证
 * 
 * @date 2015年7月17日
 * @return
 */
private LayeredConnectionSocketFactory getSSLSocketFactory() {
	try {
		SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {

			// 信任所有
			public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
				return true;
			}
		}).build();

		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext,
				SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
		return sslsf;
	} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
		logger.error(e.getMessage(), e);
		throw new RuntimeException(e.getMessage(), e);
	}
}
 
开发者ID:swxiao,项目名称:bubble2,代码行数:25,代码来源:HttpUtils.java

示例13: getSslSocketFactory

import java.security.KeyManagementException; //导入依赖的package包/类
public static SSLParams getSslSocketFactory(InputStream[] certificates, InputStream bksFile, String password) {
    SSLParams sslParams = new SSLParams();
    try {
        TrustManager[] trustManagers = prepareTrustManager(certificates);
        KeyManager[] keyManagers = prepareKeyManager(bksFile, password);
        SSLContext sslContext = SSLContext.getInstance("TLS");
        X509TrustManager trustManager = null;
        if (trustManagers != null) {
            trustManager = new MyTrustManager(chooseTrustManager(trustManagers));
        } else {
            trustManager = new UnSafeTrustManager();
        }
        sslContext.init(keyManagers, new TrustManager[]{trustManager}, null);
        sslParams.sSLSocketFactory = sslContext.getSocketFactory();
        sslParams.trustManager = trustManager;
        return sslParams;
    } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
        throw new AssertionError(e);
    }
}
 
开发者ID:huashengzzz,项目名称:SmartChart,代码行数:21,代码来源:HttpsUtils.java

示例14: initTrustedSSLSocketFactory

import java.security.KeyManagementException; //导入依赖的package包/类
/**
 * Initialize the factory with custom trustStore
 * @param trustStore KeyStore
 */
public static synchronized void initTrustedSSLSocketFactory(final KeyStore trustStore)
{
    try
    {
        final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509");
        trustManagerFactory.init(trustStore);
        context = SSLContext.getInstance("SSL");
        context.init(null, trustManagerFactory.getTrustManagers(), SecureRandom.getInstance("SHA1PRNG"));
    }
    catch (NoSuchAlgorithmException nsae)
    {
        throw new AlfrescoRuntimeException("The SSL socket factory cannot be initialized.", nsae);
    }
    catch (KeyStoreException kse)
    {
        throw new AlfrescoRuntimeException("The SSL socket factory cannot be initialized.", kse);
    }
    catch (KeyManagementException kme)
    {
        throw new AlfrescoRuntimeException("The SSL socket factory cannot be initialized.", kme);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:27,代码来源:AlfrescoSSLSocketFactory.java

示例15: create

import java.security.KeyManagementException; //导入依赖的package包/类
private void create(Path path)
    throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException,
    KeyManagementException {
  TrustManager[] trustManagers;
  KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
  keyStore.load(null, null);

  installCertificates(path, keyStore);

  String defaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
  TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(defaultAlgorithm);
  trustManagerFactory.init(keyStore);
  trustManagers = trustManagerFactory.getTrustManagers();
  sslContext = SSLContext.getInstance("TLS");
  sslContext.init(null, trustManagers, null);
  trustManager = (X509TrustManager) trustManagers[0];
  X509Certificate[] acceptedIssuers = trustManager.getAcceptedIssuers();
  for (X509Certificate acceptedIssuer : acceptedIssuers) {
    logger.info("installed cert details: subject={} issuer={}",
        acceptedIssuer.getSubjectX500Principal(), acceptedIssuer.getIssuerX500Principal());
  }
}
 
开发者ID:dehora,项目名称:outland,代码行数:23,代码来源:CertificateLoader.java


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