@@ -22,13 +22,18 @@ public abstract partial class PfxIterationCountTests
2222
2323 [ ConditionalTheory ]
2424 [ MemberData ( nameof ( GetCertsWith_IterationCountNotExceedingDefaultLimit_AndNullOrEmptyPassword_MemberData ) ) ]
25- public void Import_IterationCounLimitNotExceeded_Succeeds ( string name , bool usesPbes2 , byte [ ] blob , long iterationCount )
25+ public void Import_IterationCounLimitNotExceeded_Succeeds ( string name , bool usesPbes2 , byte [ ] blob , long iterationCount , bool usesRC2 )
2626 {
2727 if ( usesPbes2 && ! PfxTests . Pkcs12PBES2Supported )
2828 {
2929 throw new SkipTestException ( name + " uses PBES2 which is not supported on this version." ) ;
3030 }
3131
32+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
33+ {
34+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
35+ }
36+
3237 if ( PfxTests . IsPkcs12IterationCountAllowed ( iterationCount , PfxTests . DefaultIterations ) )
3338 {
3439 X509Certificate cert = Import ( blob ) ;
@@ -38,7 +43,7 @@ public void Import_IterationCounLimitNotExceeded_Succeeds(string name, bool uses
3843
3944 [ ConditionalTheory ]
4045 [ MemberData ( nameof ( GetCertsWith_IterationCountExceedingDefaultLimit_MemberData ) ) ]
41- public void Import_IterationCountLimitExceeded_Throws ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount )
46+ public void Import_IterationCountLimitExceeded_Throws ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount , bool usesRC2 )
4247 {
4348 _ = password ;
4449 _ = iterationCount ;
@@ -48,19 +53,29 @@ public void Import_IterationCountLimitExceeded_Throws(string name, string passwo
4853 throw new SkipTestException ( name + " uses PBES2 which is not supported on this version." ) ;
4954 }
5055
56+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
57+ {
58+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
59+ }
60+
5161 CryptographicException ce = Assert . Throws < CryptographicException > ( ( ) => Import ( blob ) ) ;
5262 Assert . Contains ( "2233907" , ce . Message ) ;
5363 }
5464
5565 [ ConditionalTheory ]
5666 [ MemberData ( nameof ( GetCertsWith_IterationCountExceedingDefaultLimit_MemberData ) ) ]
57- public void ImportWithPasswordOrFileName_IterationCountLimitExceeded ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount )
67+ public void ImportWithPasswordOrFileName_IterationCountLimitExceeded ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount , bool usesRC2 )
5868 {
5969 if ( usesPbes2 && ! PfxTests . Pkcs12PBES2Supported )
6070 {
6171 throw new SkipTestException ( name + " uses PBES2 which is not supported on this version." ) ;
6272 }
6373
74+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
75+ {
76+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
77+ }
78+
6479 using ( TempFileHolder tempFile = new TempFileHolder ( blob ) )
6580 {
6681 string fileName = tempFile . FilePath ;
@@ -99,13 +114,18 @@ internal static void VerifyThrowsCryptoExButDoesNotThrowPfxWithoutPassword(Actio
99114
100115 [ ConditionalTheory ]
101116 [ MemberData ( nameof ( GetCertsWith_NonNullOrEmptyPassword_MemberData ) ) ]
102- public void Import_NonNullOrEmptyPasswordExpected_Throws ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount )
117+ public void Import_NonNullOrEmptyPasswordExpected_Throws ( string name , string password , bool usesPbes2 , byte [ ] blob , long iterationCount , bool usesRC2 )
103118 {
104119 if ( usesPbes2 && ! PfxTests . Pkcs12PBES2Supported )
105120 {
106121 throw new SkipTestException ( name + " uses PBES2 which is not supported on this version." ) ;
107122 }
108123
124+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
125+ {
126+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
127+ }
128+
109129 CryptographicException ce = Assert . ThrowsAny < CryptographicException > ( ( ) => Import ( blob ) ) ;
110130
111131 if ( PfxTests . IsPkcs12IterationCountAllowed ( iterationCount , PfxTests . DefaultIterations ) )
@@ -139,7 +159,7 @@ internal static List<PfxInfo> GetCertificates()
139159 certificates . Add ( new PfxInfo (
140160 nameof ( TestData . Pkcs12WindowsDotnetExportEmptyPassword ) , "" , 6000 , false , TestData . Pkcs12WindowsDotnetExportEmptyPassword . HexToByteArray ( ) ) ) ;
141161 certificates . Add ( new PfxInfo (
142- nameof ( TestData . Pkcs12MacosKeychainCreated ) , null , 4097 , false , TestData . Pkcs12MacosKeychainCreated . HexToByteArray ( ) ) ) ;
162+ nameof ( TestData . Pkcs12MacosKeychainCreated ) , null , 4097 , false , TestData . Pkcs12MacosKeychainCreated . HexToByteArray ( ) , usesRC2 : true ) ) ;
143163 certificates . Add ( new PfxInfo (
144164 nameof ( TestData . Pkcs12BuilderSaltWithMacNullPassword ) , null , 120000 , true , TestData . Pkcs12BuilderSaltWithMacNullPassword . HexToByteArray ( ) ) ) ;
145165 certificates . Add ( new PfxInfo (
@@ -162,23 +182,23 @@ public static IEnumerable<object[]> GetCertsWith_IterationCountNotExceedingDefau
162182 c => c . IterationCount <= DefaultIterationLimit &&
163183 string . IsNullOrEmpty ( c . Password ) ) )
164184 {
165- yield return new object [ ] { p . Name , p . UsesPbes2 , p . Blob , p . IterationCount } ;
185+ yield return new object [ ] { p . Name , p . UsesPbes2 , p . Blob , p . IterationCount , p . UsesRC2 } ;
166186 }
167187 }
168188
169189 public static IEnumerable < object [ ] > GetCertsWith_IterationCountExceedingDefaultLimit_MemberData ( )
170190 {
171191 foreach ( PfxInfo p in s_Certificates . Where ( c => c . IterationCount > DefaultIterationLimit ) )
172192 {
173- yield return new object [ ] { p . Name , p . Password , p . UsesPbes2 , p . Blob , p . IterationCount } ;
193+ yield return new object [ ] { p . Name , p . Password , p . UsesPbes2 , p . Blob , p . IterationCount , p . UsesRC2 } ;
174194 }
175195 }
176196
177197 public static IEnumerable < object [ ] > GetCertsWith_NonNullOrEmptyPassword_MemberData ( )
178198 {
179199 foreach ( PfxInfo p in s_Certificates . Where ( c => ! string . IsNullOrEmpty ( c . Password ) ) )
180200 {
181- yield return new object [ ] { p . Name , p . Password , p . UsesPbes2 , p . Blob , p . IterationCount } ;
201+ yield return new object [ ] { p . Name , p . Password , p . UsesPbes2 , p . Blob , p . IterationCount , p . UsesRC2 } ;
182202 }
183203 }
184204 }
@@ -190,14 +210,16 @@ public class PfxInfo
190210 internal long IterationCount { get ; set ; }
191211 internal bool UsesPbes2 { get ; set ; }
192212 internal byte [ ] Blob { get ; set ; }
213+ internal bool UsesRC2 { get ; set ; }
193214
194- internal PfxInfo ( string name , string ? password , long iterationCount , bool usesPbes2 , byte [ ] blob )
215+ internal PfxInfo ( string name , string password , long iterationCount , bool usesPbes2 , byte [ ] blob , bool usesRC2 = false )
195216 {
196217 Name = name ;
197218 Password = password ;
198219 IterationCount = iterationCount ;
199220 UsesPbes2 = usesPbes2 ;
200221 Blob = blob ;
222+ UsesRC2 = usesRC2 ;
201223 }
202224 }
203225}
0 commit comments