From c26be980c50b08015e0b85c3f3f5695eea080a4d Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 19 Apr 2023 02:26:51 -0400 Subject: [PATCH] *Refactor loading of ssl --- src/modules/ssl.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/modules/ssl.ts b/src/modules/ssl.ts index 1438640..8066b8a 100644 --- a/src/modules/ssl.ts +++ b/src/modules/ssl.ts @@ -62,11 +62,21 @@ export class SSLManager { } private _maybeUpdateContext() { - if (b4a.isBuffer(this._cert) && b4a.isBuffer(this._key)) { - this._context = tls.createSecureContext({ - cert: this._cert, + const valid = (value: any) => + b4a.isBuffer(value) || typeof value === "string" || Array.isArray(value); + + if (valid(this._cert) && valid(this._key)) { + const opts: tls.SecureContextOptions = { key: this._key, - }); + }; + + if (Array.isArray(this._cert)) { + opts.ca = this._cert.slice(1); + opts.cert = this._cert[0]; + } else { + opts.cert = this._cert; + } + this._context = tls.createSecureContext(opts); } } }