{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/comments/40788947","id":40788947,"diff_hunk":"@@ -0,0 +1,107 @@\n+// Copyright (c) Microsoft. All rights reserved.\n+// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n+\n+using System;\n+using System.Runtime.InteropServices;\n+using Microsoft.Win32.SafeHandles;\n+\n+internal static partial class Interop\n+{\n+    internal static partial class libssl\n+    {\n+        internal sealed class SafeSslContextHandle : SafeHandle\n+        {\n+            public SafeSslContextHandle(IntPtr method)\n+                : base(IntPtr.Zero, true)\n+            {\n+                handle = SSL_CTX_new(method);\n+            }\n+\n+            public override bool IsInvalid\n+            {\n+                get { return handle == IntPtr.Zero; }\n+            }\n+\n+            protected override bool ReleaseHandle()\n+            {\n+                SSL_CTX_free(handle);\n+                return true;\n+            }\n+        }\n+\n+        internal sealed class SafeSslHandle : SafeHandle\n+        {\n+            private readonly SafeBioHandle _readBio;\n+            private readonly SafeBioHandle _writeBio;\n+            private bool _isServer;\n+\n+            public bool IsServer\n+            {\n+                get {return _isServer;}\n+            }\n+\n+            public SafeBioHandle InputBio\n+            {\n+                get\n+                {\n+                    return _readBio;\n+                }\n+            }\n+\n+            public SafeBioHandle OutputBio\n+            {\n+                get\n+                {\n+                    return _writeBio;\n+                }\n+            }\n+\n+            public SafeSslHandle(SafeSslContextHandle context, bool isServer)\n+                : base(IntPtr.Zero, true)\n+            {\n+                _isServer = isServer;\n+\n+                IntPtr memMethod = Interop.libcrypto.BIO_s_mem();\n+                _readBio = Interop.libcrypto.BIO_new(memMethod);\n+                _writeBio = Interop.libcrypto.BIO_new(memMethod);\n+                \n+                IntPtr tempHandle = SSL_new(context);\n+                if (tempHandle == IntPtr.Zero)\n+                {\n+                    return;\n+                }\n+\n+                // After SSL_set_bio, the BIO handles are owned by SSL pointer\n+                // and are automatically freed by SSL_free. To prevent a double\n+                // free, we need to keep the ref counts bumped up till SSL_free\n+                bool gotReadRef = false, gotWriteRef = false;\n+                _readBio.DangerousAddRef(ref gotReadRef);\n+                _writeBio.DangerousAddRef(ref gotWriteRef);\n+                SSL_set_bio(tempHandle, _readBio.DangerousGetHandle(), _writeBio.DangerousGetHandle());\n+                handle = tempHandle;\n+\n+                if (isServer)\n+                {\n+                    SSL_set_accept_state(handle);\n+                }\n+                else\n+                {\n+                    SSL_set_connect_state(handle);\n+                }\n+            }\n+\n+            public override bool IsInvalid\n+            {\n+                get { return handle == IntPtr.Zero; }\n+            }\n+\n+            protected override bool ReleaseHandle()\n+            {\n+                SSL_free(handle);\n+                _readBio.SetHandleAsInvalid();  // BIO got freed in SSL_free","path":"src/Common/src/Interop/Unix/libssl/Interop.SafeSslHandle.cs","position":101,"original_position":101,"commit_id":"04a1c741639b471222f7985a22ffd6c6f36fb379","original_commit_id":"de77db1d1f90d240ff951b24e8871c67203bf419","user":{"login":"bartonjs","id":10642668,"avatar_url":"https://avatars.githubusercontent.com/u/10642668?v=3","gravatar_id":"","url":"https://api.github.com/users/bartonjs","html_url":"https://github.com/bartonjs","followers_url":"https://api.github.com/users/bartonjs/followers","following_url":"https://api.github.com/users/bartonjs/following{/other_user}","gists_url":"https://api.github.com/users/bartonjs/gists{/gist_id}","starred_url":"https://api.github.com/users/bartonjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartonjs/subscriptions","organizations_url":"https://api.github.com/users/bartonjs/orgs","repos_url":"https://api.github.com/users/bartonjs/repos","events_url":"https://api.github.com/users/bartonjs/events{/privacy}","received_events_url":"https://api.github.com/users/bartonjs/received_events","type":"User","site_admin":false},"body":"Oh... I think I understand the problem; it's that you need to write into / read from them still.\r\n\r\nRight.  Nevermind :)","created_at":"2015-09-30T12:49:49Z","updated_at":"2015-09-30T12:49:49Z","html_url":"https://github.com/dotnet/corefx/pull/3528#discussion_r40788947","pull_request_url":"https://api.github.com/repos/dotnet/corefx/pulls/3528","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments/40788947"},"html":{"href":"https://github.com/dotnet/corefx/pull/3528#discussion_r40788947"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3528"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/3528","id":46277524,"html_url":"https://github.com/dotnet/corefx/pull/3528","diff_url":"https://github.com/dotnet/corefx/pull/3528.diff","patch_url":"https://github.com/dotnet/corefx/pull/3528.patch","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/3528","number":3528,"state":"open","locked":false,"title":"Using SafeHandles instead of IntPtrs in Interop.libssl","user":{"login":"vijaykota","id":11638339,"avatar_url":"https://avatars.githubusercontent.com/u/11638339?v=3","gravatar_id":"","url":"https://api.github.com/users/vijaykota","html_url":"https://github.com/vijaykota","followers_url":"https://api.github.com/users/vijaykota/followers","following_url":"https://api.github.com/users/vijaykota/following{/other_user}","gists_url":"https://api.github.com/users/vijaykota/gists{/gist_id}","starred_url":"https://api.github.com/users/vijaykota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vijaykota/subscriptions","organizations_url":"https://api.github.com/users/vijaykota/orgs","repos_url":"https://api.github.com/users/vijaykota/repos","events_url":"https://api.github.com/users/vijaykota/events{/privacy}","received_events_url":"https://api.github.com/users/vijaykota/received_events","type":"User","site_admin":false},"body":"Changed the Unix code to use SafeHandles\r\n\r\ncc: @stephentoub @bartonjs @rajansingh10 @shrutigarg ","created_at":"2015-09-29T13:37:44Z","updated_at":"2015-09-30T12:49:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ecfbe0ce4fcea136785afc1a3c0b33e08a7ec9e3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corefx/pulls/3528/commits","review_comments_url":"https://api.github.com/repos/dotnet/corefx/pulls/3528/comments","review_comment_url":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/3528/comments","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/04a1c741639b471222f7985a22ffd6c6f36fb379","head":{"label":"vijaykota:feature","ref":"feature","sha":"04a1c741639b471222f7985a22ffd6c6f36fb379","user":{"login":"vijaykota","id":11638339,"avatar_url":"https://avatars.githubusercontent.com/u/11638339?v=3","gravatar_id":"","url":"https://api.github.com/users/vijaykota","html_url":"https://github.com/vijaykota","followers_url":"https://api.github.com/users/vijaykota/followers","following_url":"https://api.github.com/users/vijaykota/following{/other_user}","gists_url":"https://api.github.com/users/vijaykota/gists{/gist_id}","starred_url":"https://api.github.com/users/vijaykota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vijaykota/subscriptions","organizations_url":"https://api.github.com/users/vijaykota/orgs","repos_url":"https://api.github.com/users/vijaykota/repos","events_url":"https://api.github.com/users/vijaykota/events{/privacy}","received_events_url":"https://api.github.com/users/vijaykota/received_events","type":"User","site_admin":false},"repo":{"id":39578675,"name":"corefx","full_name":"vijaykota/corefx","owner":{"login":"vijaykota","id":11638339,"avatar_url":"https://avatars.githubusercontent.com/u/11638339?v=3","gravatar_id":"","url":"https://api.github.com/users/vijaykota","html_url":"https://github.com/vijaykota","followers_url":"https://api.github.com/users/vijaykota/followers","following_url":"https://api.github.com/users/vijaykota/following{/other_user}","gists_url":"https://api.github.com/users/vijaykota/gists{/gist_id}","starred_url":"https://api.github.com/users/vijaykota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vijaykota/subscriptions","organizations_url":"https://api.github.com/users/vijaykota/orgs","repos_url":"https://api.github.com/users/vijaykota/repos","events_url":"https://api.github.com/users/vijaykota/events{/privacy}","received_events_url":"https://api.github.com/users/vijaykota/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vijaykota/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":true,"url":"https://api.github.com/repos/vijaykota/corefx","forks_url":"https://api.github.com/repos/vijaykota/corefx/forks","keys_url":"https://api.github.com/repos/vijaykota/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vijaykota/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vijaykota/corefx/teams","hooks_url":"https://api.github.com/repos/vijaykota/corefx/hooks","issue_events_url":"https://api.github.com/repos/vijaykota/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/vijaykota/corefx/events","assignees_url":"https://api.github.com/repos/vijaykota/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/vijaykota/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/vijaykota/corefx/tags","blobs_url":"https://api.github.com/repos/vijaykota/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vijaykota/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vijaykota/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/vijaykota/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vijaykota/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/vijaykota/corefx/languages","stargazers_url":"https://api.github.com/repos/vijaykota/corefx/stargazers","contributors_url":"https://api.github.com/repos/vijaykota/corefx/contributors","subscribers_url":"https://api.github.com/repos/vijaykota/corefx/subscribers","subscription_url":"https://api.github.com/repos/vijaykota/corefx/subscription","commits_url":"https://api.github.com/repos/vijaykota/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/vijaykota/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/vijaykota/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/vijaykota/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/vijaykota/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/vijaykota/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vijaykota/corefx/merges","archive_url":"https://api.github.com/repos/vijaykota/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vijaykota/corefx/downloads","issues_url":"https://api.github.com/repos/vijaykota/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/vijaykota/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/vijaykota/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/vijaykota/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vijaykota/corefx/labels{/name}","releases_url":"https://api.github.com/repos/vijaykota/corefx/releases{/id}","created_at":"2015-07-23T16:32:30Z","updated_at":"2015-07-23T16:32:47Z","pushed_at":"2015-09-30T04:12:20Z","git_url":"git://github.com/vijaykota/corefx.git","ssh_url":"git@github.com:vijaykota/corefx.git","clone_url":"https://github.com/vijaykota/corefx.git","svn_url":"https://github.com/vijaykota/corefx","homepage":"http://dotnet.github.io/core/","size":32715,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"ebd82ba9e5032813ef68a381400130e51b682c88","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":"2015-09-30T12:14:08Z","pushed_at":"2015-09-30T04:53:47Z","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/core/","size":73911,"stargazers_count":8412,"watchers_count":8412,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1828,"mirror_url":null,"open_issues_count":621,"forks":1828,"open_issues":621,"watchers":8412,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3528"},"html":{"href":"https://github.com/dotnet/corefx/pull/3528"},"issue":{"href":"https://api.github.com/repos/dotnet/corefx/issues/3528"},"comments":{"href":"https://api.github.com/repos/dotnet/corefx/issues/3528/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3528/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3528/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corefx/statuses/04a1c741639b471222f7985a22ffd6c6f36fb379"}}}}