hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (HTTPCLIENT-1119) Server Name Indication (SNI) Support
Date Fri, 17 May 2013 07:43:17 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13659629#comment-13659629
] 

Oleg Kalnichevski edited comment on HTTPCLIENT-1119 at 5/17/13 7:41 AM:
------------------------------------------------------------------------

For the record, this is how to enable SNI with HttpClient 4.3 using BeanUtils

https://wiki.apache.org/HttpComponents/SNISupport

Oleg
                
      was (Author: olegk):
    For the record, this is how to enable SNI with HttpClient 4.3 using BeanUtils

---
SSLContext sslcontext = SSLContexts.createSystemDefault();
SSLSocketFactory sslsf = new SSLSocketFactory(sslcontext) {

	@Override
	public Socket connectSocket(
			int connectTimeout, 
			Socket socket,
			HttpHost host, 
			InetSocketAddress remoteAddress,
			InetSocketAddress localAddress, 
			HttpContext context) throws IOException, ConnectTimeoutException {
		if (socket instanceof SSLSocket) {
			try {
				PropertyUtils.setProperty(socket, "host", host.getHostName());
			} catch (NoSuchMethodException ex) {
			} catch (IllegalAccessException ex) {
			} catch (InvocationTargetException ex) {
			}
		}
		return super.connectSocket(connectTimeout, socket, host, remoteAddress,
				localAddress, context);
	}
	
};

CloseableHttpClient httpclient = HttpClients.custom()
		.setSSLSocketFactory(sslsf)
		.build();
CloseableHttpResponse response = httpclient.execute(new HttpGet("https://verisign.com/"));
try {
	System.out.println(response.getStatusLine());
	EntityUtils.consume(response.getEntity());
} finally {
	response.close();
}
---

Oleg
                  
> Server Name Indication (SNI) Support
> ------------------------------------
>
>                 Key: HTTPCLIENT-1119
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1119
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>          Components: HttpClient
>            Reporter: Gus Power
>              Labels: sni, ssl, tls, vhost
>             Fix For: Future
>
>         Attachments: HTTPCLIENT-1119-support-SNI-on-Java-7-via-setHost-of.patch
>
>
> Provide support for Server Name Indication (SNI) support as per RFC 3546 (section 3.1).
> Currently attempting to connect to SNI enabled host 'expectedhost' over SSL using http
client results in an SSLException similar to:
> javax.net.ssl.SSLException: hostname in certificate didn't match: <expectedhost>
!= <defaulthost>
>   at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:220)
> We use SNI on some of our environments and were trying to use httpclient to automatically
test host access and availability.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message