Skip to content

Commit e78b72b

Browse files
authored
Fix certificate test failures on iOS(-likes)
Also don't run ExportMultiplePrivateKeys on platforms that don't have Exportable
1 parent 2d0dff4 commit e78b72b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509CertificateLoader.iOS.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,29 @@ private static partial ICertificatePal LoadCertificatePal(ReadOnlySpan<byte> dat
2222
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
2323
}
2424

25-
return LoadX509(data);
25+
ICertificatePal? result = null;
26+
27+
// If the data starts with 0x30, only try the DER loader.
28+
// Otherwise, try PEM.
29+
// If it's not PEM and not 0x30, still call the DER loader to get the system error.
30+
if (data[0] != 0x30)
31+
{
32+
AppleCertificatePal.TryDecodePem(
33+
data,
34+
(derData, contentType) =>
35+
{
36+
if (contentType != X509ContentType.Cert)
37+
{
38+
// true: keep looking
39+
return true;
40+
}
41+
42+
result = LoadX509(derData);
43+
return false;
44+
});
45+
}
46+
47+
return result ?? LoadX509(data);
2648
}
2749

2850
private static partial ICertificatePal LoadCertificatePalFromFile(string path)

src/libraries/System.Security.Cryptography/tests/X509Certificates/CollectionTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ public static void MultipleImport()
800800
}
801801

802802
[Fact]
803+
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "The PKCS#12 Exportable flag is not supported on iOS/MacCatalyst/tvOS")]
803804
public static void ExportMultiplePrivateKeys()
804805
{
805806
var collection = new X509Certificate2Collection();

0 commit comments

Comments
 (0)