Compare commits
No commits in common. "714da70209f95efcaa939405f062f6ea2eb930da" and "7f1dde272a43ad8f6a5409282b41b722e0997544" have entirely different histories.
714da70209
...
7f1dde272a
|
@ -26,7 +26,6 @@ switch (os.platform()) {
|
||||||
config.inject({
|
config.inject({
|
||||||
"core.confdir": configDir,
|
"core.confdir": configDir,
|
||||||
"core.port": 8080,
|
"core.port": 8080,
|
||||||
"core.apport": 80,
|
|
||||||
"core.loglevel": "info",
|
"core.loglevel": "info",
|
||||||
"core.plugindir": path.resolve(configDir, "..", "plugins"),
|
"core.plugindir": path.resolve(configDir, "..", "plugins"),
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,6 @@ import log from "../log.js";
|
||||||
import fastify from "fastify";
|
import fastify from "fastify";
|
||||||
import type { FastifyInstance } from "fastify";
|
import type { FastifyInstance } from "fastify";
|
||||||
import { getKeyPair } from "../lib/seed.js";
|
import { getKeyPair } from "../lib/seed.js";
|
||||||
import config from "../config";
|
|
||||||
|
|
||||||
let app: FastifyInstance;
|
let app: FastifyInstance;
|
||||||
|
|
||||||
|
@ -17,5 +16,5 @@ export async function start() {
|
||||||
res.send(Buffer.from(keyPair.publicKey).toString("hex"));
|
res.send(Buffer.from(keyPair.publicKey).toString("hex"));
|
||||||
});
|
});
|
||||||
|
|
||||||
await app.listen({ port: config.uint("core.appport"), host: "0.0.0.0" });
|
await app.listen({ port: 80, host: "0.0.0.0" });
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ export async function start() {
|
||||||
const dht = getSwarm();
|
const dht = getSwarm();
|
||||||
let sslOptions: boolean | http2.SecureServerOptions = false;
|
let sslOptions: boolean | http2.SecureServerOptions = false;
|
||||||
|
|
||||||
if (getSslManager().ready) {
|
if (getSslManager().enabled) {
|
||||||
sslOptions = {
|
sslOptions = {
|
||||||
SNICallback: () => getSslManager().context,
|
SNICallback: () => getSslManager().context,
|
||||||
} as http2.SecureServerOptions;
|
} as http2.SecureServerOptions;
|
||||||
|
|
|
@ -6,47 +6,37 @@ import config from "../config.js";
|
||||||
export type SSLManagerRenewHandler = (domain: string) => Promise<boolean>;
|
export type SSLManagerRenewHandler = (domain: string) => Promise<boolean>;
|
||||||
|
|
||||||
export class SSLManager {
|
export class SSLManager {
|
||||||
|
private _context?: tls.SecureContext;
|
||||||
private _key?: Buffer;
|
private _key?: Buffer;
|
||||||
|
private _cert?: Buffer;
|
||||||
private _domain: string;
|
private _domain: string;
|
||||||
|
private _renewHandler?: SSLManagerRenewHandler;
|
||||||
|
|
||||||
constructor(domain: string) {
|
constructor(domain: string) {
|
||||||
this._domain = domain;
|
this._domain = domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _context?: tls.SecureContext;
|
|
||||||
|
|
||||||
get context(): tls.SecureContext {
|
get context(): tls.SecureContext {
|
||||||
return this._context as tls.SecureContext;
|
return this._context as tls.SecureContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _cert?: Buffer;
|
|
||||||
|
|
||||||
set cert(cert: Buffer) {
|
|
||||||
this._cert = cert;
|
|
||||||
this._maybeUpdateContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
private _renewHandler?: SSLManagerRenewHandler;
|
|
||||||
|
|
||||||
get renewHandler(): SSLManagerRenewHandler {
|
|
||||||
return this._renewHandler as any;
|
|
||||||
}
|
|
||||||
|
|
||||||
set renewHandler(value: SSLManagerRenewHandler) {
|
|
||||||
this._renewHandler = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
set privateKey(key: Buffer) {
|
set privateKey(key: Buffer) {
|
||||||
this._key = key;
|
this._key = key;
|
||||||
this._maybeUpdateContext();
|
this._maybeUpdateContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
get enabled() {
|
set cert(cert: Buffer) {
|
||||||
return config.bool("core.ssl");
|
this._cert = cert;
|
||||||
|
this._maybeUpdateContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
get ready() {
|
private _maybeUpdateContext() {
|
||||||
return this.enabled && this.renewHandler;
|
if (b4a.isBuffer(this._cert) && b4a.isBuffer(this._key)) {
|
||||||
|
this._context = tls.createSecureContext({
|
||||||
|
cert: this._cert,
|
||||||
|
key: this._key,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async renew(): Promise<boolean> {
|
public async renew(): Promise<boolean> {
|
||||||
|
@ -60,13 +50,8 @@ export class SSLManager {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _maybeUpdateContext() {
|
get enabled() {
|
||||||
if (b4a.isBuffer(this._cert) && b4a.isBuffer(this._key)) {
|
return config.bool("core.ssl") && this._renewHandler;
|
||||||
this._context = tls.createSecureContext({
|
|
||||||
cert: this._cert,
|
|
||||||
key: this._key,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue