Skip to content

Commit 2d7185f

Browse files
authored
#265 optional ssl params, wip on rejectUnauthorized (#266)
* #265 optional ssl params, wip on rejectUnauthorized * narrowed function arg type * handling rejectUnauthorized
1 parent 1badd18 commit 2d7185f

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/client.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,10 @@ export type ClientListenersParams = {
743743
}
744744

745745
export interface SSLConnectionParams {
746-
key: string
747-
cert: string
746+
key?: string
747+
cert?: string
748748
ca?: string
749+
rejectUnauthorized?: boolean
749750
}
750751

751752
export type AddressResolverParams =
@@ -765,7 +766,7 @@ export interface ClientParams {
765766
frameMax?: number
766767
heartbeat?: number
767768
listeners?: ClientListenersParams
768-
ssl?: SSLConnectionParams
769+
ssl?: SSLConnectionParams | boolean
769770
bufferSizeSettings?: BufferSizeSettings
770771
socketTimeout?: number
771772
addressResolver?: AddressResolverParams

src/connection.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,22 @@ import { SaslHandshakeResponse } from "./responses/sasl_handshake_response"
3232
import { TuneResponse } from "./responses/tune_response"
3333
import {
3434
DEFAULT_FRAME_MAX,
35+
DEFAULT_SSL_CONFIG,
3536
DEFAULT_UNLIMITED_FRAME_MAX,
3637
REQUIRED_MANAGEMENT_VERSION,
3738
isString,
3839
removeFrom,
3940
} from "./util"
4041
import { Version, checkServerDeclaredVersions, getClientSupportedVersions } from "./versions"
4142
import { WaitingResponse } from "./waiting_response"
42-
import { ClientListenersParams, ClientParams, ClosingParams, QueryOffsetParams, StoreOffsetParams } from "./client"
43+
import {
44+
ClientListenersParams,
45+
ClientParams,
46+
ClosingParams,
47+
QueryOffsetParams,
48+
SSLConnectionParams,
49+
StoreOffsetParams,
50+
} from "./client"
4351
import { QueryPublisherResponse } from "./responses/query_publisher_response"
4452
import { QueryPublisherRequest } from "./requests/query_publisher_request"
4553
import { StoreOffsetRequest } from "./requests/store_offset_request"
@@ -134,10 +142,7 @@ export class Connection {
134142

135143
private createSocket() {
136144
const socket = this.params.ssl
137-
? tls.connect(this.params.port, this.params.hostname, {
138-
...this.params.ssl,
139-
rejectUnauthorized: false,
140-
})
145+
? tls.connect(this.params.port, this.params.hostname, buildSSLParams(this.params.ssl))
141146
: new Socket().connect(this.params.port, this.params.hostname)
142147
if (this.params.socketTimeout) socket.setTimeout(this.params.socketTimeout)
143148
return socket
@@ -634,3 +639,9 @@ export function partition<T>(arr: T[], predicate: (t: T) => boolean): [T[], T[]]
634639
function isSameStream({ metadataInfo }: { metadataInfo: MetadataInfo }): (e: ListenerEntry) => boolean {
635640
return (e) => e.stream === metadataInfo.stream
636641
}
642+
643+
function buildSSLParams(ssl: SSLConnectionParams | true) {
644+
if (ssl === true) return DEFAULT_SSL_CONFIG
645+
646+
return ssl
647+
}

src/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export function range(count: number): number[] {
1313
return ret
1414
}
1515

16+
export const DEFAULT_SSL_CONFIG = { rejectUnauthorized: false }
17+
1618
export const DEFAULT_FRAME_MAX = 1048576
1719
export const DEFAULT_UNLIMITED_FRAME_MAX = 0
1820
export const REQUIRED_MANAGEMENT_VERSION = "3.13.0"

0 commit comments

Comments
 (0)