-
Notifications
You must be signed in to change notification settings - Fork 36
Connect: Accommodate for making gRPC server creds in shared process #1220
Changes from all commits
e3a0234
2481831
e97dd25
d2e4176
d7c7544
be9639e
fcda61e
dea4d67
69575b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { | ||
| ChannelCredentials, | ||
| credentials, | ||
| ServerCredentials, | ||
| } from '@grpc/grpc-js'; | ||
|
|
||
| import { RuntimeSettings } from 'teleterm/mainProcess/types'; | ||
|
|
||
| export function createClientCredentials( | ||
| clientKeyPair: { cert: Buffer; key: Buffer }, | ||
| serverCert: Buffer | ||
| ): ChannelCredentials { | ||
| return credentials.createSsl( | ||
| serverCert, | ||
| clientKeyPair.key, | ||
| clientKeyPair.cert | ||
| ); | ||
| } | ||
|
|
||
| export function createServerCredentials( | ||
| serverKeyPair: { cert: Buffer; key: Buffer }, | ||
| clientCert: Buffer | ||
| ): ServerCredentials { | ||
| return ServerCredentials.createSsl( | ||
| clientCert, | ||
| [ | ||
| { | ||
| cert_chain: serverKeyPair.cert, | ||
| private_key: serverKeyPair.key, | ||
| }, | ||
| ], | ||
| true | ||
| ); | ||
| } | ||
|
|
||
| export function createInsecureClientCredentials(): ChannelCredentials { | ||
| return credentials.createInsecure(); | ||
| } | ||
|
|
||
| export function createInsecureServerCredentials(): ServerCredentials { | ||
| return ServerCredentials.createInsecure(); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the gRPC connection should be encrypted. | ||
| * The only source of truth is the type of tshd protocol. | ||
| * Any protocol other than `unix` should be encrypted. | ||
| * The same check is performed on the tshd side. | ||
| */ | ||
| export function shouldEncryptConnection( | ||
| runtimeSettings: RuntimeSettings | ||
| ): boolean { | ||
| return ( | ||
| new URL(runtimeSettings.tshd.requestedNetworkAddress).protocol !== 'unix:' | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export * from './clientCredentials'; | ||
| export * from './serverCredentials'; | ||
| export * from './types'; | ||
| export * from './credentials'; | ||
| export * from './files'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,9 @@ interface GeneratedCert { | |
| cert: string; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a self-signed cert. commonName should be a valid domain name. | ||
| */ | ||
| export async function makeCert({ | ||
| commonName, | ||
| validityDays, | ||
|
|
@@ -69,6 +72,15 @@ export async function makeCert({ | |
| digitalSignature: true, | ||
| keyEncipherment: true, | ||
| }, | ||
| { | ||
| name: 'subjectAltName', | ||
| altNames: [ | ||
| { | ||
| type: 2, // DNS type | ||
| value: commonName, | ||
| }, | ||
| ], | ||
| }, | ||
|
Comment on lines
+75
to
+83
Member
Author
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. To my surprise, Go didn't complain when a cert without this was used as a client cert, but it was a problem when I tried to use it as a server cert for the client credentials. |
||
| ]; | ||
|
|
||
| return await generateRawCert({ | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| // `Client` and `TshServer` file names are also used on the tshd side | ||
| // Each process creates its own key pair. The public key is saved to disk under the specified | ||
| // filename, the private key stays in the memory. | ||
| // | ||
| // `Renderer` and `Tshd` file names are also used on the tshd side. | ||
| export enum GrpcCertName { | ||
| Client = 'client.crt', | ||
|
Member
Author
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. Now that we're going to have both a gRPC client and a gRPC server in the renderer process, the name "client" stopped being sufficient. I refactored this so that it closer reflects what we want to achieve with gRPC certs – each process owns its own key pair, keeps the private key in memory and the public key is saved to the file. |
||
| TshServer = 'tsh_server.crt', | ||
| SharedServer = 'shared_server.crt', | ||
| Renderer = 'renderer.crt', | ||
| Tshd = 'tshd.crt', | ||
| Shared = 'shared.crt', | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if any of these promises fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createGrpcCredentialswill throw, then after itgetElectronGlobalswill throw.getElectronGlobalsgets exposed through contextBridge aswindow.electron:webapps/packages/teleterm/src/preload.ts
Line 33 in be9639e
It's used in
boot.tsx:webapps/packages/teleterm/src/ui/boot.tsx
Lines 13 to 14 in be9639e
getElectronGlobalsinboot.tsxcallswindow.electronunderneath, so it will fail as well, triggering thecatchbranch:webapps/packages/teleterm/src/ui/boot.tsx
Lines 28 to 30 in be9639e
This will show the error to the user in the actual browser window.