Skip to content

Commit

Permalink
Add HTTPS support with command line switches
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadoum committed Aug 9, 2023
1 parent 2f389fc commit 00b112f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import vibe.core.core;
import vibe.http.websockets;
import vibe.http.server;
import vibe.http.router;
import vibe.stream.tls;
import vibe.web.web;

import slf4d;
Expand Down Expand Up @@ -52,13 +53,24 @@ int main(string[] args) {
ushort port = 6969;

string configurationPath = expandTilde("~/.config/anisette-v3");

string certificateChainPath = null;
string privateKeyPath = null;

auto helpInformation = getopt(
args,
"n|host", format!"The hostname to bind to (default: %s)"(hostname), &hostname,
"p|port", format!"The port to bind to (default: %s)"(port), &port,
"a|adi-path", format!"Where the provisioning information should be stored on the computer for anisette-v1 backwards compat (default: %s)"(configurationPath), &configurationPath,
"private-key", "Path to the PEM-formatted private key file for HTTPS support (requires --cert-chain)", &certificateChainPath,
"cert-chain", "Path to the PEM-formatted certificate chain file for HTTPS support (requires --private-key)", &privateKeyPath,
);

if ((certificateChainPath && !privateKeyPath) || (!certificateChainPath && privateKeyPath)) {
log.error("--certificate-chain and --private-key must both be specified for HTTPS support (they can be both be in the same file though).");
return 1;
}

if (helpInformation.helpWanted) {
defaultGetoptPrinter("anisette-server with v3 support", helpInformation.options);
return 0;
Expand Down Expand Up @@ -145,6 +157,11 @@ int main(string[] args) {
settings.port = port;
settings.bindAddresses = [hostname];
settings.sessionStore = new MemorySessionStore;
if (certificateChainPath) {
settings.tlsContext = createTLSContext(TLSContextKind.server);
settings.tlsContext.useCertificateChainFile(certificateChainPath);
settings.tlsContext.usePrivateKeyFile(privateKeyPath);
}

auto listener = listenHTTP(settings, router);

Expand Down

0 comments on commit 00b112f

Please sign in to comment.