Skip to content

Commit

Permalink
Merge pull request #453 from shapehq/fix/catch-decrypt-error
Browse files Browse the repository at this point in the history
In case we fail to decrypt auth info is omitted
  • Loading branch information
ulrikandersen authored Dec 5, 2024
2 parents ec4af52 + 67c466c commit 96a807e
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/features/projects/data/GitHubProjectDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
ProjectConfigRemoteVersion,
IGitHubRepositoryDataSource,
GitHubRepository,
GitHubRepositoryRef
GitHubRepositoryRef,
ProjectConfigRemoteSpecification
} from "../domain"
import RemoteConfig from "../domain/RemoteConfig"
import { IRemoteConfigEncoder } from "../domain/RemoteConfigEncoder"
Expand Down Expand Up @@ -178,11 +179,7 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
const specifications = remoteVersion.specifications.map(e => {
const remoteConfig: RemoteConfig = {
url: e.url,
auth: e.auth ? {
type: e.auth.type,
username: this.encryptionService.decrypt(e.auth.encryptedUsername),
password: this.encryptionService.decrypt(e.auth.encryptedPassword)
} : undefined
auth: this.tryDecryptAuth(e)
};

const encodedRemoteConfig = this.remoteConfigEncoder.encode(remoteConfig);
Expand Down Expand Up @@ -232,4 +229,21 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
.replace(/ /g, "-")
.replace(/[^A-Za-z0-9-]/g, "")
}

private tryDecryptAuth(projectConfigRemoteSpec: ProjectConfigRemoteSpecification): { type: string, username: string, password: string } | undefined {
if (!projectConfigRemoteSpec.auth) {
return undefined
}

try {
return {
type: projectConfigRemoteSpec.auth.type,
username: this.encryptionService.decrypt(projectConfigRemoteSpec.auth.encryptedUsername),
password: this.encryptionService.decrypt(projectConfigRemoteSpec.auth.encryptedPassword)
}
} catch (error) {
console.error(`Failed to decrypt remote specification auth for ${projectConfigRemoteSpec.url}. Perhaps a different public key was used?:`, error);
return undefined
}
}
}

0 comments on commit 96a807e

Please sign in to comment.