Repository navigation
Expand file tree
/
Copy pathUpdate-TCPConnection.ps1
More file actions
55 lines (44 loc) · 2.31 KB
/
Copy pathUpdate-TCPConnection.ps1
File metadata and controls
55 lines (44 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<#
.SYNOPSIS
Register a new TcpClient and open its SSL stream.
.DESCRIPTION
`Update-TCPConnection` sets the provided `TcpClient` into the runtime private
TCP container and calls `Open-SSLStream` to wrap and authenticate the connection
as client or server depending on the `IsClient` flag.
.PARAMETER Client
| Name | Type | Description | Default |
|--------|------------------------------|-------------------------------------------|---------|
| Client | System.Net.Sockets.TcpClient | Connected TCP client instance to register | $null |
.PARAMETER Endpoint
| Name | Type | Description | Default |
|----------|---------------|-------------------------------------------------|---------|
| Endpoint | System.String | Remote endpoint name (used for client SSL auth) | $null |
.PARAMETER IsClient
| Name | Type | Description | Default |
|----------|------------------------|-------------------------------------------------|---------|
| IsClient | System.SwitchParameter | When set perform client-side SSL authentication | $false |
.OUTPUTS
None -- Result codes from `Open-SSLStream` are forwarded via `Write-FunctionReturnValue`.
.EXAMPLE
PS> Update-TCPConnection -Client $c -Endpoint 'example.com' -IsClient
.NOTES
Validates `$Client` and returns `UpdateTcpClientInvalid` when missing.
SPDX-FileCopyrightText: 2026 Icinga GmbH <https://icinga.com>
SPDX-License-Identifier: GPL-3.0-or-later
#>
function Update-TCPConnection()
{
param (
[System.Net.Sockets.TcpClient]$Client = $null,
[string]$Endpoint = $null,
[switch]$IsClient = $false
);
if ($null -eq $Client) {
return (Write-FunctionReturnValue -ReturnValue 'UpdateTcpClientInvalid' -Data @{ 'Endpoint' = $Endpoint; 'IsClient' = $IsClient });
}
# Our Tcp client is valid, set it globally
(Get-GlobalRuntimeVariable).Private.TCP.Client = $Client;
# Open an SslStream for this connection and share the setting if we are a client and the name of the endpoint
# We connected to. This is needed for Ssl authentication with the server certificate for the TCP Protocol.
return (Open-SSLStream -IsClient:$IsClient -Endpoint $Endpoint);
}