httpsurlconnection

SSL TrustManager setup on lower Android APIs

谁说胖子不能爱 提交于 2019-11-29 10:28:31
问题 I have an app communicating with a HTTPS RPC. The HTTP server is using a CAcert signed certificate. I'm using a custom TrustManager for validating the certificate. Because I can not be sure, CAcert is included in all devices' trusted key store. Because I want to allow only CAcert to sign a certificate for this connection. However, I'm following Google's best practices. The only thing I changed is: Load the CAcert root certificate from a static byte[] instead a file Replace the last part,

Getting a reference to Java's default http(s) URLStreamHandler

柔情痞子 提交于 2019-11-29 04:33:29
I have a library that I need to use in one of my projects, which unfortunately registers its own URLStreamHandler to handle http- URLs . Is there a way to get a reference to Java's default http- and https- URLStreamHandlers , so I can specify one of them in the URL 's constructor to open a standard http connection without using the protocol overridden by the library? Found it: sun.net.www.protocol.http.Handler With that, I can now do: URL url = new URL(null, "http://...", new sun.net.www.protocol.http.Handler()); HttpURLConnection cxn = (HttpURLConnection) url.openConnection(); And I get a

how to use HttpsUrlConnection instead of DefaultHttpClient

孤者浪人 提交于 2019-11-28 20:41:13
问题 DefaultHttpClient, ThreadSafeClientConnManager, HttpParams,HttpProtocolParams, SchemeRegistry, SSLSocketFactory, NameValuePair, HttpResponse are deprecated. I tried to use HttpsUrlConnection but i confused about them. protected Gson gson; private ThreadSafeClientConnManager threadSafeClientConnManager; private DefaultHttpClient client; AbstractServiceApi() { // sets up parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

通过JSSE来发起Https请求

≯℡__Kan透↙ 提交于 2019-11-28 11:48:16
工作中会遇到https请求和接受相关的问题,这篇文章介绍的挺不错,转来记录一下,抽时间还会在这篇文章的基础上增加一些自己理解的东东。 摘 要 JSSE是一个SSL和TLS的纯Java实现,通过JSSE可以很容易地编程实现对HTTPS站点的访问。但是,如果该站点的证书未经权威机构的验证,JSSE将拒绝信任该证书从而不能访问HTTPS站点。本文在简要介绍JSSE的基础上提出了两种解决该问题的方法。    引言   过去的十几年,网络上已经积累了大量的Web应用。如今,无论是整合原有的Web应用系统,还是进行新的Web开发,都要求通过编程来访问某些Web页面。传统的方法是使用Socket接口,但现在很多开发平台或工具如.NET、Java或PHP等都提供了简单的Web访问接口,使用这些接口很容易编程实现与Web应用系统的交互访问,即使要访问那些采用了HTTPS而不是HTTP的Web应用系统。   HTTPS,即安全的超文本传输协议,采用了SSL技术,被广泛使用以保证Web应用系统的安全性。访问Web应用的编程接口大多封装了SSL,使得访问HTTPS和访问HTTP一样简单。但是很多中、小型应用系统或基于局域网、校园网的应用系统所使用的证书并不是由权威的认证机构发行或者被其验证,直接使用这些编程接口将不能访问HTTPS。   本文将在简要介绍JSSE的基础上

How to use HttpsURLConnection through proxy by setProperty?

孤街醉人 提交于 2019-11-28 09:53:06
Network environment: Https Client<=============>Proxy Server<==============>Https Server 192.168.17.11<-----extranet------>192.168.17.22 10.100.21.10<----intranet----->10.100.21.11 ps: Http Client without default gateway, but it can ping to 10.100.21.11 Description: OS: Ubuntu 12.04 on 3 hosts Https Client: Implement with java(openjdk-6).Have one network-interface. Proxy Server: Apache2.2.Have two network-interfaces. Https Server: Tomcat6.Have one network-interface. I use two method to implement httpsurlconnection through proxy: (For facilitate I do not write down about ssl handle function for

How to set the list of ciphers and protocols to be used for sockets created by using HttpsURLConnection?

自作多情 提交于 2019-11-28 09:05:08
问题 The normal way to get an SSLSocketFactory would be to initialize a new SSLContext with a TrustManager , KeyManager and SecureRandom and use the getSocketFactory() method. However, this does not allow me to enable the required cipher suites or protocols. The only configuration that HttpsURLConnection permits that would allow such a change is by setting its default SSLSocketFactory . I can create a class that extends SSLSocketFactory and override the getDefaultCipherSuites() method and wrap the

Java HttpsURLConnection and TLS 1.2

独自空忆成欢 提交于 2019-11-27 18:47:59
I read in an article that HttpsURLConnection will transparently negotiate the SSL connection. The official document says: This class uses HostnameVerifier and SSLSocketFactory. There are default implementations defined for both classes. [ 1 ] Does that mean once you open a connection with httpsCon = (HttpsURLConnection) url.openConnection(); It is already SSL/TLS encrypted without any more hassle? How can I view and set the TLS version for the standard implementation? (Should be TLS 1.2 for Java 8 and TLS 1.0 for Java 7) References Oracle Corp. (2011). javax.net.ssl.HttpsURLConnection .

Getting a reference to Java's default http(s) URLStreamHandler

蹲街弑〆低调 提交于 2019-11-27 18:36:10
问题 I have a library that I need to use in one of my projects, which unfortunately registers its own URLStreamHandler to handle http- URLs . Is there a way to get a reference to Java's default http- and https- URLStreamHandlers , so I can specify one of them in the URL 's constructor to open a standard http connection without using the protocol overridden by the library? 回答1: Found it: sun.net.www.protocol.http.Handler With that, I can now do: URL url = new URL(null, "http://...", new sun.net.www

How to override the cipherlist sent to the server by Android when using HttpsURLConnection?

≡放荡痞女 提交于 2019-11-27 04:17:19
During TLS negotiation, clients send a list of supported ciphers to the server, the server picks one, and encryption starts. I want to change this cipherlist sent to the server by Android, when I'm using HttpsURLConnection for communication. I know that I can use setSSLSocketFactory on the HttpsURLConnection object to set it up to use a SSLSocketFactory . This is useful when I want to change the trustmanager etc used by the SSLSocket returned by the SSLSocketFactory . I know that in general this ciphersuite list can be edited using an SSLParameters object and passing it to SSlsocket or

How to use HttpsURLConnection through proxy by setProperty?

情到浓时终转凉″ 提交于 2019-11-27 03:16:29
问题 Network environment: Https Client<=============>Proxy Server<==============>Https Server 192.168.17.11<-----extranet------>192.168.17.22 10.100.21.10<----intranet----->10.100.21.11 ps: Http Client without default gateway, but it can ping to 10.100.21.11 Description: OS: Ubuntu 12.04 on 3 hosts Https Client: Implement with java(openjdk-6).Have one network-interface. Proxy Server: Apache2.2.Have two network-interfaces. Https Server: Tomcat6.Have one network-interface. I use two method to