Skip to content

Commit fa3d6be

Browse files
committed
tls: use internal API instead of crypto module
PR-URL: #22501 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
1 parent a081b43 commit fa3d6be

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/_tls_common.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const {
3131

3232
const { SSL_OP_CIPHER_SERVER_PREFERENCE } = process.binding('constants').crypto;
3333

34-
// Lazily loaded
35-
var crypto = null;
34+
// Lazily loaded from internal/crypto/util.
35+
let toBuf = null;
3636

3737
const { internalBinding } = require('internal/bootstrap/loaders');
3838
const { SecureContext: NativeSecureContext } = internalBinding('crypto');
@@ -178,26 +178,26 @@ exports.createSecureContext = function createSecureContext(options, context) {
178178
}
179179

180180
if (options.pfx) {
181-
if (!crypto)
182-
crypto = require('crypto');
181+
if (!toBuf)
182+
toBuf = require('internal/crypto/util').toBuf;
183183

184184
if (Array.isArray(options.pfx)) {
185185
for (i = 0; i < options.pfx.length; i++) {
186186
const pfx = options.pfx[i];
187187
const raw = pfx.buf ? pfx.buf : pfx;
188-
const buf = crypto._toBuf(raw);
188+
const buf = toBuf(raw);
189189
const passphrase = pfx.passphrase || options.passphrase;
190190
if (passphrase) {
191-
c.context.loadPKCS12(buf, crypto._toBuf(passphrase));
191+
c.context.loadPKCS12(buf, toBuf(passphrase));
192192
} else {
193193
c.context.loadPKCS12(buf);
194194
}
195195
}
196196
} else {
197-
const buf = crypto._toBuf(options.pfx);
197+
const buf = toBuf(options.pfx);
198198
const passphrase = options.passphrase;
199199
if (passphrase) {
200-
c.context.loadPKCS12(buf, crypto._toBuf(passphrase));
200+
c.context.loadPKCS12(buf, toBuf(passphrase));
201201
} else {
202202
c.context.loadPKCS12(buf);
203203
}

0 commit comments

Comments
 (0)