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: Provide full certificate in checkServerIdentity callback #1968

Merged
Merged
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
25 changes: 5 additions & 20 deletions packages/grpc-js/src/channel-credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ function verifyIsBufferOrNull(obj: any, friendlyName: string): void {
}
}

/**
* A certificate as received by the checkServerIdentity callback.
*/
export interface Certificate {
/**
* The raw certificate in DER form.
*/
raw: Buffer;
}

/**
* A callback that will receive the expected hostname and presented peer
* certificate as parameters. The callback should return an error to
Expand All @@ -45,7 +35,7 @@ export interface Certificate {
*/
export type CheckServerIdentityCallback = (
hostname: string,
cert: Certificate
cert: PeerCertificate
) => Error | undefined;

function bufferOrNullEqual(buf1: Buffer | null, buf2: Buffer | null) {
Expand Down Expand Up @@ -192,15 +182,10 @@ class SecureChannelCredentialsImpl extends ChannelCredentials {
cert: certChain || undefined,
ciphers: CIPHER_SUITES,
});
this.connectionOptions = { secureContext };
if (verifyOptions && verifyOptions.checkServerIdentity) {
this.connectionOptions.checkServerIdentity = (
host: string,
cert: PeerCertificate
) => {
return verifyOptions.checkServerIdentity!(host, { raw: cert.raw });
};
}
this.connectionOptions = {
secureContext,
checkServerIdentity: verifyOptions?.checkServerIdentity
};
}

compose(callCredentials: CallCredentials): ChannelCredentials {
Expand Down