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

Trusting certificates does not work anymore #2272

Open
cpetrov opened this issue Sep 6, 2023 · 0 comments
Open

Trusting certificates does not work anymore #2272

cpetrov opened this issue Sep 6, 2023 · 0 comments

Comments

@cpetrov
Copy link
Member

cpetrov commented Sep 6, 2023

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:
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
  1. Map the domain name foo.bar to 127.0.0.1:
echo "127.0.0.1 foo.bar" | sudo tee -a /etc/hosts
  1. Create a sample server using that self-signed certificate (a Deno-based service used in the example):
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" }
    });
  }
);
  1. In a Tabris.js app, configure the self-signed certificate to be trusted and send a request to the server:
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant