Skip to content

Commit 67c466c

Browse files
committed
In case we fail to decrypt auth info is omitted
This can happen if a different public key was used for encrypting username and/or password.
1 parent ec4af52 commit 67c466c

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/features/projects/data/GitHubProjectDataSource.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
ProjectConfigRemoteVersion,
99
IGitHubRepositoryDataSource,
1010
GitHubRepository,
11-
GitHubRepositoryRef
11+
GitHubRepositoryRef,
12+
ProjectConfigRemoteSpecification
1213
} from "../domain"
1314
import RemoteConfig from "../domain/RemoteConfig"
1415
import { IRemoteConfigEncoder } from "../domain/RemoteConfigEncoder"
@@ -178,11 +179,7 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
178179
const specifications = remoteVersion.specifications.map(e => {
179180
const remoteConfig: RemoteConfig = {
180181
url: e.url,
181-
auth: e.auth ? {
182-
type: e.auth.type,
183-
username: this.encryptionService.decrypt(e.auth.encryptedUsername),
184-
password: this.encryptionService.decrypt(e.auth.encryptedPassword)
185-
} : undefined
182+
auth: this.tryDecryptAuth(e)
186183
};
187184

188185
const encodedRemoteConfig = this.remoteConfigEncoder.encode(remoteConfig);
@@ -232,4 +229,21 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
232229
.replace(/ /g, "-")
233230
.replace(/[^A-Za-z0-9-]/g, "")
234231
}
232+
233+
private tryDecryptAuth(projectConfigRemoteSpec: ProjectConfigRemoteSpecification): { type: string, username: string, password: string } | undefined {
234+
if (!projectConfigRemoteSpec.auth) {
235+
return undefined
236+
}
237+
238+
try {
239+
return {
240+
type: projectConfigRemoteSpec.auth.type,
241+
username: this.encryptionService.decrypt(projectConfigRemoteSpec.auth.encryptedUsername),
242+
password: this.encryptionService.decrypt(projectConfigRemoteSpec.auth.encryptedPassword)
243+
}
244+
} catch (error) {
245+
console.error(`Failed to decrypt remote specification auth for ${projectConfigRemoteSpec.url}. Perhaps a different public key was used?:`, error);
246+
return undefined
247+
}
248+
}
235249
}

0 commit comments

Comments
 (0)