Skip to content
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

Move checkDevCert to be Modal #7704

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
122 changes: 66 additions & 56 deletions src/shared/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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<boolean> {
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;
}
}
Loading