-
Notifications
You must be signed in to change notification settings - Fork 13.3k
"Chain could not be linked to a trust anchor" using mongoDB stitch #6209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
FWIW the URL for the eu-west-1 stitch can't negotiate a proper connection with Firefox, either, but that might just be some regional restrictions in place so I can't get to it from US-West. Fingerprints don't actually check chains, they just take the SHA fingerprint of the server and the one you send in and compare. I imagine there are load balancers in between you and the service, so it might be that you're getting the cert for the load balancer which is not always going to be the same as you bounce around. A quick OpenSSL run on my own server seems to match your fingerprint, though. The other thing that could be happening is that, technically, the SHA1 fingerprint is taken on a specially formatted ASN.1 document (since reordering elements could cause a different fingerprint). BearSSL doesn't support reordering elements inside the ASN.1 since it could require 10s of KB of RAM and breaks the very cool stream setup they have. Since you're tying yourself to a specific cert with specific pub/private key already with the fingerprint, I would suggest just extracting the public key from the cert and using it as a KnownKey. You're just as secure as before, because you can't negotiate with anyone who doesn't have that server's private key, anyway. |
In fact, I was wondering about the solution in the last lines of your reply. |
Fingerprint doesn't check anything in the certificate, only that the final hash of its contents matches what is expected. So SNI is ignored, expiry dates, etc. Using knownkey is simple enough and should get you what you want without doing a full validation. |
I guess your reply closes the issue. |
My guess was wrong. I have tried to use the pubkey as suggested, but the problem is still there. From a reply on the thread I opened on MongoDB community, your words, and a number of posts that I found googling around, my new guess is that the problem is that SNI thing, which is not implemented in BearSSL. Broadly speaking, it corresponds to the "load balancer" situation you mentioned. In the case of MongoDB-Stitch, which is a serverless cloud provision, it is totally justified and, IMHO, unavoidable. From the other thread (https://jira.mongodb.org/browse/SUPPORT-2675, but you need to be registered to have access) I obtain the following reply to a direct answer: "Hi Augusto Ciuffoletti, we don't believe there is an issue as we require clients to support SNI such that the right certificate is served. I believe this would be an issue on the Arduino side." Is there a way out? |
BearSSL supports SNI https://bearssl.org/gitweb/?p=BearSSL;a=blob;f=inc/bearssl_ssl.h;h=f2ecc3782828bb54a18e625b72db46aefb061c5b;hb=HEAD#l2814 which means the connect(host, port) host needs to correspond to the hostname that SNI will present. We call the API with the hostname you used in your connect() call at
|
@d-a-v, was there a way to get packet dumps from the 8266? This would be very simple to diagnosis using Wireshark or even plain hex dumps of the SSL handshake. |
Use a (Linux) PC as WiFi hotspot and use tcpdump on the wifi iface?
Il giorno ven 28 giu 2019 alle ore 22:38 Earle F. Philhower, III <
[email protected]> ha scritto:
… @d-a-v <https://github.com/d-a-v>, was there a way to get packet dumps
from the 8266? This would be very simple to diagnosis using Wireshark or
even plain hex dumps of the SSL handshake.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#6209?email_source=notifications&email_token=AGEP724LVKZNTCYU65XN363P4ZZELA5CNFSM4HZB7N22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY3DM6Y#issuecomment-506869371>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGEP722HDK64WJZBX5RXTR3P4ZZELANCNFSM4HZB7N2Q>
.
--
Augusto Ciuffoletti
Dipartimento di Informatica
Università di Pisa
56100 - Pisa (Italy)
|
Use a (Linux) PC as WiFi hotspot and use tcpdump on the wifi iface?
Yes, or this from inside the esp if you have a closed firmware router:
https://github.com/d-a-v/EspGoodies/tree/master/examples/netdump (check
also the tcpdump example)
Or @hreinkte fork on my repository
|
@AugustoCiuffoletti , any luck yet? Again, since it's against your private shard I can't reproduce anything locally so without packet traces I don't think we're going to be able to get very far here... |
Sorry, but it is not a priority for me right now, as I prefer to finish the
project, which aims at research, not production. I'll try to provide you a
trace and details during next week, the task is in my todo list now.
Il giorno sab 6 lug 2019 alle ore 06:22 Earle F. Philhower, III <
[email protected]> ha scritto:
… @AugustoCiuffoletti <https://github.com/AugustoCiuffoletti> , any luck
yet? Again, since it's against your private shard I can't reproduce
anything locally so without packet traces I don't think we're going to be
able to get very far here...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6209?email_source=notifications&email_token=AGEP727UXO23ZHFRHJITA43P6AMWLA5CNFSM4HZB7N22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZKSEWA#issuecomment-508895832>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGEP727XEXF23QSLHYVLIPLP6AMWLANCNFSM4HZB7N2Q>
.
--
Augusto Ciuffoletti
Dipartimento di Informatica
Università di Pisa
56100 - Pisa (Italy)
|
Dear @earle and others, I've collected the trace for the fingerprint case, which is the initial issue in this thread. This is the story, useful to reproduce:
Notes: I pasted in the "dump" function from @d-a-v examples and added the definition of the phy_capture hook, moved the WiFi credential in a secret.h file, changed the definition of host, url and fingerprint.
while using the fingerprint:
I leave the thread open, right? Thank you for your help, Augusto |
I added some debugging info to the FP mismatch case, will do a PR later, but the problem is simply the FP doesn't match:
A binary dump of the certificate shows it's correct (no SNI issue), and that the SHA1 over it is the received one above.
If I take the SHA1 over the DER form of the cert, it matches what BearSSL calculated, so BSSL is doing the math right, as far as it knows. But, OpenSSL calculates the FP you're giving, so there's obviously some difference and OpenSSL is normalizing/dropping fields before doing the SHA1. As I said before, BearSSL code streams the cert and doesn't do things like reordering or normalizing in order to calculate a FP. It just doesn't have the memory. You could either use the BSSL calculated FP or use the cert itself and do full X509 validation to connect securely. |
This explains the issue you're hitting: |
Basic Infos
Platform
Settings in IDE
I am trying to interface a Wemos with a mongoDB stitch using HTTPS with fingerprint authentication, and I meet the problem in the title. I am successfully running a similar interface with mLab, another database service from the same provider.
To reproduce my problem, start from the HTTPSRequest example in ESP8266WiFi, and replace
with
Adding the following lines just before the "connection failed" printout around line 60 we have some debugging info. The output on Serial is the following:
Replacing the ''fingerprint()'' method with ''setInsecure()'' everything works fine with no errors.
Inspecting the SSL protocol with
when is eu-west-1.aws.webhooks.mongodb-stitch.com I obtain (only the chain"):
With the mLab server api.mlab.com (which does not exhibit the problem) the chain is similar:
My suspect is that either the library or the certificate are not exactly compliant. I started asking you.
Thank you for your attention.
The text was updated successfully, but these errors were encountered: