@@ -74,6 +74,10 @@ export class ConnectionInfo {
7474 }
7575}
7676
77+ export interface ReconnectAction {
78+ ( profile : IConnectionInfo ) : Promise < void > ;
79+ }
80+
7781// ConnectionManager class is the main controller for connection management
7882export default class ConnectionManager {
7983 private _statusView : StatusView ;
@@ -422,17 +426,28 @@ export default class ConnectionManager {
422426 // Check if the error is an expired password
423427 if ( result . errorNumber === Constants . errorPasswordExpired || result . errorNumber === Constants . errorPasswordNeedsReset ) {
424428 // TODO: we should allow the user to change their password here once corefx supports SqlConnection.ChangePassword()
425- Utils . showErrorMsg ( Utils . formatString ( LocalizedConstants . msgConnectionErrorPasswordExpired , result . errorNumber , result . errorMessage ) ) ;
429+ Utils . showErrorMsg ( Utils . formatString ( LocalizedConstants . msgConnectionErrorPasswordExpired ,
430+ result . errorNumber , result . errorMessage ) ) ;
431+ connection . errorNumber = result . errorNumber ;
432+ connection . errorMessage = result . errorMessage ;
433+ } else if ( result . errorNumber === Constants . errorSSLCertificateValidationFailed ) {
434+ this . showInstructionTextAsWarning ( connection . credentials , async updatedConnection => {
435+ vscode . commands . executeCommand ( Constants . cmdConnectObjectExplorerProfile , updatedConnection ) ;
436+ } ) ;
437+ return ;
426438 } else if ( result . errorNumber !== Constants . errorLoginFailed ) {
427439 Utils . showErrorMsg ( Utils . formatString ( LocalizedConstants . msgConnectionError , result . errorNumber , result . errorMessage ) ) ;
428440 // check whether it's a firewall rule error
429441 let firewallResult = await this . firewallService . handleFirewallRule ( result . errorNumber , result . errorMessage ) ;
430442 if ( firewallResult . result && firewallResult . ipAddress ) {
431443 this . _failedUriToFirewallIpMap . set ( fileUri , firewallResult . ipAddress ) ;
432444 }
445+ connection . errorNumber = result . errorNumber ;
446+ connection . errorMessage = result . errorMessage ;
447+ } else {
448+ connection . errorNumber = result . errorNumber ;
449+ connection . errorMessage = result . errorMessage ;
433450 }
434- connection . errorNumber = result . errorNumber ;
435- connection . errorMessage = result . errorMessage ;
436451 } else {
437452 const platformInfo = await PlatformInformation . getCurrent ( ) ;
438453 if ( ! platformInfo . isWindows && result . errorMessage && result . errorMessage . includes ( 'Kerberos' ) ) {
@@ -462,6 +477,27 @@ export default class ConnectionManager {
462477 ) ;
463478 }
464479
480+ public async showInstructionTextAsWarning ( profile : IConnectionInfo , reconnectAction : ReconnectAction ) : Promise < void > {
481+ const instructionText = `${ LocalizedConstants . msgPromptSSLCertificateValidationFailed } ` ;
482+ await this . vscodeWrapper . showWarningMessageAdvanced ( instructionText ,
483+ { modal : false } ,
484+ [
485+ LocalizedConstants . enableTrustServerCertificate ,
486+ LocalizedConstants . readMore ,
487+ LocalizedConstants . cancel
488+ ] )
489+ . then ( async ( selection ) => {
490+ if ( selection && selection === LocalizedConstants . enableTrustServerCertificate ) {
491+ profile . encrypt = 'Mandatory' ;
492+ profile . trustServerCertificate = true ;
493+ await reconnectAction ( profile ) ;
494+ } else if ( selection && selection === LocalizedConstants . readMore ) {
495+ this . vscodeWrapper . openExternal ( Constants . encryptionReadMoreLink ) ;
496+ this . showInstructionTextAsWarning ( profile , reconnectAction ) ;
497+ }
498+ } ) ;
499+ }
500+
465501 private async tryAddMruConnection ( connection : ConnectionInfo , newConnection : IConnectionInfo ) : Promise < void > {
466502 if ( newConnection ) {
467503 let connectionToSave : IConnectionInfo = Object . assign ( { } , newConnection ) ;
0 commit comments