diff options
author | syeyoung <cyong06@naver.com> | 2021-03-02 21:25:13 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-03-02 21:25:13 +0900 |
commit | 0b9a21c54720ca8a3c271c2dacbe98df9dac03b2 (patch) | |
tree | 3b0034bc6f46e850e29a2ec18bdbaa62c0ec997d /src/main/java/kr/syeyoung | |
parent | 7c65ce860af23f227d6f5d34c7eb2627ceb2cc27 (diff) | |
download | Skyblock-Dungeons-Guide-0b9a21c54720ca8a3c271c2dacbe98df9dac03b2.tar.gz Skyblock-Dungeons-Guide-0b9a21c54720ca8a3c271c2dacbe98df9dac03b2.tar.bz2 Skyblock-Dungeons-Guide-0b9a21c54720ca8a3c271c2dacbe98df9dac03b2.zip |
magical hack
Diffstat (limited to 'src/main/java/kr/syeyoung')
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/stomp/StompClient.java | 46 | ||||
-rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/stomp/StompPayload.java | 2 |
2 files changed, 37 insertions, 11 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompClient.java b/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompClient.java index 0c938f3c..e61892fc 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompClient.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompClient.java @@ -6,9 +6,7 @@ import org.java_websocket.handshake.ServerHandshake; import org.java_websocket.server.DefaultSSLWebSocketServerFactory; import sun.security.ssl.SSLSocketFactoryImpl; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.*; import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.URI; @@ -24,7 +22,7 @@ import java.util.Map; public class StompClient extends WebSocketClient implements StompInterface { private SSLSocketFactory getSocketfactory() throws NoSuchAlgorithmException, KeyManagementException, CertificateException, KeyStoreException, IOException { - X509Certificate a = (X509Certificate) CertificateFactory.getInstance("X.509") + final X509Certificate a = (X509Certificate) CertificateFactory.getInstance("X.509") .generateCertificate(new ByteArrayInputStream(("-----BEGIN CERTIFICATE-----\n" + "MIIEZTCCA02gAwIBAgIQQAF1BIMUpMghjISpDBbN3zANBgkqhkiG9w0BAQsFADA/\n" + "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" + @@ -56,11 +54,36 @@ public class StompClient extends WebSocketClient implements StompInterface { b.load(null, null); b.setCertificateEntry(Integer.toString(1), a); - TrustManagerFactory c = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - c.init(b); + X509TrustManager trustManager = new X509TrustManager() { + @Override + public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { + for (X509Certificate x509Certificate : x509Certificates) { + if (x509Certificate.equals(a)) { + return; + } + } + throw new CertificateException("invalid"); + } + + @Override + public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { + for (X509Certificate x509Certificate : x509Certificates) { + if (x509Certificate.equals(a)) { + return; + } + } + throw new CertificateException("invalid"); + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[] {a}; + } + }; SSLContext d = SSLContext.getInstance("TLSv1.2"); - d.init(null, c.getTrustManagers(), null); + d.init(null, new TrustManager[]{ trustManager}, null); + return d.getSocketFactory(); } public StompClient(URI serverUri, final String token, CloseListener closeListener) throws Exception { @@ -69,8 +92,13 @@ public class StompClient extends WebSocketClient implements StompInterface { addHeader("Authorization", token); setSocketFactory(getSocketfactory()); - connectBlocking(); + System.out.println("connecting websocket"); + if (!connectBlocking()) { + throw new RuntimeException("Can't connect to ws"); + } + System.out.println("connected, stomp handshake"); while(this.stompClientStatus == StompClientStatus.CONNECTING); + System.out.println("fully connected"); } private CloseListener closeListener; @@ -134,7 +162,7 @@ public class StompClient extends WebSocketClient implements StompInterface { @Override public void onError(Exception ex) { - + ex.printStackTrace(); } private Map<Integer, StompSubscription> stompSubscriptionMap = new HashMap<Integer, StompSubscription>(); diff --git a/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompPayload.java b/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompPayload.java index eb5b1735..c3e00de7 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompPayload.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/stomp/StompPayload.java @@ -37,13 +37,11 @@ public class StompPayload { if (payload != null) sb.append(payload); sb.append((char) 0); - if (FeatureRegistry.DEBUG.isEnabled()) System.out.println("Probably sending "+sb.toString()); return sb.toString(); } public static StompPayload parse(String payload) { - if (FeatureRegistry.DEBUG.isEnabled()) System.out.println("Parsing "+payload); Scanner scanner = new Scanner(payload); StompPayload stompPayload = new StompPayload(); |