|
6 | 6 | import * as vscode from 'vscode'; |
7 | 7 |
|
8 | 8 | import { RemoteAttachPicker, DotNetAttachItemsProviderFactory, AttachPicker, AttachItem } from '../features/processPicker'; |
| 9 | +import { Options } from '../omnisharp/options'; |
9 | 10 | import { PlatformInformation } from '../platform'; |
10 | | - |
| 11 | +import { hasDotnetDevCertsHttps, createSelfSignedCert, CertToolStatusCodes } from '../utils/DotnetDevCertsHttps'; |
| 12 | +import { EventStream } from '../EventStream'; |
| 13 | +import { DevCertCreationFailure, ShowChannel } from '../omnisharp/loggingEvents'; |
| 14 | + |
11 | 15 | export class DotnetDebugConfigurationProvider implements vscode.DebugConfigurationProvider { |
12 | | - constructor(public platformInformation: PlatformInformation) {} |
| 16 | + constructor(public platformInformation: PlatformInformation, private readonly eventStream: EventStream, private options: Options) {} |
13 | 17 |
|
14 | 18 | public async resolveDebugConfigurationWithSubstitutedVariables(folder: vscode.WorkspaceFolder | undefined, debugConfiguration: vscode.DebugConfiguration, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration | null | undefined> |
15 | 19 | { |
@@ -59,7 +63,66 @@ export class DotnetDebugConfigurationProvider implements vscode.DebugConfigurati |
59 | 63 | return undefined; |
60 | 64 | } |
61 | 65 | } |
| 66 | + |
| 67 | + // We want to ask the user if we should run dotnet dev-certs https --trust, but this doesn't work in a few cases -- |
| 68 | + // Linux -- not supported by the .NET CLI as there isn't a single root cert store |
| 69 | + // VS Code remoting/Web UI -- the trusted cert work would need to happen on the client machine, but we don't have a way to run code there currently |
| 70 | + // pipeTransport -- the dev cert on the server will be different from the client |
| 71 | + if (!this.platformInformation.isLinux() && !vscode.env.remoteName && vscode.env.uiKind != vscode.UIKind.Web && !debugConfiguration.pipeTransport) |
| 72 | + { |
| 73 | + if(debugConfiguration.checkForDevCert === undefined && debugConfiguration.serverReadyAction) |
| 74 | + { |
| 75 | + debugConfiguration.checkForDevCert = true; |
| 76 | + } |
| 77 | + |
| 78 | + if (debugConfiguration.checkForDevCert) |
| 79 | + { |
| 80 | + checkForDevCerts(this.options.dotNetCliPaths, this.eventStream); |
| 81 | + } |
| 82 | + } |
62 | 83 |
|
63 | 84 | return debugConfiguration; |
64 | 85 | } |
65 | 86 | } |
| 87 | + |
| 88 | +function checkForDevCerts(dotNetCliPaths: string[], eventStream: EventStream){ |
| 89 | + hasDotnetDevCertsHttps(dotNetCliPaths).then(async (returnData) => { |
| 90 | + let errorCode = returnData.error?.code; |
| 91 | + if(errorCode === CertToolStatusCodes.CertificateNotTrusted || errorCode === CertToolStatusCodes.ErrorNoValidCertificateFound) |
| 92 | + { |
| 93 | + const labelYes: string = "Yes"; |
| 94 | + const labelNotNow: string = "Not Now"; |
| 95 | + const labelMoreInfo: string = "More Information"; |
| 96 | + |
| 97 | + const result = await vscode.window.showInformationMessage( |
| 98 | + "The selected launch configuration is configured to launch a web browser but no trusted development certificate was found. Create a trusted self-signed certificate?", |
| 99 | + { title:labelYes }, { title:labelNotNow, isCloseAffordance: true }, { title:labelMoreInfo } |
| 100 | + ); |
| 101 | + if (result?.title === labelYes) |
| 102 | + { |
| 103 | + let returnData = await createSelfSignedCert(dotNetCliPaths); |
| 104 | + if (returnData.error === null) //if the prcess returns 0, returnData.error is null, otherwise the return code can be acessed in returnData.error.code |
| 105 | + { |
| 106 | + let message = errorCode === CertToolStatusCodes.CertificateNotTrusted ? 'trusted' : 'created'; |
| 107 | + vscode.window.showInformationMessage(`Self-signed certificate sucessfully ${message}.`); |
| 108 | + } |
| 109 | + else |
| 110 | + { |
| 111 | + eventStream.post(new DevCertCreationFailure(`${returnData.error.message}\ncode: ${returnData.error.code}\nstdout: ${returnData.stdout}`)); |
| 112 | + |
| 113 | + const labelShowOutput: string = "Show Output"; |
| 114 | + const result = await vscode.window.showWarningMessage("Couldn't create self-signed certificate. See output for more information.", labelShowOutput); |
| 115 | + if (result === labelShowOutput){ |
| 116 | + eventStream.post(new ShowChannel()); |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + if (result?.title === labelMoreInfo) |
| 121 | + { |
| 122 | + const launchjsonDescriptionURL = 'https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#check-for-devcert'; |
| 123 | + vscode.env.openExternal(vscode.Uri.parse(launchjsonDescriptionURL)); |
| 124 | + checkForDevCerts(dotNetCliPaths, eventStream); |
| 125 | + } |
| 126 | + } |
| 127 | + }); |
| 128 | +} |
0 commit comments