@@ -9,7 +9,7 @@ import { LocalAppClient } from '@gitpod/local-app-api-grpcweb/lib/localapp_pb_se
9
9
import { NodeHttpTransport } from '@improbable-eng/grpc-web-node-http-transport' ;
10
10
import { grpc } from '@improbable-eng/grpc-web' ;
11
11
import { Workspace , WorkspaceInstanceStatus_Phase } from '@gitpod/public-api/lib/gitpod/experimental/v1/workspaces_pb' ;
12
- import { WorkspaceInfo } from '@gitpod/gitpod-protocol' ;
12
+ import { UserSSHPublicKeyValue , WorkspaceInfo } from '@gitpod/gitpod-protocol' ;
13
13
import * as cp from 'child_process' ;
14
14
import * as fs from 'fs' ;
15
15
import * as http from 'http' ;
@@ -38,6 +38,7 @@ import { getOpenSSHVersion } from './ssh/sshVersion';
38
38
import { NotificationService } from './notification' ;
39
39
import { UserFlowTelemetry } from './common/telemetry' ;
40
40
import { GitpodPublicApi } from './publicApi' ;
41
+ import { SSHKey } from '@gitpod/public-api/lib/gitpod/experimental/v1/user_pb' ;
41
42
42
43
interface SSHConnectionParams {
43
44
workspaceId : string ;
@@ -538,7 +539,7 @@ export default class RemoteConnector extends Disposable {
538
539
const [ workspaceInfo , ownerToken , registeredSSHKeys ] = await withServerApi ( session . accessToken , serviceUrl . toString ( ) , service => Promise . all ( [
539
540
this . publicApi ? this . publicApi . getWorkspace ( workspaceId ) : service . server . getWorkspace ( workspaceId ) ,
540
541
this . publicApi ? this . publicApi . getOwnerToken ( workspaceId ) : service . server . getOwnerToken ( workspaceId ) ,
541
- sshKeysSupported ? service . server . getSSHPublicKeys ( ) : undefined
542
+ sshKeysSupported ? ( this . publicApi ? this . publicApi . getSSHKeys ( ) : service . server . getSSHPublicKeys ( ) ) : undefined
542
543
] ) , this . logger ) ;
543
544
544
545
const isRunning = this . publicApi
@@ -618,9 +619,21 @@ export default class RemoteConnector extends Disposable {
618
619
let identityKeys = await this . getIdentityKeys ( hostConfiguration ) ;
619
620
620
621
if ( registeredSSHKeys ) {
621
- this . logger . trace ( `Registered public keys in Gitpod account:` , registeredSSHKeys . length ? registeredSSHKeys . map ( k => `${ k . name } SHA256:${ k . fingerprint } ` ) . join ( '\n' ) : 'None' ) ;
622
+ const registeredKeys = this . publicApi
623
+ ? ( registeredSSHKeys as SSHKey [ ] ) . map ( k => {
624
+ const parsedResult = sshUtils . parseKey ( k . key ) ;
625
+ if ( parsedResult instanceof Error || ! parsedResult ) {
626
+ this . logger . error ( `Error while parsing SSH public key ${ k . name } :` , parsedResult ) ;
627
+ return { name : k . name , fingerprint : '' } ;
628
+ }
629
+
630
+ const parsedKey = parsedResult as ParsedKey ;
631
+ return { name : k . name , fingerprint : crypto . createHash ( 'sha256' ) . update ( parsedKey . getPublicSSH ( ) ) . digest ( 'base64' ) } ;
632
+ } )
633
+ : ( registeredSSHKeys as UserSSHPublicKeyValue [ ] ) . map ( k => ( { name : k . name , fingerprint : k . fingerprint } ) ) ;
634
+ this . logger . trace ( `Registered public keys in Gitpod account:` , registeredKeys . length ? registeredKeys . map ( k => `${ k . name } SHA256:${ k . fingerprint } ` ) . join ( '\n' ) : 'None' ) ;
622
635
623
- identityKeys = identityKeys . filter ( k => ! ! registeredSSHKeys . find ( regKey => regKey . fingerprint === k . fingerprint ) ) ;
636
+ identityKeys = identityKeys . filter ( k => ! ! registeredKeys . find ( regKey => regKey . fingerprint === k . fingerprint ) ) ;
624
637
} else {
625
638
if ( identityKeys . length ) {
626
639
sshDestInfo . user = `${ workspaceId } #${ ownerToken } ` ;
@@ -811,10 +824,7 @@ export default class RemoteConnector extends Disposable {
811
824
const usePublicApi = await this . experiments . getRaw < boolean > ( 'gitpod_experimental_publicApi' , session . account . id , { gitpodHost : params . gitpodHost } ) ;
812
825
this . logger . info ( `Going to use ${ usePublicApi ? 'public' : 'server' } API` ) ;
813
826
if ( usePublicApi ) {
814
- if ( ! this . publicApi ) {
815
- this . publicApi = new GitpodPublicApi ( ) ;
816
- }
817
- await this . publicApi . init ( session . accessToken , params . gitpodHost ) ;
827
+ this . publicApi = new GitpodPublicApi ( session . accessToken , params . gitpodHost ) ;
818
828
}
819
829
820
830
const forceUseLocalApp = getServiceURL ( params . gitpodHost ) === 'https://gitpod.io'
@@ -971,7 +981,7 @@ export default class RemoteConnector extends Disposable {
971
981
}
972
982
}
973
983
974
- private async initializeRemoteExtensions ( flow : UserFlowTelemetry & { quiet : boolean , flowId : string } ) {
984
+ private async initializeRemoteExtensions ( flow : UserFlowTelemetry & { quiet : boolean ; flowId : string } ) {
975
985
this . telemetry . sendUserFlowStatus ( 'enabled' , flow ) ;
976
986
let syncData : { ref : string ; content : string } | undefined ;
977
987
try {
@@ -1132,7 +1142,7 @@ export default class RemoteConnector extends Disposable {
1132
1142
1133
1143
const syncExtFlow = { ...connectionInfo , gitpodVersion : gitpodVersion . raw , userId : session . account . id , flow : 'sync_local_extensions' } ;
1134
1144
this . initializeRemoteExtensions ( { ...syncExtFlow , quiet : true , flowId : uuid ( ) } ) ;
1135
- this . context . subscriptions . push ( vscode . commands . registerCommand ( " gitpod.installLocalExtensions" , ( ) => {
1145
+ this . context . subscriptions . push ( vscode . commands . registerCommand ( ' gitpod.installLocalExtensions' , ( ) => {
1136
1146
this . initializeRemoteExtensions ( { ...syncExtFlow , quiet : false , flowId : uuid ( ) } ) ;
1137
1147
} ) ) ;
1138
1148
0 commit comments