Skip to content

Commit f70132e

Browse files
GabrielCousinsevbch
authored andcommitted
feat: disable ssl checks
1 parent 179d869 commit f70132e

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/lib/ggshield-configuration-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ export async function getConfiguration(
1616
const ggshieldPath: string | undefined = config.get("GGShieldPath");
1717
const apiUrl: string | undefined = config.get("apiUrl");
1818
const allowSelfSigned: boolean = config.get("allowSelfSigned", false);
19+
const ignoreSSLErrors = allowSelfSigned;
1920

2021
const pathToGGShield: string = await getGGShield(
2122
os.platform(),
2223
os.arch(),
2324
context,
24-
outputChannel
25+
outputChannel,
26+
ignoreSSLErrors
2527
);
2628

2729
return new GGShieldConfiguration(

src/lib/ggshield-resolver-utils.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from "path";
22
import * as fs from "fs";
33
import * as tar from "tar";
44
import axios, { AxiosRequestConfig} from "axios";
5+
import { Agent } from "https";
56

67
const AdmZip = require("adm-zip");
78
import { ExtensionContext, OutputChannel } from "vscode";
@@ -23,7 +24,8 @@ export async function getGGShield(
2324
platform: NodeJS.Platform,
2425
arch: string,
2526
context: ExtensionContext,
26-
outputChannel: OutputChannel
27+
outputChannel: OutputChannel,
28+
ignoreSSLErrors: boolean
2729
): Promise<string> {
2830
const version = fs
2931
.readFileSync(path.join(context.extensionPath, "ggshield_version"), "utf8")
@@ -54,7 +56,7 @@ export async function getGGShield(
5456
}
5557
fs.mkdirSync(ggshieldFolder);
5658
// install GGShield
57-
await installGGShield(platform, arch, ggshieldFolder, version);
59+
await installGGShield(platform, arch, ggshieldFolder, version, ignoreSSLErrors);
5860
outputChannel.appendLine(
5961
`Updated to GGShield v${version}. Checkout https://github.com/GitGuardian/ggshield for more info.`
6062
);
@@ -132,7 +134,8 @@ export async function installGGShield(
132134
platform: NodeJS.Platform,
133135
arch: string,
134136
ggshieldFolder: string,
135-
version: string
137+
version: string,
138+
ignoreSSLErrors: boolean,
136139
): Promise<void> {
137140
let extension: string = "";
138141
switch (platform) {
@@ -153,7 +156,7 @@ export async function installGGShield(
153156
version
154157
)}.${extension}`;
155158
const downloadUrl: string = `https://github.com/GitGuardian/ggshield/releases/download/v${version}/${fileName}`;
156-
await downloadGGShieldFromGitHub(fileName, downloadUrl, ggshieldFolder);
159+
await downloadGGShieldFromGitHub(fileName, downloadUrl, ggshieldFolder, ignoreSSLErrors);
157160
extractGGShieldBinary(path.join(ggshieldFolder, fileName), ggshieldFolder);
158161
}
159162

@@ -189,12 +192,21 @@ export function extractGGShieldBinary(
189192
async function downloadGGShieldFromGitHub(
190193
fileName: string,
191194
downloadUrl: string,
192-
ggshieldFolder: string
195+
ggshieldFolder: string,
196+
ignoreSSLErrors: boolean
193197
): Promise<void> {
194198
console.log(`Downloading GGShield from ${downloadUrl}`);
199+
200+
const instance = ignoreSSLErrors
201+
? new Agent({
202+
rejectUnauthorized: false,
203+
})
204+
: undefined;
205+
195206
const { data } = await axios.get(downloadUrl, {
196207
...defaultRequestConfig,
197-
responseType: 'arraybuffer'
208+
responseType: 'arraybuffer',
209+
httpsAgent: instance
198210
});
199211

200212
fs.writeFileSync(path.join(ggshieldFolder, fileName), data);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ suite("getGGShield integration tests", async () => {
5454
platform,
5555
arch,
5656
mockContext,
57-
outputChannel
57+
outputChannel,
58+
false
5859
);
5960

6061
assert.strictEqual(result, binaryPath);
@@ -79,7 +80,8 @@ suite("getGGShield integration tests", async () => {
7980
platform,
8081
arch,
8182
mockContext,
82-
outputChannel
83+
outputChannel,
84+
false
8385
);
8486

8587
assert(fs.existsSync(result));
@@ -102,7 +104,8 @@ suite("getGGShield integration tests", async () => {
102104
platform,
103105
arch,
104106
mockContext,
105-
outputChannel
107+
outputChannel,
108+
false
106109
);
107110

108111
assert(fs.existsSync(result));

0 commit comments

Comments
 (0)