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


Java XmppDomainVerifier类代码示例

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


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

示例1: getTlsFactoryVerifier

import eu.siacs.conversations.crypto.XmppDomainVerifier; //导入依赖的package包/类
private TlsFactoryVerifier getTlsFactoryVerifier() throws NoSuchAlgorithmException, KeyManagementException, IOException {
	final SSLContext sc = SSLSocketHelper.getSSLContext();
	MemorizingTrustManager trustManager = this.mXmppConnectionService.getMemorizingTrustManager();
	KeyManager[] keyManager;
	if (account.getPrivateKeyAlias() != null && account.getPassword().isEmpty()) {
		keyManager = new KeyManager[]{new MyKeyManager()};
	} else {
		keyManager = null;
	}
	String domain = account.getJid().getDomainpart();
	sc.init(keyManager, new X509TrustManager[]{mInteractive ? trustManager.getInteractive(domain) : trustManager.getNonInteractive(domain)}, mXmppConnectionService.getRNG());
	final SSLSocketFactory factory = sc.getSocketFactory();
	final DomainHostnameVerifier verifier = trustManager.wrapHostnameVerifier(new XmppDomainVerifier(), mInteractive);
	return new TlsFactoryVerifier(factory, verifier);
}
 
开发者ID:siacs,项目名称:Conversations,代码行数:16,代码来源:XmppConnection.java

示例2: switchOverToTls

import eu.siacs.conversations.crypto.XmppDomainVerifier; //导入依赖的package包/类
private void switchOverToTls(final Tag currentTag) throws XmlPullParserException, IOException {
	tagReader.readTag();
	try {
		final SSLContext sc = SSLContext.getInstance("TLS");
		MemorizingTrustManager trustManager = this.mXmppConnectionService.getMemorizingTrustManager();
		KeyManager[] keyManager;
		if (account.getPrivateKeyAlias() != null && account.getPassword().isEmpty()) {
			keyManager = new KeyManager[]{ mKeyManager };
		} else {
			keyManager = null;
		}
		sc.init(keyManager,new X509TrustManager[]{mInteractive ? trustManager : trustManager.getNonInteractive()},mXmppConnectionService.getRNG());
		final SSLSocketFactory factory = sc.getSocketFactory();
		final HostnameVerifier verifier;
		if (mInteractive) {
			verifier = trustManager.wrapHostnameVerifier(new XmppDomainVerifier());
		} else {
			verifier = trustManager.wrapHostnameVerifierNonInteractive(new XmppDomainVerifier());
		}
		final InetAddress address = socket == null ? null : socket.getInetAddress();

		if (factory == null || address == null || verifier == null) {
			throw new IOException("could not setup ssl");
		}

		final SSLSocket sslSocket = (SSLSocket) factory.createSocket(socket,address.getHostAddress(), socket.getPort(),true);

		if (sslSocket == null) {
			throw new IOException("could not initialize ssl socket");
		}

		final String[] supportProtocols;
		final Collection<String> supportedProtocols = new LinkedList<>(
				Arrays.asList(sslSocket.getSupportedProtocols()));
		supportedProtocols.remove("SSLv3");
		supportProtocols = supportedProtocols.toArray(new String[supportedProtocols.size()]);

		sslSocket.setEnabledProtocols(supportProtocols);

		final String[] cipherSuites = CryptoHelper.getOrderedCipherSuites(
				sslSocket.getSupportedCipherSuites());
		//Log.d(Config.LOGTAG, "Using ciphers: " + Arrays.toString(cipherSuites));
		if (cipherSuites.length > 0) {
			sslSocket.setEnabledCipherSuites(cipherSuites);
		}

		if (!verifier.verify(account.getServer().getDomainpart(),sslSocket.getSession())) {
			Log.d(Config.LOGTAG,account.getJid().toBareJid()+": TLS certificate verification failed");
			throw new SecurityException();
		}
		tagReader.setInputStream(sslSocket.getInputStream());
		tagWriter.setOutputStream(sslSocket.getOutputStream());
		sendStartStream();
		Log.d(Config.LOGTAG, account.getJid().toBareJid()+ ": TLS connection established");
		features.encryptionEnabled = true;
		final Tag tag = tagReader.readTag();
		if (tag != null && tag.isStart("stream")) {
			processStream();
		} else {
			throw new IOException("server didn't restart stream after STARTTLS");
		}
		sslSocket.close();
	} catch (final NoSuchAlgorithmException | KeyManagementException e1) {
		Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": TLS certificate verification failed");
		throw new SecurityException();
	}
}
 
开发者ID:xavierle,项目名称:messengerxmpp,代码行数:68,代码来源:XmppConnection.java


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