@@ -116,7 +116,7 @@ private void ListCertificates()
116
116
var certificates = store . Certificates ;
117
117
foreach ( var certificate in certificates )
118
118
{
119
- Output . WriteLine ( $ "Certificate: '{ Convert . ToBase64String ( certificate . Export ( X509ContentType . Cert ) ) } '.") ;
119
+ Output . WriteLine ( $ "Certificate: { certificate . Subject } '{ Convert . ToBase64String ( certificate . Export ( X509ContentType . Cert ) ) } '.") ;
120
120
certificate . Dispose ( ) ;
121
121
}
122
122
@@ -225,7 +225,7 @@ public void EnsureCreateHttpsCertificate_CanExportTheCertInPemFormat_WithoutKey(
225
225
public void EnsureCreateHttpsCertificate_CanImport_ExportedPfx ( )
226
226
{
227
227
// Arrange
228
- const string CertificateName = nameof ( EnsureCreateHttpsCertificate_DoesNotCreateACertificate_WhenThereIsAnExistingHttpsCertificates ) + ".pfx" ;
228
+ const string CertificateName = nameof ( EnsureCreateHttpsCertificate_CanImport_ExportedPfx ) + ".pfx" ;
229
229
var certificatePassword = Guid . NewGuid ( ) . ToString ( ) ;
230
230
231
231
_fixture . CleanupCertificates ( ) ;
@@ -258,7 +258,7 @@ public void EnsureCreateHttpsCertificate_CanImport_ExportedPfx()
258
258
public void EnsureCreateHttpsCertificate_CanImport_ExportedPfx_FailsIfThereAreCertificatesPresent ( )
259
259
{
260
260
// Arrange
261
- const string CertificateName = nameof ( EnsureCreateHttpsCertificate_DoesNotCreateACertificate_WhenThereIsAnExistingHttpsCertificates ) + ".pfx" ;
261
+ const string CertificateName = nameof ( EnsureCreateHttpsCertificate_CanImport_ExportedPfx_FailsIfThereAreCertificatesPresent ) + ".pfx" ;
262
262
var certificatePassword = Guid . NewGuid ( ) . ToString ( ) ;
263
263
264
264
_fixture . CleanupCertificates ( ) ;
@@ -280,6 +280,47 @@ public void EnsureCreateHttpsCertificate_CanImport_ExportedPfx_FailsIfThereAreCe
280
280
Assert . Equal ( ImportCertificateResult . ExistingCertificatesPresent , result ) ;
281
281
}
282
282
283
+ [ ConditionalFact ]
284
+ [ SkipOnHelix ( "https://github.com/dotnet/aspnetcore/issues/6720" , Queues = "All.OSX" ) ]
285
+ public void EnsureCreateHttpsCertificate_CannotImportIfTheSubjectNameIsWrong ( )
286
+ {
287
+ // Arrange
288
+ const string CertificateName = nameof ( EnsureCreateHttpsCertificate_CannotImportIfTheSubjectNameIsWrong ) + ".pfx" ;
289
+ var certificatePassword = Guid . NewGuid ( ) . ToString ( ) ;
290
+
291
+ _fixture . CleanupCertificates ( ) ;
292
+
293
+ var now = DateTimeOffset . UtcNow ;
294
+ now = new DateTimeOffset ( now . Year , now . Month , now . Day , now . Hour , now . Minute , now . Second , 0 , now . Offset ) ;
295
+ var creation = _manager . EnsureAspNetCoreHttpsDevelopmentCertificate ( now , now . AddYears ( 1 ) , path : null , trust : false , isInteractive : false ) ;
296
+ Output . WriteLine ( creation . ToString ( ) ) ;
297
+ ListCertificates ( ) ;
298
+
299
+ var httpsCertificate = _manager . ListCertificates ( StoreName . My , StoreLocation . CurrentUser , isValid : false ) . Single ( c => c . Subject == TestCertificateSubject ) ;
300
+
301
+ _manager . CleanupHttpsCertificates ( ) ;
302
+
303
+ using var privateKey = httpsCertificate . GetRSAPrivateKey ( ) ;
304
+ var csr = new CertificateRequest ( httpsCertificate . Subject + "Not" , privateKey , HashAlgorithmName . SHA256 , RSASignaturePadding . Pkcs1 ) ;
305
+ foreach ( var extension in httpsCertificate . Extensions )
306
+ {
307
+ csr . CertificateExtensions . Add ( extension ) ;
308
+ }
309
+ var wrongSubjectCertificate = csr . CreateSelfSigned ( httpsCertificate . NotBefore , httpsCertificate . NotAfter ) ;
310
+
311
+ Assert . True ( CertificateManager . IsHttpsDevelopmentCertificate ( wrongSubjectCertificate ) ) ;
312
+ Assert . NotEqual ( _manager . Subject , wrongSubjectCertificate . Subject ) ;
313
+
314
+ File . WriteAllBytes ( CertificateName , wrongSubjectCertificate . Export ( X509ContentType . Pfx , certificatePassword ) ) ;
315
+
316
+ // Act
317
+ var result = _manager . ImportCertificate ( CertificateName , certificatePassword ) ;
318
+
319
+ // Assert
320
+ Assert . Equal ( ImportCertificateResult . NoDevelopmentHttpsCertificate , result ) ;
321
+ Assert . Empty ( _manager . ListCertificates ( StoreName . My , StoreLocation . CurrentUser , isValid : false ) ) ;
322
+ }
323
+
283
324
[ ConditionalFact ]
284
325
[ SkipOnHelix ( "https://github.com/dotnet/aspnetcore/issues/6720" , Queues = "All.OSX" ) ]
285
326
public void EnsureCreateHttpsCertificate_CanExportTheCertInPemFormat_WithoutPassword ( )
0 commit comments