Friday, January 11, 2019

Procedure to resolve error "The request was aborted: Could not create SSL/TLS secure channel." for SharePoint CSOM against SharePoint online

Recently, when I try to use SharePoint client object model (CSOM) to retrieve, update, and manage data in SharePoint online, I got the following error.

"The request was aborted: Could not create SSL/TLS secure channel." 

This is strange since we have been doing this type of PowerShell using CSOM against SharePoint online for few years. After working with Microsoft on this issue (#12681743), we identify the root cause is SharePoint online stopped to support SSL/TLS 1.0 since November 2018. This change has been gradually pushed to tenant gradually.

The solution to fix this issue is to add the following line in the beginning of the PowerShell script.

[System.Net.ServicePointManager]::SecurityProtocol =[System.Net.SecurityProtocolType]::Tls12

You could also to use the following line to allow different version of TLS to run the script.
[System.Net.ServicePointManager]::SecurityProtocol =[System.Net.SecurityProtocolType]::TLS -bor [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls11  

Here is one example when we enable app SideLoading in your non-developer SharePoint online site collection.

[System.Net.ServicePointManager]::SecurityProtocol =[System.Net.SecurityProtocolType]::Tls12

# Add-Type dll.
# Get user name and password
# …
[Microsoft.SharePoint.Client.ClientContext]$cc = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl)
[Microsoft.SharePoint.Client.SharePointOnlineCredentials]$spocreds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)

$cc.Credentials = $spocreds
$sideLoadingEnabled = [Microsoft.SharePoint.Client.appcatalog]::IsAppSideloadingEnabled($cc);
#Add your commands here …
   
$cc.ExecuteQuery()


Bow the code runs without error.

Please note Microsoft may change the supported TLS version in the future, you may need to keep track the supported version.

No comments:

Post a Comment