tauri: [feat] ignore ssl certificate errors

Describe the problem

My app lets users connect to self-hosted services that often use self-signed or otherwise untrusted ssl certificates. I cannot access these services with tauri because of certificate errors.

Describe the solution you’d like

Ideal solution would be a prompt that lets users chose to trust the certificate. Another way would be how electron handles it, you can hook to a certificate-error event and ignore the errors, something like this:

// SSL/TSL: this is the self signed certificate support
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
    // On certificate error we disable default behaviour (stop loading the page)
    // and we then say "it is all fine - true" to the callback
    event.preventDefault();
    callback(true);
});

source

Alternatives considered

Even a command line flag like chromiums --ignore-certificate-errors would be helpful.

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 11
  • Comments: 16 (5 by maintainers)

Commits related to this issue

Most upvoted comments

That is one of the disable-security requests we get oftenly but aren’t planning on implementing anytime soon. Maybe we reconsider when we have more control over the webview.

Yea i get that, no worries 😃 Just for future readers, the idea proposed by @JonasKruckenberg works as expected. Thanks!

Can you please share the example code?

Yea i get that, no worries 😃 Just for future readers, the idea proposed by @JonasKruckenberg works as expected. Thanks!

@realtebo Just to be sure, are you really talking about http or do you mean https? For http certificates should not matter, no?

If it’s http, you’re using tauri v1, and you’re dealing with mixed-content errors (windows only) then try this setting https://v1.tauri.app/v1/api/config/#securityconfig.dangeroususehttpscheme - if not then we’ll need more info.

Under the hood, chromium allows flag to disable verification of certificates and also to allow fetching http resoureces.

We are in the main and vital need to connect to a local odata provider using http and we are stalled

Maybe the http client used in tauri is attohttpc and reqwest. https://github.com/tauri-apps/tauri/blob/dev/core/tauri/src/api/http.rs#L136 And .danger_accept_invalid_certs(true) can use to bypass attohttpc/reqwest tls verfification. https://github.com/sbstp/attohttpc/blob/3fe9967ee83258c8a5012736f07c8111e642ee69/tests/test_invalid_certs.rs#L12-L26 seanmonstar/reqwest#182 (comment) seanmonstar/reqwest#1210 (comment)

have you tried this

Windows 10 + tauri 1.3.0 I have already tried and it works! My Steps:

  • Modify tauri’s http.rs in .cargo (C:/Users/**/.cargo/registry/src/**/tauri-1.3.0/src/api/http.rs), add one line just under line:136
// line:136
let mut request_builder = attohttpc::RequestBuilder::try_new(method, &request.url)?;
// after change
let mut request_builder = attohttpc::RequestBuilder::try_new(method, &request.url)?;
request_builder = request_builder.danger_accept_invalid_certs(true);
  • Delete target/* in your project to recompile changes
  • ReBuild your project

Finally you will find that you can use ClientBuilder and HttpRequestBuilder to access https apis under a self-signed certificate.

You got that right yeah! You can write some nicer JS abstraction on top of invoke that replicates the same interface fetch has, so you wouldn’t even have to change your current code much