UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED when using System.Net's ClientWebSocket

Trying to connect to a secure websocket (wss scheme) on localhost throws the following error:

Handshake failed - error code: UNITYTLS_INTERNAL_ERROR, verify result: UNITYTLS_X509VERIFY_FLAG_NOT_TRUSTED
My connection code:

async void Start()
    {
        DontDestroyOnLoad(gameObject);

        clientWebSocket = new ClientWebSocket();
        clientWebSocket.Options.AddSubProtocol("Tls");

        Debug.Log("[WS]:Attempting connection.");
        try
        {
            Uri uri = new Uri("wss://localhost:8080/ws/chat");
            await clientWebSocket.ConnectAsync(uri, CancellationToken.None);
            if (clientWebSocket.State == WebSocketState.Open)
            {
                Debug.Log("Input message ('exit' to exit): ");
                Listen();
                StartCoroutine(SendTest(10));
            }
            Debug.Log("[WS][connect]:" + "Connected");
        }
        catch (Exception e)
        {
            Debug.Log("[WS][exception]:" + e.Message);
            if (e.InnerException != null)
            {
                Debug.Log("[WS][inner exception]:" + e.InnerException.Message);
                if (e.InnerException.InnerException != null)
                {
                    Debug.Log("[WS][inner exception][inner exception]:" + e.InnerException.InnerException.Message);
                }
            }
        }
        Debug.Log("End");
    }

Everything works fine with the ws scheme.

Any suggestions on how to fix this would be appreciated!

Looks like the error you’d get if you used a self signed certificate but the client doesn’t know it is ok to use. Since the address is local host, I’m assuming that is the case since no actual certificate authority would issue one for localhost. Since you’re connecting to yourself, why do you even need to encrypt the data anyways though?