@@ -468,6 +468,70 @@ public async Task TestEncryptMailboxesAsync ()
468
468
}
469
469
}
470
470
471
+ [ Test ]
472
+ public void TestEncryptDnsNames ( )
473
+ {
474
+ var certificate = SecureMimeTestsBase . DomainCertificate ;
475
+
476
+ foreach ( var domain in certificate . DnsNames ) {
477
+ var entity = new TextPart ( "plain" ) { Text = "This is some text..." } ;
478
+ var mailbox = new MailboxAddress ( "MimeKit UnitTests" , "mimekit@" + domain ) ;
479
+ var mailboxes = new [ ] { mailbox } ;
480
+
481
+ using ( var ctx = CreateContext ( ) ) {
482
+ ApplicationPkcs7Mime encrypted ;
483
+ MimeEntity decrypted ;
484
+ TextPart text ;
485
+
486
+ ctx . Import ( certificate . FileName , "no.secret" ) ;
487
+
488
+ encrypted = ApplicationPkcs7Mime . Encrypt ( mailboxes , entity ) ;
489
+ decrypted = encrypted . Decrypt ( ctx ) ;
490
+ Assert . That ( decrypted , Is . InstanceOf < TextPart > ( ) , "Decrypted from Encrypt(mailboxes, entity)" ) ;
491
+ text = ( TextPart ) decrypted ;
492
+ Assert . That ( text . Text , Is . EqualTo ( entity . Text ) , "Decrypted text" ) ;
493
+
494
+ encrypted = ApplicationPkcs7Mime . Encrypt ( ctx , mailboxes , entity ) ;
495
+ decrypted = encrypted . Decrypt ( ctx ) ;
496
+ Assert . That ( decrypted , Is . InstanceOf < TextPart > ( ) , "Encrypt(ctx, mailboxes, entity)" ) ;
497
+ text = ( TextPart ) decrypted ;
498
+ Assert . That ( text . Text , Is . EqualTo ( entity . Text ) , "Decrypted text" ) ;
499
+ }
500
+ }
501
+ }
502
+
503
+ [ Test ]
504
+ public async Task TestEncryptDnsNamesAsync ( )
505
+ {
506
+ var certificate = SecureMimeTestsBase . DomainCertificate ;
507
+
508
+ foreach ( var domain in certificate . DnsNames ) {
509
+ var entity = new TextPart ( "plain" ) { Text = "This is some text..." } ;
510
+ var mailbox = new MailboxAddress ( "MimeKit UnitTests" , "mimekit@" + domain ) ;
511
+ var mailboxes = new [ ] { mailbox } ;
512
+
513
+ using ( var ctx = CreateContext ( ) ) {
514
+ ApplicationPkcs7Mime encrypted ;
515
+ MimeEntity decrypted ;
516
+ TextPart text ;
517
+
518
+ await ctx . ImportAsync ( certificate . FileName , "no.secret" ) . ConfigureAwait ( false ) ;
519
+
520
+ encrypted = await ApplicationPkcs7Mime . EncryptAsync ( mailboxes , entity ) . ConfigureAwait ( false ) ;
521
+ decrypted = await encrypted . DecryptAsync ( ctx ) . ConfigureAwait ( false ) ;
522
+ Assert . That ( decrypted , Is . InstanceOf < TextPart > ( ) , "Decrypted from EncryptAsync(mailboxes, entity)" ) ;
523
+ text = ( TextPart ) decrypted ;
524
+ Assert . That ( text . Text , Is . EqualTo ( entity . Text ) , "Decrypted text" ) ;
525
+
526
+ encrypted = await ApplicationPkcs7Mime . EncryptAsync ( ctx , mailboxes , entity ) . ConfigureAwait ( false ) ;
527
+ decrypted = await encrypted . DecryptAsync ( ctx ) . ConfigureAwait ( false ) ;
528
+ Assert . That ( decrypted , Is . InstanceOf < TextPart > ( ) , "EncryptAsync(ctx, mailboxes, entity)" ) ;
529
+ text = ( TextPart ) decrypted ;
530
+ Assert . That ( text . Text , Is . EqualTo ( entity . Text ) , "Decrypted text" ) ;
531
+ }
532
+ }
533
+ }
534
+
471
535
void AssertSignResults ( SMimeCertificate certificate , SecureMimeContext ctx , ApplicationPkcs7Mime signed , TextPart entity )
472
536
{
473
537
var signatures = signed . Verify ( ctx , out var encapsulated ) ;
@@ -578,6 +642,42 @@ public async Task TestSignMailboxAsync ()
578
642
}
579
643
}
580
644
645
+ [ Test ]
646
+ public void TestSignDnsNames ( )
647
+ {
648
+ var certificate = SecureMimeTestsBase . DomainCertificate ;
649
+
650
+ using ( var ctx = CreateContext ( ) ) {
651
+ ImportAll ( ctx ) ;
652
+
653
+ foreach ( var domain in certificate . DnsNames ) {
654
+ var mailbox = new MailboxAddress ( "MimeKit UnitTests" , "mimekit@" + domain ) ;
655
+ var entity = new TextPart ( "plain" ) { Text = "This is some text..." } ;
656
+
657
+ var signed = ApplicationPkcs7Mime . Sign ( ctx , mailbox , DigestAlgorithm . Sha224 , entity ) ;
658
+ AssertSignResults ( certificate , ctx , signed , entity ) ;
659
+ }
660
+ }
661
+ }
662
+
663
+ [ Test ]
664
+ public async Task TestSignDnsNamesAsync ( )
665
+ {
666
+ var certificate = SecureMimeTestsBase . DomainCertificate ;
667
+
668
+ using ( var ctx = CreateContext ( ) ) {
669
+ await ImportAllAsync ( ctx ) . ConfigureAwait ( false ) ;
670
+
671
+ foreach ( var domain in certificate . DnsNames ) {
672
+ var mailbox = new MailboxAddress ( "MimeKit UnitTests" , "mimekit@" + domain ) ;
673
+ var entity = new TextPart ( "plain" ) { Text = "This is some text..." } ;
674
+
675
+ var signed = await ApplicationPkcs7Mime . SignAsync ( ctx , mailbox , DigestAlgorithm . Sha224 , entity ) . ConfigureAwait ( false ) ;
676
+ AssertSignResults ( certificate , ctx , signed , entity ) ;
677
+ }
678
+ }
679
+ }
680
+
581
681
void AssertSignAndEncryptResults ( SMimeCertificate certificate , SecureMimeContext ctx , ApplicationPkcs7Mime encrypted , TextPart entity )
582
682
{
583
683
var decrypted = encrypted . Decrypt ( ctx ) ;
@@ -753,6 +853,44 @@ public async Task TestSignAndEncryptMailboxesAsync ()
753
853
}
754
854
}
755
855
}
856
+
857
+ [ Test ]
858
+ public void TestSignAndEncryptDnsNames ( )
859
+ {
860
+ var certificate = SecureMimeTestsBase . DomainCertificate ;
861
+
862
+ using ( var ctx = CreateContext ( ) ) {
863
+ ImportAll ( ctx ) ;
864
+
865
+ foreach ( var domain in certificate . DnsNames ) {
866
+ var mailbox = new MailboxAddress ( "MimeKit UnitTests" , "mimekit@" + domain ) ;
867
+ var entity = new TextPart ( "plain" ) { Text = "This is some text..." } ;
868
+ var recipients = new MailboxAddress [ ] { mailbox } ;
869
+
870
+ var encrypted = ApplicationPkcs7Mime . SignAndEncrypt ( mailbox , DigestAlgorithm . Sha224 , recipients , entity ) ;
871
+ AssertSignAndEncryptResults ( certificate , ctx , encrypted , entity ) ;
872
+ }
873
+ }
874
+ }
875
+
876
+ [ Test ]
877
+ public async Task TestSignAndEncryptDnsNamesAsync ( )
878
+ {
879
+ var certificate = SecureMimeTestsBase . DomainCertificate ;
880
+
881
+ using ( var ctx = CreateContext ( ) ) {
882
+ await ImportAllAsync ( ctx ) . ConfigureAwait ( false ) ;
883
+
884
+ foreach ( var domain in certificate . DnsNames ) {
885
+ var mailbox = new MailboxAddress ( "MimeKit UnitTests" , "mimekit@" + domain ) ;
886
+ var entity = new TextPart ( "plain" ) { Text = "This is some text..." } ;
887
+ var recipients = new MailboxAddress [ ] { mailbox } ;
888
+
889
+ var encrypted = await ApplicationPkcs7Mime . SignAndEncryptAsync ( mailbox , DigestAlgorithm . Sha224 , recipients , entity ) . ConfigureAwait ( false ) ;
890
+ await AssertSignAndEncryptResultsAsync ( certificate , ctx , encrypted , entity ) . ConfigureAwait ( false ) ;
891
+ }
892
+ }
893
+ }
756
894
}
757
895
758
896
[ TestFixture ]
0 commit comments