Home » Java » asp.net core – SignalR JAVA Client HTTPS Connection Certificate Issues-Exceptionshub

asp.net core – SignalR JAVA Client HTTPS Connection Certificate Issues-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Trying to create a connection between my Client and Server (ASP.Net Core 2.2 – SignalR) . Server has a self-signed Certificate which the client is refusing:

Hostname XXX not verified:

certificate: XXX

DN: XXX, O=XXX, L=XXX, ST=XXX, C=XXX

subjectAltNames: [] at io.reactivex.internal.util.ExceptionHelper.wrapOrThrow(ExceptionHelper.java:46)
at io.reactivex.internal.observers.BlockingMultiObserver.blockingGet(BlockingMultiObserver.java:93)
at io.reactivex.Completable.blockingAwait(Completable.java:1227)

Is there a way to add my invalid certificate as an exception? Apparently it doesnt use my cacerts in jre/lib/security, because doing a simple get request on my server works without any issues.

How my SignalR client is build:

public Messenger(String address) {
        h = HubConnectionBuilder.create(address+"/ChatHub").build();
        h.on("Send", (message) -> {
                System.out.println("New message: " + message);
            }
        }, String.class);

        h.onClosed( (error) -> {
            JOptionPane.showMessageDialog(null, "Connection to the server lost.", "Error", JOptionPane.ERROR_MESSAGE);
            boolean connection = false;

            while(!connection) {
                //System.out.println("Trying to reconnect..");
                h.start();
                if( h.getConnectionState() == HubConnectionState.CONNECTED) {
                    connection = true;
                    JOptionPane.showMessageDialog(null, "Reconnected to the server.", "Success", JOptionPane.ERROR_MESSAGE);
                }
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });

        h.start().blockingAwait();
    }
How to&Answers: