@@ -24,13 +24,18 @@ public abstract partial class PfxIterationCountTests
2424
2525 [ ConditionalTheory ]
2626 [ MemberData ( nameof ( GetCertsWith_IterationCountNotExceedingDefaultLimit_AndNullOrEmptyPassword_MemberData ) ) ]
27- public void Import_IterationCounLimitNotExceeded_Succeeds ( string name , bool usesPbes2 , byte [ ] blob , long iterationCount )
27+ public void Import_IterationCounLimitNotExceeded_Succeeds ( string name , bool usesPbes2 , byte [ ] blob , long iterationCount , bool usesRC2 )
2828 {
2929 if ( usesPbes2 && ! PfxTests . Pkcs12PBES2Supported )
3030 {
3131 throw new SkipTestException ( name + " uses PBES2, which is not supported on this version." ) ;
3232 }
3333
34+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
35+ {
36+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
37+ }
38+
3439 if ( PfxTests . IsPkcs12IterationCountAllowed ( iterationCount , PfxTests . DefaultIterations ) )
3540 {
3641 X509Certificate cert = Import ( blob ) ;
@@ -40,7 +45,7 @@ public void Import_IterationCounLimitNotExceeded_Succeeds(string name, bool uses
4045
4146 [ ConditionalTheory ]
4247 [ MemberData ( nameof ( GetCertsWith_IterationCountExceedingDefaultLimit_MemberData ) ) ]
43- public void Import_IterationCountLimitExceeded_Throws ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount )
48+ public void Import_IterationCountLimitExceeded_Throws ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount , bool usesRC2 )
4449 {
4550 _ = password ;
4651 _ = iterationCount ;
@@ -50,13 +55,18 @@ public void Import_IterationCountLimitExceeded_Throws(string name, string passwo
5055 throw new SkipTestException ( name + " uses PBES2, which is not supported on this version." ) ;
5156 }
5257
58+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
59+ {
60+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
61+ }
62+
5363 CryptographicException ce = Assert . Throws < CryptographicException > ( ( ) => Import ( blob ) ) ;
5464 Assert . Contains ( FwlinkId , ce . Message ) ;
5565 }
5666
5767 [ ConditionalTheory ]
5868 [ MemberData ( nameof ( GetCertsWith_IterationCountExceedingDefaultLimit_MemberData ) ) ]
59- public void ImportWithPasswordOrFileName_IterationCountLimitExceeded ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount )
69+ public void ImportWithPasswordOrFileName_IterationCountLimitExceeded ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount , bool usesRC2 )
6070 {
6171 _ = iterationCount ;
6272
@@ -65,6 +75,11 @@ public void ImportWithPasswordOrFileName_IterationCountLimitExceeded(string name
6575 throw new SkipTestException ( name + " uses PBES2, which is not supported on this version." ) ;
6676 }
6777
78+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
79+ {
80+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
81+ }
82+
6883 using ( TempFileHolder tempFile = new TempFileHolder ( blob ) )
6984 {
7085 string fileName = tempFile . FilePath ;
@@ -100,13 +115,18 @@ internal static void VerifyThrowsCryptoExButDoesNotThrowPfxWithoutPassword(Actio
100115
101116 [ ConditionalTheory ]
102117 [ MemberData ( nameof ( GetCertsWith_NonNullOrEmptyPassword_MemberData ) ) ]
103- public void Import_NonNullOrEmptyPasswordExpected_Throws ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount )
118+ public void Import_NonNullOrEmptyPasswordExpected_Throws ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount , bool usesRC2 )
104119 {
105120 if ( usesPbes2 && ! PfxTests . Pkcs12PBES2Supported )
106121 {
107122 throw new SkipTestException ( name + " uses PBES2, which is not supported on this version." ) ;
108123 }
109124
125+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
126+ {
127+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
128+ }
129+
110130 CryptographicException ce = Assert . ThrowsAny < CryptographicException > ( ( ) => Import ( blob ) ) ;
111131
112132 if ( PfxTests . IsPkcs12IterationCountAllowed ( iterationCount , PfxTests . DefaultIterations ) )
@@ -123,7 +143,7 @@ public void Import_NonNullOrEmptyPasswordExpected_Throws(string name, string pas
123143 }
124144 }
125145
126- [ Fact ]
146+ [ ConditionalFact ( typeof ( PlatformSupport ) , nameof ( PlatformSupport . IsRC2Supported ) ) ]
127147 public void ExportedPfxWithNullPassword_DecryptReturnsValidPaddingWithEmptyPassword ( )
128148 {
129149 Assert . NotNull ( Import ( TestData . MsCertificateExportedToPfx_NullPassword ) ) ;
@@ -160,7 +180,7 @@ private static List<PfxInfo> GetCertificates()
160180 certificates . Add ( new PfxInfo (
161181 nameof ( TestData . Pkcs12WindowsDotnetExportEmptyPassword ) , "" , 6000 , false , TestData . Pkcs12WindowsDotnetExportEmptyPassword ) ) ;
162182 certificates . Add ( new PfxInfo (
163- nameof ( TestData . Pkcs12MacosKeychainCreated ) , null , 4097 , false , TestData . Pkcs12MacosKeychainCreated ) ) ;
183+ nameof ( TestData . Pkcs12MacosKeychainCreated ) , null , 4097 , false , TestData . Pkcs12MacosKeychainCreated , usesRC2 : true ) ) ;
164184 certificates . Add ( new PfxInfo (
165185 nameof ( TestData . Pkcs12BuilderSaltWithMacNullPassword ) , null , 120000 , true , TestData . Pkcs12BuilderSaltWithMacNullPassword ) ) ;
166186 certificates . Add ( new PfxInfo (
@@ -183,7 +203,7 @@ public static IEnumerable<object[]> GetCertsWith_IterationCountNotExceedingDefau
183203 {
184204 if ( p . IterationCount <= DefaultIterationLimit && string . IsNullOrEmpty ( p . Password ) )
185205 {
186- yield return new object [ ] { p . Name , p . UsesPbes2 , p . Blob , p . IterationCount } ;
206+ yield return new object [ ] { p . Name , p . UsesPbes2 , p . Blob , p . IterationCount , p . UsesRC2 } ;
187207 }
188208 }
189209 }
@@ -194,7 +214,7 @@ public static IEnumerable<object[]> GetCertsWith_IterationCountExceedingDefaultL
194214 {
195215 if ( p . IterationCount > DefaultIterationLimit )
196216 {
197- yield return new object [ ] { p . Name , p . Password , p . UsesPbes2 , p . Blob , p . IterationCount } ;
217+ yield return new object [ ] { p . Name , p . Password , p . UsesPbes2 , p . Blob , p . IterationCount , p . UsesRC2 } ;
198218 }
199219 }
200220 }
@@ -205,7 +225,7 @@ public static IEnumerable<object[]> GetCertsWith_NonNullOrEmptyPassword_MemberDa
205225 {
206226 if ( ! string . IsNullOrEmpty ( p . Password ) )
207227 {
208- yield return new object [ ] { p . Name , p . Password , p . UsesPbes2 , p . Blob , p . IterationCount } ;
228+ yield return new object [ ] { p . Name , p . Password , p . UsesPbes2 , p . Blob , p . IterationCount , p . UsesRC2 } ;
209229 }
210230 }
211231 }
@@ -218,14 +238,16 @@ public class PfxInfo
218238 internal long IterationCount { get ; set ; }
219239 internal bool UsesPbes2 { get ; set ; }
220240 internal byte [ ] Blob { get ; set ; }
241+ internal bool UsesRC2 { get ; set ; }
221242
222- internal PfxInfo ( string name , string password , long iterationCount , bool usesPbes2 , byte [ ] blob )
243+ internal PfxInfo ( string name , string password , long iterationCount , bool usesPbes2 , byte [ ] blob , bool usesRC2 = false )
223244 {
224245 Name = name ;
225246 Password = password ;
226247 IterationCount = iterationCount ;
227248 UsesPbes2 = usesPbes2 ;
228249 Blob = blob ;
250+ UsesRC2 = usesRC2 ;
229251 }
230252 }
231253}
0 commit comments