Skip to content

Commit

Permalink
Merge pull request #1968 from murgatroid99/grpc-js_certificate_check_…
Browse files Browse the repository at this point in the history
…callback

grpc-js: Provide full certificate in `checkServerIdentity` callback
  • Loading branch information
murgatroid99 committed Nov 16, 2021
2 parents bf11e4b + 472baec commit e675406
Showing 1 changed file with 5 additions and 20 deletions.
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

0 comments on commit e675406

Please sign in to comment.