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 @@ -2443,9 +2443,9 @@ internal static extern int WSManSetSessionOption(IntPtr wsManSessionHandle,
/// <param name="value">
/// An int (DWORD) data.
/// </param>
/// <returns></returns>
/// <returns>Zero on success, otherwise the error code.</returns>
[DllImport(WSManNativeApi.WSManClientApiDll, SetLastError = false, CharSet = CharSet.Unicode)]
internal static extern void WSManGetSessionOptionAsDword(IntPtr wsManSessionHandle,
internal static extern int WSManGetSessionOptionAsDword(IntPtr wsManSessionHandle,
WSManSessionOption option,
out int value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1546,8 +1546,13 @@ private void Initialize(Uri connectionUri, WSManConnectionInfo connectionInfo)
throw new PSRemotingTransportException(PSRemotingErrorId.ConnectFailed, RemotingErrorIdStrings.BasicAuthOverHttpNotSupported);
}

// Allow HTTPS on Unix only if SkipCACheck and SkipCNCheck are selected, because OMI client does not support validating server certificates.
if (isSSLSpecified && (!connectionInfo.SkipCACheck || !connectionInfo.SkipCNCheck))
// The OMI client distributed with PowerShell does not support validating server certificates on Unix.
// Check if third-party psrpclient and MI support the verification.
// If WSManGetSessionOptionAsDword does not return 0 then it's not supported.
bool verificationAvailable = WSManNativeApi.WSManGetSessionOptionAsDword(_wsManSessionHandle,
WSManNativeApi.WSManSessionOption.WSMAN_OPTION_SKIP_CA_CHECK, out _) == 0;

if (isSSLSpecified && !verificationAvailable && (!connectionInfo.SkipCACheck || !connectionInfo.SkipCNCheck))
{
throw new PSRemotingTransportException(PSRemotingErrorId.ConnectSkipCheckFailed, RemotingErrorIdStrings.UnixOnlyHttpsWithoutSkipCACheckNotSupported);
}
Expand Down