Skip to content
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

feat: add support for server name #1476

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/connection.ts
Expand Up @@ -779,6 +779,14 @@ export interface ConnectionOptions {
*/
rowCollectionOnRequestCompletion?: boolean;

/**
* A string, that will allow user to provide their custom Common Name (CN) which matches a Common Name (CN)
* present in the server certificate.
*
* (no default)
*/
serverName?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small nit: Use servername instead, that would match the option name used by Node.js.


/**
* The version of TDS to use. If server doesn't support specified version, negotiated version is used instead.
*
Expand Down Expand Up @@ -1620,6 +1628,13 @@ class Connection extends EventEmitter {
this.config.options.rowCollectionOnRequestCompletion = config.options.rowCollectionOnRequestCompletion;
}

if (config.options.serverName !== undefined) {
if (typeof config.options.serverName !== 'string') {
throw new TypeError('The "config.options.serverName" property must be of type string.');
}
this.config.options.serverName = config.options.serverName;
}

if (config.options.tdsVersion !== undefined) {
if (typeof config.options.tdsVersion !== 'string') {
throw new TypeError('The "config.options.tdsVersion" property must be of type string.');
Expand Down Expand Up @@ -3170,7 +3185,7 @@ Connection.prototype.STATE = {

try {
this.transitionTo(this.STATE.SENT_TLSSSLNEGOTIATION);
await this.messageIo.startTls(this.secureContextOptions, this.routingData?.server ?? this.config.server, this.config.options.trustServerCertificate);
await this.messageIo.startTls(this.secureContextOptions, this.config.options.serverName ? this.config.options.serverName : this.routingData?.server ?? this.config.server, this.config.options.trustServerCertificate);
} catch (err: any) {
return this.socketError(err);
}
Expand Down