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

[BUG] HTTPS API request not supported - net::ERR_CERT_AUTHORITY_INVALID #102

Open
LBF38 opened this issue Aug 18, 2023 · 8 comments
Open
Labels
bug Something isn't working important Important issues that need attention

Comments

@LBF38
Copy link
Owner

LBF38 commented Aug 18, 2023

Describe the bug

Can't make an HTTPS API request to the Syncthing REST API. It throws an error.
Same issue on mobile too.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the plugin's settings tab.
  2. Change the Syncthing base URL to use the https protocol.
  3. Click on "Check API Status"
  4. See error

Expected behavior

Should display "Syncthing Ping : Pong" to correctly check the API status.

Screenshots

On Desktop :
image

On Mobile :
image

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Brave
  • Version:

Smartphone (please complete the following information):

  • Device: Android
  • OS:
  • Browser:
  • Version:

Additional context

Need to make some researches on HTTPS requests.

@LBF38 LBF38 added bug Something isn't working help wanted Extra attention is needed important Important issues that need attention labels Aug 18, 2023
@LBF38
Copy link
Owner Author

LBF38 commented Aug 22, 2023

Link to the open topic for this issue :

@LBF38
Copy link
Owner Author

LBF38 commented Aug 28, 2023

Here is a SO response to add the CA to a fetch request : https://stackoverflow.com/questions/31861109/tls-what-exactly-does-rejectunauthorized-mean-for-me

But the issue is that it is possible in a nodejs environment, thus not on mobile.

@LBF38
Copy link
Owner Author

LBF38 commented Sep 1, 2023

As far as I know, here are some solutions/ideas I have found to resolve, in some way, the HTTPS issue :

  1. Adding the self-signed certificate to the trusted certificates store : It should also work on mobile, even thought the procedure to make it work is longer to achieve and tougher. Might be the best solution.
  2. Ignore the certificate validation by using the rejectUnauthorized: false header inside the request : This has been mentioned in the NodeJS documentation. Therefore, I need to test it on mobile to see if it would work.
  3. Disabling the HTTPS : This one is the simplest but less secure of all. It will work on mobile while exposing sensitive data if not on a trusted network. Therefore, it is suboptimal but at least it works.
  4. Change the certificate to a Let's Encrypt certificate (or other one) : This one would resolve the issue of the untrusted certificate. But it needs to be modified inside the Syncthing configuration, thus it needs more research.

@LBF38
Copy link
Owner Author

LBF38 commented Sep 1, 2023

@LBF38
Copy link
Owner Author

LBF38 commented Sep 19, 2023

From the Syncthing Forum answers :
https://letsencrypt.org/docs/certificates-for-localhost/

openssl req -x509 -out localhost.crt -keyout localhost.key \ 
-newkey rsa:2048 -nodes -sha256 \ 
-subj '/CN=localhost' -extensions EXT -config <( \ 
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth") 

@LBF38
Copy link
Owner Author

LBF38 commented Oct 2, 2023

Problem solved on PC / Desktop !!! 🎉
Here are the steps to follow:

  1. Stop Syncthing
  2. Go to the Syncthing local config directory : <your user path>\AppData\Local\Syncthing
  3. Generate a private key
openssl genrsa -out https-key.pem 2048
  1. Generate the certificate for localhost :
openssl req -new -x509 -key https-key.pem -out https-cert.pem -days 1095 -subj "/CN=localhost/O=Syncthing/OU=Syncthing Automatically Generated" -addext "subjectAltName = DNS:localhost"

Note

The -days 1095 is required for Syncthing to not generate another certificate and erase the one we generate. It seems that the system automatically regenerates the HTTPS certificate to still be valid.
1095 days = 3 years.

  1. Generate a https-cert.cer from the generated certificate :
openssl x509 -in https-cert.pem -outform der -out https-cert.cer
  1. Add your newly generated certificate https-cert.cer to your PC's certificate root store and make it trustworthy.
  2. Restart Syncthing
  3. Go to https://localhost:8384, you should see a valid, trusted certificate !
  4. Now, in Obsidian, in the Syncthing Integration plugin's settings, test the API Status, you should get Syncthing ping: pong notification !
  5. Enjoy ! Full-HTTPS connection !
Screenshot of the configuration w/ HTTPS connection

image

Now, I need to test this on mobile to see if it also works !!

@LBF38 LBF38 pinned this issue Oct 2, 2023
@LBF38
Copy link
Owner Author

LBF38 commented Jan 21, 2024

This issue should now be solved thanks to this PR (syncthing/syncthing-android#2013).
The import/export config feature is available in both Syncthing Android app (Official and Fork version).

The setup needs to be tested before closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working important Important issues that need attention
Projects
Status: 🏗 In progress
Development

No branches or pull requests

1 participant