Skip to content

Commit

Permalink
Merge pull request #1964 from ExchangeUnion/fix/check-tls-on-startup
Browse files Browse the repository at this point in the history
fix: tls certificate check on startup (#1510)
  • Loading branch information
Karl Ranna authored Nov 9, 2020
2 parents 3fb5f18 + 9633678 commit f0b2ac9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/cli/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ const loadXudConfig = async (argv: Arguments<any>) => {
}
};

const getTlsCert = (certPath: string) => {
try {
return fs.readFileSync(certPath);
} catch (err) {
if (err.code === 'ENOENT') {
throw `tls cert could not be found at ${certPath}, it may take several seconds to be created on xud's first run`;
}

throw err;
}
};

/**
* A generic function to instantiate an XU client.
* @param argv the command line arguments
Expand All @@ -46,7 +58,7 @@ export const loadXudClient = async (argv: Arguments<any>) => {
await loadXudConfig(argv);

const certPath = argv.tlscertpath || path.join(argv.xudir, 'tls.cert');
const cert = fs.readFileSync(certPath);
const cert = getTlsCert(certPath);
const credentials = grpc.credentials.createSsl(cert);

return new XudClient(`${argv.rpchost}:${argv.rpcport}`, credentials);
Expand All @@ -56,7 +68,7 @@ export const loadXudInitClient = async (argv: Arguments<any>) => {
await loadXudConfig(argv);

const certPath = argv.tlscertpath || path.join(argv.xudir, 'tls.cert');
const cert = fs.readFileSync(certPath);
const cert = getTlsCert(certPath);
const credentials = grpc.credentials.createSsl(cert);

return new XudInitClient(`${argv.rpchost}:${argv.rpcport}`, credentials);
Expand Down

0 comments on commit f0b2ac9

Please sign in to comment.