Fixed https.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3734 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -468,38 +468,37 @@ 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) {
|
||||
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 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(await File.readFile(kPrivateKeyPath));
|
||||
var certificate = new TextDecoder("ASCII").decode(await File.readFile(kCertificatePath));
|
||||
|
||||
tls.context = new TlsContext();
|
||||
tls.context.setPrivateKey(privateKey);
|
||||
tls.context.setCertificate(certificate);
|
||||
tls.certStat = stat[0];
|
||||
tls.keyStat = stat[1];
|
||||
}
|
||||
tls.context = new TlsContext();
|
||||
tls.context.setPrivateKey(privateKey);
|
||||
tls.context.setCertificate(certificate);
|
||||
tls.certStat = stat[0];
|
||||
tls.keyStat = stat[1];
|
||||
}
|
||||
|
||||
return client.startTls(tls.context);
|
||||
}).catch(function(error) {
|
||||
logError("[" + new Date() + "] [" + client.peerName + "] " + error);
|
||||
});
|
||||
});
|
||||
handleConnection(client);
|
||||
return client.startTls(tls.context);
|
||||
} catch (error) {
|
||||
logError("[" + new Date() + "] [" + client.peerName + "] " + error);
|
||||
}
|
||||
});
|
||||
}).catch(function(error) {
|
||||
logError("[" + new Date() + "] bind error " + error);
|
||||
|
Reference in New Issue
Block a user