forked from cory/tildefriends
Fixed https.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3734 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
24cf18651a
commit
c02a3d3659
20
core/core.js
20
core/core.js
@ -380,6 +380,17 @@ async function perfettoHandler(request, response, uri) {
|
||||
}
|
||||
}
|
||||
|
||||
async function wellKnownHandler(request, response, path) {
|
||||
var data = await File.readFile("data/global/.well-known/" + path);
|
||||
if (data) {
|
||||
response.writeHead(200, {"Content-Type": "text/plain", "Content-Length": data.length});
|
||||
response.end(data);
|
||||
} else {
|
||||
response.writeHead(404, {"Content-Type": "text/plain", "Content-Length": "File not found".length});
|
||||
response.end("File not found");
|
||||
}
|
||||
}
|
||||
|
||||
function sendData(response, data, type) {
|
||||
if (data) {
|
||||
if (startsWithBytes(data, [0xff, 0xd8, 0xff, 0xdb]) ||
|
||||
@ -555,14 +566,7 @@ loadSettings().then(function() {
|
||||
} else if (request.uri == "/robots.txt") {
|
||||
return blobHandler(request, response, null, request.uri);
|
||||
} else if ((match = /^\/.well-known\/(.*)/.exec(request.uri)) && request.uri.indexOf("..") == -1) {
|
||||
var data = File.readFile("data/global/.well-known/" + match[1]);
|
||||
if (data) {
|
||||
response.writeHead(200, {"Content-Type": "text/plain", "Content-Length": data.length});
|
||||
response.end(data);
|
||||
} else {
|
||||
response.writeHead(404, {"Content-Type": "text/plain", "Content-Length": "File not found".length});
|
||||
response.end("File not found");
|
||||
}
|
||||
return wellKnownHandler(request, response, match[1]);
|
||||
} else {
|
||||
var data = "File not found.";
|
||||
response.writeHead(404, {"Content-Type": "text/plain; charset=utf-8", "Content-Length": data.length.toString()});
|
||||
|
@ -468,25 +468,24 @@ if (tildefriends.https_port) {
|
||||
var tls = {};
|
||||
var secureSocket = new Socket();
|
||||
secureSocket.bind(kHost, tildefriends.https_port).then(function() {
|
||||
return secureSocket.listen(kBacklog, function() {
|
||||
return secureSocket.accept().then(function(client) {
|
||||
handleConnection(client);
|
||||
|
||||
return secureSocket.listen(kBacklog, async function() {
|
||||
try {
|
||||
var client = await secureSocket.accept();
|
||||
const kCertificatePath = "data/httpd/certificate.pem";
|
||||
const kPrivateKeyPath = "data/httpd/privatekey.pem";
|
||||
|
||||
return Promise.all([
|
||||
File.stat(kCertificatePath),
|
||||
File.stat(kPrivateKeyPath),
|
||||
]).then(function(stat) {
|
||||
var stat = await Promise.all([
|
||||
await File.stat(kCertificatePath),
|
||||
await File.stat(kPrivateKeyPath),
|
||||
]);
|
||||
if (!tls.context ||
|
||||
tls.certStat.mtime != stat[0].mtime ||
|
||||
tls.certStat.size != stat[0].size ||
|
||||
tls.keyStat.mtime != stat[1].mtime ||
|
||||
tls.keyStat.size != stat[1].size) {
|
||||
print("Reloading " + kCertificatePath + " and " + kPrivateKeyPath);
|
||||
var privateKey = new TextDecoder("ASCII").decode(File.readFile(kPrivateKeyPath));
|
||||
var certificate = new TextDecoder("ASCII").decode(File.readFile(kCertificatePath));
|
||||
var privateKey = new TextDecoder("ASCII").decode(await File.readFile(kPrivateKeyPath));
|
||||
var certificate = new TextDecoder("ASCII").decode(await File.readFile(kCertificatePath));
|
||||
|
||||
tls.context = new TlsContext();
|
||||
tls.context.setPrivateKey(privateKey);
|
||||
@ -495,11 +494,11 @@ if (tildefriends.https_port) {
|
||||
tls.keyStat = stat[1];
|
||||
}
|
||||
|
||||
handleConnection(client);
|
||||
return client.startTls(tls.context);
|
||||
}).catch(function(error) {
|
||||
} catch (error) {
|
||||
logError("[" + new Date() + "] [" + client.peerName + "] " + error);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}).catch(function(error) {
|
||||
logError("[" + new Date() + "] bind error " + error);
|
||||
|
@ -376,6 +376,7 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||
.count = 1,
|
||||
.script = "core/core.js",
|
||||
.http_port = 12345,
|
||||
.https_port = 12346,
|
||||
.ssb_port = 8009,
|
||||
.db_path = "db.sqlite",
|
||||
.secrets_path = "/.config/tildefriends/secret",
|
||||
|
Loading…
Reference in New Issue
Block a user