@@ -24,13 +24,18 @@ public abstract partial class PfxIterationCountTests
24
24
25
25
[ ConditionalTheory ]
26
26
[ 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 )
28
28
{
29
29
if ( usesPbes2 && ! PfxTests . Pkcs12PBES2Supported )
30
30
{
31
31
throw new SkipTestException ( name + " uses PBES2, which is not supported on this version." ) ;
32
32
}
33
33
34
+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
35
+ {
36
+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
37
+ }
38
+
34
39
if ( PfxTests . IsPkcs12IterationCountAllowed ( iterationCount , PfxTests . DefaultIterations ) )
35
40
{
36
41
X509Certificate cert = Import ( blob ) ;
@@ -40,7 +45,7 @@ public void Import_IterationCounLimitNotExceeded_Succeeds(string name, bool uses
40
45
41
46
[ ConditionalTheory ]
42
47
[ 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 )
44
49
{
45
50
_ = password ;
46
51
_ = iterationCount ;
@@ -50,13 +55,18 @@ public void Import_IterationCountLimitExceeded_Throws(string name, string passwo
50
55
throw new SkipTestException ( name + " uses PBES2, which is not supported on this version." ) ;
51
56
}
52
57
58
+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
59
+ {
60
+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
61
+ }
62
+
53
63
CryptographicException ce = Assert . Throws < CryptographicException > ( ( ) => Import ( blob ) ) ;
54
64
Assert . Contains ( FwlinkId , ce . Message ) ;
55
65
}
56
66
57
67
[ ConditionalTheory ]
58
68
[ 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 )
60
70
{
61
71
_ = iterationCount ;
62
72
@@ -65,6 +75,11 @@ public void ImportWithPasswordOrFileName_IterationCountLimitExceeded(string name
65
75
throw new SkipTestException ( name + " uses PBES2, which is not supported on this version." ) ;
66
76
}
67
77
78
+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
79
+ {
80
+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
81
+ }
82
+
68
83
using ( TempFileHolder tempFile = new TempFileHolder ( blob ) )
69
84
{
70
85
string fileName = tempFile . FilePath ;
@@ -100,13 +115,18 @@ internal static void VerifyThrowsCryptoExButDoesNotThrowPfxWithoutPassword(Actio
100
115
101
116
[ ConditionalTheory ]
102
117
[ 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 )
104
119
{
105
120
if ( usesPbes2 && ! PfxTests . Pkcs12PBES2Supported )
106
121
{
107
122
throw new SkipTestException ( name + " uses PBES2, which is not supported on this version." ) ;
108
123
}
109
124
125
+ if ( usesRC2 && ! PlatformSupport . IsRC2Supported )
126
+ {
127
+ throw new SkipTestException ( name + " uses RC2, which is not supported on this platform." ) ;
128
+ }
129
+
110
130
CryptographicException ce = Assert . ThrowsAny < CryptographicException > ( ( ) => Import ( blob ) ) ;
111
131
112
132
if ( PfxTests . IsPkcs12IterationCountAllowed ( iterationCount , PfxTests . DefaultIterations ) )
@@ -123,7 +143,7 @@ public void Import_NonNullOrEmptyPasswordExpected_Throws(string name, string pas
123
143
}
124
144
}
125
145
126
- [ Fact ]
146
+ [ ConditionalFact ( typeof ( PlatformSupport ) , nameof ( PlatformSupport . IsRC2Supported ) ) ]
127
147
public void ExportedPfxWithNullPassword_DecryptReturnsValidPaddingWithEmptyPassword ( )
128
148
{
129
149
Assert . NotNull ( Import ( TestData . MsCertificateExportedToPfx_NullPassword ) ) ;
@@ -160,7 +180,7 @@ private static List<PfxInfo> GetCertificates()
160
180
certificates . Add ( new PfxInfo (
161
181
nameof ( TestData . Pkcs12WindowsDotnetExportEmptyPassword ) , "" , 6000 , false , TestData . Pkcs12WindowsDotnetExportEmptyPassword ) ) ;
162
182
certificates . Add ( new PfxInfo (
163
- nameof ( TestData . Pkcs12MacosKeychainCreated ) , null , 4097 , false , TestData . Pkcs12MacosKeychainCreated ) ) ;
183
+ nameof ( TestData . Pkcs12MacosKeychainCreated ) , null , 4097 , false , TestData . Pkcs12MacosKeychainCreated , usesRC2 : true ) ) ;
164
184
certificates . Add ( new PfxInfo (
165
185
nameof ( TestData . Pkcs12BuilderSaltWithMacNullPassword ) , null , 120000 , true , TestData . Pkcs12BuilderSaltWithMacNullPassword ) ) ;
166
186
certificates . Add ( new PfxInfo (
@@ -183,7 +203,7 @@ public static IEnumerable<object[]> GetCertsWith_IterationCountNotExceedingDefau
183
203
{
184
204
if ( p . IterationCount <= DefaultIterationLimit && string . IsNullOrEmpty ( p . Password ) )
185
205
{
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 } ;
187
207
}
188
208
}
189
209
}
@@ -194,7 +214,7 @@ public static IEnumerable<object[]> GetCertsWith_IterationCountExceedingDefaultL
194
214
{
195
215
if ( p . IterationCount > DefaultIterationLimit )
196
216
{
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 } ;
198
218
}
199
219
}
200
220
}
@@ -205,7 +225,7 @@ public static IEnumerable<object[]> GetCertsWith_NonNullOrEmptyPassword_MemberDa
205
225
{
206
226
if ( ! string . IsNullOrEmpty ( p . Password ) )
207
227
{
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 } ;
209
229
}
210
230
}
211
231
}
@@ -218,14 +238,16 @@ public class PfxInfo
218
238
internal long IterationCount { get ; set ; }
219
239
internal bool UsesPbes2 { get ; set ; }
220
240
internal byte [ ] Blob { get ; set ; }
241
+ internal bool UsesRC2 { get ; set ; }
221
242
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 )
223
244
{
224
245
Name = name ;
225
246
Password = password ;
226
247
IterationCount = iterationCount ;
227
248
UsesPbes2 = usesPbes2 ;
228
249
Blob = blob ;
250
+ UsesRC2 = usesRC2 ;
229
251
}
230
252
}
231
253
}
0 commit comments