Skip to content

Commit 263e459

Browse files
authored
Merge pull request #101 from GitGuardian/agateau/insecure
Add insecure option, deprecate allowSelfSigned
2 parents dc82c8d + 703f104 commit 263e459

File tree

8 files changed

+91
-47
lines changed

8 files changed

+91
-47
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# GitGuardian Secret Security Changelog
22

3+
## [0.16.0]
4+
5+
### Added
6+
7+
- Added `gitguardian.insecure` option to replace the ambiguous `gitguardian.allowSelfSigned` one.
8+
9+
### Changed
10+
11+
- Updated to [ggshield 1.44.1](https://github.com/GitGuardian/ggshield/releases/v1.44.1).
12+
13+
### Deprecated
14+
15+
- Marked `gitguardian.allowSelfSigned` as deprecated.
16+
317
## [0.15.0]
418

519
### Changed

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,21 @@
3434
"gitguardian.apiUrl": {
3535
"type": "string",
3636
"default": "",
37-
"markdownDescription": "You can override the value here for On Premise installations"
37+
"markdownDescription": "You can override the value here for On Premise installations",
38+
"order": 1
39+
},
40+
"gitguardian.insecure": {
41+
"type": "boolean",
42+
"default": false,
43+
"markdownDescription": "Skip all certificate verification checks.\n\nWARNING: this option makes the transfer insecure.",
44+
"order": 2
3845
},
3946
"gitguardian.allowSelfSigned": {
4047
"type": "boolean",
4148
"default": false,
42-
"markdownDescription": "Allow Self Signed Certificates"
49+
"markdownDescription": "Allow Self Signed Certificates",
50+
"markdownDeprecationMessage": "Deprecated: Please use `#gitguardian.insecure#` instead.",
51+
"order": 100
4352
}
4453
}
4554
},

src/lib/ggshield-configuration-utils.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@ export async function getConfiguration(
1313
): Promise<GGShieldConfiguration> {
1414
const config = workspace.getConfiguration("gitguardian");
1515

16-
const ggshieldPath: string | undefined = config.get("GGShieldPath");
1716
const apiUrl: string | undefined = config.get("apiUrl");
18-
const allowSelfSigned: boolean = config.get("allowSelfSigned", false);
17+
const insecure: boolean = config.get(
18+
"insecure",
19+
// Read allowSelfSigned for backward compatibility
20+
config.get("allowSelfSigned", false),
21+
);
1922

2023
const pathToGGShield: string = await getGGShield(
2124
os.platform(),
2225
os.arch(),
2326
context,
2427
outputChannel,
25-
allowSelfSigned,
28+
insecure,
2629
);
2730

28-
return new GGShieldConfiguration(
29-
pathToGGShield,
30-
apiUrl,
31-
allowSelfSigned || false,
32-
);
31+
return new GGShieldConfiguration(pathToGGShield, apiUrl, insecure || false);
3332
}

src/lib/ggshield-configuration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
export class GGShieldConfiguration {
22
ggshieldPath: string;
33
apiUrl: string;
4-
allowSelfSigned: boolean;
4+
insecure: boolean;
55

66
constructor(
77
ggshieldPath: string = "",
88
apiUrl: string = "",
9-
allowSelfSigned: boolean = false,
9+
insecure: boolean = false,
1010
) {
1111
this.ggshieldPath = ggshieldPath;
1212
this.apiUrl = apiUrl;
13-
this.allowSelfSigned = allowSelfSigned;
13+
this.insecure = insecure;
1414
}
1515
}

src/lib/ggshield-resolver-utils.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function getGGShield(
3636
arch: string,
3737
context: ExtensionContext,
3838
outputChannel: OutputChannel,
39-
allowSelfSigned: boolean,
39+
insecure: boolean,
4040
): Promise<string> {
4141
const version = getGGShieldVersion(context);
4242
console.log(`Latest GGShield version: ${version}`);
@@ -65,13 +65,7 @@ export async function getGGShield(
6565
}
6666
fs.mkdirSync(ggshieldFolder);
6767
// install GGShield
68-
await installGGShield(
69-
platform,
70-
arch,
71-
ggshieldFolder,
72-
version,
73-
allowSelfSigned,
74-
);
68+
await installGGShield(platform, arch, ggshieldFolder, version, insecure);
7569
outputChannel.appendLine(
7670
`Updated to GGShield v${version}. Checkout https://github.com/GitGuardian/ggshield for more info.`,
7771
);
@@ -138,7 +132,7 @@ export async function installGGShield(
138132
arch: string,
139133
ggshieldFolder: string,
140134
version: string,
141-
allowSelfSigned: boolean,
135+
insecure: boolean,
142136
): Promise<void> {
143137
let extension: string = "";
144138
switch (platform) {
@@ -163,7 +157,7 @@ export async function installGGShield(
163157
fileName,
164158
downloadUrl,
165159
ggshieldFolder,
166-
allowSelfSigned,
160+
insecure,
167161
);
168162
extractGGShieldBinary(path.join(ggshieldFolder, fileName), ggshieldFolder);
169163
}
@@ -201,11 +195,11 @@ async function downloadGGShieldFromGitHub(
201195
fileName: string,
202196
downloadUrl: string,
203197
ggshieldFolder: string,
204-
allowSelfSigned: boolean,
198+
insecure: boolean,
205199
): Promise<void> {
206200
console.log(`Downloading GGShield from ${downloadUrl}`);
207201

208-
const instance = allowSelfSigned
202+
const instance = insecure
209203
? new Agent({
210204
rejectUnauthorized: false,
211205
})

src/lib/run-ggshield.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ export function runGGShieldCommand(
3737
if (workspace.workspaceFolders?.length || 0 > 0) {
3838
options["cwd"] = workspace.workspaceFolders![0].uri.fsPath;
3939
}
40-
// if allowSelfSigned is enabled, add the --allow-self-signed flag
41-
if (configuration.allowSelfSigned) {
42-
args = ["--allow-self-signed"].concat(args);
40+
if (configuration.insecure) {
41+
args = ["--insecure"].concat(args);
4342
}
4443

4544
if (configuration.apiUrl && !args.includes("--version")) {

src/test/suite/lib/ggshield-configuration-utils.test.ts

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,35 @@ suite("getConfiguration", () => {
2727
simple.restore();
2828
});
2929

30+
/**
31+
* Helper class to fake different configurations of the extension
32+
*/
33+
class FakeConfiguration {
34+
records: Record<string, any>;
35+
36+
constructor(records: Record<string, any>) {
37+
this.records = records;
38+
}
39+
40+
public get(section: string, defaultValue: any): any {
41+
if (this.records.hasOwnProperty(section)) {
42+
return this.records[section];
43+
}
44+
return defaultValue;
45+
}
46+
}
47+
3048
test("Vscode settings are correctly read", async () => {
3149
const context = {} as ExtensionContext;
3250
const outputChannel = window.createOutputChannel("GitGuardian");
3351
simple.mock(context, "asAbsolutePath").returnWith("");
3452

35-
getConfigurationMock.returnWith({
36-
get: (key: string) => {
37-
if (key === "apiUrl") {
38-
return "https://custom-url.com";
39-
}
40-
if (key === "allowSelfSigned") {
41-
return true;
42-
}
43-
},
44-
});
53+
getConfigurationMock.returnWith(
54+
new FakeConfiguration({
55+
apiUrl: "https://custom-url.com",
56+
insecure: true,
57+
} as Record<string, any>),
58+
);
4559
const configuration = await getConfiguration(context, outputChannel);
4660

4761
// Assert both workspace.getConfiguration and GGShieldConfiguration constructor were called
@@ -52,6 +66,21 @@ suite("getConfiguration", () => {
5266

5367
// Assert that the configuration has the expected values
5468
assert.strictEqual(configuration.apiUrl, "https://custom-url.com");
55-
assert.strictEqual(configuration.allowSelfSigned, true);
69+
assert.strictEqual(configuration.insecure, true);
70+
});
71+
test("insecure falls back on allowSelfSigned", async () => {
72+
const context = {} as ExtensionContext;
73+
const outputChannel = window.createOutputChannel("GitGuardian");
74+
simple.mock(context, "asAbsolutePath").returnWith("");
75+
76+
getConfigurationMock.returnWith(
77+
new FakeConfiguration({
78+
allowSelfSigned: true,
79+
} as Record<string, any>),
80+
);
81+
const configuration = await getConfiguration(context, outputChannel);
82+
83+
// Assert that the configuration has the expected values
84+
assert.strictEqual(configuration.insecure, true);
5685
});
5786
});

src/test/suite/lib/run-ggshield.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ suite("runGGShieldCommand", () => {
3636
delete process.env.TEST_GLOBAL_VAR;
3737
});
3838

39-
const testCasesAllowSelfSigned = [
39+
const testCasesInsecure = [
4040
{
41-
allowSelfSigned: true,
41+
insecure: true,
4242
description:
43-
"GGshield is called with flag --allow-self-signed when allowSelfSigned is true",
43+
"GGshield is called with flag --insecure when insecure is true",
4444
},
4545
{
46-
allowSelfSigned: false,
46+
insecure: false,
4747
description:
48-
"GGshield is not called with flag --allow-self-signed when allowSelfSigned is false",
48+
"GGshield is not called with flag --insecure when insecure is false",
4949
},
5050
];
5151

52-
testCasesAllowSelfSigned.forEach(({ allowSelfSigned, description }) => {
52+
testCasesInsecure.forEach(({ insecure: insecure, description }) => {
5353
test(description, () => {
5454
process.env.TEST_GLOBAL_VAR = "GlobalValue";
5555

5656
runGGShield.runGGShieldCommand(
5757
{
5858
ggshieldPath: "path/to/ggshield",
5959
apiUrl: "",
60-
allowSelfSigned: allowSelfSigned,
60+
insecure: insecure,
6161
} as GGShieldConfiguration,
6262
["test"],
6363
);
@@ -67,7 +67,7 @@ suite("runGGShieldCommand", () => {
6767
const spawnSyncArgs = spawnSyncMock.lastCall.args;
6868
const args = spawnSyncArgs[1];
6969

70-
assert.strictEqual(args[0] === "--allow-self-signed", allowSelfSigned);
70+
assert.strictEqual(args[0] === "--insecure", insecure);
7171
});
7272
});
7373

0 commit comments

Comments
 (0)