Skip to content

Commit

Permalink
Fix certificate test failures on iOS(-likes)
Browse files Browse the repository at this point in the history
Also don't run ExportMultiplePrivateKeys on platforms that don't have Exportable
  • Loading branch information
bartonjs authored Jul 4, 2024
1 parent 2d0dff4 commit e78b72b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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

0 comments on commit e78b72b

Please sign in to comment.