@make-u-free/migi 0.2.9 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/tls.js +10 -8
package/package.json
CHANGED
package/src/tls.js
CHANGED
|
@@ -17,11 +17,13 @@ function scanDir(dir) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function findCA() {
|
|
20
|
-
// 優先順: 環境変数 → カレント.migi/ → ホーム.migi/
|
|
20
|
+
// 優先順: 環境変数 → カレント.migi/ → カレント直下 → ホーム.migi/ → ホーム直下
|
|
21
21
|
const candidates = [
|
|
22
22
|
process.env.NODE_EXTRA_CA_CERTS,
|
|
23
23
|
...scanDir(join(process.cwd(), '.migi')),
|
|
24
|
+
...scanDir(process.cwd()),
|
|
24
25
|
...scanDir(join(homedir(), '.migi')),
|
|
26
|
+
...scanDir(homedir()),
|
|
25
27
|
].filter(Boolean)
|
|
26
28
|
|
|
27
29
|
for (const p of candidates) {
|
|
@@ -39,13 +41,13 @@ if (caPath) {
|
|
|
39
41
|
|
|
40
42
|
// ① tls.createSecureContext パッチ
|
|
41
43
|
// Node 18+ built-in fetch (undici) を含む全TLS接続に効く
|
|
44
|
+
// デフォルトのCA(tls.rootCertificates)に追加する形にする
|
|
42
45
|
const _origCreate = tls.createSecureContext
|
|
43
46
|
tls.createSecureContext = (options = {}) => {
|
|
44
|
-
const
|
|
45
|
-
const existing = options.ca
|
|
47
|
+
const base = options.ca
|
|
46
48
|
? (Array.isArray(options.ca) ? options.ca : [options.ca])
|
|
47
|
-
:
|
|
48
|
-
return _origCreate({ ...options, ca: [...
|
|
49
|
+
: tls.rootCertificates // デフォルトCAを引き継ぐ
|
|
50
|
+
return _origCreate({ ...options, ca: [...base, caCert] })
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
// ② NODE_EXTRA_CA_CERTS(環境変数で起動する場合のフォールバック)
|
|
@@ -53,12 +55,12 @@ if (caPath) {
|
|
|
53
55
|
process.env.NODE_EXTRA_CA_CERTS = caPath
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
// ③ https.Agent
|
|
57
|
-
_httpsAgent = new https.Agent({ ca: caCert })
|
|
58
|
+
// ③ https.Agent: デフォルトCA + Zscaler CA を合わせて渡す
|
|
59
|
+
_httpsAgent = new https.Agent({ ca: [...tls.rootCertificates, caCert] })
|
|
58
60
|
|
|
59
61
|
console.log(` [TLS] CA loaded: ${caPath}`)
|
|
60
62
|
} else {
|
|
61
|
-
console.log(' [TLS] CA未設定 (社内エラー時は
|
|
63
|
+
console.log(' [TLS] CA未設定 (社内エラー時は ~/.migi/ か ~/ に .crt/.pem を配置)')
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
export const httpsAgent = _httpsAgent
|