{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/comments/182724312","pull_request_review_id":113577723,"id":182724312,"diff_hunk":"@@ -51,6 +51,132 @@ public void SslStream_ClientSendsSNIServerReceives_Ok(string hostName)\n                 });\n         }\n \n+        [Theory]\n+        [MemberData(nameof(HostNameData))]\n+        public void SslStream_ServerCallbackAndLocalCertificateSelectionSet_Throws(string hostName)\n+        {\n+            X509Certificate serverCert = Configuration.Certificates.GetSelfSignedServerCertificate();\n+\n+            int timesCallbackCalled = 0;\n+\n+            var selectionCallback = new LocalCertificateSelectionCallback((object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] issuers) =>\n+            {\n+                Assert.True(false, \"LocalCertificateSelectionCallback called when AuthenticateAsServerAsync was expected to fail.\");\n+                return null;\n+            });\n+\n+            var validationCallback = new RemoteCertificateValidationCallback((object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>\n+            {\n+                Assert.Equal(serverCert, certificate);\n+                return true; \n+            });\n+\n+            VirtualNetwork vn = new VirtualNetwork();\n+            using (VirtualNetworkStream serverStream = new VirtualNetworkStream(vn, isServer: true),\n+                                        clientStream = new VirtualNetworkStream(vn, isServer: false))\n+            using (SslStream server = new SslStream(serverStream, false, null, selectionCallback),\n+                             client = new SslStream(clientStream, leaveInnerStreamOpen: false, validationCallback))\n+            {\n+                Task clientJob = Task.Run(() => {\n+                    client.AuthenticateAsClient(hostName);\n+                    Assert.True(false, \"RemoteCertificateValidationCallback called when AuthenticateAsServerAsync was expected to fail.\");\n+                });\n+\n+                SslServerAuthenticationOptions options = DefaultServerOptions();\n+                options.ServerCertificateSelectionCallback = (sender, actualHostName) =>\n+                {\n+                    timesCallbackCalled++;\n+                    Assert.Equal(hostName, actualHostName);\n+                    return serverCert;\n+                };\n+\n+                var cts = new CancellationTokenSource();\n+                Assert.Throws<InvalidOperationException>(() => {server.AuthenticateAsServerAsync(options, cts.Token).Wait();});\n+\n+                Assert.Equal(0, timesCallbackCalled);\n+            }\n+        }\n+\n+        [Theory]\n+        [MemberData(nameof(HostNameData))]\n+        public void SslStream_ServerCallbackNotSet_UsesLocalCertificateSelection(string hostName)\n+        {\n+            X509Certificate serverCert = Configuration.Certificates.GetSelfSignedServerCertificate();\n+\n+            int timesCallbackCalled = 0;\n+\n+            var selectionCallback = new LocalCertificateSelectionCallback((object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] issuers) =>\n+            {\n+                Assert.Equal(targetHost, string.Empty);\n+                Assert.True(localCertificates.Contains(serverCert));\n+                timesCallbackCalled++;\n+                return serverCert;\n+            });\n+\n+            var validationCallback = new RemoteCertificateValidationCallback((object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>\n+            {\n+                Assert.Equal(serverCert, certificate);\n+                return true;\n+            });\n+\n+            VirtualNetwork vn = new VirtualNetwork();\n+            using (VirtualNetworkStream serverStream = new VirtualNetworkStream(vn, isServer: true),\n+                                        clientStream = new VirtualNetworkStream(vn, isServer: false))\n+            using (SslStream server = new SslStream(serverStream, false, null, selectionCallback),\n+                             client = new SslStream(clientStream, leaveInnerStreamOpen: false, validationCallback))\n+            {\n+                Task clientJob = Task.Run(() => {\n+                    client.AuthenticateAsClient(hostName);\n+                });\n+\n+                SslServerAuthenticationOptions options = DefaultServerOptions();\n+                options.ServerCertificate = serverCert;\n+\n+                var cts = new CancellationTokenSource();\n+                server.AuthenticateAsServerAsync(options, cts.Token).Wait();\n+\n+                Assert.Equal(1, timesCallbackCalled);\n+                clientJob.Wait();","path":"src/System.Net.Security/tests/FunctionalTests/SslStreamSniTest.cs","position":89,"original_position":89,"commit_id":"820fcdbaefe7194a4e2cf73520682bba6c590124","original_commit_id":"820fcdbaefe7194a4e2cf73520682bba6c590124","user":{"login":"stephentoub","id":2642209,"avatar_url":"https://avatars0.githubusercontent.com/u/2642209?v=4","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":"```C#\r\nawait clientJob;\r\n```","created_at":"2018-04-19T12:13:33Z","updated_at":"2018-04-19T12:13:33Z","html_url":"https://github.com/dotnet/corefx/pull/29167#discussion_r182724312","pull_request_url":"https://api.github.com/repos/dotnet/corefx/pulls/29167","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments/182724312"},"html":{"href":"https://github.com/dotnet/corefx/pull/29167#discussion_r182724312"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/29167"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/29167","id":182325406,"html_url":"https://github.com/dotnet/corefx/pull/29167","diff_url":"https://github.com/dotnet/corefx/pull/29167.diff","patch_url":"https://github.com/dotnet/corefx/pull/29167.patch","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/29167","number":29167,"state":"open","locked":false,"title":"Ensure LocalCertificateSelectionCallback is still called with AuthenticateAsServerAsync","user":{"login":"rmkerr","id":4656175,"avatar_url":"https://avatars2.githubusercontent.com/u/4656175?v=4","gravatar_id":"","url":"https://api.github.com/users/rmkerr","html_url":"https://github.com/rmkerr","followers_url":"https://api.github.com/users/rmkerr/followers","following_url":"https://api.github.com/users/rmkerr/following{/other_user}","gists_url":"https://api.github.com/users/rmkerr/gists{/gist_id}","starred_url":"https://api.github.com/users/rmkerr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmkerr/subscriptions","organizations_url":"https://api.github.com/users/rmkerr/orgs","repos_url":"https://api.github.com/users/rmkerr/repos","events_url":"https://api.github.com/users/rmkerr/events{/privacy}","received_events_url":"https://api.github.com/users/rmkerr/received_events","type":"User","site_admin":false},"body":"In .NET Core 2.0, we call `LocalCertificateSelectionCallback` to choose the certificate during `AuthenticateAsServerAsync`. As part of adding support for SNI, this functionality was removed. However, some users have already implemented SNI using `LocalCertificateSelectionCallback`, and we should aim to maintain compatibility for them.\r\n\r\nThis change ensures that we maintain the old behavior of `LocalCertificateSelectionCallback` when the new SNI callback is not set. When both are set, we default to the new behavior. I also added two tests to verify this behavior.\r\n\r\nFixes: #29110","created_at":"2018-04-17T22:50:42Z","updated_at":"2018-04-19T12:13:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4117c17957fa671dfc61e5ffabb53cf61fb1be7f","assignee":{"login":"rmkerr","id":4656175,"avatar_url":"https://avatars2.githubusercontent.com/u/4656175?v=4","gravatar_id":"","url":"https://api.github.com/users/rmkerr","html_url":"https://github.com/rmkerr","followers_url":"https://api.github.com/users/rmkerr/followers","following_url":"https://api.github.com/users/rmkerr/following{/other_user}","gists_url":"https://api.github.com/users/rmkerr/gists{/gist_id}","starred_url":"https://api.github.com/users/rmkerr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmkerr/subscriptions","organizations_url":"https://api.github.com/users/rmkerr/orgs","repos_url":"https://api.github.com/users/rmkerr/repos","events_url":"https://api.github.com/users/rmkerr/events{/privacy}","received_events_url":"https://api.github.com/users/rmkerr/received_events","type":"User","site_admin":false},"assignees":[{"login":"rmkerr","id":4656175,"avatar_url":"https://avatars2.githubusercontent.com/u/4656175?v=4","gravatar_id":"","url":"https://api.github.com/users/rmkerr","html_url":"https://github.com/rmkerr","followers_url":"https://api.github.com/users/rmkerr/followers","following_url":"https://api.github.com/users/rmkerr/following{/other_user}","gists_url":"https://api.github.com/users/rmkerr/gists{/gist_id}","starred_url":"https://api.github.com/users/rmkerr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmkerr/subscriptions","organizations_url":"https://api.github.com/users/rmkerr/orgs","repos_url":"https://api.github.com/users/rmkerr/repos","events_url":"https://api.github.com/users/rmkerr/events{/privacy}","received_events_url":"https://api.github.com/users/rmkerr/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":497898777,"url":"https://api.github.com/repos/dotnet/corefx/labels/area-System.Net.Security","name":"area-System.Net.Security","color":"d4c5f9","default":false},{"id":145399955,"url":"https://api.github.com/repos/dotnet/corefx/labels/bug","name":"bug","color":"207de5","default":true}],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corefx/pulls/29167/commits","review_comments_url":"https://api.github.com/repos/dotnet/corefx/pulls/29167/comments","review_comment_url":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/29167/comments","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/820fcdbaefe7194a4e2cf73520682bba6c590124","head":{"label":"rmkerr:SslStream_LocalCertificateSelectionCallback_CalledOnServer","ref":"SslStream_LocalCertificateSelectionCallback_CalledOnServer","sha":"820fcdbaefe7194a4e2cf73520682bba6c590124","user":{"login":"rmkerr","id":4656175,"avatar_url":"https://avatars2.githubusercontent.com/u/4656175?v=4","gravatar_id":"","url":"https://api.github.com/users/rmkerr","html_url":"https://github.com/rmkerr","followers_url":"https://api.github.com/users/rmkerr/followers","following_url":"https://api.github.com/users/rmkerr/following{/other_user}","gists_url":"https://api.github.com/users/rmkerr/gists{/gist_id}","starred_url":"https://api.github.com/users/rmkerr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmkerr/subscriptions","organizations_url":"https://api.github.com/users/rmkerr/orgs","repos_url":"https://api.github.com/users/rmkerr/repos","events_url":"https://api.github.com/users/rmkerr/events{/privacy}","received_events_url":"https://api.github.com/users/rmkerr/received_events","type":"User","site_admin":false},"repo":{"id":112786865,"name":"corefx","full_name":"rmkerr/corefx","owner":{"login":"rmkerr","id":4656175,"avatar_url":"https://avatars2.githubusercontent.com/u/4656175?v=4","gravatar_id":"","url":"https://api.github.com/users/rmkerr","html_url":"https://github.com/rmkerr","followers_url":"https://api.github.com/users/rmkerr/followers","following_url":"https://api.github.com/users/rmkerr/following{/other_user}","gists_url":"https://api.github.com/users/rmkerr/gists{/gist_id}","starred_url":"https://api.github.com/users/rmkerr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmkerr/subscriptions","organizations_url":"https://api.github.com/users/rmkerr/orgs","repos_url":"https://api.github.com/users/rmkerr/repos","events_url":"https://api.github.com/users/rmkerr/events{/privacy}","received_events_url":"https://api.github.com/users/rmkerr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rmkerr/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. We welcome contributions.","fork":true,"url":"https://api.github.com/repos/rmkerr/corefx","forks_url":"https://api.github.com/repos/rmkerr/corefx/forks","keys_url":"https://api.github.com/repos/rmkerr/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rmkerr/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rmkerr/corefx/teams","hooks_url":"https://api.github.com/repos/rmkerr/corefx/hooks","issue_events_url":"https://api.github.com/repos/rmkerr/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/rmkerr/corefx/events","assignees_url":"https://api.github.com/repos/rmkerr/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/rmkerr/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/rmkerr/corefx/tags","blobs_url":"https://api.github.com/repos/rmkerr/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rmkerr/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rmkerr/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/rmkerr/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rmkerr/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/rmkerr/corefx/languages","stargazers_url":"https://api.github.com/repos/rmkerr/corefx/stargazers","contributors_url":"https://api.github.com/repos/rmkerr/corefx/contributors","subscribers_url":"https://api.github.com/repos/rmkerr/corefx/subscribers","subscription_url":"https://api.github.com/repos/rmkerr/corefx/subscription","commits_url":"https://api.github.com/repos/rmkerr/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/rmkerr/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/rmkerr/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/rmkerr/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/rmkerr/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/rmkerr/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rmkerr/corefx/merges","archive_url":"https://api.github.com/repos/rmkerr/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rmkerr/corefx/downloads","issues_url":"https://api.github.com/repos/rmkerr/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/rmkerr/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/rmkerr/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/rmkerr/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rmkerr/corefx/labels{/name}","releases_url":"https://api.github.com/repos/rmkerr/corefx/releases{/id}","deployments_url":"https://api.github.com/repos/rmkerr/corefx/deployments","created_at":"2017-12-01T21:06:31Z","updated_at":"2018-04-10T17:34:13Z","pushed_at":"2018-04-18T22:21:29Z","git_url":"git://github.com/rmkerr/corefx.git","ssh_url":"git@github.com:rmkerr/corefx.git","clone_url":"https://github.com/rmkerr/corefx.git","svn_url":"https://github.com/rmkerr/corefx","homepage":"https://github.com/dotnet/core","size":176356,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"1a8d874e3449213d75ce3028fdeb008ccedf3c21","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars0.githubusercontent.com/u/9141961?v=4","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://avatars0.githubusercontent.com/u/9141961?v=4","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. We welcome contributions.","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}","deployments_url":"https://api.github.com/repos/dotnet/corefx/deployments","created_at":"2014-11-06T23:42:48Z","updated_at":"2018-04-19T11:29:38Z","pushed_at":"2018-04-19T12:07:34Z","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":"https://github.com/dotnet/core","size":177344,"stargazers_count":13778,"watchers_count":13778,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3949,"mirror_url":null,"archived":false,"open_issues_count":2235,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":3949,"open_issues":2235,"watchers":13778,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/29167"},"html":{"href":"https://github.com/dotnet/corefx/pull/29167"},"issue":{"href":"https://api.github.com/repos/dotnet/corefx/issues/29167"},"comments":{"href":"https://api.github.com/repos/dotnet/corefx/issues/29167/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/29167/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/29167/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corefx/statuses/820fcdbaefe7194a4e2cf73520682bba6c590124"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"stephentoub"}}