@@ -110,6 +110,10 @@ export interface ICertificateGenerationOptions {
110
110
* How many days the certificate should be valid for.
111
111
*/
112
112
validityInDays ?: number ;
113
+ /**
114
+ * Skip trusting a certificate. Defaults to false.
115
+ */
116
+ skipCertificateTrust ?: boolean ;
113
117
}
114
118
115
119
const MAX_CERTIFICATE_VALIDITY_DAYS : 365 = 365 ;
@@ -135,10 +139,9 @@ export class CertificateManager {
135
139
public async ensureCertificateAsync (
136
140
canGenerateNewCertificate : boolean ,
137
141
terminal : ITerminal ,
138
- generationOptions ?: ICertificateGenerationOptions
142
+ options ?: ICertificateGenerationOptions
139
143
) : Promise < ICertificate > {
140
- const optionsWithDefaults : Required < ICertificateGenerationOptions > =
141
- applyDefaultOptions ( generationOptions ) ;
144
+ const optionsWithDefaults : Required < ICertificateGenerationOptions > = applyDefaultOptions ( options ) ;
142
145
143
146
const { certificateData : existingCert , keyData : existingKey } = this . _certificateStore ;
144
147
@@ -226,7 +229,9 @@ export class CertificateManager {
226
229
if ( canGenerateNewCertificate ) {
227
230
messages . push ( 'Attempting to untrust the certificate and generate a new one.' ) ;
228
231
terminal . writeWarningLine ( messages . join ( ' ' ) ) ;
229
- await this . untrustCertificateAsync ( terminal ) ;
232
+ if ( ! options ?. skipCertificateTrust ) {
233
+ await this . untrustCertificateAsync ( terminal ) ;
234
+ }
230
235
return await this . _ensureCertificateInternalAsync ( optionsWithDefaults , terminal ) ;
231
236
} else {
232
237
messages . push (
@@ -732,10 +737,9 @@ export class CertificateManager {
732
737
} ) ;
733
738
}
734
739
735
- const trustCertificateResult : boolean = await this . _tryTrustCertificateAsync (
736
- tempCertificatePath ,
737
- terminal
738
- ) ;
740
+ const trustCertificateResult : boolean = options . skipCertificateTrust
741
+ ? true
742
+ : await this . _tryTrustCertificateAsync ( tempCertificatePath , terminal ) ;
739
743
740
744
let subjectAltNames : readonly string [ ] | undefined ;
741
745
if ( trustCertificateResult ) {
@@ -787,6 +791,7 @@ function applyDefaultOptions(
787
791
) : Required < ICertificateGenerationOptions > {
788
792
const subjectNames : ReadonlyArray < string > | undefined = options ?. subjectAltNames ;
789
793
const subjectIpAddresses : ReadonlyArray < string > | undefined = options ?. subjectIPAddresses ;
794
+ const skipCertificateTrust : boolean | undefined = options ?. skipCertificateTrust || false ;
790
795
return {
791
796
subjectAltNames : subjectNames ?. length ? subjectNames : DEFAULT_CERTIFICATE_SUBJECT_NAMES ,
792
797
subjectIPAddresses : subjectIpAddresses ?. length
@@ -795,7 +800,8 @@ function applyDefaultOptions(
795
800
validityInDays : Math . min (
796
801
MAX_CERTIFICATE_VALIDITY_DAYS ,
797
802
options ?. validityInDays ?? MAX_CERTIFICATE_VALIDITY_DAYS
798
- )
803
+ ) ,
804
+ skipCertificateTrust : skipCertificateTrust
799
805
} ;
800
806
}
801
807
0 commit comments