Skip to content
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

mbedtls_x509_crt_parse_path() fails to load the ca-bundle on Fedora #3005

Closed
jp-bennett opened this issue Jan 23, 2020 · 5 comments · Fixed by #3008
Closed

mbedtls_x509_crt_parse_path() fails to load the ca-bundle on Fedora #3005

jp-bennett opened this issue Jan 23, 2020 · 5 comments · Fixed by #3008
Labels
enhancement help-wanted This issue is not being actively worked on, but PRs welcome.

Comments

@jp-bennett
Copy link
Contributor

Type: Bug
Possibly related to #2409. I've tracked down an issue in OBS on Fedora where RTMPS streams fail to authenticate. See: https://obsproject.com/forum/threads/unable-to-live-stream-to-facebook-live-over-rtmps.102849/

The root issue is that on Fedora, the ca-bundle in /etc/ssl/certs/ is a symlink, and mbedtls_x509_crt_parse_path() explicitly skips loading anything that isn't a regular file.

https://github.com/ARMmbed/mbedtls/blob/ccdeb47cdf0f4f070c7d48d46e5e098f025c005b/library/x509_crt.c#L1616

Line 1616 seems to be the issue. I don't know of any security problems with allowing symlinked bundles, so perhaps it should read:
if( !( S_ISREG( sb.st_mode ) || S_IFLNK( sb.st_mode ) ) )

If that seems like a reasonable solution, I can submit a patch, or feel free to just make the change, as it's trivial.

@yanesca
Copy link
Contributor

yanesca commented Jan 24, 2020

Hi @jp-bennett

Yes, it looks like a reasonable solution to me. Thank you for offering your help, please submit a PR to address this issue, we will be happy to take it.

@yanesca yanesca added enhancement help-wanted This issue is not being actively worked on, but PRs welcome. labels Jan 24, 2020
jp-bennett added a commit to jp-bennett/mbedtls that referenced this issue Jan 24, 2020
When mbedtls_x509_crt_parse_path() checks each object in the supplied path, it only processes regular files. This change makes it also accept a symlink to a file. Fixes Mbed-TLS#3005.

This was observed to be a problem on Fedora/CentOS/RHEL systems, where the ca-bundle in the default location is actually a symlink.
@jp-bennett
Copy link
Contributor Author

@yanesca Submitted the PR. I may have noticed a related issue, also in mbedtls_x509_crt_parse_path()
There doesn't seem to be a check that valid certificates were loaded. If that function doesn't attempt to parse any files, it returns 0. So, call parse_path on an empty folder, and you get a success result. That doesn't seem to be intended. The Windows implementation, for instance, returns an IO error if the given path is empty. It seems like there should be a final check just before returning, that at least one valid certificate was loaded onto the chain.

@yanesca
Copy link
Contributor

yanesca commented Jan 27, 2020

Thank you very much for your contribution!

Indeed, that behaviour is not intended: the documentation of mbedtls_x509_crt_parse_path() function promises to load "one or more certificate files" and should return an error if it can't find any files at the given path.

Thank you for catching this! Could you please open a new issue for this matter?

Patater pushed a commit to Patater/mbedtls that referenced this issue Jan 28, 2020
When mbedtls_x509_crt_parse_path() checks each object in the supplied path, it only processes regular files. This change makes it also accept a symlink to a file. Fixes Mbed-TLS#3005.

This was observed to be a problem on Fedora/CentOS/RHEL systems, where the ca-bundle in the default location is actually a symlink.
Patater pushed a commit to Patater/mbedtls that referenced this issue Jan 28, 2020
When mbedtls_x509_crt_parse_path() checks each object in the supplied path, it only processes regular files. This change makes it also accept a symlink to a file. Fixes Mbed-TLS#3005.

This was observed to be a problem on Fedora/CentOS/RHEL systems, where the ca-bundle in the default location is actually a symlink.
@jp-bennett
Copy link
Contributor Author

@yanesca @Patater I just discovered that I was wrong. The changes I suggested can be reverted. stat() will never return S_IFLNK as the file type, as stat() explicitly follows symlinks. The bug was in OBS. A positive return value was considered a total failure.

Sorry for the useless noise.

@yanesca
Copy link
Contributor

yanesca commented Jan 31, 2020

@jp-bennett Thank you for reporting your findings!

I am reopening this issue as #3008 and its backports need reverting.

@yanesca yanesca reopened this Jan 31, 2020
yanesca added a commit to yanesca/mbedtls that referenced this issue Feb 4, 2020
…development-2.16"

This reverts commit 7550e85, reversing
changes made to d0c2575.

stat() will never return S_IFLNK as the file type, as stat()
explicitly follows symlinks.

Fixes Mbed-TLS#3005.
yanesca added a commit to yanesca/mbedtls that referenced this issue Feb 4, 2020
…development-2.7"

This reverts commit 130e136, reversing
changes made to 071b3e1.

stat() will never return S_IFLNK as the file type, as stat() explicitly
follows symlinks.

Fixes Mbed-TLS#3005.
@yanesca yanesca closed this as completed in 85de7a6 Feb 5, 2020
simonbutcher pushed a commit to simonbutcher/mbedtls that referenced this issue Mar 13, 2020
When mbedtls_x509_crt_parse_path() checks each object in the supplied path, it only processes regular files. This change makes it also accept a symlink to a file. Fixes Mbed-TLS#3005.

This was observed to be a problem on Fedora/CentOS/RHEL systems, where the ca-bundle in the default location is actually a symlink.
simonbutcher pushed a commit to simonbutcher/mbedtls that referenced this issue Mar 13, 2020
…development-2.16"

This reverts commit 7550e85, reversing
changes made to d0c2575.

stat() will never return S_IFLNK as the file type, as stat()
explicitly follows symlinks.

Fixes Mbed-TLS#3005.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help-wanted This issue is not being actively worked on, but PRs welcome.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants