{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/comments/40958654","id":40958654,"diff_hunk":"@@ -0,0 +1,212 @@\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.IO;\n+\n+namespace System.Data.SqlClient.SNI\n+{\n+    /// <summary>\n+    /// SSL encapsulated over TDS transport. During SSL handshake, SSL packets are\n+    /// transported in TDS packet type 0x12. Once SSL handshake has completed, SSL\n+    /// packets are sent transparently.\n+    /// </summary>\n+    internal sealed class SslOverTdsStream : Stream\n+    {\n+        private Stream _stream;\n+        private bool _encapsulate;\n+        private int _packetBytes = 0;\n+\n+        /// <summary>\n+        /// Constructor\n+        /// </summary>\n+        /// <param name=\"stream\">Underlying stream</param>\n+        public SslOverTdsStream(Stream stream)\n+        {\n+            _stream = stream;\n+            _encapsulate = true;\n+        }\n+\n+        /// <summary>\n+        /// Finish SSL handshake. Stop encapsulating in TDS.\n+        /// </summary>\n+        public void FinishHandshake()\n+        {\n+            _encapsulate = false;\n+        }\n+\n+        /// <summary>\n+        /// Read buffer\n+        /// </summary>\n+        /// <param name=\"buffer\">Buffer</param>\n+        /// <param name=\"offset\">Offset</param>\n+        /// <param name=\"count\">Byte count</param>\n+        /// <returns>Bytes read</returns>\n+        public override int Read(byte[] buffer, int offset, int count)\n+        {\n+            int readBytes;\n+            byte[] scratch = new byte[count < 8 ? 8 : count];\n+\n+            if (_encapsulate)\n+            {\n+                if (_packetBytes == 0)\n+                {\n+                    readBytes = _stream.Read(scratch, 0, 8);\n+                    _packetBytes = scratch[2] * 256;\n+                    _packetBytes += scratch[3];\n+                    _packetBytes -= 8;\n+                }\n+\n+                if (count > _packetBytes)\n+                {\n+                    count = _packetBytes;\n+                }\n+            }\n+\n+            readBytes = _stream.Read(scratch, 0, count);\n+\n+            if (_encapsulate)\n+            {\n+                _packetBytes -= readBytes;\n+            }\n+\n+            Buffer.BlockCopy(scratch, 0, buffer, offset, readBytes);\n+            return readBytes;\n+        }\n+\n+        /// <summary>\n+        /// Write buffer\n+        /// </summary>\n+        /// <param name=\"buffer\">Buffer</param>\n+        /// <param name=\"offset\">Offset</param>\n+        /// <param name=\"count\">Byte count</param>\n+        public override void Write(byte[] buffer, int offset, int count)\n+        {\n+            int currentCount = 0;\n+            int currentOffset = offset;\n+\n+            while (count > 0)\n+            {\n+                // During the SSL negotiation phase, SSL is tunnelled over TDS packet type 0x12. After\n+                // negotiation, the underlying socket only sees SSL frames.\n+                //\n+                if (_encapsulate)\n+                {\n+                    if (count > 4088)\n+                    {\n+                        currentCount = 4088;\n+                    }\n+                    else\n+                    {\n+                        currentCount = count;\n+                    }\n+\n+                    count -= currentCount;\n+\n+                    byte[] header = new byte[8];\n+\n+                    // We can only send 4088 bytes in one packet. Header[1] is set to 1 if this is a \n+                    // partial packet (whether or not count != 0).\n+                    // \n+                    header[0] = 0x12;\n+                    header[1] = (byte)(count > 0 ? 0 : 1);\n+                    header[2] = (byte)((currentCount + 8) / 256);\n+                    header[3] = (byte)((currentCount + 8) % 256);\n+                    header[4] = 0;\n+                    header[5] = 0;\n+                    header[6] = 0;\n+                    header[7] = 0;\n+\n+                    _stream.Write(header, 0, 8);\n+                    _stream.Flush();\n+                }\n+                else\n+                {\n+                    currentCount = count;\n+                    count = 0;\n+                }\n+\n+                _stream.Write(buffer, currentOffset, currentCount);\n+                _stream.Flush();\n+                currentOffset += currentCount;\n+            }\n+        }\n+\n+        /// <summary>\n+        /// Set stream length. \n+        /// </summary>\n+        /// <param name=\"value\">Length</param>\n+        public override void SetLength(long value)\n+        {\n+            throw NotImplemented.ByDesignWithMessage(\"Not required\");","path":"src/System.Data.SqlClient/src/System/Data/SqlClient/SNI/SslOverTdsStream.cs","position":140,"original_position":140,"commit_id":"b0f1241bdd5f3e98810ece67f963bfa7ac91a9fd","original_commit_id":"b0f1241bdd5f3e98810ece67f963bfa7ac91a9fd","user":{"login":"corivera","id":12820011,"avatar_url":"https://avatars.githubusercontent.com/u/12820011?v=3","gravatar_id":"","url":"https://api.github.com/users/corivera","html_url":"https://github.com/corivera","followers_url":"https://api.github.com/users/corivera/followers","following_url":"https://api.github.com/users/corivera/following{/other_user}","gists_url":"https://api.github.com/users/corivera/gists{/gist_id}","starred_url":"https://api.github.com/users/corivera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/corivera/subscriptions","organizations_url":"https://api.github.com/users/corivera/orgs","repos_url":"https://api.github.com/users/corivera/repos","events_url":"https://api.github.com/users/corivera/events{/privacy}","received_events_url":"https://api.github.com/users/corivera/received_events","type":"User","site_admin":false},"body":"Fixed.","created_at":"2015-10-01T19:56:21Z","updated_at":"2015-10-01T19:56:21Z","html_url":"https://github.com/dotnet/corefx/pull/3567#discussion_r40958654","pull_request_url":"https://api.github.com/repos/dotnet/corefx/pulls/3567","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments/40958654"},"html":{"href":"https://github.com/dotnet/corefx/pull/3567#discussion_r40958654"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3567"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/3567","id":46474607,"html_url":"https://github.com/dotnet/corefx/pull/3567","diff_url":"https://github.com/dotnet/corefx/pull/3567.diff","patch_url":"https://github.com/dotnet/corefx/pull/3567.patch","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/3567","number":3567,"state":"open","locked":false,"title":"Adding the Managed SNI for System.Data.SqlClient for xplat","user":{"login":"saurabh500","id":1623701,"avatar_url":"https://avatars.githubusercontent.com/u/1623701?v=3","gravatar_id":"","url":"https://api.github.com/users/saurabh500","html_url":"https://github.com/saurabh500","followers_url":"https://api.github.com/users/saurabh500/followers","following_url":"https://api.github.com/users/saurabh500/following{/other_user}","gists_url":"https://api.github.com/users/saurabh500/gists{/gist_id}","starred_url":"https://api.github.com/users/saurabh500/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saurabh500/subscriptions","organizations_url":"https://api.github.com/users/saurabh500/orgs","repos_url":"https://api.github.com/users/saurabh500/repos","events_url":"https://api.github.com/users/saurabh500/events{/privacy}","received_events_url":"https://api.github.com/users/saurabh500/received_events","type":"User","site_admin":false},"body":"The code contains the Network interaction of the SqlDriver ported to Managed code.\r\n\r\nThe code supports tcp connectivity scenario.\r\n","created_at":"2015-10-01T00:47:08Z","updated_at":"2015-10-01T19:56:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9e7fa49bf6d6c864f8b9f81dd4b613ab2848061e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corefx/pulls/3567/commits","review_comments_url":"https://api.github.com/repos/dotnet/corefx/pulls/3567/comments","review_comment_url":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/3567/comments","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/b0f1241bdd5f3e98810ece67f963bfa7ac91a9fd","head":{"label":"saurabh500:managedsni","ref":"managedsni","sha":"b0f1241bdd5f3e98810ece67f963bfa7ac91a9fd","user":{"login":"saurabh500","id":1623701,"avatar_url":"https://avatars.githubusercontent.com/u/1623701?v=3","gravatar_id":"","url":"https://api.github.com/users/saurabh500","html_url":"https://github.com/saurabh500","followers_url":"https://api.github.com/users/saurabh500/followers","following_url":"https://api.github.com/users/saurabh500/following{/other_user}","gists_url":"https://api.github.com/users/saurabh500/gists{/gist_id}","starred_url":"https://api.github.com/users/saurabh500/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saurabh500/subscriptions","organizations_url":"https://api.github.com/users/saurabh500/orgs","repos_url":"https://api.github.com/users/saurabh500/repos","events_url":"https://api.github.com/users/saurabh500/events{/privacy}","received_events_url":"https://api.github.com/users/saurabh500/received_events","type":"User","site_admin":false},"repo":{"id":41459213,"name":"corefx","full_name":"saurabh500/corefx","owner":{"login":"saurabh500","id":1623701,"avatar_url":"https://avatars.githubusercontent.com/u/1623701?v=3","gravatar_id":"","url":"https://api.github.com/users/saurabh500","html_url":"https://github.com/saurabh500","followers_url":"https://api.github.com/users/saurabh500/followers","following_url":"https://api.github.com/users/saurabh500/following{/other_user}","gists_url":"https://api.github.com/users/saurabh500/gists{/gist_id}","starred_url":"https://api.github.com/users/saurabh500/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saurabh500/subscriptions","organizations_url":"https://api.github.com/users/saurabh500/orgs","repos_url":"https://api.github.com/users/saurabh500/repos","events_url":"https://api.github.com/users/saurabh500/events{/privacy}","received_events_url":"https://api.github.com/users/saurabh500/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/saurabh500/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/saurabh500/corefx","forks_url":"https://api.github.com/repos/saurabh500/corefx/forks","keys_url":"https://api.github.com/repos/saurabh500/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/saurabh500/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/saurabh500/corefx/teams","hooks_url":"https://api.github.com/repos/saurabh500/corefx/hooks","issue_events_url":"https://api.github.com/repos/saurabh500/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/saurabh500/corefx/events","assignees_url":"https://api.github.com/repos/saurabh500/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/saurabh500/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/saurabh500/corefx/tags","blobs_url":"https://api.github.com/repos/saurabh500/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/saurabh500/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/saurabh500/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/saurabh500/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/saurabh500/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/saurabh500/corefx/languages","stargazers_url":"https://api.github.com/repos/saurabh500/corefx/stargazers","contributors_url":"https://api.github.com/repos/saurabh500/corefx/contributors","subscribers_url":"https://api.github.com/repos/saurabh500/corefx/subscribers","subscription_url":"https://api.github.com/repos/saurabh500/corefx/subscription","commits_url":"https://api.github.com/repos/saurabh500/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/saurabh500/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/saurabh500/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/saurabh500/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/saurabh500/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/saurabh500/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/saurabh500/corefx/merges","archive_url":"https://api.github.com/repos/saurabh500/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/saurabh500/corefx/downloads","issues_url":"https://api.github.com/repos/saurabh500/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/saurabh500/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/saurabh500/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/saurabh500/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/saurabh500/corefx/labels{/name}","releases_url":"https://api.github.com/repos/saurabh500/corefx/releases{/id}","created_at":"2015-08-27T01:41:34Z","updated_at":"2015-08-27T01:41:53Z","pushed_at":"2015-10-01T00:41:46Z","git_url":"git://github.com/saurabh500/corefx.git","ssh_url":"git@github.com:saurabh500/corefx.git","clone_url":"https://github.com/saurabh500/corefx.git","svn_url":"https://github.com/saurabh500/corefx","homepage":"http://dotnet.github.io/core/","size":33643,"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":"05137b690dedb6f71ea3decafd8ff99fe0d11b3b","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-10-01T16:42:03Z","pushed_at":"2015-10-01T19:47:25Z","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":74030,"stargazers_count":8416,"watchers_count":8416,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1829,"mirror_url":null,"open_issues_count":628,"forks":1829,"open_issues":628,"watchers":8416,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3567"},"html":{"href":"https://github.com/dotnet/corefx/pull/3567"},"issue":{"href":"https://api.github.com/repos/dotnet/corefx/issues/3567"},"comments":{"href":"https://api.github.com/repos/dotnet/corefx/issues/3567/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3567/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/3567/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corefx/statuses/b0f1241bdd5f3e98810ece67f963bfa7ac91a9fd"}}}}