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

Fix CA certificates #189

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

throwaway96
Copy link
Member

The node binary contains a built-in set of trusted CA certificates that never gets updated. Therefore, Node.js services are stuck using whatever certs were bundled when that potentially ancient Node version was released.

Newer versions of Node.js (on webOS 5+) support the --use-openssl-ca option, which makes node use /etc/ssl/certs instead of its own bundle—but that doesn't help us on older versions. Indeed, there doesn't seem to be a clean way to fix this globally on Node 0.10.x and 0.12.x. So, I ended up creating a wrapper around fetch() that controls what certificates it trusts.

All PEM certs in <service dir>/certs will be treated as trusted. I have included the Mozilla CA cert bundle from curl, but users can also add additional certs. If people don't think that's useful, I could simplify the code by just loading a single file (which users could still modify). We could also theoretically just embed the certs in a JS file and avoid the "parsing" part altogether, but that would significantly reduce flexibility.

While testing this on webOS 1, I was able to download and install Kodi and apps hosted on GitHub. It could use more testing on other webOS versions. It's not perfect, but I'm tired. And I want to get a release out this year.

@throwaway96 throwaway96 added the bug Something isn't working label Jun 10, 2024
@throwaway96 throwaway96 added this to the 0.6.4 milestone Jun 10, 2024
services/fetch-wrapper.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,147 @@
/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider your repo as a module.

{
  "dependencies": {
    /* ... */,
    "node-load-cert-dir": "github:throwaway96/node-load-cert-dir"
  }
}

see https://stackoverflow.com/a/45156653.

Copy link
Member Author

@throwaway96 throwaway96 Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think the separate module is cleaner? There are advantages, I guess...

Note: I used a module for v0.6.4-test21; see 5c19c0f. (That was before I switched to the Mozilla CA cert bundle.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do it this way, it should be pinned to a specific commit. Part of me feels like it's better off just living in this repo, but it could be useful to other WebOS apps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think the separate module is cleaner? There are advantages, I guess...

well, if you want to make changes, then you need to manually keep the repository and module in sync.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do it this way, it should be pinned to a specific commit. Part of me feels like it's better off just living in this repo, but it could be useful to other WebOS apps.

you can also use tags. latest is quite suitable. ;P

This should work on all webOS versions. It loads certificates from the
Mozilla CA cert bundle. Users may add additional certs by placing
PEM-encoded files in the "certs" directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants