{"action":"created","comment":{"url":"https://api.github.com/repos/minio/minio/pulls/comments/171271433","pull_request_review_id":100093953,"id":171271433,"diff_hunk":"@@ -412,16 +441,191 @@ func DecryptRequest(client io.Writer, r *http.Request, metadata map[string]strin\n \treturn DecryptRequestWithSequenceNumber(client, r, 0, metadata)\n }\n \n-// getStartOffset - get sequence number, start offset and rlength.\n-func getStartOffset(offset, length int64) (seqNumber uint32, startOffset int64, rlength int64) {\n-\tseqNumber = uint32(offset / (64 * 1024))\n-\tstartOffset = int64(seqNumber) * (64*1024 + 32)\n+// DecryptBlocksWriter - decrypts multipart parts, while implementing a io.Writer compatible interface.\n+type DecryptBlocksWriter struct {\n+\t// Original writer where the plain data will be written\n+\twriter io.Writer\n+\t// Current decrypter for the current encrypted data block\n+\tdecrypter io.WriteCloser\n+\t// Start sequence number\n+\tstartSeqNum uint32\n+\t// Current part index\n+\tpartIndex int\n+\t// Parts information\n+\tparts    []objectPartInfo\n+\treq      *http.Request\n+\tmetadata map[string]string\n+\n+\tpartEncRelOffset int64\n+\n+\t// Customer Key\n+\tcustomerKeyHeader string\n+}\n \n-\trlength = (length / (64 * 1024)) * (64*1024 + 32)\n-\tif length%(64*1024) > 0 {\n-\t\trlength += 64*1024 + 32\n+func (w *DecryptBlocksWriter) buildDecrypter(partID int) error {\n+\tm := make(map[string]string)\n+\tfor k, v := range w.metadata {\n+\t\tm[k] = v\n \t}\n-\treturn seqNumber, startOffset, rlength\n+\t// Initialize the first decrypter, new decrypters will be initialized in Write() operation as needed.\n+\tw.req.Header.Set(SSECustomerKey, w.customerKeyHeader)\n+\tkey, err := ParseSSECustomerRequest(w.req)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tobjectEncryptionKey, err := decryptObjectInfo(key, m)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tsha := sha256.New() // derive part  encryption key\n+\tsha.Write(objectEncryptionKey)\n+\tsha.Write([]byte(\"-\" + fmt.Sprintf(\"%d\", partID)))\n+\tpartEncryptionKey := sha.Sum(nil)\n+\n+\tdelete(m, SSECustomerKey) // make sure we do not save the key by accident\n+\n+\tdecrypter, err := newDecryptWriterWithObjectKey(w.writer, partEncryptionKey, w.startSeqNum, m)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tw.decrypter = decrypter\n+\treturn nil\n+}\n+\n+func (w *DecryptBlocksWriter) Write(p []byte) (int, error) {\n+\tvar err error\n+\tvar n1 int\n+\tif int64(len(p)) < w.parts[w.partIndex].Size-w.partEncRelOffset {\n+\t\tn1, err = w.decrypter.Write(p)\n+\t\tif err != nil {\n+\t\t\treturn 0, err\n+\t\t}\n+\t\tw.partEncRelOffset += int64(n1)\n+\t} else {\n+\t\tn1, err = w.decrypter.Write(p[:w.parts[w.partIndex].Size-w.partEncRelOffset])\n+\t\tif err != nil {\n+\t\t\treturn 0, err\n+\t\t}\n+\n+\t\t// We should now proceed to next part, reset all values appropriately.\n+\t\tw.partEncRelOffset = 0\n+\t\tw.startSeqNum = 0\n+\n+\t\tw.partIndex++\n+\n+\t\terr = w.buildDecrypter(w.partIndex + 1)\n+\t\tif err != nil {\n+\t\t\treturn 0, err\n+\t\t}\n+\n+\t\tn1, err = w.decrypter.Write(p[n1:])\n+\t\tif err != nil {\n+\t\t\treturn 0, err\n+\t\t}\n+\n+\t\tw.partEncRelOffset += int64(n1)\n+\t}\n+\n+\treturn len(p), nil\n+}\n+\n+// Close closes the LimitWriter. It behaves like io.Closer.\n+func (w *DecryptBlocksWriter) Close() error {\n+\tif closer, ok := w.writer.(io.Closer); ok {","path":"cmd/encryption-v1.go","position":null,"original_position":209,"commit_id":"0c80649ef945ed74f6fcf5f6fb33cf77e13dda39","original_commit_id":"98c1dff675e6734bb176bdb2209b89b0b750753b","user":{"login":"vadmeste","id":283197,"avatar_url":"https://avatars1.githubusercontent.com/u/283197?v=4","gravatar_id":"","url":"https://api.github.com/users/vadmeste","html_url":"https://github.com/vadmeste","followers_url":"https://api.github.com/users/vadmeste/followers","following_url":"https://api.github.com/users/vadmeste/following{/other_user}","gists_url":"https://api.github.com/users/vadmeste/gists{/gist_id}","starred_url":"https://api.github.com/users/vadmeste/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vadmeste/subscriptions","organizations_url":"https://api.github.com/users/vadmeste/orgs","repos_url":"https://api.github.com/users/vadmeste/repos","events_url":"https://api.github.com/users/vadmeste/events{/privacy}","received_events_url":"https://api.github.com/users/vadmeste/received_events","type":"User","site_admin":false},"body":"> You are supposed to close the decrypter here - otherwise you miss internally buffered data.\r\n> See https://github.com/minio/sio/blob/master/dare.go#L151\r\n\r\nDone","created_at":"2018-02-28T14:58:31Z","updated_at":"2018-02-28T14:58:31Z","html_url":"https://github.com/minio/minio/pull/5576#discussion_r171271433","pull_request_url":"https://api.github.com/repos/minio/minio/pulls/5576","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/minio/minio/pulls/comments/171271433"},"html":{"href":"https://github.com/minio/minio/pull/5576#discussion_r171271433"},"pull_request":{"href":"https://api.github.com/repos/minio/minio/pulls/5576"}},"in_reply_to_id":171249792},"pull_request":{"url":"https://api.github.com/repos/minio/minio/pulls/5576","id":171139008,"html_url":"https://github.com/minio/minio/pull/5576","diff_url":"https://github.com/minio/minio/pull/5576.diff","patch_url":"https://github.com/minio/minio/pull/5576.patch","issue_url":"https://api.github.com/repos/minio/minio/issues/5576","number":5576,"state":"open","locked":false,"title":"Add support of multipart SSE-C Encryption","user":{"login":"vadmeste","id":283197,"avatar_url":"https://avatars1.githubusercontent.com/u/283197?v=4","gravatar_id":"","url":"https://api.github.com/users/vadmeste","html_url":"https://github.com/vadmeste","followers_url":"https://api.github.com/users/vadmeste/followers","following_url":"https://api.github.com/users/vadmeste/following{/other_user}","gists_url":"https://api.github.com/users/vadmeste/gists{/gist_id}","starred_url":"https://api.github.com/users/vadmeste/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vadmeste/subscriptions","organizations_url":"https://api.github.com/users/vadmeste/orgs","repos_url":"https://api.github.com/users/vadmeste/repos","events_url":"https://api.github.com/users/vadmeste/events{/privacy}","received_events_url":"https://api.github.com/users/vadmeste/received_events","type":"User","site_admin":false},"body":"<!--- Provide a general summary of your changes in the Title above -->\r\n\r\n## Description\r\nThis PR adds support of SSE encryption in multipart.\r\n\r\n## Motivation and Context\r\nFixes #5494 \r\nFixes #5471 \r\n\r\n## How Has This Been Tested?\r\ngo test + manually\r\n\r\n## Types of changes\r\n<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->\r\n- [ ] Bug fix (non-breaking change which fixes an issue)\r\n- [x] New feature (non-breaking change which adds functionality)\r\n- [ ] Breaking change (fix or feature that would cause existing functionality to change)\r\n\r\n## Checklist:\r\n<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->\r\n<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->\r\n- [x] My code follows the code style of this project.\r\n- [ ] My change requires a change to the documentation.\r\n- [ ] I have updated the documentation accordingly.\r\n- [ ] I have added unit tests to cover my changes.\r\n- [ ] I have added/updated functional tests in [mint](https://github.com/minio/mint). (If yes, add `mint` PR # here: )\r\n- [x] All new and existing tests passed.","created_at":"2018-02-23T23:15:56Z","updated_at":"2018-02-28T14:58:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ba382c04f01bf7d422758ccde79a78a47b10960a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":{"url":"https://api.github.com/repos/minio/minio/milestones/15","html_url":"https://github.com/minio/minio/milestone/15","labels_url":"https://api.github.com/repos/minio/minio/milestones/15/labels","id":2426553,"number":15,"title":"Next Release","description":"- In this release\r\n * Bug Fixes\r\n * Admin Heal APIs","creator":{"login":"deekoder","id":1700901,"avatar_url":"https://avatars1.githubusercontent.com/u/1700901?v=4","gravatar_id":"","url":"https://api.github.com/users/deekoder","html_url":"https://github.com/deekoder","followers_url":"https://api.github.com/users/deekoder/followers","following_url":"https://api.github.com/users/deekoder/following{/other_user}","gists_url":"https://api.github.com/users/deekoder/gists{/gist_id}","starred_url":"https://api.github.com/users/deekoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deekoder/subscriptions","organizations_url":"https://api.github.com/users/deekoder/orgs","repos_url":"https://api.github.com/users/deekoder/repos","events_url":"https://api.github.com/users/deekoder/events{/privacy}","received_events_url":"https://api.github.com/users/deekoder/received_events","type":"User","site_admin":false},"open_issues":45,"closed_issues":466,"state":"open","created_at":"2017-04-01T00:36:55Z","updated_at":"2018-02-26T00:11:39Z","due_on":"2018-02-28T08:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/minio/minio/pulls/5576/commits","review_comments_url":"https://api.github.com/repos/minio/minio/pulls/5576/comments","review_comment_url":"https://api.github.com/repos/minio/minio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/minio/minio/issues/5576/comments","statuses_url":"https://api.github.com/repos/minio/minio/statuses/0c80649ef945ed74f6fcf5f6fb33cf77e13dda39","head":{"label":"vadmeste:add_enc_multipart","ref":"add_enc_multipart","sha":"0c80649ef945ed74f6fcf5f6fb33cf77e13dda39","user":{"login":"vadmeste","id":283197,"avatar_url":"https://avatars1.githubusercontent.com/u/283197?v=4","gravatar_id":"","url":"https://api.github.com/users/vadmeste","html_url":"https://github.com/vadmeste","followers_url":"https://api.github.com/users/vadmeste/followers","following_url":"https://api.github.com/users/vadmeste/following{/other_user}","gists_url":"https://api.github.com/users/vadmeste/gists{/gist_id}","starred_url":"https://api.github.com/users/vadmeste/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vadmeste/subscriptions","organizations_url":"https://api.github.com/users/vadmeste/orgs","repos_url":"https://api.github.com/users/vadmeste/repos","events_url":"https://api.github.com/users/vadmeste/events{/privacy}","received_events_url":"https://api.github.com/users/vadmeste/received_events","type":"User","site_admin":false},"repo":{"id":30432336,"name":"minio","full_name":"vadmeste/minio","owner":{"login":"vadmeste","id":283197,"avatar_url":"https://avatars1.githubusercontent.com/u/283197?v=4","gravatar_id":"","url":"https://api.github.com/users/vadmeste","html_url":"https://github.com/vadmeste","followers_url":"https://api.github.com/users/vadmeste/followers","following_url":"https://api.github.com/users/vadmeste/following{/other_user}","gists_url":"https://api.github.com/users/vadmeste/gists{/gist_id}","starred_url":"https://api.github.com/users/vadmeste/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vadmeste/subscriptions","organizations_url":"https://api.github.com/users/vadmeste/orgs","repos_url":"https://api.github.com/users/vadmeste/repos","events_url":"https://api.github.com/users/vadmeste/events{/privacy}","received_events_url":"https://api.github.com/users/vadmeste/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vadmeste/minio","description":"Minio is an open source object storage inspired by Amazon S3 and Facebook Haystack ","fork":true,"url":"https://api.github.com/repos/vadmeste/minio","forks_url":"https://api.github.com/repos/vadmeste/minio/forks","keys_url":"https://api.github.com/repos/vadmeste/minio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vadmeste/minio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vadmeste/minio/teams","hooks_url":"https://api.github.com/repos/vadmeste/minio/hooks","issue_events_url":"https://api.github.com/repos/vadmeste/minio/issues/events{/number}","events_url":"https://api.github.com/repos/vadmeste/minio/events","assignees_url":"https://api.github.com/repos/vadmeste/minio/assignees{/user}","branches_url":"https://api.github.com/repos/vadmeste/minio/branches{/branch}","tags_url":"https://api.github.com/repos/vadmeste/minio/tags","blobs_url":"https://api.github.com/repos/vadmeste/minio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vadmeste/minio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vadmeste/minio/git/refs{/sha}","trees_url":"https://api.github.com/repos/vadmeste/minio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vadmeste/minio/statuses/{sha}","languages_url":"https://api.github.com/repos/vadmeste/minio/languages","stargazers_url":"https://api.github.com/repos/vadmeste/minio/stargazers","contributors_url":"https://api.github.com/repos/vadmeste/minio/contributors","subscribers_url":"https://api.github.com/repos/vadmeste/minio/subscribers","subscription_url":"https://api.github.com/repos/vadmeste/minio/subscription","commits_url":"https://api.github.com/repos/vadmeste/minio/commits{/sha}","git_commits_url":"https://api.github.com/repos/vadmeste/minio/git/commits{/sha}","comments_url":"https://api.github.com/repos/vadmeste/minio/comments{/number}","issue_comment_url":"https://api.github.com/repos/vadmeste/minio/issues/comments{/number}","contents_url":"https://api.github.com/repos/vadmeste/minio/contents/{+path}","compare_url":"https://api.github.com/repos/vadmeste/minio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vadmeste/minio/merges","archive_url":"https://api.github.com/repos/vadmeste/minio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vadmeste/minio/downloads","issues_url":"https://api.github.com/repos/vadmeste/minio/issues{/number}","pulls_url":"https://api.github.com/repos/vadmeste/minio/pulls{/number}","milestones_url":"https://api.github.com/repos/vadmeste/minio/milestones{/number}","notifications_url":"https://api.github.com/repos/vadmeste/minio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vadmeste/minio/labels{/name}","releases_url":"https://api.github.com/repos/vadmeste/minio/releases{/id}","deployments_url":"https://api.github.com/repos/vadmeste/minio/deployments","created_at":"2015-02-06T20:48:08Z","updated_at":"2016-01-11T08:27:57Z","pushed_at":"2018-02-28T14:57:52Z","git_url":"git://github.com/vadmeste/minio.git","ssh_url":"git@github.com:vadmeste/minio.git","clone_url":"https://github.com/vadmeste/minio.git","svn_url":"https://github.com/vadmeste/minio","homepage":"http://minio.io","size":31221,"stargazers_count":0,"watchers_count":0,"language":"Go","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":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"minio:master","ref":"master","sha":"5204a754dbf5fea761369efa4abb31791b324e1d","user":{"login":"minio","id":695951,"avatar_url":"https://avatars3.githubusercontent.com/u/695951?v=4","gravatar_id":"","url":"https://api.github.com/users/minio","html_url":"https://github.com/minio","followers_url":"https://api.github.com/users/minio/followers","following_url":"https://api.github.com/users/minio/following{/other_user}","gists_url":"https://api.github.com/users/minio/gists{/gist_id}","starred_url":"https://api.github.com/users/minio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minio/subscriptions","organizations_url":"https://api.github.com/users/minio/orgs","repos_url":"https://api.github.com/users/minio/repos","events_url":"https://api.github.com/users/minio/events{/privacy}","received_events_url":"https://api.github.com/users/minio/received_events","type":"Organization","site_admin":false},"repo":{"id":29261473,"name":"minio","full_name":"minio/minio","owner":{"login":"minio","id":695951,"avatar_url":"https://avatars3.githubusercontent.com/u/695951?v=4","gravatar_id":"","url":"https://api.github.com/users/minio","html_url":"https://github.com/minio","followers_url":"https://api.github.com/users/minio/followers","following_url":"https://api.github.com/users/minio/following{/other_user}","gists_url":"https://api.github.com/users/minio/gists{/gist_id}","starred_url":"https://api.github.com/users/minio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minio/subscriptions","organizations_url":"https://api.github.com/users/minio/orgs","repos_url":"https://api.github.com/users/minio/repos","events_url":"https://api.github.com/users/minio/events{/privacy}","received_events_url":"https://api.github.com/users/minio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/minio/minio","description":"Minio is an open source object storage server compatible with Amazon S3 APIs","fork":false,"url":"https://api.github.com/repos/minio/minio","forks_url":"https://api.github.com/repos/minio/minio/forks","keys_url":"https://api.github.com/repos/minio/minio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/minio/minio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/minio/minio/teams","hooks_url":"https://api.github.com/repos/minio/minio/hooks","issue_events_url":"https://api.github.com/repos/minio/minio/issues/events{/number}","events_url":"https://api.github.com/repos/minio/minio/events","assignees_url":"https://api.github.com/repos/minio/minio/assignees{/user}","branches_url":"https://api.github.com/repos/minio/minio/branches{/branch}","tags_url":"https://api.github.com/repos/minio/minio/tags","blobs_url":"https://api.github.com/repos/minio/minio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/minio/minio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/minio/minio/git/refs{/sha}","trees_url":"https://api.github.com/repos/minio/minio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/minio/minio/statuses/{sha}","languages_url":"https://api.github.com/repos/minio/minio/languages","stargazers_url":"https://api.github.com/repos/minio/minio/stargazers","contributors_url":"https://api.github.com/repos/minio/minio/contributors","subscribers_url":"https://api.github.com/repos/minio/minio/subscribers","subscription_url":"https://api.github.com/repos/minio/minio/subscription","commits_url":"https://api.github.com/repos/minio/minio/commits{/sha}","git_commits_url":"https://api.github.com/repos/minio/minio/git/commits{/sha}","comments_url":"https://api.github.com/repos/minio/minio/comments{/number}","issue_comment_url":"https://api.github.com/repos/minio/minio/issues/comments{/number}","contents_url":"https://api.github.com/repos/minio/minio/contents/{+path}","compare_url":"https://api.github.com/repos/minio/minio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/minio/minio/merges","archive_url":"https://api.github.com/repos/minio/minio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/minio/minio/downloads","issues_url":"https://api.github.com/repos/minio/minio/issues{/number}","pulls_url":"https://api.github.com/repos/minio/minio/pulls{/number}","milestones_url":"https://api.github.com/repos/minio/minio/milestones{/number}","notifications_url":"https://api.github.com/repos/minio/minio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/minio/minio/labels{/name}","releases_url":"https://api.github.com/repos/minio/minio/releases{/id}","deployments_url":"https://api.github.com/repos/minio/minio/deployments","created_at":"2015-01-14T19:23:58Z","updated_at":"2018-02-28T11:23:50Z","pushed_at":"2018-02-28T14:57:54Z","git_url":"git://github.com/minio/minio.git","ssh_url":"git@github.com:minio/minio.git","clone_url":"https://github.com/minio/minio.git","svn_url":"https://github.com/minio/minio","homepage":"https://minio.io/downloads.html#download-server","size":31645,"stargazers_count":10208,"watchers_count":10208,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":854,"mirror_url":null,"archived":false,"open_issues_count":122,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":854,"open_issues":122,"watchers":10208,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/minio/minio/pulls/5576"},"html":{"href":"https://github.com/minio/minio/pull/5576"},"issue":{"href":"https://api.github.com/repos/minio/minio/issues/5576"},"comments":{"href":"https://api.github.com/repos/minio/minio/issues/5576/comments"},"review_comments":{"href":"https://api.github.com/repos/minio/minio/pulls/5576/comments"},"review_comment":{"href":"https://api.github.com/repos/minio/minio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/minio/minio/pulls/5576/commits"},"statuses":{"href":"https://api.github.com/repos/minio/minio/statuses/0c80649ef945ed74f6fcf5f6fb33cf77e13dda39"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"vadmeste"}}