Skip to content

Commit f4d65d3

Browse files
🌟 [Major]: Introcuding the TLS module (#2)
## Description This pull request introduces the `TLS` PowerShell module, dedicated to managing and configuring TLS settings. ### New Functions - `Get-TLSConfig`: Retrieves the current TLS configuration and lists available TLS versions. - `Set-TLSConfig`: Enables specific TLS protocols by updating the system’s SecurityProtocol settings. ### Documentation - `README.md`: Now introduces the module as `TLS`, explains its purpose, and provides detailed examples for retrieving and setting TLS configurations. - `Examples`: A new `General.md` example file demonstrates how to use the module’s functions. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [x] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent c7bebb9 commit f4d65d3

File tree

8 files changed

+218
-52
lines changed

8 files changed

+218
-52
lines changed

README.md

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# {{ NAME }}
1+
# TLS
22

3-
{{ DESCRIPTION }}
3+
A PowerShell module that helps manage and configure TLS settings on your system.
44

55
## Prerequisites
66

@@ -12,58 +12,81 @@ This uses the following external resources:
1212
To install the module from the PowerShell Gallery, you can use the following command:
1313

1414
```powershell
15-
Install-PSResource -Name {{ NAME }}
16-
Import-Module -Name {{ NAME }}
15+
Install-PSResource -Name TLS
16+
Import-Module -Name TLS
1717
```
1818

1919
## Usage
2020

21-
Here is a list of example that are typical use cases for the module.
21+
Below are some typical use cases for the module's functions:
2222

23-
### Example 1: Greet an entity
23+
### Example 1: Retrieve the Current TLS Configuration
2424

25-
Provide examples for typical commands that a user would like to do with the module.
25+
```powershell
26+
Get-TLSConfig
27+
```
28+
29+
- Returns the TLS protocol(s) currently enabled for .NET applications on the system.
30+
31+
### Example 2: List All Available TLS Protocols
32+
33+
```powershell
34+
Get-TLSConfig -ListAvailable
35+
```
36+
37+
- Displays all TLS protocol types that can be potentially enabled.
38+
39+
### Example 3: Enable TLS 1.2
2640

2741
```powershell
28-
Greet-Entity -Name 'World'
29-
Hello, World!
42+
Set-TLSConfig -Protocol Tls12
3043
```
3144

32-
### Example 2
45+
- Enables TLS 1.2 on the system without disabling previously enabled protocols.
3346

34-
Provide examples for typical commands that a user would like to do with the module.
47+
### Example 4: Enable Multiple TLS Protocols (e.g., TLS 1.2 and TLS 1.3)
3548

3649
```powershell
37-
Import-Module -Name PSModuleTemplate
50+
Set-TLSConfig -Protocol Tls12, Tls13
3851
```
3952

53+
- Simultaneously enables TLS 1.2 and TLS 1.3.
54+
4055
### Find more examples
4156

4257
To find more examples of how to use the module, please refer to the [examples](examples) folder.
4358

44-
Alternatively, you can use the Get-Command -Module 'This module' to find more commands that are available in the module.
45-
To find examples of each of the commands you can use Get-Help -Examples 'CommandName'.
59+
Alternatively, you can run:
60+
```powershell
61+
Get-Command -Module TLS
62+
```
63+
to see all available commands in the module. Then, for any command, you can do:
64+
```powershell
65+
Get-Help -Examples <CommandName>
66+
```
67+
to view examples specific to that command.
4668

4769
## Documentation
4870

49-
Link to further documentation if available, or describe where in the repository users can find more detailed documentation about
50-
the module's functions and features.
71+
Additional documentation, if available, can be found in this repository. Check out the function-level help by running:
72+
73+
```powershell
74+
Get-Help Set-TLSConfig -Full
75+
Get-Help Get-TLSConfig -Full
76+
```
77+
78+
This will show detailed usage information and parameter descriptions.
5179

5280
## Contributing
5381

5482
Coder or not, you can contribute to the project! We welcome all contributions.
5583

5684
### For Users
5785

58-
If you don't code, you still sit on valuable information that can make this project even better. If you experience that the
59-
product does unexpected things, throw errors or is missing functionality, you can help by submitting bugs and feature requests.
60-
Please see the issues tab on this project and submit a new issue that matches your needs.
86+
If you don't code, you still have valuable insights. If you experience any unexpected behavior, see errors, or want additional functionality, please
87+
submit a bug report or feature request via the Issues tab.
6188

6289
### For Developers
6390

64-
If you do code, we'd love to have your contributions. Please read the [Contribution guidelines](CONTRIBUTING.md) for more information.
65-
You can either help by picking up an existing issue or submit a new one if you have an idea for a new feature or improvement.
66-
67-
## Acknowledgements
68-
69-
Here is a list of people and projects that helped this project in some way.
91+
We’d love your help adding features, fixing bugs, and improving the module. Please read the [Contribution guidelines](CONTRIBUTING.md). You can pick
92+
up an existing issue or submit a new one if you have ideas for improvements or new features.

examples/General.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Using Get-TLSConfig and Set-TLSConfig
2+
3+
## Get-TLSConfig
4+
5+
The `Get-TLSConfig` function retrieves the current TLS configuration or lists available TLS versions.
6+
7+
### Example 1: Get Current TLS Configuration
8+
9+
```powershell
10+
Get-TLSConfig
11+
```
12+
13+
**Description:** Returns the currently configured TLS version used by .NET applications.
14+
15+
### Example 2: List Available TLS Versions
16+
17+
```powershell
18+
Get-TLSConfig -ListAvailable
19+
```
20+
21+
**Description:** Lists all available TLS versions that can be configured.
22+
23+
---
24+
25+
## Set-TLSConfig
26+
27+
The `Set-TLSConfig` function allows enabling one or more TLS protocols by modifying the system's SecurityProtocol settings.
28+
29+
### Example 1: Enable TLS 1.2
30+
31+
```powershell
32+
Set-TLSConfig -Protocol Tls12
33+
```
34+
35+
**Description:** Enables TLS 1.2 as a supported security protocol.
36+
37+
### Example 2: Enable TLS 1.2 and TLS 1.3
38+
39+
```powershell
40+
Set-TLSConfig -Protocol Tls12, Tls13
41+
```
42+
43+
**Description:** Enables both TLS 1.2 and TLS 1.3 as supported security protocols.

examples/General.ps1

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/functions/public/Get-PSModuleTest.ps1

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function Get-TLSConfig {
2+
<#
3+
.SYNOPSIS
4+
Retrieves the current TLS configuration or lists available TLS versions.
5+
6+
.DESCRIPTION
7+
This function returns the currently configured TLS version used by .NET applications.
8+
If the -ListAvailable parameter is specified, it lists all available TLS versions supported.
9+
10+
.EXAMPLE
11+
Get-TLSConfig
12+
13+
Returns the currently configured TLS version.
14+
15+
.EXAMPLE
16+
Get-TLSConfig -ListAvailable
17+
18+
Lists all available TLS versions that can be configured.
19+
20+
.LINK
21+
https://psmodule.io/TLS/Functions/Get-TLSConfig/
22+
#>
23+
[OutputType(ParameterSetName = 'Default', [System.Net.SecurityProtocolType])]
24+
[OutputType(ParameterSetName = 'ListAvailable', [Array])]
25+
[CmdletBinding(DefaultParameterSetName = 'Default')]
26+
param(
27+
# List available TLS configurations
28+
[Parameter(ParameterSetName = 'ListAvailable')]
29+
[switch] $ListAvailable
30+
)
31+
32+
if ($ListAvailable) {
33+
return [enum]::GetValues([System.Net.SecurityProtocolType])
34+
}
35+
return [System.Net.ServicePointManager]::SecurityProtocol
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function Set-TLSConfig {
2+
<#
3+
.SYNOPSIS
4+
Configures the system to enable specific TLS protocols.
5+
6+
.DESCRIPTION
7+
The Set-TLSConfig function allows enabling one or more TLS protocols by modifying the system's SecurityProtocol settings.
8+
This function updates the current security protocol settings without removing existing ones.
9+
10+
.EXAMPLE
11+
Set-TLSConfig -Protocol Tls12
12+
13+
Enables TLS 1.2 as a supported security protocol.
14+
15+
.EXAMPLE
16+
Set-TLSConfig -Protocol Tls12, Tls13
17+
18+
Enables both TLS 1.2 and TLS 1.3 as supported security protocols.
19+
20+
.LINK
21+
https://psmodule.io/TLS/Functions/Set-TLSConfig/
22+
#>
23+
[OutputType([void])]
24+
[CmdletBinding(SupportsShouldProcess)]
25+
param(
26+
# The TLS protocol to enable
27+
[Parameter(Mandatory)]
28+
[System.Net.SecurityProtocolType[]] $Protocol
29+
)
30+
31+
foreach ($protocolItem in $Protocol) {
32+
Write-Verbose "Enabling $protocolItem"
33+
if ($PSCmdlet.ShouldProcess("Security Protocol to [$Protocol]", 'Set')) {
34+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor $protocolItem
35+
}
36+
}
37+
}

tests/PSModuleTest.Tests.ps1

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/TLS.Tests.ps1

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
2+
'PSUseDeclaredVarsMoreThanAssignments', '',
3+
Justification = 'Pester code blocks'
4+
)]
5+
[CmdletBinding()]
6+
param()
7+
8+
Describe 'TLS' {
9+
Context 'Get-TLSConfig' {
10+
It 'Should return the current TLS configuration by default' {
11+
$result = Get-TLSConfig
12+
$expectedTypes = [System.Net.SecurityProtocolType]
13+
$result | Should -BeOfType $expectedTypes
14+
}
15+
16+
It 'Should return available TLS versions when -ListAvailable is specified' {
17+
$result = Get-TLSConfig -ListAvailable
18+
$expectedValues = [enum]::GetValues([System.Net.SecurityProtocolType])
19+
$result | Should -Be $expectedValues
20+
}
21+
}
22+
23+
Context 'Set-TLSConfig' {
24+
BeforeAll {
25+
$originalTLS = [System.Net.ServicePointManager]::SecurityProtocol
26+
}
27+
28+
AfterAll {
29+
[System.Net.ServicePointManager]::SecurityProtocol = $originalTLS
30+
}
31+
32+
It 'Should enable TLS 1.2 when specified' {
33+
Set-TLSConfig -Protocol Tls12
34+
$result = [System.Net.ServicePointManager]::SecurityProtocol
35+
$result.HasFlag([System.Net.SecurityProtocolType]::Tls12) | Should -BeTrue
36+
}
37+
38+
It 'Should enable multiple TLS versions when specified' {
39+
Set-TLSConfig -Protocol Tls12, Tls13
40+
$result = [System.Net.ServicePointManager]::SecurityProtocol
41+
$result -band [System.Net.SecurityProtocolType]::Tls12 | Should -Be Tls12
42+
$result -band [System.Net.SecurityProtocolType]::Tls13 | Should -Be Tls13
43+
}
44+
45+
It 'Should not remove existing TLS settings when adding new ones' {
46+
Set-TLSConfig -Protocol Tls11
47+
$resultBefore = [System.Net.ServicePointManager]::SecurityProtocol
48+
Set-TLSConfig -Protocol Tls12
49+
$resultAfter = [System.Net.ServicePointManager]::SecurityProtocol
50+
$resultAfter.HasFlag([System.Net.SecurityProtocolType]::Tls11) | Should -BeTrue
51+
$resultAfter.HasFlag([System.Net.SecurityProtocolType]::Tls12) | Should -BeTrue
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)