-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-----BEGIN PGP SIGNATURE----- | ||
Version: BCPG v1.64 | ||
|
||
iQEcBAABCgAGBQJgyOzVAAoJEIoqalWqx6keof0H/RBmG8kJawYFGQ0hULtD+aFX | ||
DgRrzRJKxker10BQ9lFfqwfIireItkxMYqHB3yVuWOiof2vaX08g1AGXlirD5C00 | ||
nniXdORWuYXgG0CtSr21tK/sh0Whws7Kmovods5uieq8YcaB+hLs6LDRiqwaXtN1 | ||
R5yImCwhBiH/xtIfH5w3czBHVLm/SEIN8PkYPyeaZAD4HU185i63VEYeceA/DW4e | ||
QtpALifbUAq8JsnQ4Dk+BSWgWGKoj9JuI/Bp4z2XF2nyg9zCFCYTQJwy4KuaRY3i | ||
MkOFoq2VPDEvbir4XUP7flzYmv2cANjRZJdm6wHIazXI5ZD1Vq9HAJuG2ZhWRKs= | ||
=hnM7 | ||
-----END PGP SIGNATURE----- |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-----BEGIN PGP SIGNATURE----- | ||
Version: BCPG v1.64 | ||
|
||
iQEcBAABCgAGBQJgyOzVAAoJEIoqalWqx6keMVYH/1gCWV5dnYXxPdCeLaUGlXwU | ||
IM8a8KczoSPjsN+gnCOrzdrhcvjzb6tTXrUP6dzYZOS0mmrcxQQ2hNmifDbTh/Xb | ||
qpAAIF1qBTWxbUWSw91sFro1ZM57n5q1yLKWB3j9uMhCUXaqZZtp6ecN1Ma88R6/ | ||
3hIHyS0Ne6xZEMoyTUEvv66/92gFyvygeWkIpvbGDFmklOFPTB0xeL1H9Aw6LX1L | ||
fSi4GbxZcHFm3AkuljurmomOKgvFr5K8DE7A0pOOf/+bDtaS9IqNPOoc9NKmoKCh | ||
XSCCxrCwJ9FKGKiT228MfyBpdzj3dgErFSPhw/oo/Uhv1tcp6C/Vzz3oE4bzc+U= | ||
=8DNo | ||
-----END PGP SIGNATURE----- |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-----BEGIN PGP SIGNATURE----- | ||
Version: BCPG v1.64 | ||
|
||
iQEcBAABCgAGBQJh2yfNAAoJEIoqalWqx6ke+qkH/A9OyB20RHao3gNV0XA5j35M | ||
ddWr9wlyf0bUgjvx19KLVCz+h3I8KXqfXT/P/jpKUZfYYNSg4NndRQLTdad/yGHb | ||
lHECSL2uVhU5yWKYWZE5ChX/6dimb0G9VHRrduR75C81bB0WlTyyiPNwh6W45kG3 | ||
b3513t/8lw0qDoz95ko9MSa4YmNIXBAak5lOt9xPuGKduT+eirUinbOFTn+RfIW5 | ||
uiWm3cdSwN7fPrJ3U1omzM/RMPNClQoF0fkAMlh9+UYGK5IGFl/kqwobzbVwalYK | ||
Lu5RlFbpSaAlaGwKR/fYuAeX2o5QmAzMJ5tW1FiRWosr0BqegF/DqGyXa0N3kks= | ||
=W95U | ||
-----END PGP SIGNATURE----- |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-----BEGIN PGP SIGNATURE----- | ||
Version: BCPG v1.64 | ||
|
||
iQEcBAABCgAGBQJh2yfNAAoJEIoqalWqx6ketWAIAJWt9qEA5eKlyDBYOssWOUyH | ||
m57v5iimjRuyzcQAdCa8bcEDMwuXilhScif1J4YMRQAfC+gm6Uz6oeTG1PjkXF50 | ||
H4CSlhfehADX9inQssd52r4wNRyqAdlG+YiPMuaeVKYoJLDL0S0LSqLm+Jxv/0yG | ||
gIJy7EnFQv2nsLklKUeH9kdXEdhnn7Zkk37ceXoX+pNS5nZxjgSrHzbETlv3uJYa | ||
OOUVeEnh3QYRBZtZa4q5fjDFVbyJFIlfAPE1KOv1q5ijinMhgrBCkns9Hwy9/7y9 | ||
qV1Um8bvA7PEY+QnRu1IZbEGvDJAd8YOHBdf9rCoZLtIhYLUcYFgr4bXmcUa3nY= | ||
=jGn8 | ||
-----END PGP SIGNATURE----- |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-----BEGIN PGP SIGNATURE----- | ||
Version: BCPG v1.64 | ||
|
||
iQEcBAABCgAGBQJh2yfNAAoJEIoqalWqx6kezqIIALRItns7BatxjQ5az7tPFN7f | ||
KItQ6LX2rLSk+fWTVWVbQDNvryvoVXuysScu0A1i1sSDEVNbLr9VPoGr7XX/t1yY | ||
YZ1jUfyRv8AeD3ISfVWjDAx5NiAO8uFeJWxnUKpWGaVCoFa9/3luxHctkbBXFkUw | ||
0+ijTBupGoKaaVU9wBiRpDFMgdwiJhOpWPgRvIx/dstkZwLIz0CCMMcZscNLNHkI | ||
kN23M0tpX1RWRKXBRzEIyRR2j9v9xDwIvBBCl530zgJwuuLDwsVFbM2cgmXKFzH+ | ||
KD1ji4e0CaEtxLwmfVw23GTBQI8N2xOMMGQeDfbbVPLb54KCmBcVu7QmT7UtdUE= | ||
=KQCd | ||
-----END PGP SIGNATURE----- |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-----BEGIN PGP SIGNATURE----- | ||
Version: BCPG v1.64 | ||
|
||
iQEcBAABCgAGBQJh3JDwAAoJEIoqalWqx6keX2oH+wZv2TNETRbsnUbzznxWRBfp | ||
8rCB615Ow8heipB/P5P52bIUX3sCbOiJ7pHIenS+j0/C94fKUPmHG0qkG1eYq1vD | ||
UwnkbSWK/qaTQrlif0Ez94NTGHn0VSF5TxRRGVWRZzuLqpVwTs+LZP3Oq68NP/C0 | ||
wA6LICH64lMBWPDG7bgVMTLX7tLJMkuANkFUd3K9sEGd6zPVs+TjKf7k/A57pLfJ | ||
XyeS+OoORs3wAnKktKc3jRxopFZShk/V7VDn4yPwfPWaDSca8GIU5OS+E6MFIJcE | ||
lMbeG2iHiRnx310ZnSEgDbCq1NHOg6jeu8S/YOMjk4GbmWsk/MtTTtHfS/xL79I= | ||
=wxTZ | ||
-----END PGP SIGNATURE----- |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-----BEGIN PGP SIGNATURE----- | ||
Version: BCPG v1.64 | ||
|
||
iQEcBAABCgAGBQJh3JDwAAoJEIoqalWqx6kepIIH/jlmXAhadRtfepIIRquHiJSF | ||
ayJoJ5j3mPNnevisPNsOdDjqO9R+UinSqYGzV6vlFkC+UtyqKdxH2sE/ePDvMeih | ||
92FHyVvxkO+eTXA2FmZ200GxN1gQ3BgOnn4SZ0gwRhHtVXWbkaKr/b4cUbmL8mzg | ||
XoFwJdOH8Ip9lmLghHyoi2ULqlLfRUs/8HkHY8XrVdFiqs+CByUEiS3ED37CJgCe | ||
I4u/dNafGjMpztlVlGuQ2TUPBqPMoai40C5M/KrF/6IjGNFC16yNunH1YI+/n5xN | ||
rRmh9ElpN1lgGDZNrFvy9JaFFePFtTuFgmsdpnTRV1r5V4cs7y4/SNdGER8KRLY= | ||
=f+aO | ||
-----END PGP SIGNATURE----- |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-----BEGIN PGP SIGNATURE----- | ||
Version: BCPG v1.64 | ||
|
||
iQEcBAABCgAGBQJh3JDwAAoJEIoqalWqx6keHCcH/RWUGEJj1geQEdnwGP6QPT/P | ||
B6ffxr0so8YS+HSjliG6v73gDH6QwweOO4zabTarRkzuuetKD0gLpC3cUS7baLGF | ||
Hw+kbtZKOj+sOPrMnYV3AGY1b4atIwgT4jsqr7AOJQCUsrqNKVBau2fECbHvaJKL | ||
tUaDhR2Fp08fipnUUif4atiT3s/AKeisayE8T2kvXzvzCC0bwVAskUuWPgWFMAm8 | ||
EbLef2993qi+vb/Q8GzIbrT8yD5AUdmzy8ZMVo7TaSrVlcRc/Y4m2aOAHDmSppQm | ||
G+ogSkyG5f/QWspa6RauJmGU1LIQXvN7qQf7mACi+pPLu8U2PVaQWvXqFixg8xw= | ||
=vHJ1 | ||
-----END PGP SIGNATURE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="WARN"> | ||
<Appenders> | ||
<Console name="Console" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> | ||
</Console> | ||
</Appenders> | ||
<Loggers> | ||
<Root level="info"> | ||
<AppenderRef ref="Console"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |
127 changes: 127 additions & 0 deletions
127
src/main/java/com/jpaulmorrison/fbp/examples/networks/SSLClientExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package com.jpaulmorrison.fbp.examples.networks; | ||
/* | ||
* Copyright (c) 2010-2020 Nathan Rajlich | ||
* | ||
* Permission is hereby granted, free of charge, to any person | ||
* obtaining a copy of this software and associated documentation | ||
* files (the "Software"), to deal in the Software without | ||
* restriction, including without limitation the rights to use, | ||
* copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following | ||
* conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.URI; | ||
import java.nio.file.Paths; | ||
import java.security.KeyStore; | ||
import javax.net.ssl.KeyManagerFactory; | ||
import javax.net.ssl.SSLContext; | ||
import javax.net.ssl.SSLSocketFactory; | ||
import javax.net.ssl.TrustManagerFactory; | ||
import org.java_websocket.client.WebSocketClient; | ||
import org.java_websocket.handshake.ServerHandshake; | ||
|
||
class WebSocketChatClient extends WebSocketClient { | ||
|
||
public WebSocketChatClient(URI serverUri) { | ||
super(serverUri); | ||
} | ||
|
||
@Override | ||
public void onOpen(ServerHandshake handshakedata) { | ||
System.out.println("Connected"); | ||
|
||
} | ||
|
||
@Override | ||
public void onMessage(String message) { | ||
System.out.println("got: " + message); | ||
|
||
} | ||
|
||
@Override | ||
public void onClose(int code, String reason, boolean remote) { | ||
System.out.println("Disconnected"); | ||
|
||
} | ||
|
||
@Override | ||
public void onError(Exception ex) { | ||
ex.printStackTrace(); | ||
|
||
} | ||
|
||
} | ||
|
||
public class SSLClientExample { | ||
|
||
/* | ||
* Keystore with certificate created like so (in JKS format): | ||
* | ||
*keytool -genkey -keyalg RSA -validity 3650 -keystore "keystore.jks" -storepass "storepassword" -keypass "keypassword" -alias "default" -dname "CN=127.0.0.1, OU=MyOrgUnit, O=MyOrg, L=MyCity, S=MyRegion, C=MyCountry" | ||
*/ | ||
public static void main(String[] args) throws Exception { | ||
WebSocketChatClient chatclient = new WebSocketChatClient(new URI("wss://localhost:8887")); | ||
|
||
// load up the key store | ||
String STORETYPE = "JKS"; | ||
String KEYSTORE = Paths.get("src", "test", "java", "org", "java_websocket", "keystore.jks") | ||
.toString(); | ||
String STOREPASSWORD = "storepassword"; | ||
String KEYPASSWORD = "keypassword"; | ||
|
||
KeyStore ks = KeyStore.getInstance(STORETYPE); | ||
File kf = new File(KEYSTORE); | ||
ks.load(new FileInputStream(kf), STOREPASSWORD.toCharArray()); | ||
|
||
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); | ||
kmf.init(ks, KEYPASSWORD.toCharArray()); | ||
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); | ||
tmf.init(ks); | ||
|
||
SSLContext sslContext = null; | ||
sslContext = SSLContext.getInstance("TLS"); | ||
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); | ||
// sslContext.init( null, null, null ); // will use java's default key and trust store which is sufficient unless you deal with self-signed certificates | ||
|
||
SSLSocketFactory factory = sslContext | ||
.getSocketFactory();// (SSLSocketFactory) SSLSocketFactory.getDefault(); | ||
|
||
chatclient.setSocketFactory(factory); | ||
|
||
chatclient.connectBlocking(); | ||
|
||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | ||
while (true) { | ||
String line = reader.readLine(); | ||
if (line.equals("close")) { | ||
chatclient.closeBlocking(); | ||
} else if (line.equals("open")) { | ||
chatclient.reconnect(); | ||
} else { | ||
chatclient.send(line); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
|