Skip to content

Commit

Permalink
[feat] enable tls.cert/key/ca to be specified directly
Browse files Browse the repository at this point in the history
- [feat] added `tls.cert`, `tls.key`, `tls.ca` to make it possible to specify certificate as a string on clients that would allow that (node). (#107)
- FIX https://github.com/nats-io/nats.js/issues/395
  • Loading branch information
aricart authored Feb 18, 2021
1 parent b8ff2cc commit 8da1cbf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
1 change: 0 additions & 1 deletion doc/snippets/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { nuid } from "../../nats-base-client/nuid.ts";
const nc = await connect(
{
servers: `demo.nats.io`,
headers: true,
},
);

Expand Down
2 changes: 1 addition & 1 deletion nats-base-client/internal_mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export { Heartbeat } from "./heartbeats.ts";
export type { PH } from "./heartbeats.ts";
export { MuxSubscription } from "./muxsubscription.ts";
export { DataBuffer } from "./databuffer.ts";
export { checkOptions } from "./options.ts";
export { checkOptions, checkUnsupportedOption } from "./options.ts";
export { Request } from "./request.ts";
export type { Authenticator } from "./authenticator.ts";
export {
Expand Down
6 changes: 6 additions & 0 deletions nats-base-client/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,9 @@ export function checkOptions(info: ServerInfo, options: ConnectionOptions) {
throw new NatsError("tls", ErrorCode.SERVER_OPTION_NA);
}
}

export function checkUnsupportedOption(prop: string, v?: string) {
if (v) {
throw new NatsError(prop, ErrorCode.INVALID_OPTION);
}
}
3 changes: 3 additions & 0 deletions nats-base-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ export interface ConnectionOptions {
// these may not be supported on all environments
export interface TlsOptions {
certFile?: string;
cert?: string;
caFile?: string;
ca?: string;
keyFile?: string;
key?: string;
}

export interface Msg {
Expand Down
9 changes: 9 additions & 0 deletions src/deno_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Deferred, deferred } from "https://deno.land/[email protected]/async/mod.ts";
import Conn = Deno.Conn;
import {
checkOptions,
checkUnsupportedOption,
ConnectionOptions,
DataBuffer,
ErrorCode,
Expand Down Expand Up @@ -131,6 +132,14 @@ export class DenoTransport implements Transport {
const tls = this.options && this.options.tls
? this.options.tls
: {} as TlsOptions;

// these options are not available in Deno
checkUnsupportedOption("tls.ca", tls.ca);
checkUnsupportedOption("tls.cert", tls.cert);
checkUnsupportedOption("tls.certFile", tls.certFile);
checkUnsupportedOption("tls.key", tls.key);
checkUnsupportedOption("tls.keyFile", tls.keyFile);

this.conn = await Deno.startTls(
this.conn,
{ hostname, certFile: tls.caFile },
Expand Down

0 comments on commit 8da1cbf

Please sign in to comment.