Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery.common.java
/
utils
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
76785094
authored
Jan 06, 2020
by
Adi Amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update no SSL validation mechanism
parent
66d4ed7b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
2 deletions
build.gradle
src/main/java/http/simpleHttpClient/SimpleHttpClient.java
build.gradle
View file @
76785094
group
'com.ipgallery.common'
group
'com.ipgallery.common'
version
'1.3.
1
'
version
'1.3.
2
'
apply
plugin:
'java'
apply
plugin:
'java'
apply
plugin:
'maven-publish'
apply
plugin:
'maven-publish'
...
...
src/main/java/http/simpleHttpClient/SimpleHttpClient.java
View file @
76785094
...
@@ -15,12 +15,15 @@ import org.apache.http.config.RegistryBuilder;
...
@@ -15,12 +15,15 @@ import org.apache.http.config.RegistryBuilder;
import
org.apache.http.config.SocketConfig
;
import
org.apache.http.config.SocketConfig
;
import
org.apache.http.conn.socket.ConnectionSocketFactory
;
import
org.apache.http.conn.socket.ConnectionSocketFactory
;
import
org.apache.http.conn.socket.PlainConnectionSocketFactory
;
import
org.apache.http.conn.socket.PlainConnectionSocketFactory
;
import
org.apache.http.conn.ssl.TrustStrategy
;
import
org.apache.http.cookie.Cookie
;
import
org.apache.http.cookie.Cookie
;
import
org.apache.http.impl.client.*
;
import
org.apache.http.impl.client.*
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLContext
;
import
java.io.*
;
import
java.io.*
;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -33,6 +36,7 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
...
@@ -33,6 +36,7 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import
org.apache.http.protocol.BasicHttpContext
;
import
org.apache.http.protocol.BasicHttpContext
;
import
org.apache.http.protocol.HttpContext
;
import
org.apache.http.protocol.HttpContext
;
import
org.apache.http.ssl.SSLContextBuilder
;
import
org.apache.http.ssl.SSLContextBuilder
;
import
org.apache.http.ssl.SSLContexts
;
public
class
SimpleHttpClient
{
public
class
SimpleHttpClient
{
...
@@ -79,12 +83,31 @@ public class SimpleHttpClient {
...
@@ -79,12 +83,31 @@ public class SimpleHttpClient {
this
.
requestTimeout
=
requestTimeout
;
this
.
requestTimeout
=
requestTimeout
;
// create an SSL context which trusts any certificate !
// create an SSL context which trusts any certificate !
// org.apache.http.ssl.SSLContextBuilder sslContextBuilder = SSLContextBuilder.create();
// sslContextBuilder.loadTrustMaterial(new org.apache.http.conn.ssl.TrustSelfSignedStrategy());
// SSLContext sslContext = sslContextBuilder.build();
// org.apache.http.conn.ssl.SSLConnectionSocketFactory sslSocketFactory =
// new SSLConnectionSocketFactory(sslContext, new org.apache.http.conn.ssl.DefaultHostnameVerifier());
org
.
apache
.
http
.
ssl
.
SSLContextBuilder
sslContextBuilder
=
SSLContextBuilder
.
create
();
org
.
apache
.
http
.
ssl
.
SSLContextBuilder
sslContextBuilder
=
SSLContextBuilder
.
create
();
sslContextBuilder
.
loadTrustMaterial
(
new
org
.
apache
.
http
.
conn
.
ssl
.
TrustSelfSignedStrategy
());
sslContextBuilder
.
loadTrustMaterial
(
new
org
.
apache
.
http
.
conn
.
ssl
.
TrustSelfSignedStrategy
());
SSLContext
sslContext
=
sslContextBuilder
.
build
();
//SSLContext sslContext = sslContextBuilder.build();
SSLContext
sslContext
=
SSLContexts
.
custom
()
//FIXME to contain real trust store
.
loadTrustMaterial
(
new
TrustStrategy
()
{
@Override
public
boolean
isTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
return
true
;
}
})
.
build
();
org
.
apache
.
http
.
conn
.
ssl
.
SSLConnectionSocketFactory
sslSocketFactory
=
org
.
apache
.
http
.
conn
.
ssl
.
SSLConnectionSocketFactory
sslSocketFactory
=
new
SSLConnectionSocketFactory
(
sslContext
,
new
org
.
apache
.
http
.
conn
.
ssl
.
DefaultHostnameVerifier
());
new
SSLConnectionSocketFactory
(
sslContext
,
new
org
.
apache
.
http
.
conn
.
ssl
.
DefaultHostnameVerifier
());
// create scheme for http & https
// create scheme for http & https
RegistryBuilder
<
ConnectionSocketFactory
>
schemeRegistry
=
RegistryBuilder
.
create
();
RegistryBuilder
<
ConnectionSocketFactory
>
schemeRegistry
=
RegistryBuilder
.
create
();
schemeRegistry
.
register
(
"http"
,
PlainConnectionSocketFactory
.
getSocketFactory
());
schemeRegistry
.
register
(
"http"
,
PlainConnectionSocketFactory
.
getSocketFactory
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment