-
Notifications
You must be signed in to change notification settings - Fork 26
util: fix util for changes to channel-credentials.ts in grpc-js
#212
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
052d161
fix util for changes to `channel-credentials.ts` in grpc-js
kartikaysaxena 4a36653
Merge branch 'main' into fix-util
kartikaysaxena 52a8aed
Move pin forward
tstirrat15 fc195bd
Use version without security flaw
tstirrat15 c96e6fe
Update grpc-js version in js-dist as well
tstirrat15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,39 +1,60 @@ | ||||||||||||
| import * as grpc from "@grpc/grpc-js"; | ||||||||||||
| import { NextCall } from "@grpc/grpc-js/build/src/client-interceptors.js"; | ||||||||||||
| import { ConnectionOptions } from "tls"; | ||||||||||||
| import * as net from "net"; | ||||||||||||
| import { SecureConnector } from "@grpc/grpc-js/build/src/channel-credentials.js"; | ||||||||||||
| import { GrpcUri } from "@grpc/grpc-js/build/src/uri-parser.js"; | ||||||||||||
|
|
||||||||||||
| // NOTE: Copied from channel-credentials.ts in gRPC Node package because its not exported: | ||||||||||||
| // https://github.com/grpc/grpc-node/blob/3106057f5ad8f79a71d2ae411e116ad308a2e835/packages/grpc-js/src/call-credentials.ts#L143 | ||||||||||||
| class ComposedChannelCredentials extends grpc.ChannelCredentials { | ||||||||||||
| constructor( | ||||||||||||
| private channelCredentials: KnownInsecureChannelCredentialsImpl, | ||||||||||||
| callCreds: grpc.CallCredentials | ||||||||||||
| private callCreds: grpc.CallCredentials | ||||||||||||
| ) { | ||||||||||||
| super(callCreds); | ||||||||||||
| super(); | ||||||||||||
|
tstirrat15 marked this conversation as resolved.
|
||||||||||||
| // NOTE: leaving this here to show what changed from the upstream. | ||||||||||||
| /* | ||||||||||||
| if (!channelCredentials._isSecure()) { | ||||||||||||
| throw new Error('Cannot compose insecure credentials'); | ||||||||||||
| } | ||||||||||||
| */ | ||||||||||||
| } | ||||||||||||
| compose(callCredentials: grpc.CallCredentials) { | ||||||||||||
| const combinedCallCredentials = | ||||||||||||
| this.callCredentials.compose(callCredentials); | ||||||||||||
| this.callCreds.compose(callCredentials); | ||||||||||||
| return new ComposedChannelCredentials( | ||||||||||||
| this.channelCredentials, | ||||||||||||
| combinedCallCredentials | ||||||||||||
| ); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| _getConnectionOptions(): ConnectionOptions | null { | ||||||||||||
| return this.channelCredentials._getConnectionOptions(); | ||||||||||||
| } | ||||||||||||
| _isSecure(): boolean { | ||||||||||||
|
tstirrat15 marked this conversation as resolved.
|
||||||||||||
| return false; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // NOTE: this is copied from the InsecureChannelCredentialsImpl class | ||||||||||||
| _createSecureConnector( | ||||||||||||
|
Comment on lines
+31
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| channelTarget: GrpcUri, | ||||||||||||
| options: grpc.ChannelOptions, | ||||||||||||
| callCredentials?: grpc.CallCredentials | ||||||||||||
| ): SecureConnector { | ||||||||||||
| return { | ||||||||||||
| connect: async (socket: net.Socket) => { | ||||||||||||
| return { socket, secure: false }; | ||||||||||||
| }, | ||||||||||||
| waitForReady: async () => {}, | ||||||||||||
| getCallCredentials: () => callCredentials || this.callCreds, | ||||||||||||
| destroy: () => {} | ||||||||||||
| }; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| _equals(other: grpc.ChannelCredentials): boolean { | ||||||||||||
| if (this === other) { | ||||||||||||
| return true; | ||||||||||||
| } | ||||||||||||
| if (other instanceof ComposedChannelCredentials) { | ||||||||||||
| return ( | ||||||||||||
| this.channelCredentials._equals(other.channelCredentials) && | ||||||||||||
| this.callCredentials._equals(other.callCredentials) | ||||||||||||
| this.callCreds._equals(other.callCreds) | ||||||||||||
| ); | ||||||||||||
| } else { | ||||||||||||
| return false; | ||||||||||||
|
|
@@ -44,25 +65,32 @@ class ComposedChannelCredentials extends grpc.ChannelCredentials { | |||||||||||
| // Create our own known insecure channel creds. | ||||||||||||
| // See https://github.com/grpc/grpc-node/issues/543 for why this is necessary. | ||||||||||||
| class KnownInsecureChannelCredentialsImpl extends grpc.ChannelCredentials { | ||||||||||||
| constructor(callCredentials?: grpc.CallCredentials) { | ||||||||||||
| super(callCredentials); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| compose(callCredentials: grpc.CallCredentials): grpc.ChannelCredentials { | ||||||||||||
| const combinedCallCredentials = | ||||||||||||
| this.callCredentials.compose(callCredentials); | ||||||||||||
| return new ComposedChannelCredentials(this, combinedCallCredentials); | ||||||||||||
| return new ComposedChannelCredentials(this, callCredentials); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| _getConnectionOptions(): ConnectionOptions { | ||||||||||||
| return {}; | ||||||||||||
| } | ||||||||||||
| _isSecure(): boolean { | ||||||||||||
| return false; | ||||||||||||
| } | ||||||||||||
| _equals(other: grpc.ChannelCredentials): boolean { | ||||||||||||
| return other instanceof KnownInsecureChannelCredentialsImpl; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| _createSecureConnector( | ||||||||||||
| channelTarget: GrpcUri, | ||||||||||||
| options: grpc.ChannelOptions, | ||||||||||||
| callCredentials: grpc.CallCredentials | ||||||||||||
| ): SecureConnector { | ||||||||||||
| return { | ||||||||||||
| connect: async (socket: net.Socket) => { | ||||||||||||
| return { socket, secure: false }; | ||||||||||||
| }, | ||||||||||||
| waitForReady: async () => {}, | ||||||||||||
| getCallCredentials: () => callCredentials, | ||||||||||||
| destroy: () => {} | ||||||||||||
| }; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| export enum ClientSecurity { | ||||||||||||
|
|
||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.