Skip to content

Conversation

@redboltz
Copy link
Owner

The reason Chrome (and some other browsers) cannot connect to the broker is as follows:

  1. The OS (Windows 11) has a client certificate named "Microsoft Your Phone".

  2. This certificate was installed at some point, but it is harmless.

  3. The connection is attempted from a local file (file:///some/mqtt.html) using MQTT.js to a WSS broker.

  4. When the browser accesses the HTML page via HTTPS, a popup appears asking the user to choose a client certificate or not send one.

    • This happens because the server is configured with verify_peer (but not mandatory) and the OS has at least one client certificate installed.
    • The browser gives the choice to send a certificate or not. In this scenario, not sending a certificate is the correct choice.

However, if the first access is directly via wss:// (not HTTPS), the choice popup cannot appear:

  • Browsers do not trigger the certificate selection dialog for JavaScript-initiated WSS connections.
  • As a result, the TLS handshake fails.

If the user first accesses the page via https://, the certificate selection popup appears, and subsequent wss:// connections succeed because the handshake can complete.

Initially, this behavior seemed surprising to me.
However, in typical use, wss:// connections originate from content already served via HTTPS on the same host. Since HTTPS access occurs before WSS, the user has the opportunity to choose a certificate (or not send one).

In my test case, I accessed WSS directly from a local file://, which caused this issue.

The reason Chrome (and some other browsers) cannot connect to the broker is as follows:

1. The OS (Windows 11) has a client certificate named **"Microsoft Your Phone"**.
2. This certificate was installed at some point, but it is harmless.
3. The connection is attempted from a local file (`file:///some/mqtt.html`) using MQTT.js to a WSS broker.
4. When the browser accesses the HTML page via **HTTPS**, a popup appears asking the user to choose a client certificate or not send one.

   * This happens because the server is configured with `verify_peer` (but not mandatory) and the OS has at least one client certificate installed.
   * The browser gives the choice to send a certificate or not. In this scenario, **not sending a certificate** is the correct choice.

However, if the first access is directly via **wss\://** (not HTTPS), the choice popup cannot appear:

* Browsers do not trigger the certificate selection dialog for JavaScript-initiated WSS connections.
* As a result, the TLS handshake fails.

If the user first accesses the page via **https\://**, the certificate selection popup appears, and subsequent **wss\://** connections succeed because the handshake can complete.

Initially, this behavior seemed surprising to me.
However, in typical use, **wss\://** connections originate from content already served via HTTPS on the same host. Since HTTPS access occurs before WSS, the user has the opportunity to choose a certificate (or not send one).

In my test case, I accessed WSS directly from a local `file://`, which caused this issue.
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.46%. Comparing base (3fc09ad) to head (22a9505).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #433      +/-   ##
==========================================
- Coverage   96.51%   96.46%   -0.06%     
==========================================
  Files         182      182              
  Lines       10307    10313       +6     
==========================================
  Hits         9948     9948              
- Misses        359      365       +6     

see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@redboltz redboltz merged commit 4139a56 into main Sep 24, 2025
12 checks passed
@redboltz redboltz deleted the verify_peer branch September 24, 2025 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants