diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml new file mode 100644 index 0000000..82d63bf --- /dev/null +++ b/.github/workflows/action.yml @@ -0,0 +1,13 @@ +on: push +name: Main Workflow +jobs: + ubuntu: + name: Test on Ubuntu + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v2 + with: + node-version: '16' + - run: npm install + - run: npm test diff --git a/README.md b/README.md index 42e8283..18856bc 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,14 @@ certFinder.findCABundle(); // /etc/ssl/certs/ca-certificates.crt ``` +## Supported Platforms + + 'aix', 'freebsd', 'linux', 'openbsd', 'sunos' + +## Unsupported Platforms + + 'ios', 'darwin', 'win32' + ## License Licensed under the [MIT License](https://nemo.mit-license.org/). See LICENSE file for details. diff --git a/index.js b/index.js index 8a2743b..eaf1c6e 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ let accessSyncBool = function(path, mode = fs.constants.R_OK) { }; let findCABundle = () => - PATHS.FILES.find( + PATHS[process.platform].files.find( e => fs.existsSync(e) && fs.existsSync(fs.realpathSync(e)) && @@ -20,7 +20,7 @@ let findCABundle = () => ); let findCAPath = () => - PATHS.DIRECTORIES.find( + PATHS[process.platform].directories.find( e => fs.existsSync(e) && fs.existsSync(fs.realpathSync(e)) && diff --git a/paths.js b/paths.js index bb2d325..983a4ff 100644 --- a/paths.js +++ b/paths.js @@ -1,44 +1,52 @@ -// Based on https://golang.org/src/crypto/x509/root_linux.go - -const FILES = [ - // Debian/Ubuntu/Gentoo etc. - "/etc/ssl/certs/ca-certificates.crt", - - // Fedora/RHEL 6 - "/etc/pki/tls/certs/ca-bundle.crt", - - // OpenSUSE - "/etc/ssl/ca-bundle.pem", - - // OpenELEC - "/etc/pki/tls/cacert.pem", - - // CentOS/RHEL 7 - "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" -]; - -// Based on https://golang.org/src/crypto/x509/root_unix.go -const DIRECTORIES = [ - // SLES10/SLES11, https://golang.org/issue/12139 - "/etc/ssl/certs", - - // Android - "/system/etc/security/cacerts", - - // FreeBSD - "/usr/local/share/certs", - - // Fedora/RHEL - "/etc/pki/tls/certs", - - // NetBSD - "/etc/openssl/certs", - - // AIX - "/var/ssl/certs" -]; - module.exports = { - FILES: FILES, - DIRECTORIES: DIRECTORIES -}; + // https://golang.org/src/crypto/x509/root_aix.go + aix: { + files: ["/var/ssl/certs/ca-bundle.crt"], + directories: ["/var/ssl/certs"], + }, + android: { + files: [], + directories: ["/system/etc/security/cacerts"], + }, + freebsd: { + files: [ + "/usr/local/etc/ssl/cert.pem", // FreeBSD + "/usr/local/share/certs/ca-root-nss.crt", // DragonFly + "/etc/openssl/certs/ca-certificates.crt", // NetBSD + ], + directories: [ + "/usr/local/share/certs", // FreeBSD + "/etc/openssl/certs", // NetBSD + ], + }, + linux: { + files: [ + "/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo/Joyent SmartOS etc + "/etc/pki/tls/certs/ca-bundle.crt", // Fedora/RHEL 6 + "/etc/ssl/ca-bundle.pem", // OpenSUSE + "/etc/pki/tls/cacert.pem", // OpenELEC + "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", // CentOS/RHEL 7 + "/etc/ssl/cert.pem", // Alpine Linux + ], + directories: [ + "/etc/ssl/certs", // SLES10/SLES11, https://golang.org/issue/12139 + "/etc/pki/tls/certs", // Fedora/RHEL + ], + }, + openbsd: { + files: [ + "/etc/ssl/cert.pem", // OpenBSD + "/usr/local/share/certs/ca-root-nss.crt", // DragonFly + "/etc/openssl/certs/ca-certificates.crt", // NetBSD + ], + directories: [], + }, + sunos: { + files: [ + "/etc/certs/ca-certificates.crt", // Solaris 11.2+ + "/etc/ssl/certs/ca-certificates.crt", // Joyent SmartOS + "/etc/ssl/cacert.pem", // OmniOS + ], + directories: ["/etc/certs/CA"], + }, +}; \ No newline at end of file