我在一篇文章中读到了HttpsURLConnection 透明地协商SSL连接的文章.
官方文件说:
该类使用HostnameVerifier和SSLSocketFactory.为这两个类定义了默认实现.[ 1 ]
这是否意味着一旦你打开一个连接
httpsCon = (HttpsURLConnection) url.openConnection();
Run Code Online (Sandbox Code Playgroud)
它已经加密了SSL/TLS而没有任何麻烦吗?
如何查看和设置标准实现的TLS版本?(应该是Java 8的TLS 1.2和Java 7的TLS 1.0)
执行摘要:我HttpsUrlConnection在Android应用程序中使用该类以串行方式通过TLS发送大量请求.所有请求都是相同类型的,并发送到同一主机.首先,我会为每个请求获得一个新的TCP连接.我能够解决这个问题,但并非没有在与readTimeout相关的某些Android版本上引起其他问题.我希望有一种更强大的方法来实现TCP连接重用.
在检查我正在使用Wireshark的Android应用程序的网络流量时,我发现每个请求都会导致建立新的TCP连接,并且正在执行新的TLS握手.这导致了相当大的延迟,特别是如果您使用的是3G/4G,每次往返都需要相对较长的时间.然后我尝试了没有TLS(即HttpUrlConnection)的相同场景.在这种情况下,我只看到一个TCP连接正在建立,然后重新用于后续请求.因此,建立新TCP连接的行为是特定的HttpsUrlConnection.
下面是一些示例代码来说明问题(真正的代码显然有证书验证,错误处理等):
class NullHostNameVerifier implements HostnameVerifier {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
protected void testRequest(final String uri) {
new AsyncTask<Void, Void, Void>() {
protected void onPreExecute() {
}
protected Void doInBackground(Void... params) {
try {
URL url = new URL("https://www.ssllabs.com/ssltest/viewMyClient.html");
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null,
new X509TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted( final X509Certificate[] chain, final String authType ) { …Run Code Online (Sandbox Code Playgroud) 我花了无数个小时试图通过Fiddler为HttpsUrlConnection解密Android SSL流量,但收效甚微.如何使用HttpsUrlConnection可靠地配置Fiddler来解密来自Android应用的SSL流量?
这是我的步骤
以上工作.问题是非浏览器的Android流量在Fiddler中显示为连接隧道.我最初的研究表明问题是由于如何通过HttpsUrlConnection信任证书,所以我确保信任所有基于本文的证书https://secure.mcafee.com/us/resources/white-papers/wp-defeating-ssl -cert-validation.pdf
不幸的是,信任所有证书对我来说并不适用于HttpsUrlConnection,所以我停止了调查.几天后,我决定再次尝试,并惊讶地发现正在为HttpsUrlConnection解密小提琴流量!不幸的是我没有做任何进一步的修改来解决这个问题所以我不能完全确定它为什么开始工作.它使用的设备是LG-Optimus L9 Android版本4.0.4并且是根的.
现在我正在尝试为Nexus 7 Android版本4.2.2(未植根)配置此功能,但我在fiddler中看到的所有内容都是连接隧道.由于两个设备上的证书都具有相同的序列号,而我正在测试的应用程序是相同的,因此我难以理解为什么我无法使用其他Android设备配置Fiddler.
总结一下
我们在android中编写了客户端应用程序,它使用HttpsUrlConnection apis与https服务器连接.由于Poodle漏洞,我们需要在调用任何请求时从启用的协议列表中禁用SSLv3.
我们遵循oracle捕获的指南,如http://www.oracle.com/technetwork/java/javase/documentation/cve-2014-3566-2342133.html
并在调用url连接之前添加了以下行
java.lang.System.setProperty("https.protocols", "TLSv1");
Run Code Online (Sandbox Code Playgroud)
这个解决方案适用于普通的java程序.尝试连接仅适用于SSLv3协议的服务器时,我们收到了SSLHandShakeException.
但值得关注的是:同样的修复不适用于Android.我错过了什么或者我应该为Android尝试另一种方法吗?请建议.
我想做一个HTTPS post方法,从我的Android应用程序发送一些数据到我的网站.
我HttpURLConnection先使用它,我的HTTP URL工作正常.我的生产网站是使用HTTPS的,我希望使用相同的POST发送HttpsURLConnection.有人可以帮我正确使用课程吗?
我在这个链接找到了一些来源:
KeyStore keyStore = ...;
TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
tmf.init(keyStore);
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, tmf.getTrustManagers(), null);
URL url = new URL("https://www.example.com/");
HttpsURLConnection urlConnection = (HttpsURLConnection)
url.openConnection();
urlConnection.setSSLSocketFactory(context.getSocketFactory());
InputStream in = urlConnection.getInputStream();
Run Code Online (Sandbox Code Playgroud)
应该是什么价值 KeyStore keyStore = ...;?
我尝试使用相同的方式发送数据 HttpURLConnection,但我看到一些POST数据丢失或出错.
我试过这个问题的方法.我在下面粘贴我的代码
String urlParameters="dateTime=" + URLEncoder.encode(dateTime,"UTF-8")+
"&mobileNum="+URLEncoder.encode(mobileNum,"UTF-8");
URL url = new URL(myurl);
HttpsURLConnection conn;
conn=(HttpsURLConnection)url.openConnection();
// Create the SSL connection
SSLContext sc;
sc = SSLContext.getInstance("TLS");
sc.init(null, null, new …Run Code Online (Sandbox Code Playgroud) 我在android中实现webview应用程序.当我尝试加载https url一到两次时,它完成了活动.Agian试图加载https网址,显示网页不可用.请在下面找到我得到的图片.

当我再次点击该网址时,它会显示网站.
我使用下面的代码加载网址.
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://www.facebook.com");
webView.clearView();
webView.measure(100, 100);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@SuppressLint("NewApi")
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
// this will ignore the Ssl error and will go forward to your site
handler.proceed();
error.getCertificate();
}
});
Run Code Online (Sandbox Code Playgroud)
请任何帮助人.......
提前致谢
网络环境:
Https客户端<=============>代理服务器<==============> Https Server
192.168.17.11 <----- extranet --- ---> 192.168.17.22
10.100.21.10 <---- intranet -----> 10.100.21.11ps:没有默认网关的Http客户端,但它可以ping到10.100.21.11
描述:
操作系统:3台主机上的Ubuntu 12.04
Https客户端:用java实现(openjdk-6).有一个网络接口.
代理服务器:Apache2.2.有两个网络接口.
Https服务器:Tomcat6.Have一个网络接口.
我使用两种方法通过代理实现httpsurlconnection :(
为方便起见我没有写下关于ssl句柄函数来检查serverTrusted和hostnameVerifier问题.如果需要我会更新.)
InetSocketAddress proxyInet = new InetSocketAddress("10.100.21.11",80);
Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyInet);
URL httpsUrl = new URL("https://192.168.17.22:8443/test");
HttpsURLConnection httpsCon = (HttpsURLConnection) httpsUrl.openConnection(proxy);
httpsCon.setDoOutput(true);
httpsCon.setDoInput(true);
httpsCon.setRequestMethod("POST");
OutputStream out = httpsCon.getOutputStream();
OutputStreamWriter owriter = new OutputStreamWriter(out);
owriter.write("<request>test</request>");
owriter.flush();
owriter.close();
...
Run Code Online (Sandbox Code Playgroud)
这种方法可行,我观察到数据包流量也符合我的期望.
HttpClient ---> ProxyServer ---> HttpServer
但是当我使用set Property方法时:
System.setProperty("http.proxySet", …Run Code Online (Sandbox Code Playgroud) 尝试使用javax.net.ssl.HttpsURLConnection连接到URL时,我得到"java.lang.ClassCastException".
我使用的是Weblogic Server 10.3.4.
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.X509Certificate;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* @author kmrgtm
*
*/
public class GatewayConnect {
public void ConnectURL()
{
try
{
System.out.println("***** Inside Class File *****");
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) { …Run Code Online (Sandbox Code Playgroud) 我OpenSSL使用该HttpsUrlConnection对象让Android连接到一个简单的服务器时遇到了麻烦(我已经通过StackOverflow和一堆在线教程进行了梳理,并按照示例进行了大量的线条,我仍然无法弄清楚为什么我的当我使用我的本地信任库时,它被破坏了.
我目前有一个Android活动试图连接到一个简单的OpenSSL server(我可以使用OpenSSL客户端连接到我的服务器),一旦HttpsUrlConnection.connect()被调用我收到" javax.net.ssl.SSLException: Connection closed by peer" error during the SSL handshake. 也许我正在设置我的样本服务器错误?
注意事项:
Android 4.1 API 16.我已经尝试过的事情:
127.0.0.1 and 10.0.2.2SecureRandom() with the SSLContext.init()'URL u = new URL("https", "10.0.2.2", 443, "/");'TrustManagerFactory.getDefaultAlgorithms()而不是"X509"
"Unexpected response code error 503"而不是"由同伴关闭的连接"提前感谢您抽出宝贵时间来审核我的问题!
使用命令启动简单服务器:
$ sudo openssl s_server -accept 443 -cert server-cert.pem -key …Run Code Online (Sandbox Code Playgroud) 在TLS协商期间,客户端将支持的密码列表发送到服务器,服务器选择一个密码,然后开始加密.当我HttpsURLConnection用于通信时,我想更改Android发送到服务器的密码列表.
我知道我可以setSSLSocketFactory在HttpsURLConnection对象上使用它来设置它SSLSocketFactory.当我想要更改由SSLSocket返回的信任管理器等时,这非常有用SSLSocketFactory.
我知道一般这个密码组列表可以使用编辑SSLParameters对象,并将其传递到SSlsocket或SSLEngine使用他们提供的方法的对象.
但SSLSocketFactory似乎没有公开这样的方法!
我找不到一种方法来改变我传递给的创建SSLParameters的返回SSLSocket对象.SSLSocketFactoryHttpsURLConnection
该怎么办?
我想这也与Java有关,不仅仅是Android.也许有一种OO方式来做(例如扩展SSLSocketFactory并提供给它HttpsURLConnection?)