diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index 2c1332f49..5032b3955 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -29,13 +29,13 @@ "Can't parse envFile {0} because of {1}": "Can't parse envFile {0} because of {1}", "Open envFile": "Open envFile", "Yes": "Yes", + "More Information": "More Information", + "Security Warning": "Security Warning", + "The selected launch configuration is configured to launch a web browser but no trusted development certificate was found. Create a trusted self-signed certificate?": "The selected launch configuration is configured to launch a web browser but no trusted development certificate was found. Create a trusted self-signed certificate?", "Self-signed certificate sucessfully {0}": "Self-signed certificate sucessfully {0}", "Couldn't create self-signed certificate. {0}\ncode: {1}\nstdout: {2}": "Couldn't create self-signed certificate. {0}\ncode: {1}\nstdout: {2}", "Show Output": "Show Output", "Couldn't create self-signed certificate. See output for more information.": "Couldn't create self-signed certificate. See output for more information.", - "Not Now": "Not Now", - "More Information": "More Information", - "The selected launch configuration is configured to launch a web browser but no trusted development certificate was found. Create a trusted self-signed certificate?": "The selected launch configuration is configured to launch a web browser but no trusted development certificate was found. Create a trusted self-signed certificate?", "No executable projects": "No executable projects", "Select the project to launch": "Select the project to launch", "Invalid project index": "Invalid project index", @@ -50,6 +50,7 @@ "WARNING": "WARNING", "The C# extension was unable to automatically decode projects in the current workspace to create a runnable launch.json file. A template launch.json file has been created as a placeholder.\n\nIf the server is currently unable to load your project, you can attempt to resolve this by restoring any missing project dependencies (example: run 'dotnet restore') and by fixing any reported errors from building the projects in your workspace.\nIf this allows the server to now load your project then --\n * Delete this file\n * Open the Visual Studio Code command palette (View->Command Palette)\n * run the command: '.NET: Generate Assets for Build and Debug'.\n\nIf your project requires a more complex launch configuration, you may wish to delete this configuration and pick a different template using the 'Add Configuration...' button at the bottom of this file.": "The C# extension was unable to automatically decode projects in the current workspace to create a runnable launch.json file. A template launch.json file has been created as a placeholder.\n\nIf the server is currently unable to load your project, you can attempt to resolve this by restoring any missing project dependencies (example: run 'dotnet restore') and by fixing any reported errors from building the projects in your workspace.\nIf this allows the server to now load your project then --\n * Delete this file\n * Open the Visual Studio Code command palette (View->Command Palette)\n * run the command: '.NET: Generate Assets for Build and Debug'.\n\nIf your project requires a more complex launch configuration, you may wish to delete this configuration and pick a different template using the 'Add Configuration...' button at the bottom of this file.", "Failed to parse tasks.json file: {0}": "Failed to parse tasks.json file: {0}", + "Not Now": "Not Now", "Don't Ask Again": "Don't Ask Again", "Required assets to build and debug are missing from '{0}'. Add them?": "Required assets to build and debug are missing from '{0}'. Add them?", "Cancel": "Cancel", diff --git a/src/shared/configurationProvider.ts b/src/shared/configurationProvider.ts index 8c4360ef6..fdd2e773d 100644 --- a/src/shared/configurationProvider.ts +++ b/src/shared/configurationProvider.ts @@ -150,7 +150,9 @@ export class BaseVsDbgConfigurationProvider implements vscode.DebugConfiguration } if (debugConfiguration.checkForDevCert) { - await this.checkForDevCerts(commonOptions.dotnetPath); + if (!(await this.checkForDevCerts(commonOptions.dotnetPath))) { + return undefined; + } } } @@ -233,70 +235,78 @@ export class BaseVsDbgConfigurationProvider implements vscode.DebugConfiguration } } - private async checkForDevCerts(dotnetPath: string) { - await hasDotnetDevCertsHttps(dotnetPath).then(async (returnData) => { + private async checkForDevCerts(dotnetPath: string): Promise { + let result: boolean | undefined = undefined; + + while (result === undefined) { + const returnData = await hasDotnetDevCertsHttps(dotnetPath); const errorCode = returnData.error?.code; if ( errorCode === CertToolStatusCodes.CertificateNotTrusted || errorCode === CertToolStatusCodes.ErrorNoValidCertificateFound ) { - const labelYes: ActionOption = { - title: vscode.l10n.t('Yes'), - action: async () => { - const returnData = await createSelfSignedCert(dotnetPath); - if (returnData.error === null) { - // if the process returns 0, returnData.error is null, otherwise the return code can be accessed in returnData.error.code - const message = - errorCode === CertToolStatusCodes.CertificateNotTrusted ? 'trusted' : 'created'; - showInformationMessage( - vscode, - vscode.l10n.t('Self-signed certificate sucessfully {0}', message) - ); - } else { - this.csharpOutputChannel.appendLine( - vscode.l10n.t( - `Couldn't create self-signed certificate. {0}\ncode: {1}\nstdout: {2}`, - returnData.error.message, - `${returnData.error.code}`, - returnData.stdout - ) - ); - - const labelShowOutput: ActionOption = { - title: vscode.l10n.t('Show Output'), - action: async () => { - this.csharpOutputChannel.show(); - }, - }; - showWarningMessage( - vscode, - vscode.l10n.t( - "Couldn't create self-signed certificate. See output for more information." - ), - labelShowOutput - ); - } - }, - }; - const labelNotNow = vscode.l10n.t('Not Now'); - const labelMoreInfo: ActionOption = { - title: vscode.l10n.t('More Information'), - action: async () => { - const launchjsonDescriptionURL = 'https://aka.ms/VSCode-CS-CheckForDevCert'; - await vscode.env.openExternal(vscode.Uri.parse(launchjsonDescriptionURL)); - await this.checkForDevCerts(dotnetPath); + const labelYes = vscode.l10n.t('Yes'); + const labelMoreInfo = vscode.l10n.t('More Information'); + + const dialogResult = await vscode.window.showWarningMessage( + vscode.l10n.t('Security Warning'), + { + modal: true, + detail: vscode.l10n.t( + 'The selected launch configuration is configured to launch a web browser but no trusted development certificate was found. Create a trusted self-signed certificate?' + ), }, - }; - showInformationMessage( - vscode, - vscode.l10n.t( - 'The selected launch configuration is configured to launch a web browser but no trusted development certificate was found. Create a trusted self-signed certificate?' - ), labelYes, - labelNotNow, labelMoreInfo ); + + if (dialogResult === labelYes) { + const returnData = await createSelfSignedCert(dotnetPath); + if (returnData.error === null) { + // if the process returns 0, returnData.error is null, otherwise the return code can be accessed in returnData.error.code + const message = errorCode === CertToolStatusCodes.CertificateNotTrusted ? 'trusted' : 'created'; + showInformationMessage( + vscode, + vscode.l10n.t('Self-signed certificate sucessfully {0}', message) + ); + + result = true; + } else { + this.csharpOutputChannel.appendLine( + vscode.l10n.t( + `Couldn't create self-signed certificate. {0}\ncode: {1}\nstdout: {2}`, + returnData.error.message, + `${returnData.error.code}`, + returnData.stdout + ) + ); + + const labelShowOutput: ActionOption = { + title: vscode.l10n.t('Show Output'), + action: async () => { + this.csharpOutputChannel.show(); + }, + }; + showWarningMessage( + vscode, + vscode.l10n.t("Couldn't create self-signed certificate. See output for more information."), + labelShowOutput + ); + + result = false; + } + } else if (dialogResult === labelMoreInfo) { + const launchjsonDescriptionURL = 'https://aka.ms/VSCode-CS-CheckForDevCert'; + await vscode.env.openExternal(vscode.Uri.parse(launchjsonDescriptionURL)); + } else if (dialogResult === undefined) { + // User cancelled dialog and wishes to continue debugging. + result = true; + } + } else { + result = true; } - }); + } + + return result; } }