Skip to content

Add option to simply enable TLS instead of providing certain config parameters, and also remove hardcoded rejectUnauthorized = false #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,17 +750,23 @@ export type ClientListenersParams = {
connection_closed?: ConnectionClosedListener
}

export interface SSLConnectionParams {
key: string
cert: string
ca?: string
export type SSLConnectionParams = {
enabled: true
options?: {
key: string
cert: string
ca?: string
rejectUnauthorized?: boolean
}
} | {
enabled: false
}

export type AddressResolverParams =
| {
enabled: true
endpoint?: { host: string; port: number }
}
enabled: true
endpoint?: { host: string; port: number }
}
Comment on lines +767 to +769
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto formatting I think

| { enabled: false }

export interface ClientParams {
Expand Down
11 changes: 4 additions & 7 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,9 @@ export class Connection {
}

private createSocket() {
const socket = this.params.ssl
? tls.connect(this.params.port, this.params.hostname, {
...this.params.ssl,
rejectUnauthorized: false,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason why this was hardcoded?

})
const sslEnabled = this.params.ssl !== undefined && this.params.ssl.enabled === true
const socket = sslEnabled
? tls.connect(this.params.port, this.params.hostname, this.params.ssl)
: new Socket().connect(this.params.port, this.params.hostname)
if (this.params.socketTimeout) socket.setTimeout(this.params.socketTimeout)
return socket
Expand Down Expand Up @@ -416,8 +414,7 @@ export class Connection {
const bufferSizeParams = this.getBufferSizeParams()
const body = cmd.toBuffer(bufferSizeParams)
this.logger.debug(
`Write cmd key: ${cmd.key.toString(16)} - no correlationId - data: ${inspect(body.toJSON())} length: ${
body.byteLength
`Write cmd key: ${cmd.key.toString(16)} - no correlationId - data: ${inspect(body.toJSON())} length: ${body.byteLength
}`
)
this.socket.write(body, (err) => {
Expand Down
10 changes: 7 additions & 3 deletions test/e2e/connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ async function createTlsClient(): Promise<Client> {
port: 5551,
mechanism: "EXTERNAL",
ssl: {
ca: await readFile("./tls-gen/basic/result/ca_certificate.pem", "utf8"),
cert: await readFile(`./tls-gen/basic/result/client_${firstNode.host}_certificate.pem`, "utf8"),
key: await readFile(`./tls-gen/basic/result/client_${firstNode.host}_key.pem`, "utf8"),
enabled: true,
options: {
ca: await readFile("./tls-gen/basic/result/ca_certificate.pem", "utf8"),
cert: await readFile(`./tls-gen/basic/result/client_${firstNode.host}_certificate.pem`, "utf8"),
key: await readFile(`./tls-gen/basic/result/client_${firstNode.host}_key.pem`, "utf8"),
rejectUnauthorized: true,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To recover previous behaviour, we can remove this!

},
},
username: "",
password: "",
Expand Down