-
Notifications
You must be signed in to change notification settings - Fork 524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for certificates #627
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
83fbf35
Add support for certificates
StephenWeatherford 3d8215d
Count
StephenWeatherford ca699ca
Comment
StephenWeatherford 6cdb233
Make opt-in and provide better error
StephenWeatherford 75c6e05
specify type
StephenWeatherford 653e211
Force rebuild
StephenWeatherford f2de70a
Read cert files
StephenWeatherford 88d5185
Skip URL tests on Linux
StephenWeatherford 2ae3ae4
...and mac
StephenWeatherford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE.md in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as fse from 'fs-extra'; | ||
import * as https from 'https'; | ||
import * as path from 'path'; | ||
import * as vscode from 'vscode'; | ||
import { callWithTelemetryAndErrorHandling, IActionContext } from "vscode-azureextensionui"; | ||
import { ext } from '../extensionVariables'; | ||
import { globAsync } from '../helpers/async'; | ||
import { isLinux, isMac, isWindows } from '../helpers/osVersion'; | ||
|
||
let _systemCertificates: (string | Buffer)[] | undefined; | ||
|
||
export async function getTrustedCertificates(): Promise<(string | Buffer)[]> { | ||
// tslint:disable-next-line:no-function-expression | ||
return callWithTelemetryAndErrorHandling('docker.certificates', async function (this: IActionContext): Promise<(string | Buffer)[]> { | ||
this.suppressTelemetry = true; | ||
|
||
let useCertificateStore: boolean = !!vscode.workspace.getConfiguration('docker').get<boolean>('useCertificateStore'); | ||
this.properties.useCertStore = String(useCertificateStore); | ||
let systemCerts: (string | Buffer)[] = useCertificateStore ? getCertificatesFromSystem() : []; | ||
|
||
let certificatePaths: string[] = vscode.workspace.getConfiguration('docker').get<string[] | undefined>('certificatePaths') || []; | ||
this.properties.certPathsCount = String(certificatePaths.length); | ||
let filesCerts = certificatePaths ? await getCertificatesFromPaths(certificatePaths) : []; | ||
|
||
this.properties.systemCertsCount = String(systemCerts.length); | ||
this.properties.fileCertsCount = String(filesCerts.length); | ||
|
||
let certificates = systemCerts; | ||
certificates.push(...filesCerts); | ||
|
||
return certificates; | ||
}); | ||
} | ||
|
||
async function getCertificatesFromPaths(paths: string[]): Promise<Buffer[]> { | ||
let certs: Buffer[] = []; | ||
|
||
for (let certPath of paths) { | ||
if (!path.isAbsolute(certPath)) { | ||
// tslint:disable-next-line: no-floating-promises | ||
ext.ui.showWarningMessage(`Certificate path "${certPath}" is not an absolute path, ignored.`); | ||
} else { | ||
let isFile = false; | ||
let isFolder = false; | ||
try { | ||
if (await fse.pathExists(certPath)) { | ||
let stat = await fse.stat(certPath); | ||
isFolder = stat.isDirectory(); | ||
isFile = stat.isFile(); | ||
} | ||
} catch { | ||
// Ignore (could be permission issues, for instance) | ||
} | ||
|
||
let certFiles: string[] = []; | ||
if (isFolder) { | ||
let files = await globAsync('**', { absolute: true, nodir: true, cwd: certPath }); | ||
certFiles.push(...files); | ||
} else if (isFile) { | ||
certFiles.push(certPath); | ||
} else { | ||
console.log(`Could not find certificate path "${certPath}.`); | ||
} | ||
|
||
for (let cf of certFiles) { | ||
certs.push(fse.readFileSync(cf)); | ||
} | ||
} | ||
} | ||
|
||
return certs; | ||
} | ||
|
||
function getCertificatesFromSystem(): (string | Buffer)[] { | ||
if (!_systemCertificates) { | ||
// {win,mac}-ca automatically read trusted certificate authorities from the system and place them into the global | ||
// Node agent. We don't want them in the global agent because that will affect all other extensions | ||
// loaded in the same process, which will make them behave inconsistently depending on whether we're loaded. | ||
let previousCertificateAuthorities = https.globalAgent.options.ca; | ||
let certificates: string | Buffer | (string | Buffer)[] = []; | ||
|
||
try { | ||
if (isWindows()) { | ||
require('win-ca'); | ||
} else if (isMac()) { | ||
require('mac-ca'); | ||
} else if (isLinux()) { | ||
} | ||
} finally { | ||
certificates = https.globalAgent.options.ca; | ||
https.globalAgent.options.ca = previousCertificateAuthorities; | ||
} | ||
|
||
if (!certificates) { | ||
certificates = []; | ||
} else if (!Array.isArray(certificates)) { | ||
certificates = [certificates]; | ||
} | ||
|
||
_systemCertificates = certificates; | ||
} | ||
|
||
return _systemCertificates; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to comment this out then you have to set
MOCHA_reporter
somewhere else otherwise the CI builds will never fail for testsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, working on that. The current situation makes it difficult to troubleshoot.