FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-ssl-test/SSLTest.java at master · lndbrg/java-ssl-test · GitHub
lndbrg
/
java-ssl-test
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
java-ssl-test
/
SSLTest.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (53 loc) · 2.12 KB
Breadcrumbs
java-ssl-test
/
SSLTest.java
Copy path
File metadata and controls
57 lines (53 loc) · 2.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Makes simple connection to SSL enabled site.
* Useful for debugging SSL Exceptions :)
*/
import
java
.
io
.
IOException
;
import
java
.
io
.
OutputStream
;
import
java
.
net
.
Socket
;
import
java
.
net
.
UnknownHostException
;
import
javax
.
net
.
ssl
.
HostnameVerifier
;
import
javax
.
net
.
ssl
.
HttpsURLConnection
;
import
javax
.
net
.
ssl
.
SSLSession
;
import
javax
.
net
.
ssl
.
SSLSocketFactory
;
public
class
SSLTest
{
/**
* @param args
* @throws IOException
* @throws UnknownHostException
* @throws NumberFormatException
*/
public
static
void
main
(
String
[]
args
)
throws
NumberFormatException
,
UnknownHostException
,
IOException
{
String
Me
=
new
Object
() { }.
getClass
().
getEnclosingClass
().
getSimpleName
();
String
Host
=
System
.
getProperty
(
"host"
);
String
Debug
=
System
.
getProperty
(
"debug"
);
Integer
Port
=
Integer
.
getInteger
(
"port"
);
if
(
Port
==
null
)
Port
=
443
;
if
(
Debug
!=
null
) {
System
.
setProperty
(
"javax.net.debug"
,
"all"
);
}
if
(
Host
==
null
|| (
Host
!=
null
&&
Host
.
length
() ==
0
) ) {
System
.
err
.
println
(
"java -Ddebug -Dhost=hostname -Dport=port "
+
Me
);
System
.
err
.
println
(
"port defaults to 443"
);
System
.
err
.
println
(
"provide hostname without protocol"
);
System
.
err
.
println
(
"example: java -Dhost=bitbucket.org "
+
Me
);
System
.
err
.
println
(
"example: java -Dhost=bitbucket.org -Djavax.net.ssl.keyStore=keystore.jks -Djavax.net.ssl.keyStorePassword=password "
+
Me
);
System
.
exit
(
1
);
}
HttpsURLConnection
.
setDefaultHostnameVerifier
(
new
HostnameVerifier
() {
public
boolean
verify
(
String
hostname
,
SSLSession
session
) {
System
.
out
.
println
(
"Verifying: "
+
hostname
);
return
true
;
}
});
Socket
s
=
SSLSocketFactory
.
getDefault
()
.
createSocket
(
Host
,
Port
);
OutputStream
out
=
s
.
getOutputStream
();
out
.
write
(
"I love you!"
.
getBytes
(
"UTF8"
));
System
.
out
.
println
(
Host
+
":"
+
Port
+
" looks okay to java!"
);
out
.
close
();
s
.
close
();
}
}
Back
|
FazBrowse Home
|
New Git URL