Skip to content

Commit f679df2

Browse files
committed
Move checkDevCert to be Modal
This PR converts the checkDevCert method to block the debug session from starting as it waits for user input.
1 parent 3abec2c commit f679df2

File tree

2 files changed

+70
-59
lines changed

2 files changed

+70
-59
lines changed

l10n/bundle.l10n.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
"Can't parse envFile {0} because of {1}": "Can't parse envFile {0} because of {1}",
3030
"Open envFile": "Open envFile",
3131
"Yes": "Yes",
32+
"More Information": "More Information",
33+
"Security Warning": "Security Warning",
34+
"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?",
3235
"Self-signed certificate sucessfully {0}": "Self-signed certificate sucessfully {0}",
3336
"Couldn't create self-signed certificate. {0}\ncode: {1}\nstdout: {2}": "Couldn't create self-signed certificate. {0}\ncode: {1}\nstdout: {2}",
3437
"Show Output": "Show Output",
3538
"Couldn't create self-signed certificate. See output for more information.": "Couldn't create self-signed certificate. See output for more information.",
36-
"Not Now": "Not Now",
37-
"More Information": "More Information",
38-
"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?",
3939
"No executable projects": "No executable projects",
4040
"Select the project to launch": "Select the project to launch",
4141
"Invalid project index": "Invalid project index",
@@ -50,6 +50,7 @@
5050
"WARNING": "WARNING",
5151
"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.",
5252
"Failed to parse tasks.json file: {0}": "Failed to parse tasks.json file: {0}",
53+
"Not Now": "Not Now",
5354
"Don't Ask Again": "Don't Ask Again",
5455
"Required assets to build and debug are missing from '{0}'. Add them?": "Required assets to build and debug are missing from '{0}'. Add them?",
5556
"Cancel": "Cancel",

src/shared/configurationProvider.ts

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ export class BaseVsDbgConfigurationProvider implements vscode.DebugConfiguration
150150
}
151151

152152
if (debugConfiguration.checkForDevCert) {
153-
await this.checkForDevCerts(commonOptions.dotnetPath);
153+
if (!(await this.checkForDevCerts(commonOptions.dotnetPath))) {
154+
return undefined;
155+
}
154156
}
155157
}
156158

@@ -233,70 +235,78 @@ export class BaseVsDbgConfigurationProvider implements vscode.DebugConfiguration
233235
}
234236
}
235237

236-
private async checkForDevCerts(dotnetPath: string) {
237-
await hasDotnetDevCertsHttps(dotnetPath).then(async (returnData) => {
238+
private async checkForDevCerts(dotnetPath: string): Promise<boolean> {
239+
let result: boolean | undefined = undefined;
240+
241+
while (result === undefined) {
242+
const returnData = await hasDotnetDevCertsHttps(dotnetPath);
238243
const errorCode = returnData.error?.code;
239244
if (
240245
errorCode === CertToolStatusCodes.CertificateNotTrusted ||
241246
errorCode === CertToolStatusCodes.ErrorNoValidCertificateFound
242247
) {
243-
const labelYes: ActionOption = {
244-
title: vscode.l10n.t('Yes'),
245-
action: async () => {
246-
const returnData = await createSelfSignedCert(dotnetPath);
247-
if (returnData.error === null) {
248-
// if the process returns 0, returnData.error is null, otherwise the return code can be accessed in returnData.error.code
249-
const message =
250-
errorCode === CertToolStatusCodes.CertificateNotTrusted ? 'trusted' : 'created';
251-
showInformationMessage(
252-
vscode,
253-
vscode.l10n.t('Self-signed certificate sucessfully {0}', message)
254-
);
255-
} else {
256-
this.csharpOutputChannel.appendLine(
257-
vscode.l10n.t(
258-
`Couldn't create self-signed certificate. {0}\ncode: {1}\nstdout: {2}`,
259-
returnData.error.message,
260-
`${returnData.error.code}`,
261-
returnData.stdout
262-
)
263-
);
264-
265-
const labelShowOutput: ActionOption = {
266-
title: vscode.l10n.t('Show Output'),
267-
action: async () => {
268-
this.csharpOutputChannel.show();
269-
},
270-
};
271-
showWarningMessage(
272-
vscode,
273-
vscode.l10n.t(
274-
"Couldn't create self-signed certificate. See output for more information."
275-
),
276-
labelShowOutput
277-
);
278-
}
279-
},
280-
};
281-
const labelNotNow = vscode.l10n.t('Not Now');
282-
const labelMoreInfo: ActionOption = {
283-
title: vscode.l10n.t('More Information'),
284-
action: async () => {
285-
const launchjsonDescriptionURL = 'https://aka.ms/VSCode-CS-CheckForDevCert';
286-
await vscode.env.openExternal(vscode.Uri.parse(launchjsonDescriptionURL));
287-
await this.checkForDevCerts(dotnetPath);
248+
const labelYes = vscode.l10n.t('Yes');
249+
const labelMoreInfo = vscode.l10n.t('More Information');
250+
251+
const dialogResult = await vscode.window.showWarningMessage(
252+
vscode.l10n.t('Security Warning'),
253+
{
254+
modal: true,
255+
detail: vscode.l10n.t(
256+
'The selected launch configuration is configured to launch a web browser but no trusted development certificate was found. Create a trusted self-signed certificate?'
257+
),
288258
},
289-
};
290-
showInformationMessage(
291-
vscode,
292-
vscode.l10n.t(
293-
'The selected launch configuration is configured to launch a web browser but no trusted development certificate was found. Create a trusted self-signed certificate?'
294-
),
295259
labelYes,
296-
labelNotNow,
297260
labelMoreInfo
298261
);
262+
263+
if (dialogResult === labelYes) {
264+
const returnData = await createSelfSignedCert(dotnetPath);
265+
if (returnData.error === null) {
266+
// if the process returns 0, returnData.error is null, otherwise the return code can be accessed in returnData.error.code
267+
const message = errorCode === CertToolStatusCodes.CertificateNotTrusted ? 'trusted' : 'created';
268+
showInformationMessage(
269+
vscode,
270+
vscode.l10n.t('Self-signed certificate sucessfully {0}', message)
271+
);
272+
273+
result = true;
274+
} else {
275+
this.csharpOutputChannel.appendLine(
276+
vscode.l10n.t(
277+
`Couldn't create self-signed certificate. {0}\ncode: {1}\nstdout: {2}`,
278+
returnData.error.message,
279+
`${returnData.error.code}`,
280+
returnData.stdout
281+
)
282+
);
283+
284+
const labelShowOutput: ActionOption = {
285+
title: vscode.l10n.t('Show Output'),
286+
action: async () => {
287+
this.csharpOutputChannel.show();
288+
},
289+
};
290+
showWarningMessage(
291+
vscode,
292+
vscode.l10n.t("Couldn't create self-signed certificate. See output for more information."),
293+
labelShowOutput
294+
);
295+
296+
result = false;
297+
}
298+
} else if (dialogResult === labelMoreInfo) {
299+
const launchjsonDescriptionURL = 'https://aka.ms/VSCode-CS-CheckForDevCert';
300+
await vscode.env.openExternal(vscode.Uri.parse(launchjsonDescriptionURL));
301+
} else if (dialogResult === undefined) {
302+
// User cancelled dialog and wishes to continue debugging.
303+
result = true;
304+
}
305+
} else {
306+
result = true;
299307
}
300-
});
308+
}
309+
310+
return result;
301311
}
302312
}

0 commit comments

Comments
 (0)