2020-03-24 07:42:14 -04:00
|
|
|
function New-IcingaSSLStream()
|
|
|
|
|
{
|
|
|
|
|
param(
|
2020-03-24 15:13:28 -04:00
|
|
|
[System.Net.Sockets.TcpClient]$Client = $null,
|
2020-03-24 07:42:14 -04:00
|
|
|
[Security.Cryptography.X509Certificates.X509Certificate2]$Certificate = $null
|
|
|
|
|
);
|
|
|
|
|
|
2020-03-24 15:13:28 -04:00
|
|
|
if ($null -eq $Client) {
|
|
|
|
|
return $null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 08:31:40 -05:00
|
|
|
[System.Net.Security.SslStream]$SSLStream = $null;
|
|
|
|
|
|
2020-03-27 11:43:18 -04:00
|
|
|
try {
|
2024-05-14 04:41:43 -04:00
|
|
|
$SSLStream = New-Object System.Net.Security.SslStream($Client.GetStream(), $false);
|
|
|
|
|
$TLSProtocols = [System.Security.Authentication.SslProtocols]::Tls12 -bor [System.Security.Authentication.SslProtocols]::Tls13;
|
|
|
|
|
$SSLStream.AuthenticateAsServer($Certificate, $false, $TLSProtocols, $true) | Out-Null;
|
2020-03-27 11:43:18 -04:00
|
|
|
} catch {
|
2023-11-15 08:31:40 -05:00
|
|
|
if ($null -ne $SSLStream) {
|
|
|
|
|
$SSLStream.Close();
|
|
|
|
|
$SSLStream.Dispose();
|
|
|
|
|
$SSLStream = $null;
|
|
|
|
|
}
|
2021-12-09 11:42:06 -05:00
|
|
|
Write-IcingaEventMessage -EventId 1500 -Namespace 'Framework' -ExceptionObject $_ -Objects $Client.Client;
|
2020-03-27 11:43:18 -04:00
|
|
|
return $null;
|
|
|
|
|
}
|
2020-03-24 07:42:14 -04:00
|
|
|
|
|
|
|
|
return $SSLStream;
|
|
|
|
|
}
|