Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,29 @@ private static partial ICertificatePal LoadCertificatePal(ReadOnlySpan<byte> dat
throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding);
}

return LoadX509(data);
ICertificatePal? result = null;

// If the data starts with 0x30, only try the DER loader.
// Otherwise, try PEM.
// If it's not PEM and not 0x30, still call the DER loader to get the system error.
if (data[0] != 0x30)
{
AppleCertificatePal.TryDecodePem(
data,
(derData, contentType) =>
{
if (contentType != X509ContentType.Cert)
{
// true: keep looking
return true;
}

result = LoadX509(derData);
return false;
});
}

return result ?? LoadX509(data);
}

private static partial ICertificatePal LoadCertificatePalFromFile(string path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ public static void MultipleImport()
}

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