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

grpc-js: Call custom checkServerIdentity when target name override is set #2704

Merged
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
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.10.4",
"version": "1.10.5",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
Expand Down
8 changes: 6 additions & 2 deletions packages/grpc-js/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,13 @@ export class Http2SubchannelConnector implements SubchannelConnector {
if (options['grpc.ssl_target_name_override']) {
const sslTargetNameOverride =
options['grpc.ssl_target_name_override']!;
const originalCheckServerIdentity =
connectionOptions.checkServerIdentity ?? checkServerIdentity;
connectionOptions.checkServerIdentity = (
host: string,
cert: PeerCertificate
): Error | undefined => {
return checkServerIdentity(sslTargetNameOverride, cert);
return originalCheckServerIdentity(sslTargetNameOverride, cert);
};
connectionOptions.servername = sslTargetNameOverride;
} else {
Expand Down Expand Up @@ -804,11 +806,13 @@ export class Http2SubchannelConnector implements SubchannelConnector {
// This option is used for testing only.
if (options['grpc.ssl_target_name_override']) {
const sslTargetNameOverride = options['grpc.ssl_target_name_override']!;
const originalCheckServerIdentity =
connectionOptions.checkServerIdentity ?? checkServerIdentity;
connectionOptions.checkServerIdentity = (
host: string,
cert: PeerCertificate
): Error | undefined => {
return checkServerIdentity(sslTargetNameOverride, cert);
return originalCheckServerIdentity(sslTargetNameOverride, cert);
};
connectionOptions.servername = sslTargetNameOverride;
} else {
Expand Down
30 changes: 28 additions & 2 deletions packages/grpc-js/test/test-channel-credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ describe('ChannelCredentials Implementation', () => {
describe('ChannelCredentials usage', () => {
let client: ServiceClient;
let server: grpc.Server;
let portNum: number;
let caCert: Buffer;
const hostnameOverride = 'foo.test.google.fr';
before(async () => {
const { ca, key, cert } = await pFixtures;
caCert = ca;
const serverCreds = grpc.ServerCredentials.createSsl(null, [
{ private_key: key, cert_chain: cert },
]);
Expand All @@ -178,9 +182,10 @@ describe('ChannelCredentials usage', () => {
reject(err);
return;
}
portNum = port;
client = new echoService(`localhost:${port}`, combinedCreds, {
'grpc.ssl_target_name_override': 'foo.test.google.fr',
'grpc.default_authority': 'foo.test.google.fr',
'grpc.ssl_target_name_override': hostnameOverride,
'grpc.default_authority': hostnameOverride,
});
server.start();
resolve();
Expand All @@ -207,4 +212,25 @@ describe('ChannelCredentials usage', () => {
);
assert2.afterMustCallsSatisfied(done);
});

it('Should call the checkServerIdentity callback', done => {
const channelCreds = ChannelCredentials.createSsl(caCert, null, null, {
checkServerIdentity: assert2.mustCall((hostname, cert) => {
assert.strictEqual(hostname, hostnameOverride);
return undefined;
}),
});
const client = new echoService(`localhost:${portNum}`, channelCreds, {
'grpc.ssl_target_name_override': hostnameOverride,
'grpc.default_authority': hostnameOverride,
});
client.echo(
{ value: 'test value', value2: 3 },
assert2.mustCall((error: ServiceError, response: any) => {
assert.ifError(error);
assert.deepStrictEqual(response, { value: 'test value', value2: 3 });
})
);
assert2.afterMustCallsSatisfied(done);
});
});