+20
-6
@@ -24,3 +24,3 @@ "use strict"; | ||
| exports.convert = exports.Format = exports.addToGlobalAgent = exports.get = void 0; | ||
| var https_1 = require("https"); | ||
| var https = require("https"); | ||
| var tls_1 = require("tls"); | ||
@@ -33,2 +33,3 @@ var child_process_1 = require("child_process"); | ||
| var isMac = process.platform === 'darwin'; | ||
| var globalAgent = https.globalAgent; | ||
| var getParamsDefaults = { | ||
@@ -57,3 +58,3 @@ keychain: 'all', | ||
| } | ||
| if (params.keychain === 'all' || params.keychain === 'SystemRootCertificates') { | ||
| if (params.keychain === 'all' || params.keychain === 'current') { | ||
| var trusted = (0, child_process_1.spawnSync)('/usr/bin/security', args) | ||
@@ -85,3 +86,3 @@ .stdout.toString() | ||
| ; | ||
| var originalCA = https_1.globalAgent.options.ca; | ||
| var originalCA = globalAgent.options.ca; | ||
| var addToGlobalAgent = function (params) { | ||
@@ -99,5 +100,18 @@ if (params === void 0) { params = getParamsDefaults; } | ||
| } | ||
| get(__assign(__assign(__assign({}, getParamsDefaults), params), { format: formatter_1.Format.pem })) | ||
| .forEach(function (cert) { return cas.push(cert); }); | ||
| https_1.globalAgent.options.ca = cas; | ||
| get(__assign(__assign(__assign({}, getParamsDefaults), params), { format: formatter_1.Format.pem, excludeBundled: false })).forEach(function (cert) { return cas.push(cert); }); | ||
| //Sets the root certs in https.globalAgent | ||
| globalAgent.options.ca = cas; | ||
| //Modify the https.Agent constructor so that each new instance of the agent | ||
| //inherits the root certs from the global agent. | ||
| // @ts-ignore | ||
| https.Agent = (function (original) { | ||
| return function (options) { | ||
| var opts = typeof options !== 'undefined' ? __assign({}, options) : {}; | ||
| if (typeof opts.ca === 'undefined') { | ||
| opts.ca = cas; | ||
| } | ||
| return original.call(this, opts); | ||
| }; | ||
| })(https.Agent); | ||
| //Sets the root certs in undici. This is what the new native "fetch" uses. | ||
| (0, undici_1.setGlobalDispatcher)(new undici_1.Agent({ | ||
@@ -104,0 +118,0 @@ connect: { |
+1
-1
| { | ||
| "name": "mac-ca", | ||
| "version": "3.0.1", | ||
| "version": "3.1.0", | ||
| "description": "Get Mac OS Root certificates", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
+22
-13
@@ -27,2 +27,3 @@ # mac-ca | ||
| Install with | ||
| ``` | ||
@@ -33,6 +34,15 @@ npm install --save mac-ca | ||
| And then use it as follows: | ||
| ``` | ||
| require('mac-ca').addToGlobalAgent(); | ||
| //or | ||
| require('mac-ca/register'); | ||
| ``` | ||
| You can also do: | ||
| ``` | ||
| node --require mac-ca/register app.js | ||
| ``` | ||
| If called in other operative systems the method will just do nothing. | ||
@@ -47,7 +57,6 @@ | ||
| ```js | ||
| let ca = require('mac-ca') | ||
| let forge = require('node-forge') | ||
| let ca = require("mac-ca"); | ||
| let forge = require("node-forge"); | ||
| for (let pem of ca.get()) | ||
| console.log(pem) | ||
| for (let pem of ca.get()) console.log(pem); | ||
| ``` | ||
@@ -58,17 +67,17 @@ | ||
| ```js | ||
| ca.get({ format: ca.Format.der }) | ||
| ca.get({ format: ca.Format.der }); | ||
| ``` | ||
| Available values for `format` are: | ||
| | Constant | Value | Meaning | ||
| |---|---:|--- | ||
| der2.der | 0 | DER-format (binary, Node's [Buffer][]) | ||
| |der2.pem | 1 | PEM-format (text, Base64-encoded) | ||
| |der2.txt| 2 | PEM-format plus some info as text | ||
| |der2.asn1| 3 | ASN.1-parsed certificate | ||
| | * | * | Certificate in `node-forge` format (RSA only) | ||
| | Constant | Value | Meaning | | ||
| | --------- | ----: | --------------------------------------------- | | ||
| | der2.der | 0 | DER-format (binary, Node's [Buffer][]) | | ||
| | der2.pem | 1 | PEM-format (text, Base64-encoded) | | ||
| | der2.txt | 2 | PEM-format plus some info as text | | ||
| | der2.asn1 | 3 | ASN.1-parsed certificate | | ||
| | \* | \* | Certificate in `node-forge` format (RSA only) | | ||
| Other options for `get`: | ||
| - `keychain` (defaults to `all`): it could be `all`, `current` or `SystemRootCertificates`. | ||
@@ -75,0 +84,0 @@ - `unique` (defaults to `true`): exclude duplicated certificates found. |
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
14934
6.63%258
5.74%98
10.11%4
33.33%