Skip to content

Commit 7729fb7

Browse files
authored
Merge pull request #2956 from murgatroid99/grpc-js_sni_fix
grpc-js: Fix ability to set SNI with ssl_target_name_override option
2 parents 863a81a + a1aff9d commit 7729fb7

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

packages/grpc-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grpc/grpc-js",
3-
"version": "1.13.3",
3+
"version": "1.13.4",
44
"description": "gRPC Library for Node - pure JS implementation",
55
"homepage": "https://grpc.io/",
66
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

packages/grpc-js/src/channel-credentials.ts

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ function getConnectionOptions(secureContext: SecureContext, verifyOptions: Verif
206206
const connectionOptions: ConnectionOptions = {
207207
secureContext: secureContext
208208
};
209+
let realTarget: GrpcUri = channelTarget;
210+
if ('grpc.http_connect_target' in options) {
211+
const parsedTarget = parseUri(options['grpc.http_connect_target']!);
212+
if (parsedTarget) {
213+
realTarget = parsedTarget;
214+
}
215+
}
216+
const targetPath = getDefaultAuthority(realTarget);
217+
const hostPort = splitHostPort(targetPath);
218+
const remoteHost = hostPort?.host ?? targetPath;
219+
connectionOptions.host = remoteHost;
220+
209221
if (verifyOptions.checkServerIdentity) {
210222
connectionOptions.checkServerIdentity = verifyOptions.checkServerIdentity;
211223
}
@@ -225,36 +237,11 @@ function getConnectionOptions(secureContext: SecureContext, verifyOptions: Verif
225237
};
226238
connectionOptions.servername = sslTargetNameOverride;
227239
} else {
228-
if ('grpc.http_connect_target' in options) {
229-
/* This is more or less how servername will be set in createSession
230-
* if a connection is successfully established through the proxy.
231-
* If the proxy is not used, these connectionOptions are discarded
232-
* anyway */
233-
const targetPath = getDefaultAuthority(
234-
parseUri(options['grpc.http_connect_target'] as string) ?? {
235-
path: 'localhost',
236-
}
237-
);
238-
const hostPort = splitHostPort(targetPath);
239-
connectionOptions.servername = hostPort?.host ?? targetPath;
240-
}
240+
connectionOptions.servername = remoteHost;
241241
}
242242
if (options['grpc-node.tls_enable_trace']) {
243243
connectionOptions.enableTrace = true;
244244
}
245-
246-
let realTarget: GrpcUri = channelTarget;
247-
if ('grpc.http_connect_target' in options) {
248-
const parsedTarget = parseUri(options['grpc.http_connect_target']!);
249-
if (parsedTarget) {
250-
realTarget = parsedTarget;
251-
}
252-
}
253-
const targetPath = getDefaultAuthority(realTarget);
254-
const hostPort = splitHostPort(targetPath);
255-
const remoteHost = hostPort?.host ?? targetPath;
256-
connectionOptions.host = remoteHost;
257-
connectionOptions.servername = remoteHost;
258245
return connectionOptions;
259246
}
260247

0 commit comments

Comments
 (0)