Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell could not create ssl/tsl secure

Tags:

powershell

I'm using a powershell script to download and execute a file, but since some time I go I get a could not create ssl/tsl secure channel.

$down = New-Object System.Net.WebClient; 
$url = 'url'; 
$file = 'file';
$down.DownloadFile($url,$file); 
$exec = New-Object -com shell.application; 
$exec.shellexecute($file); 
exit; 
like image 640
kate maran Avatar asked Apr 12 '18 15:04

kate maran


People also ask

Is TLS enabled in Windows Server 2012 R2?

Thanks for reply .Yes, TLS1.2 is enabled. I am using window server 2012 r2 . it is the exchange server. Was this post helpful? Thanks for your feedback! This person is a verified professional.

Is there a forum for SSL/TLS in IIS?

As your issue is more related with SSL/TLS, which is out of Windows Server 2012 support forum. We recommend to create a thread on IIS forum, they are more familiar with this issue and also should have more resources for you. If my redirection is useful for you, please mark it as answer.

What if the client doesn’t support the latest TLS protocol?

Usually what happens is the server requires the latest TLS protocol (TLS 1.2) but the client is has an older OS or targets a framework that does not support the latest TLS version. The first step is figuring out what version of TLS is required.

What version of TLS does the local server support?

The local server (that this was being attempted on) is fine with TLS 1.2, although the remote server (which was previously "confirmed" as fine for TLS 1.2 by a 3rd party) seems not to be. Hope this helps someone. Show activity on this post.


2 Answers

TLS 1.2 should be enabled to get it working. In PowerShell you can find out which protocols your system supports by running this code:

[Enum]::GetNames([Net.SecurityProtocolType]) -contains 'Tls12'

If the result is True then your system supports TLS 1.2. You can find out which protocols are being used by running:

[System.Net.ServicePointManager]::SecurityProtocol.HasFlag([Net.SecurityProtocolType]::Tls12)

If the result is True then TLS 1.2 is being used . However, you can add TLS 1.2 explicitly by using:

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12

This should solve these problems.

like image 60
Ashfaq Avatar answered Sep 20 '22 09:09

Ashfaq


It may be that the site you are connection to requires TLS 1.2, whereas powershell uses TLS 1.0 by default (if I remember correctly)

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$down = New-Object System.Net.WebClient
$url = 'https://github.com/mpdairy/posh.git'
$file = 'C:\ExistingDirectory\test.git'
$down.DownloadFile($url,$file)
$exec = New-Object -com shell.application
$exec.shellexecute($file)
exit

Without using Tls 1.2, I get this error:

Exception calling "DownloadFile" with "2" argument(s): "The request was aborted: Could not create SSL/TLS
secure channel."
At line:1 char:1
+ $down.DownloadFile($url,$file)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException
like image 30
G42 Avatar answered Sep 20 '22 09:09

G42