{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/83516052","pull_request_review_id":4355847,"id":83516052,"diff_hunk":"@@ -0,0 +1,176 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.spark.network.sasl.aes;\n+\n+import java.io.IOException;\n+import java.nio.channels.WritableByteChannel;\n+\n+import com.google.common.base.Preconditions;\n+import io.netty.buffer.ByteBuf;\n+import io.netty.buffer.Unpooled;\n+import io.netty.channel.*;\n+import io.netty.util.AbstractReferenceCounted;\n+import org.apache.commons.crypto.stream.CryptoInputStream;\n+import org.apache.commons.crypto.stream.CryptoOutputStream;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import org.apache.spark.network.util.ByteArrayReadableChannel;\n+import org.apache.spark.network.util.ByteArrayWritableChannel;\n+\n+public class AesEncryption {\n+  public static final String ENCRYPTION_HANDLER_NAME = \"AesEncryption\";\n+  public static final String DECRYPTION_HANDLER_NAME = \"AesDecryption\";\n+\n+  public static void addToChannel(Channel ch, AesCipher cipher) {\n+    ch.pipeline().addFirst(ENCRYPTION_HANDLER_NAME, new AesEncryptHandler(cipher))\n+      .addFirst(DECRYPTION_HANDLER_NAME, new AesDecryptHandler(cipher));\n+  }\n+\n+  private static class AesEncryptHandler extends ChannelOutboundHandlerAdapter {\n+    private final AesCipher cipher;\n+    private ByteArrayWritableChannel byteChannel;\n+\n+    AesEncryptHandler(AesCipher cipher) {\n+      this.cipher = cipher;\n+      byteChannel = new ByteArrayWritableChannel(AesCipher.STREAM_BUFFER_SIZE);\n+    }\n+\n+    @Override\n+    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)\n+      throws Exception {\n+      ctx.write(new EncryptMessage(cipher, msg, byteChannel), promise);\n+    }\n+  }\n+\n+  private static class AesDecryptHandler extends ChannelInboundHandlerAdapter {\n+    private final AesCipher cipher;\n+    private CryptoInputStream cis;\n+    private ByteArrayReadableChannel byteChannel;\n+\n+    AesDecryptHandler(AesCipher cipher) {\n+      this.cipher = cipher;\n+      byteChannel = new ByteArrayReadableChannel();\n+    }\n+\n+    @Override\n+    public void channelRead(ChannelHandlerContext ctx, Object data) throws Exception {\n+      ByteBuf in = (ByteBuf) data;\n+\n+      try {\n+        while (in.isReadable()) {\n+          byteChannel.feedData(in);\n+          cis = cipher.CreateInputStream(byteChannel);","path":"common/network-common/src/main/java/org/apache/spark/network/sasl/aes/AesEncryption.java","position":78,"original_position":78,"commit_id":"64b8f33789268c378db775da8dd9c03f68da828f","original_commit_id":"64b8f33789268c378db775da8dd9c03f68da828f","user":{"login":"vanzin","id":1694083,"avatar_url":"https://avatars.githubusercontent.com/u/1694083?v=3","gravatar_id":"","url":"https://api.github.com/users/vanzin","html_url":"https://github.com/vanzin","followers_url":"https://api.github.com/users/vanzin/followers","following_url":"https://api.github.com/users/vanzin/following{/other_user}","gists_url":"https://api.github.com/users/vanzin/gists{/gist_id}","starred_url":"https://api.github.com/users/vanzin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vanzin/subscriptions","organizations_url":"https://api.github.com/users/vanzin/orgs","repos_url":"https://api.github.com/users/vanzin/repos","events_url":"https://api.github.com/users/vanzin/events{/privacy}","received_events_url":"https://api.github.com/users/vanzin/received_events","type":"User","site_admin":false},"body":"Why isn't this done once in the constructor? Then you can explicitly close it in the `channelInactive` callback, and avoid the cache in `AesCipher` too.","created_at":"2016-10-14T23:14:12Z","updated_at":"2016-10-14T23:37:04Z","html_url":"https://github.com/apache/spark/pull/15172#discussion_r83516052","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/15172","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/83516052"},"html":{"href":"https://github.com/apache/spark/pull/15172#discussion_r83516052"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/15172"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/15172","id":86083615,"html_url":"https://github.com/apache/spark/pull/15172","diff_url":"https://github.com/apache/spark/pull/15172.diff","patch_url":"https://github.com/apache/spark/pull/15172.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/15172","number":15172,"state":"open","locked":false,"title":"[SPARK-13331] AES support for over-the-wire encryption","user":{"login":"cjjnjust","id":3960228,"avatar_url":"https://avatars.githubusercontent.com/u/3960228?v=3","gravatar_id":"","url":"https://api.github.com/users/cjjnjust","html_url":"https://github.com/cjjnjust","followers_url":"https://api.github.com/users/cjjnjust/followers","following_url":"https://api.github.com/users/cjjnjust/following{/other_user}","gists_url":"https://api.github.com/users/cjjnjust/gists{/gist_id}","starred_url":"https://api.github.com/users/cjjnjust/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjjnjust/subscriptions","organizations_url":"https://api.github.com/users/cjjnjust/orgs","repos_url":"https://api.github.com/users/cjjnjust/repos","events_url":"https://api.github.com/users/cjjnjust/events{/privacy}","received_events_url":"https://api.github.com/users/cjjnjust/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\n\r\nDIGEST-MD5 mechanism is used for SASL authentication and secure communication. DIGEST-MD5 mechanism supports 3DES, DES, and RC4 ciphers. However, 3DES, DES and RC4 are slow relatively.\r\n\r\nAES provide better performance and security by design and is a replacement for 3DES according to NIST. Apache Common Crypto is a cryptographic library optimized with AES-NI, this patch employ Apache Common Crypto as enc/dec backend for SASL authentication and secure channel to improve spark RPC.\r\n\r\n## How was this patch tested?\r\n\r\nUnit tests and Integration test.\r\n\r\n\r\n\r\n\r\n","created_at":"2016-09-21T01:24:25Z","updated_at":"2016-10-14T23:37:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eb3e550c115a1ffbb673e86f647b939a03462b04","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/15172/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/15172/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/15172/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/64b8f33789268c378db775da8dd9c03f68da828f","head":{"label":"cjjnjust:shuffle_rpc_encrypt","ref":"shuffle_rpc_encrypt","sha":"64b8f33789268c378db775da8dd9c03f68da828f","user":{"login":"cjjnjust","id":3960228,"avatar_url":"https://avatars.githubusercontent.com/u/3960228?v=3","gravatar_id":"","url":"https://api.github.com/users/cjjnjust","html_url":"https://github.com/cjjnjust","followers_url":"https://api.github.com/users/cjjnjust/followers","following_url":"https://api.github.com/users/cjjnjust/following{/other_user}","gists_url":"https://api.github.com/users/cjjnjust/gists{/gist_id}","starred_url":"https://api.github.com/users/cjjnjust/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjjnjust/subscriptions","organizations_url":"https://api.github.com/users/cjjnjust/orgs","repos_url":"https://api.github.com/users/cjjnjust/repos","events_url":"https://api.github.com/users/cjjnjust/events{/privacy}","received_events_url":"https://api.github.com/users/cjjnjust/received_events","type":"User","site_admin":false},"repo":{"id":66990632,"name":"spark","full_name":"cjjnjust/spark","owner":{"login":"cjjnjust","id":3960228,"avatar_url":"https://avatars.githubusercontent.com/u/3960228?v=3","gravatar_id":"","url":"https://api.github.com/users/cjjnjust","html_url":"https://github.com/cjjnjust","followers_url":"https://api.github.com/users/cjjnjust/followers","following_url":"https://api.github.com/users/cjjnjust/following{/other_user}","gists_url":"https://api.github.com/users/cjjnjust/gists{/gist_id}","starred_url":"https://api.github.com/users/cjjnjust/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjjnjust/subscriptions","organizations_url":"https://api.github.com/users/cjjnjust/orgs","repos_url":"https://api.github.com/users/cjjnjust/repos","events_url":"https://api.github.com/users/cjjnjust/events{/privacy}","received_events_url":"https://api.github.com/users/cjjnjust/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cjjnjust/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/cjjnjust/spark","forks_url":"https://api.github.com/repos/cjjnjust/spark/forks","keys_url":"https://api.github.com/repos/cjjnjust/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cjjnjust/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cjjnjust/spark/teams","hooks_url":"https://api.github.com/repos/cjjnjust/spark/hooks","issue_events_url":"https://api.github.com/repos/cjjnjust/spark/issues/events{/number}","events_url":"https://api.github.com/repos/cjjnjust/spark/events","assignees_url":"https://api.github.com/repos/cjjnjust/spark/assignees{/user}","branches_url":"https://api.github.com/repos/cjjnjust/spark/branches{/branch}","tags_url":"https://api.github.com/repos/cjjnjust/spark/tags","blobs_url":"https://api.github.com/repos/cjjnjust/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cjjnjust/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cjjnjust/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/cjjnjust/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cjjnjust/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/cjjnjust/spark/languages","stargazers_url":"https://api.github.com/repos/cjjnjust/spark/stargazers","contributors_url":"https://api.github.com/repos/cjjnjust/spark/contributors","subscribers_url":"https://api.github.com/repos/cjjnjust/spark/subscribers","subscription_url":"https://api.github.com/repos/cjjnjust/spark/subscription","commits_url":"https://api.github.com/repos/cjjnjust/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/cjjnjust/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/cjjnjust/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/cjjnjust/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/cjjnjust/spark/contents/{+path}","compare_url":"https://api.github.com/repos/cjjnjust/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cjjnjust/spark/merges","archive_url":"https://api.github.com/repos/cjjnjust/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cjjnjust/spark/downloads","issues_url":"https://api.github.com/repos/cjjnjust/spark/issues{/number}","pulls_url":"https://api.github.com/repos/cjjnjust/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/cjjnjust/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/cjjnjust/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cjjnjust/spark/labels{/name}","releases_url":"https://api.github.com/repos/cjjnjust/spark/releases{/id}","deployments_url":"https://api.github.com/repos/cjjnjust/spark/deployments","created_at":"2016-08-31T01:18:07Z","updated_at":"2016-08-31T01:18:30Z","pushed_at":"2016-10-12T12:43:33Z","git_url":"git://github.com/cjjnjust/spark.git","ssh_url":"git@github.com:cjjnjust/spark.git","clone_url":"https://github.com/cjjnjust/spark.git","svn_url":"https://github.com/cjjnjust/spark","homepage":null,"size":239904,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"apache:master","ref":"master","sha":"7e418e99cff4cf512ab2a9fa74221c4655048c8d","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2016-10-14T22:40:36Z","pushed_at":"2016-10-14T23:14:01Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":595880,"stargazers_count":10361,"watchers_count":10361,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9628,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":474,"forks":9628,"open_issues":474,"watchers":10361,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/15172"},"html":{"href":"https://github.com/apache/spark/pull/15172"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/15172"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/15172/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/15172/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/15172/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/64b8f33789268c378db775da8dd9c03f68da828f"}}}}
{"actor":{"display_login":"vanzin"}}