Skip to content
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

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed) Mac OSX High Sierra 10.13.5 #26388

Closed
corretge opened this issue Jun 5, 2018 · 26 comments
Assignees
Milestone

Comments

@corretge
Copy link

corretge commented Jun 5, 2018

In PowerShell I try to test an SQL connection from a Mac OSX 10.13.5. DotNet Core and PowerShell were installed through homebrew.

$sqlStr = 'Data Source=SERVER;Initial Catalog=DB;Integrated Security=False;User ID=USER;Password=PASSWORD;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;'
$sqlConn = New-Object System.Data.SqlClient.SqlConnection $sqlStr
$con = $sqlConn.Open()

And I get this error:

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)

dotnet --version : 2.1.300
$PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.2
PSEdition                      Core
GitCommitId                    v6.1.0-preview.2
OS                             Darwin 17.6.0 Darwin Kernel Version 17.6.0: Tue May  8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@AfsanehR-zz AfsanehR-zz self-assigned this Jun 5, 2018
@AfsanehR-zz
Copy link
Contributor

Hi @corretge your issue seems to be similar to #1048 and #1090.
Looks like this is resolved in the latest .NET Core 2.1. Could you please provide the output of dotnet --info?

@moconchobhair
Copy link

I am seeing the same issue running .NET Core 2.1.300.

@keeratsingh
Copy link

@corretge @moconchobhair
As confirmed I was able to successfully connect to a local MSSQLServer hosted on Windows 10 as seen from the output below using PowerShell Core version v6.1.0-preview.2 and .NET Core version 2.1.300 on Mac OSX 10.13.5

Could you kindly download and install the .NET Core SDK 2.1.300 from the link above and try again.

Mac OSX version

PS /Users/dotnet/Desktop> sw_vers                                               
ProductName:	Mac OS X
ProductVersion:	10.13.5
BuildVersion:	17F77

PowerShell Core Script

$sqlStr = 'Data Source={SERVER_IP};Initial Catalog=master;Integrated Security=False;User ID={USER};Password={PASS};Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;'
$sqlConn = New-Object System.Data.SqlClient.SqlConnection($sqlStr)
$con = $sqlConn.Open()
Write-Output "Connection Open"
$strCmd ="SELECT @@VERSION,compatibility_level FROM sys.databases WHERE name = 'master';"
$sqlCmd = New-Object System.Data.SqlClient.SqlCommand($strCmd,$sqlConn)
$dataReader = $sqlCmd.ExecuteReader();
while($dataReader.Read())
{
    Write-Output "SQLServer Version = " $dataReader.GetString(0)
}

$sqlConn.Close()
Write-Output "Connection Closed"

PowerShell Core script output

PS /Users/dotnet/Desktop> pwsh ./gh_30147.ps1                                   
Connection Open
SQLServer Version = 
Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64) 
	Aug 22 2017 17:04:49 
	Copyright (C) 2017 Microsoft Corporation
	Enterprise Edition (64-bit) on Windows 10 Enterprise 10.0 <X64> (Build 17134: )

Connection Closed
PS /Users/dotnet/Desktop> 

PowerShell Core version

PS /Users/dotnet/Desktop> pwsh --version                                        
PowerShell v6.1.0-preview.2
PS /Users/dotnet/Desktop> $PSVersionTable                                       

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.2
PSEdition                      Core
GitCommitId                    v6.1.0-preview.2
OS                             Darwin 17.6.0 Darwin Kernel Version 17.6.0: T...
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

.NET Core version and info

PS /Users/dotnet/Desktop> dotnet --version                                      
2.1.300

PS /Users/dotnet/Desktop> dotnet --info                                         
.NET Core SDK (reflecting any global.json):
 Version:   2.1.300
 Commit:    adab45bf0c

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.13
 OS Platform: Darwin
 RID:         osx.10.13-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.1.300/

Host (useful for support):
  Version: 2.1.0
  Commit:  caa7b7e2ba

.NET Core SDKs installed:
  2.1.300 [/usr/local/share/dotnet/sdk]


.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

@keeratsingh
Copy link

@corretge @moconchobhair Did you get a chance to test the connection with the latest version of .NET Core SDK 2.1.300 ?

@mcblakeb
Copy link

I am still seeing this issue on High Sierra 10.13.5

The new version of sql ops studio I downloaded fixed the issue, but I can't seem to get a .net core app to use Entity Framework to connect to a data (the same error as above and the same error I was seeing in Sql Ops Studio before I upgraded). I've tried updating all my packages in my proj file to the absolute latest nuget version with no luck:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.1" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Test.Common\Test.Common.csproj" />
  </ItemGroup>
  <PropertyGroup>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
  </PropertyGroup>
</Project>

@las3r
Copy link

las3r commented Jun 24, 2018

I have the same sort of issue. With a plain vanilla project (.net core 2.1) deployed to a CentOS Box with entity framework I receive the same stacktraces in my application as soon as it is trying to connect to SQL server (it's on the same box). I tried localhost, 127.0.0.1, domain, but all give the same error. Connecting from Windows with SQL Server Management studio works fine, so this must be an issue in the tooling / runtime available for linux or mac osx

@keeratsingh
Copy link

@corretge @moconchobhair Do you still see this issue with PowerShell Core as initially mentioned ?

@mcblakeb Could you kindly share a repro for the issue, I am unable to repro this in my environment even
with Entity Framework.

@las3r I was able to successfully connect using both localhost and 127.0.0.1 with:

  • SQL Server hosted on Windows machine from both Mac OSX and Linux client.
  • SQL Server hosted on Linux machine from both Mac OSX and Linux client.
  • SQL Server hosted on Docker on Linux machine from both Mac OSX and Linux client.

Could you kindly share:

  1. A repro of the issue, which includes the Connection String being used.
  2. Output of the command netstat -ano | grep "1433" if using Linux OR netstat -ano | find "1433" if using Windows

@gro22
Copy link

gro22 commented Jul 13, 2018

Hi @keeratsingh the same issue on the CentOS 7

sdk 2.1.302 net core 2.1.2

Was problem with nuget v3 but fix DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=false works.

And now

Retrying 'FindPackagesByIdAsync' for source 'https://api.nuget.org/v3-flatcontainer/microsoft.visualstudio.web.codegeneration.design/index.json'.
The SSL connection could not be established, see inner exception.
error:2006D002:BIO routines:BIO_new_file:system lib
Retrying 'FindPackagesByIdAsync' for source 'https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.all/index.json'.

System.Data.SqlClient.SqlException : A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)
---- Interop+Crypto+OpenSslCryptographicException : error:2006D002:BIO routines:BIO_new_file:system lib
Stack Trace:
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)

@keeratsingh
Copy link

Hi @bartonjs, @saurabh500 mentioned you might be able to guide us in the right direction on how to tackle this issue. Any suggestions/ideas ?

@bartonjs
Copy link
Member

Interop+Crypto+OpenSslCryptographicException : error:2006D002:BIO routines:BIO_new_file:system lib happening during a time when you would expect a certificate chain / trust decision means that there are files in /etc/ssl/ (or wherever the correct directory is for the distro) that are broken symlinks or they point to files the current user can't read. This is/was #26294, which will be fixed in 2.1.3.

Workarounds mainly involve fixing the contents of the cert store directory.

@corretge
Copy link
Author

Sorry @keeratsingh, I tested it but did not answer 😱

I have the same issue:

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)

dotnet version: 2.1.300

But now I can connect with the last version of SQL Operations Studio. Maybe this info helps.

@keeratsingh
Copy link

@corretge @moconchobhair @mcblakeb
This issue is fixed by dotnet/corefx#30155 as suggested by Jeremy. Could you kindly download and confirm with the Latest .NET Core SDK 2.1.302 Build if the issue is resolved.

@mcblakeb
Copy link

@keeratsingh It does indeed appear to be fixed after installing 2.1.302 on Mac. I had to update all projects over use netcoreapp2.1 as well.

@moconchobhair
Copy link

@keeratsingh I am able to successfully connect to all of my databases. Thank you so much!

@keeratsingh
Copy link

Thank you for confirmation. I will go ahead and close this issue. Feel free to reopen if the issue still exists.

@iGad
Copy link

iGad commented Jul 26, 2018

@keeratsingh the issue still exists.
dotnet --info

.NET Core SDK (reflecting any global.json):
Version: 2.1.302
Commit: 9048955

Runtime Environment:
OS Name: centos
OS Version: 7
OS Platform: Linux
RID: centos.7-x64
Base Path: /usr/share/dotnet/sdk/2.1.302/

Host (useful for support):
Version: 2.1.2
Commit: 811c3ce6c0

.NET Core SDKs installed:
2.1.302 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed) ---> Interop+Crypto+OpenSslCryptographicException: error:2006D002:BIO routines:BIO_new_file:system lib

@jsgbrl
Copy link

jsgbrl commented Jul 26, 2018

Hello, I am still having this issue on centos 7 with net core sdk 2.1.302:

os version

cat /etc/*-release

CentOS Linux release 7.5.1804 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.5.1804 (Core)
CentOS Linux release 7.5.1804 (Core)

net core version

dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   2.1.302
 Commit:    9048955601

Runtime Environment:
 OS Name:     centos
 OS Version:  7
 OS Platform: Linux
 RID:         centos.7-x64
 Base Path:   /usr/share/dotnet/sdk/2.1.302/

Host (useful for support):
  Version: 2.1.2
  Commit:  811c3ce6c0

.NET Core SDKs installed:
  2.1.302 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

systemd service definition

cat /etc/systemd/system/myservice-dev.service

[Unit]
Description=myservice
After=network.target

[Service]
WorkingDirectory=/usr/local/myservice-dev
ExecStart=/usr/bin/dotnet /usr/local/myservice-dev/webserviceproject.dll
Restart=always
# Restart service after 10 seconds if dotnet service crashes
RestartSec=10
SyslogIdentifier=myservice-dev
User=myserviceuser
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

if the user running the service is set to root then there is no exception thrown, with any other user this exception is thrown:

System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error
: 31 - Encryption(ssl/tls) handshake failed) ---> Interop+Crypto+OpenSslCryptographicException: error:2006D002:BIO routines:BIO_new_file:system lib

@iGad
Copy link

iGad commented Jul 26, 2018

Thanks @jsgbrl ! root help me.

@jbruce716
Copy link

This affects me as well, but the Ec2 that we're running doesn't have access to the root account. Our only option is a service account with sudo rights.

@dbafromthecold
Copy link

I was having this issue connecting to SQL running in a docker container via SQL Ops Studio on my laptop running Ubuntu 16.04 (logged as a bug here: - microsoft/azuredatastudio#2150). It was resolved by running: -
sudo update-ca-certificates --fresh

@fcabalfiera
Copy link

You can set TLS 1.0 to fix this.

Also , this problem can be related to a firewall in the middle that is doing SSL inspection.

I Suggest you either try again using another connection not doing SSL inspection, or ask your firewall admin to create an exemption for the source and/or destination you are connecting to,

Cheers!

@anapaolacw
Copy link

I am having this issue on Net core 2.2

@CumpsD
Copy link

CumpsD commented Jun 22, 2020

Getting this on 3.1.5 with an Azure SQL server (AspNetCore.HealthChecks.SqlServer with both Microsoft.Data.SqlClient 1.1.3 and 2.0.0)

@CumpsD
Copy link

CumpsD commented Jun 22, 2020

Sorry, my mistake getting A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: HTTP Provider, error: 0 - )

@Kane78
Copy link

Kane78 commented Jul 10, 2020

Sorry, my mistake getting A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: HTTP Provider, error: 0 - )

I got this error last week following change of one of our application to upgrade dot net core 3.1.
This quick fix was to change the connection string to add this configuration ;TrustServerCertificate=true

Look like default behavior has changed between 2.2 and 3.1

Hope that will help you

@dasiths
Copy link
Member

dasiths commented Oct 27, 2020

I don't know if this was related to the core issue but my connection string had "database=blah" and changing it to "initial catalog=blah" fixed it for me.

// Didn't work
Data Source=$(Database_Server);Database=Sitecore_Core;User ID=$(Core_Database_Username);Password=$(Core_Database_Password)

// Did work
Data Source=$(Database_Server);Initial Catalog=Sitecore_Core;User ID=$(Core_Database_Username);Password=$(Core_Database_Password)

@msftbot msftbot bot locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests