Skip to content

Commit

Permalink
Handle OSSL 3.4 change to SAN:othername formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bartonjs authored Jan 26, 2025
1 parent 1084c54 commit a40f92e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ public static partial class PlatformDetection
throw new PlatformNotSupportedException();

private static readonly Version s_openssl3Version = new Version(3, 0, 0);
public static bool IsOpenSsl3 => !IsApplePlatform && !IsWindows && !IsAndroid && !IsBrowser ?
GetOpenSslVersion() >= s_openssl3Version :
false;
private static readonly Version s_openssl3_4Version = new Version(3, 4, 0);

public static bool IsOpenSsl3 => IsOpenSslVersionAtLeast(s_openssl3Version);
public static bool IsOpenSsl3_4 => IsOpenSslVersionAtLeast(s_openssl3_4Version);

/// <summary>
/// If gnulibc is available, returns the release, such as "stable".
Expand Down Expand Up @@ -140,6 +141,18 @@ private static Version GetOpenSslVersion()
return s_opensslVersion;
}

// The "IsOpenSsl" properties answer false on Apple, even if OpenSSL is present for lightup,
// as they are answering the question "is OpenSSL the primary crypto provider".
private static bool IsOpenSslVersionAtLeast(Version minVersion)
{
if (IsApplePlatform || IsWindows || IsAndroid || IsBrowser)
{
return false;
}

return GetOpenSslVersion() >= minVersion;
}

private static Version ToVersion(string versionString)
{
// In some distros/versions we cannot discover the distro version; return something valid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ public static void TestSubjectAlternativeName_Unix()

string s = asnData.Format(false);
bool isOpenSsl3 = PlatformDetection.IsOpenSsl3;
bool isOpenSsl3_4 = PlatformDetection.IsOpenSsl3_4;

string expected = string.Join(
", ",
// Choice[0]: OtherName
isOpenSsl3 ? "othername: UPN::[email protected]" : "othername:<unsupported>",
isOpenSsl3_4 ? "othername: UPN:[email protected]" :
isOpenSsl3 ? "othername: UPN::[email protected]" : "othername:<unsupported>",
// Choice[1]: Rfc822Name (EmailAddress)
"email:[email protected]",
// Choice[2]: DnsName
Expand Down

0 comments on commit a40f92e

Please sign in to comment.