-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tls13 support for win_get_url #573
Conversation
Using the win_get_url module I was getting the following error: "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel" However, from the machine the download was working fine with in a powershell terminal. After some troubleshooting, I noticed that the issue was with TLS1.3. Adding an extra condition for TLS1.3 actually fixed the issue. Please let me know what you think.
Hmm I was hoping that the initial value The change itself is fine but we would a changelog fragment as documented under https://docs.ansible.com/ansible/latest/community/development_process.html#creating-changelog-fragments for this |
Just tested myself and can confirm even with |
Sorry I have been a bit busy lately. Another way we could deal with this, would be to add a condition to check the .NET Framework version, since the issue only seems to appear with tls1.3 in Windows 11 and Server 2022, if less than 528449 (Windows 11 and Server 2022), we enable tls1.1 and 1.2 otherwise we can just skip this block and leave whatever the system has for default. I will look at how to create a changelog fragment. |
I have added the changelog fragment, let me know if this looks ok to you. |
I've just come across something interesting. I initially tried your changes against a TLS 1.3 only host and it was failing, it would only work if I explicitly set the TLS 1.3 protocol on the PS C:\Users\vagrant-domain> powershell.exe -File C:\temp\web-tls.ps1
{"tls": {"protocol": "TLSv1.3", "cipher": "TLS_AES_256_GCM_SHA384"}, "request_headers": {"Host": "192.168.56.1:41669", "Connection": "Keep-Alive"}}
PS C:\Users\vagrant-domain> Invoke-Command localhost -FilePath C:\temp\web-tls.ps1
Exception calling "GetResponse" with "0" argument(s): "The request was aborted: Could not create SSL/TLS secure
channel."
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
+ PSComputerName : localhost Turns out that due to how the PSRemoting WSMan host is configured it has PS C:\Users\vagrant-domain> invoke-command localhost { [System.Net.ServicePointManager]::SecurityProtocol }
PSComputerName RunspaceId Value
-------------- ---------- -----
localhost ba9a7483-7d6a-40da-a2dd-4a04efc9dffa Tls, Tls11, Tls12 Unfortunately in this scenario we can't just set the $code = {
[System.Net.ServicePointManager].GetField(
's_disableSystemDefaultTlsVersions',
[System.Reflection.BindingFlags]'NonPublic, Static').GetValue($null)
}
powershell.exe $code
# $false
Invoke-Command localhost $code
# $true Which means for us to actually rely on the OS settings we also need to reconfigure this policy which requires reflection. I'll submit a suggestion to the code needed here which works locally for both the |
From a security standpoint with the future in mind, I think best practice in general is not to set/force TLS version in the app. It seems like letting the OS/.net decide on what version of TLS to use is best so that system wide settings are applied. Newer versions of .net 4.7.2, etc use TLS 1.2 and 4.8+ can use TLS 1.3. Think of a major issue with TLS 1.3 or TLS 1.2 coming out tomorrow and businesses being required to disable one of them (like what has happened with earlier TLS versions). Using system wide settings would make it easier to deal with. I know I have had to set .net registry settings for some older TLS versions to get them to use TLS 1.2. I do get that isn't convenient though. To me it seems like the app shouldn't set anything by default but then have the ability to force it if the user needs. It will allow newer TLS versions to be used many years from now instead of needing newer TLS versions added as time go by. |
That's what the suggested change does. If the The extra logic added is to ensure that the OS policies are used if the PSRemoting host is used with the |
Co-authored-by: Jordan Borean <jborean93@gmail.com>
Sorry I have been away for a long time. |
Thanks for working on this @yacine-learning! |
SUMMARY
Using the win_get_url module I was getting the following error: "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel"
However, from the machine the download was working fine within a powershell terminal. After some troubleshooting, I noticed that the issue was with TLS1.3.
Adding an extra condition for TLS1.3 actually fixed the issue. Please let me know what you think.
ISSUE TYPE
COMPONENT NAME
win_get_url
ADDITIONAL INFORMATION
Ansible Version
OS
Ansible controller: Ubuntu 20.04
Target Machine: Windows Server 2022
Before change
After change