*Refactor loading of ssl

This commit is contained in:
Derrick Hammer 2023-04-19 02:26:51 -04:00
parent d5a4956be7
commit c26be980c5
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 4 deletions

View File

@ -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);
}
}
}