Skip to content

Commit

Permalink
actually fix the websocket this time, dumb aah bs
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikePaladin committed Feb 10, 2024
1 parent 1e6f2d0 commit f6d80c6
Showing 1 changed file with 2 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,21 @@ public class KeyStoreHelper {
public static WebSocket websocketWithBackendCertificates(String token) throws WebSocketException {
FiguraMod.LOGGER.info("Initializing custom websocket");
try {
KeyStore keyStore = getKeyStore();
WebSocketFactory wsFactory = new WebSocketFactory();
SSLContext context = SSLContext.getInstance("TLSv1.2");
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(keyStore, password);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(keyStore);
context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
wsFactory.setSocketFactory(context.getSocketFactory());
wsFactory.setSSLSocketFactory(context.getSocketFactory());
wsFactory.setSSLContext(context);
String serverName = ServerAddress.parseString(Configs.SERVER_IP.value).getHost();
wsFactory.setServerName(serverName);
WebSocket socket = wsFactory.createSocket(FiguraWebSocketAdapter.getBackendAddress());
socket.addListener(new FiguraWebSocketAdapter(token));
socket.removeProtocol("TLSv1");
socket.removeProtocol("TLSv1.1");
socket.clearProtocols();
socket.addProtocol("TLSv1.2");
socket.addExtension(WebSocketExtension.PERMESSAGE_DEFLATE);
return socket;
} catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException |
UnrecoverableKeyException | KeyManagementException e) {
} catch (IOException e) {
FiguraMod.LOGGER.error("Failed to load in the backend's certificates during Websocket creation!", e);
NetworkStuff.disconnect("Failed to load certificates for the backend :c");
}
throw new WebSocketException(WebSocketError.SOCKET_CONNECT_ERROR);
}

// Not needed on anything newer than Java 8
// Derived from https://github.com/MinecraftForge/Installer/blob/1.x/src/main/java/net/minecraftforge/installer/FixSSL.java
private static KeyStore getKeyStore() throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException {
final KeyStore jdkKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
Expand Down

0 comments on commit f6d80c6

Please sign in to comment.