{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/6750","repository_url":"https://api.github.com/repos/dotnet/corefx","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/6750/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/6750/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/6750/events","html_url":"https://github.com/dotnet/corefx/pull/6750","id":139368309,"number":6750,"title":"Two error handling changes to SslStream","user":{"login":"stephentoub","id":2642209,"avatar_url":"https://avatars.githubusercontent.com/u/2642209?v=3","gravatar_id":"","url":"https://api.github.com/users/stephentoub","html_url":"https://github.com/stephentoub","followers_url":"https://api.github.com/users/stephentoub/followers","following_url":"https://api.github.com/users/stephentoub/following{/other_user}","gists_url":"https://api.github.com/users/stephentoub/gists{/gist_id}","starred_url":"https://api.github.com/users/stephentoub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stephentoub/subscriptions","organizations_url":"https://api.github.com/users/stephentoub/orgs","repos_url":"https://api.github.com/users/stephentoub/repos","events_url":"https://api.github.com/users/stephentoub/events{/privacy}","received_events_url":"https://api.github.com/users/stephentoub/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/corefx/labels/2%20-%20In%20Progress","name":"2 - In Progress","color":"CCCCCC"},{"url":"https://api.github.com/repos/dotnet/corefx/labels/cla-already-signed","name":"cla-already-signed","color":"009800"},{"url":"https://api.github.com/repos/dotnet/corefx/labels/System.Net","name":"System.Net","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-08T19:19:00Z","updated_at":"2016-03-08T23:02:07Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/6750","html_url":"https://github.com/dotnet/corefx/pull/6750","diff_url":"https://github.com/dotnet/corefx/pull/6750.diff","patch_url":"https://github.com/dotnet/corefx/pull/6750.patch"},"body":"Commit (1). Pass Exception through SecurityStatusPal in SslStream. There isn't a good mapping between OpenSSL errors and most of the errors in SecurityStatusPal.  As a result, with the current set up, important information about errors that occurred is getting lost and translated into meaningless information by the time it makes it out to the developer, making it difficult to diagnose the cause of a failure. This commit allows the original exception behind a failure to be passed through the PAL layer, such that when an exception is eventually thrown, the Unix implementation can choose to use the original exception rather than translating the error code.  For example, instead of:\r\n```\r\nSystem.Security.Authentication.AuthenticationException : A call to SSPI failed, see inner exception.\r\n---- Interop+OpenSsl+SslException : Operation failed with error - 12.\r\n```\r\n(where \"12\" is the number that ends up getting used for all failures, as the numerical value of SecurityStatusPal.InternalError), we now get:\r\n```\r\nSystem.Security.Authentication.AuthenticationException : A call to SSPI failed, see inner exception.\r\n---- Interop+OpenSsl+SslException : SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.\r\n-------- Interop+Crypto+OpenSslCryptographicException : error:140740B5:SSL routines:SSL23_CLIENT_HELLO:no ciphers available\r\n```\r\n\r\nCommit (2). Use ExceptionDispatchInfo in SslStream. Currently in SslStream, exceptions get captured and then later thrown with \"throw exception;\".  This causes their stack traces to get overwritten, losing information about where the exception actually came from.  This commit changes these locations to use ExceptionDispatchInfo instead, enabling the stacks and Watson bucket information to be preserved. For example, instead of:\r\n```\r\nSystem.IO.IOException: Authentication failed because the remote party has closed the transport stream.\r\n     at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult) in corefx\\src\\System.Net.Security\\src\\System\\Net\\SecureProtocols\\SslState.cs:line 752\r\n     at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result) in corefx\\src\\System.Net.Security\\src\\System\\Net\\SecureProtocols\\SslState.cs:line 722\r\n     at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult) in corefx\\src\\System.Net.Security\\src\\System\\Net\\SecureProtocols\\SslStream.cs:line 125\r\n     at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)\r\n  --- End of stack trace from previous location where exception was thrown ---\r\n     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n     at Xunit.Assert.<RecordExceptionAsync>d__61.MoveNext()\r\n```\r\nwe now get:\r\n```\r\nSystem.IO.IOException: Authentication failed because the remote party has closed the transport stream.\r\n     at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) in corefx\\src\\System.Net.Security\\src\\System\\Net\\SecureProtocols\\SslState.cs:line 882\r\n     at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest) in corefx\\src\\System.Net.Security\\src\\System\\Net\\SecureProtocols\\SslState.cs:line 1110\r\n  --- End of stack trace from previous location where exception was thrown ---\r\n     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n     at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult) in corefx\\src\\System.Net.Security\\src\\System\\Net\\SecureProtocols\\SslState.cs:line 752\r\n     at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result) in corefx\\src\\System.Net.Security\\src\\System\\Net\\SecureProtocols\\SslState.cs:line 722\r\n     at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult) in corefx\\src\\System.Net.Security\\src\\System\\Net\\SecureProtocols\\SslStream.cs:line 125\r\n     at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)\r\n  --- End of stack trace from previous location where exception was thrown ---\r\n     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n     at Xunit.Assert.<RecordExceptionAsync>d__61.MoveNext()\r\n```\r\nContributes to https://github.com/dotnet/corefx/issues/5606 and https://github.com/dotnet/corefx/issues/5890. For both this doesn't completely fix the issue: I've stayed away from touching NegotiateStream to avoid conflicts with the incoming PR from the NegotiateStream work on Unix.\r\n\r\nCommit (3).  Fixes some warnings during the build for the System.Net.Security.Tests project when building for Unix.\r\n\r\ncc: @davidsh, @cipop, @ericeil, @bartonjs, @vijaykota, @kapilash "},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/194008515","html_url":"https://github.com/dotnet/corefx/pull/6750#issuecomment-194008515","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/6750","id":194008515,"user":{"login":"mmitche","id":8725170,"avatar_url":"https://avatars.githubusercontent.com/u/8725170?v=3","gravatar_id":"","url":"https://api.github.com/users/mmitche","html_url":"https://github.com/mmitche","followers_url":"https://api.github.com/users/mmitche/followers","following_url":"https://api.github.com/users/mmitche/following{/other_user}","gists_url":"https://api.github.com/users/mmitche/gists{/gist_id}","starred_url":"https://api.github.com/users/mmitche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmitche/subscriptions","organizations_url":"https://api.github.com/users/mmitche/orgs","repos_url":"https://api.github.com/users/mmitche/repos","events_url":"https://api.github.com/users/mmitche/events{/privacy}","received_events_url":"https://api.github.com/users/mmitche/received_events","type":"User","site_admin":false},"created_at":"2016-03-08T23:02:07Z","updated_at":"2016-03-08T23:02:07Z","body":"@stephentoub Just demoing"}}