eclipsesource / eclipsesource/tabris-js
Trusting certificates does not work anymore
- Dominant language
- JavaScript
- Stars
- 1.4k
- Forks
- 171
- PR merge metrics
- No merged PRs in 30d
Description
### Problem description
Despite using `app.trustedCertificates` to configure a self-signed certificate as trusted, `fetch()` throws an error when sending a REST request to a server using that certificate:
```
TypeError: The operation couldn’t be completed. (NSURLErrorDomain error -1012.)
at ./src/app.js:10:8
```
### Environment
- Tabris.js version: 3.9.0
- Device: Simulator
- OS: iOS 16.4
### Code snippet
1. Create a self-signed certificate for the domain name `foo.bar`:
```sh
openssl genpkey -algorithm RSA -out self-signed-key.pem
# In the next step, configure the common name to be `foo.bar`
openssl req -new -x509 -days 365 -key self-signed-key.pem -out self-signed-cert.pem
openssl x509 -outform der -in self-signed-cert.pem -out self-signed-cert.der
```
2. Map the domain name `foo.bar` to `127.0.0.1`:
```
echo "127.0.0.1 foo.bar" | sudo tee -a /etc/hosts
```
2. Create a sample server using that self-signed certificate (a [Deno](https://deno.com/)-based service used in the example):
```ts
Deno.serve(
{
port: 8080,
cert: Deno.readTextFileSync("./self-signed-cert.pem"),
key: Deno.readTextFileSync("./self-signed-key.pem"),
},
() => {
const body = JSON.stringify({ message: "OK" });
return new Response(body, {
status: 200,
headers: { "content-type": "application/json; charset=utf-8" }
});
}
);
```
3. In a Tabris.js app, configure the self-signed certificate to be trusted and send a request to the server:
```js
const { app } = require("tabris");
(async () => {
const response = await fetch("./self-signed-cert.der");
if (!response.ok) throw new Error("cannot fetch cert");
app.trustedCertificates = [await response.arrayBuffer()];
fetch("https://foo.bar:8080")
.then((r) => r.json())
.then((r) => {
console.log(r);
})
.catch((e) => {
console.error(e);
});
})().catch(console.error);
```
Contributor guide
Assessment
This issue has not been assessed yet.