{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/comments/50395496","id":50395496,"diff_hunk":"@@ -19,6 +19,11 @@ extern \"C\" uint64_t CryptoNative_ErrGetError()\n     return ERR_get_error();\n }\n \n+extern \"C\" uint64_t CryptoNative_ErrPeekError()\n+{\n+    return ERR_peek_error();\n+}\n+\n // TODO: temporarily keeping the un-prefixed signature of this method  ","path":"src/Native/System.Security.Cryptography.Native/pal_err.cpp","position":9,"original_position":9,"commit_id":"197ee70335901000b953eff23bc1bacddba40670","original_commit_id":"197ee70335901000b953eff23bc1bacddba40670","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},"body":"Yes.  There's already a PR out to fix these TODOs, though, so I'm not adding the number.","created_at":"2016-01-21T12:39:04Z","updated_at":"2016-01-21T12:39:04Z","html_url":"https://github.com/dotnet/corefx/pull/5551#discussion_r50395496","pull_request_url":"https://api.github.com/repos/dotnet/corefx/pulls/5551","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments/50395496"},"html":{"href":"https://github.com/dotnet/corefx/pull/5551#discussion_r50395496"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/5551"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/5551","id":56634320,"html_url":"https://github.com/dotnet/corefx/pull/5551","diff_url":"https://github.com/dotnet/corefx/pull/5551.diff","patch_url":"https://github.com/dotnet/corefx/pull/5551.patch","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/5551","number":5551,"state":"open","locked":false,"title":"Several System.Net.Security fixes","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},"body":"1. Windows and Unix.  The ProcessAuthentication method sets a flag to indicate that an operation is in progress, then kicks off the operation, and then in a finally block potentially resets the flag.  The intent of resetting it is to reset the flag iff the operation is no longer in progress, which would be the case if the operation was synchronous or if the initiation of the asynchronous operation resulted in an exception.  As such, the finally block is checking whether the operation was synchronous or whether an exception has been captured. However, for the exceptional case, this leads to race conditions.  The initiation of the asynchronous operaiton can lead to the operation running concurrently with the remainder of the ProcessAuthentication method, namely concurrently with the finally block.  If the operation starts quickly and fails quickly, it'll store the exception, which will cause the finally block to see that an exception has been captured and mistakenly believe that the operation failed synchronously, thus resetting the flag.  But the operation was actually asynchronous, and when EndAuthentication is called, it'll see that the flag has been reset and think that the EndAuthentication call is erroneous, thus throwing an exception.  While it should throw an exception (the one that caused the operation to fail), it ends up throwing an InvalidOperationException instead to signal that EndAuthentication was used incorrectly. The fix is to move the check for the exceptional situation out of the finally and into a catch block.  The catch block is then used to reset the flag only if an exception emerges synchronously, and the finally block is used to reset the flag only for synchronous operations.  (It's possible that for synchronous operations that fail, the flag could be written as 0 twice... that's fine.) This fixes the failure on both Windows and Unix.  The failure wasn't reproing on Windows but only because of differences in timing... adding a brief pause at the end of the try block would trigger the failure on Windows as well.\r\n\r\n2. Unix.  The design of AuthenticateAsServerAsync has a clientCertificatesRequired flag.  On Unix we were mapping that to \"SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT\", which causes OpenSSL to fail the handshake if no cert is provided.  But the Windows code actually still allows this through, instead setting a policy error to indicate that no certificate was required.  I'm simply removing the SSL_VERIFY_FAIL_IF_NO_PEER_CERT flag to match that design.  I've also updated the test to assert that the error is actually being set.\r\n\r\n3. Unix.  When SSL failures occur, there are multiple places to check for errors.  One starts with SSL errors, then potentially examines general crypto errors, and then potentially examines errno values.  Our code wasn't properly handling this, and even for situations where it was, it was potentially conflating all of the values together as the first category, making it more difficult to interpret and tell them apart.  This updates the code to capture the appropriate exception information.  There are still some issues around properly mapping and roundtripping error values between the Unix PAL implementation and the consuming shared code, but this at least makes it easier for a developer of the library to debug issues.\r\n\r\n4. Linux.  All of the System.Net.Security tests were disabled on Unix.  I've re-enabled them on Linux now that the causes for the failures have been fixed.  I've not yet verified the fixes on OS X, so I've left them disabled there for now.\r\n\r\ncc: @bartonjs, @ericeil, @cipop, @davidsh, @vijaykota \r\nFixes https://github.com/dotnet/corefx/issues/4317, https://github.com/dotnet/corefx/issues/4606","created_at":"2016-01-20T16:47:35Z","updated_at":"2016-01-21T12:39:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3d0bc8b1808ee44a2aeefeecc9a12048fc78c778","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corefx/pulls/5551/commits","review_comments_url":"https://api.github.com/repos/dotnet/corefx/pulls/5551/comments","review_comment_url":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/5551/comments","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/197ee70335901000b953eff23bc1bacddba40670","head":{"label":"stephentoub:secure_unix","ref":"secure_unix","sha":"197ee70335901000b953eff23bc1bacddba40670","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},"repo":{"id":26551529,"name":"corefx","full_name":"stephentoub/corefx","owner":{"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},"private":false,"html_url":"https://github.com/stephentoub/corefx","description":"This repository contains the foundational libraries that make up the .NET Core development stack.","fork":true,"url":"https://api.github.com/repos/stephentoub/corefx","forks_url":"https://api.github.com/repos/stephentoub/corefx/forks","keys_url":"https://api.github.com/repos/stephentoub/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stephentoub/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stephentoub/corefx/teams","hooks_url":"https://api.github.com/repos/stephentoub/corefx/hooks","issue_events_url":"https://api.github.com/repos/stephentoub/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/stephentoub/corefx/events","assignees_url":"https://api.github.com/repos/stephentoub/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/stephentoub/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/stephentoub/corefx/tags","blobs_url":"https://api.github.com/repos/stephentoub/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stephentoub/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stephentoub/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/stephentoub/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stephentoub/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/stephentoub/corefx/languages","stargazers_url":"https://api.github.com/repos/stephentoub/corefx/stargazers","contributors_url":"https://api.github.com/repos/stephentoub/corefx/contributors","subscribers_url":"https://api.github.com/repos/stephentoub/corefx/subscribers","subscription_url":"https://api.github.com/repos/stephentoub/corefx/subscription","commits_url":"https://api.github.com/repos/stephentoub/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/stephentoub/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/stephentoub/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/stephentoub/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/stephentoub/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/stephentoub/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stephentoub/corefx/merges","archive_url":"https://api.github.com/repos/stephentoub/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stephentoub/corefx/downloads","issues_url":"https://api.github.com/repos/stephentoub/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/stephentoub/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/stephentoub/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/stephentoub/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stephentoub/corefx/labels{/name}","releases_url":"https://api.github.com/repos/stephentoub/corefx/releases{/id}","created_at":"2014-11-12T19:06:24Z","updated_at":"2016-01-11T15:13:21Z","pushed_at":"2016-01-21T02:34:21Z","git_url":"git://github.com/stephentoub/corefx.git","ssh_url":"git@github.com:stephentoub/corefx.git","clone_url":"https://github.com/stephentoub/corefx.git","svn_url":"https://github.com/stephentoub/corefx","homepage":"","size":45880,"stargazers_count":1,"watchers_count":1,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"4aa6ec7b20e846e9b6f1207cb3b152d907ce6ade","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":26295345,"name":"corefx","full_name":"dotnet/corefx","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/corefx","description":"This repo contains the .NET Core foundational libraries, called CoreFX. It includes classes for collections, file systems, console, XML, async and many others.","fork":false,"url":"https://api.github.com/repos/dotnet/corefx","forks_url":"https://api.github.com/repos/dotnet/corefx/forks","keys_url":"https://api.github.com/repos/dotnet/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/corefx/teams","hooks_url":"https://api.github.com/repos/dotnet/corefx/hooks","issue_events_url":"https://api.github.com/repos/dotnet/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/corefx/events","assignees_url":"https://api.github.com/repos/dotnet/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/corefx/tags","blobs_url":"https://api.github.com/repos/dotnet/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/corefx/languages","stargazers_url":"https://api.github.com/repos/dotnet/corefx/stargazers","contributors_url":"https://api.github.com/repos/dotnet/corefx/contributors","subscribers_url":"https://api.github.com/repos/dotnet/corefx/subscribers","subscription_url":"https://api.github.com/repos/dotnet/corefx/subscription","commits_url":"https://api.github.com/repos/dotnet/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/corefx/merges","archive_url":"https://api.github.com/repos/dotnet/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/corefx/downloads","issues_url":"https://api.github.com/repos/dotnet/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/corefx/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/corefx/releases{/id}","created_at":"2014-11-06T23:42:48Z","updated_at":"2016-01-21T12:29:06Z","pushed_at":"2016-01-21T08:43:45Z","git_url":"git://github.com/dotnet/corefx.git","ssh_url":"git@github.com:dotnet/corefx.git","clone_url":"https://github.com/dotnet/corefx.git","svn_url":"https://github.com/dotnet/corefx","homepage":"http://dotnet.github.io/","size":55974,"stargazers_count":8971,"watchers_count":8971,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2064,"mirror_url":null,"open_issues_count":827,"forks":2064,"open_issues":827,"watchers":8971,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/5551"},"html":{"href":"https://github.com/dotnet/corefx/pull/5551"},"issue":{"href":"https://api.github.com/repos/dotnet/corefx/issues/5551"},"comments":{"href":"https://api.github.com/repos/dotnet/corefx/issues/5551/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/5551/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/5551/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corefx/statuses/197ee70335901000b953eff23bc1bacddba40670"}}}}