{"action":"created","comment":{"url":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/comments/73830777","id":73830777,"diff_hunk":"@@ -0,0 +1,297 @@\n+:BEP: ??\n+:Title: Encrypted Torrent Payload\n+:Version: $Revision$\n+:Last-Modified: $Date$\n+:Author:  The 8472 <the8472.bep@infinite-source.de>\n+:Status:  Draft\n+:Type:  Standards Track\n+:Content-Type: text/x-rst\n+:Created: 04-Oct-2015\n+:Post-History: \n+\n+\n+Abstract\n+========\n+\n+This BEP specifies a way to apply symmetric encryption to torrent payload at the storage layer and additionally encrypt some metadata with the following goals:\n+\n+* confidentiality\n+* limited privacy\n+\n+and non-goals:\n+\n+* forward-secrecy\n+* anonymity\n+* signature-based authentication, already covered by [BEP 35]\n+* authentication of peer connections\n+  \n+\n+\n+Rationale\n+=========\n+\n+BitTorrent swarms are mostly an open system well-suited for mass-distribution of data to the public.\n+\n+Some use-cases require that the data is only distributed to a closed, trusted group of peers.\n+In other cases the content may be meant for open distribution within a community without intent of announcing the content to the whole world. This is analogous to web content that is open to human visitors but requests via robots.txt[robots]_ that it should not be announced to the world by web crawlers.   \n+\n+\n+While the private flag [BEP-27]_ may be sufficient in a controlled environment to prevent information about the torrent (e.g. its infohash) from escaping and thus preventing others from connecting to the swarm this is a very brittle form of security which also prevents the use of public infrastructure such as open trackers, PEX or the DHT.\n+Similarly Message Stream Encryption provides limited protection from passive eavesdroppers on the network layer but does not prevent the infohash from escaping.   \n+\n+\n+Instead of attempting to restrict access to the swarm or metadata this BEP proposes to make all data opaque to 3rd parties by encrypting it with a shared secret that is not available through any torrent-related protocol, i.e. must be obtained separately by the user.\n+\n+In principle the same properties can be provided by simply storing the data in an encrypted archive and using a nondescript filename, but that requires users to store the data twice or to use additional filesystem layers to transparently access the data, which is even more cumbersome when encryption is involved. It also prevents bittorrent clients from reusing already-downloaded files in a multi-file torrent. \n+\n+Metadata format\n+===============\n+\n+\n+.. parsed-literal::\n+\n+    {\n+      info: {\n+        bepXX: {\n+          mac: *<32bytes of hmac output (string)>*,\n+          salt: *<32bytes of random binary data (string)>*,\n+          shadow: *<optional, bencoded-then-encrypted dictionary (string)>*\n+          v: *<version (integer)>*,\n+        },\n+        length *or* files: *<unchanged>*,\n+        name: *<public name (string)>*,\n+        piece length: *<unchanged>*\n+        pieces: *<N*20 bytes, piece hashes of the payload ciphertext (string)>*\n+      },\n+    }\n+\n+\n+``salt``\n+  the random data must be generated by a cryptographically secure RNG to avoid IV reuse.\n+\n+``v``\n+  The protocol version used to encrypt the torrent, currently *1*. New versions may be introduced by updates to this BEP if cryptographic weaknesses necessitate incompatible changes. Implementations should check if they support the version indicated in the metadata file and otherwise inform the user that they can download the data but not decrypt it.\n+\n+``shadow``\n+  bencoded-then-encrypted dictionary of key-value pairs that shadow entries in the info dictionary.\n+  If it is absent only the payload is encrypted and all info dictionary entries are non-shadowed.\n+  Implementations should only shadow a whitelist of keys which they have a shadowing strategy and ignore other keys.\n+  Shadowable keys suggested by this BEP: ``length, files, name, comment``.\n+\n+``mac``\n+  message authentication code covering the info dictionary\n+\n+``name``\n+  the name field is a mandatory part of [BEP 3]_, therefore a placeholder MUST be provided if a shadow name is used. An implementation may either generate a random string consisting of filesystem-friendly characters or allow the user to choose a public name that reveals less information than the shadow name.\n+\n+``files``, ``length``\n+  The shadow dictionary MAY override the single/multifile nature indicated by the public info dictionary. If it does not shadow either key then the public information is canonical.\n+  If the ``files`` or ``length`` are shadowed then the overall payload length MUST be consistent with the public version.\n+  If a shadow dictionary is present the public information should be treated as decorative / advisory until it can be determined whether it has been shadowed, i.e. until the shadow data can be decrypted. \n+\n+\n+To protect privacy an implementation should use shadowing for any additional keys that reveal information about the payload\n+\n+\n+Encryption\n+==========\n+\n+Building blocks used:  SHA2-256[rfc6234]_, ChaCha20[rfc7539]_, HMAC[rfc2104]_, PBKDF2[rfc2898]_  \n+\n+.. parsed-literal::\n+\n+    Key.root = random key, recommended strength: 256bits\n+\n+    Key.payload = PBKDF2(HMAC−SHA256, Key.root, salt || \"payload\", 4096, 256)\n+\n+    Key.shadow =  sha256(Key.payload || \"shadow\")\n+    \n+    mac = HMAC−SHA256(info-dict without mac, Key.shadow)\n+\n+    IV.payload = truncate_64(sha256(salt || \"payload\"))\n+\n+    IV.shadow = truncate_64(sha256(salt || \"shadow\"))\n+\n+PBKDF2 key derivation is used in case root keys with less entropy than the recommended are used, e.g. for password-based schemes. But for general use this BEP assumes that the root key consists of random binary data and hence mandates hexadecimal encoding when the keys need to be displayed in a human-readable format.\n+\n+ChaCha20 is used to both encrypt the shadow dictionary and the torrent payload.\n+\n+The optional ``shadow`` dictionary is encrypted after bencoding with ``Key.shadow`` and ``IV.shadow``.\n+\n+The ``mac`` is calculated over the bencoded info-dictionary including the ``bepXX`` dictionary but excluding the ``mac`` key value pair.","path":"html/beps/bep_encrypted_data.rst","position":121,"original_position":121,"commit_id":"675c7aa4eb51e2107262eaadf6044b07d0b20a75","original_commit_id":"675c7aa4eb51e2107262eaadf6044b07d0b20a75","user":{"login":"the8472","id":1065730,"avatar_url":"https://avatars.githubusercontent.com/u/1065730?v=3","gravatar_id":"","url":"https://api.github.com/users/the8472","html_url":"https://github.com/the8472","followers_url":"https://api.github.com/users/the8472/followers","following_url":"https://api.github.com/users/the8472/following{/other_user}","gists_url":"https://api.github.com/users/the8472/gists{/gist_id}","starred_url":"https://api.github.com/users/the8472/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the8472/subscriptions","organizations_url":"https://api.github.com/users/the8472/orgs","repos_url":"https://api.github.com/users/the8472/repos","events_url":"https://api.github.com/users/the8472/events{/privacy}","received_events_url":"https://api.github.com/users/the8472/received_events","type":"User","site_admin":false},"body":"it would require a fairly advanced bdecoder to exploit that property, but sure, I can change that.","created_at":"2016-08-08T07:16:32Z","updated_at":"2016-08-08T07:16:32Z","html_url":"https://github.com/bittorrent/bittorrent.org/pull/20#discussion_r73830777","pull_request_url":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/20","_links":{"self":{"href":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/comments/73830777"},"html":{"href":"https://github.com/bittorrent/bittorrent.org/pull/20#discussion_r73830777"},"pull_request":{"href":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/20","id":47346018,"html_url":"https://github.com/bittorrent/bittorrent.org/pull/20","diff_url":"https://github.com/bittorrent/bittorrent.org/pull/20.diff","patch_url":"https://github.com/bittorrent/bittorrent.org/pull/20.patch","issue_url":"https://api.github.com/repos/bittorrent/bittorrent.org/issues/20","number":20,"state":"open","locked":false,"title":"Encrypted torrents","user":{"login":"the8472","id":1065730,"avatar_url":"https://avatars.githubusercontent.com/u/1065730?v=3","gravatar_id":"","url":"https://api.github.com/users/the8472","html_url":"https://github.com/the8472","followers_url":"https://api.github.com/users/the8472/followers","following_url":"https://api.github.com/users/the8472/following{/other_user}","gists_url":"https://api.github.com/users/the8472/gists{/gist_id}","starred_url":"https://api.github.com/users/the8472/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the8472/subscriptions","organizations_url":"https://api.github.com/users/the8472/orgs","repos_url":"https://api.github.com/users/the8472/repos","events_url":"https://api.github.com/users/the8472/events{/privacy}","received_events_url":"https://api.github.com/users/the8472/received_events","type":"User","site_admin":false},"body":"Based on discussion in #18\r\n\r\nThe BEP still lacks test vectors, but I would prefer some review/feedback before finalizing it.","created_at":"2015-10-10T13:53:50Z","updated_at":"2016-08-08T07:16:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1ea5cee1cf1bcbecf1608279d05460be38e0ab69","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/20/commits","review_comments_url":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/20/comments","review_comment_url":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bittorrent/bittorrent.org/issues/20/comments","statuses_url":"https://api.github.com/repos/bittorrent/bittorrent.org/statuses/675c7aa4eb51e2107262eaadf6044b07d0b20a75","head":{"label":"the8472:encrypted_torrents","ref":"encrypted_torrents","sha":"675c7aa4eb51e2107262eaadf6044b07d0b20a75","user":{"login":"the8472","id":1065730,"avatar_url":"https://avatars.githubusercontent.com/u/1065730?v=3","gravatar_id":"","url":"https://api.github.com/users/the8472","html_url":"https://github.com/the8472","followers_url":"https://api.github.com/users/the8472/followers","following_url":"https://api.github.com/users/the8472/following{/other_user}","gists_url":"https://api.github.com/users/the8472/gists{/gist_id}","starred_url":"https://api.github.com/users/the8472/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the8472/subscriptions","organizations_url":"https://api.github.com/users/the8472/orgs","repos_url":"https://api.github.com/users/the8472/repos","events_url":"https://api.github.com/users/the8472/events{/privacy}","received_events_url":"https://api.github.com/users/the8472/received_events","type":"User","site_admin":false},"repo":{"id":38005694,"name":"bittorrent.org","full_name":"the8472/bittorrent.org","owner":{"login":"the8472","id":1065730,"avatar_url":"https://avatars.githubusercontent.com/u/1065730?v=3","gravatar_id":"","url":"https://api.github.com/users/the8472","html_url":"https://github.com/the8472","followers_url":"https://api.github.com/users/the8472/followers","following_url":"https://api.github.com/users/the8472/following{/other_user}","gists_url":"https://api.github.com/users/the8472/gists{/gist_id}","starred_url":"https://api.github.com/users/the8472/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/the8472/subscriptions","organizations_url":"https://api.github.com/users/the8472/orgs","repos_url":"https://api.github.com/users/the8472/repos","events_url":"https://api.github.com/users/the8472/events{/privacy}","received_events_url":"https://api.github.com/users/the8472/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/the8472/bittorrent.org","description":"","fork":true,"url":"https://api.github.com/repos/the8472/bittorrent.org","forks_url":"https://api.github.com/repos/the8472/bittorrent.org/forks","keys_url":"https://api.github.com/repos/the8472/bittorrent.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/the8472/bittorrent.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/the8472/bittorrent.org/teams","hooks_url":"https://api.github.com/repos/the8472/bittorrent.org/hooks","issue_events_url":"https://api.github.com/repos/the8472/bittorrent.org/issues/events{/number}","events_url":"https://api.github.com/repos/the8472/bittorrent.org/events","assignees_url":"https://api.github.com/repos/the8472/bittorrent.org/assignees{/user}","branches_url":"https://api.github.com/repos/the8472/bittorrent.org/branches{/branch}","tags_url":"https://api.github.com/repos/the8472/bittorrent.org/tags","blobs_url":"https://api.github.com/repos/the8472/bittorrent.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/the8472/bittorrent.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/the8472/bittorrent.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/the8472/bittorrent.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/the8472/bittorrent.org/statuses/{sha}","languages_url":"https://api.github.com/repos/the8472/bittorrent.org/languages","stargazers_url":"https://api.github.com/repos/the8472/bittorrent.org/stargazers","contributors_url":"https://api.github.com/repos/the8472/bittorrent.org/contributors","subscribers_url":"https://api.github.com/repos/the8472/bittorrent.org/subscribers","subscription_url":"https://api.github.com/repos/the8472/bittorrent.org/subscription","commits_url":"https://api.github.com/repos/the8472/bittorrent.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/the8472/bittorrent.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/the8472/bittorrent.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/the8472/bittorrent.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/the8472/bittorrent.org/contents/{+path}","compare_url":"https://api.github.com/repos/the8472/bittorrent.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/the8472/bittorrent.org/merges","archive_url":"https://api.github.com/repos/the8472/bittorrent.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/the8472/bittorrent.org/downloads","issues_url":"https://api.github.com/repos/the8472/bittorrent.org/issues{/number}","pulls_url":"https://api.github.com/repos/the8472/bittorrent.org/pulls{/number}","milestones_url":"https://api.github.com/repos/the8472/bittorrent.org/milestones{/number}","notifications_url":"https://api.github.com/repos/the8472/bittorrent.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/the8472/bittorrent.org/labels{/name}","releases_url":"https://api.github.com/repos/the8472/bittorrent.org/releases{/id}","deployments_url":"https://api.github.com/repos/the8472/bittorrent.org/deployments","created_at":"2015-06-24T19:14:24Z","updated_at":"2016-07-30T23:54:23Z","pushed_at":"2016-08-07T16:28:32Z","git_url":"git://github.com/the8472/bittorrent.org.git","ssh_url":"git@github.com:the8472/bittorrent.org.git","clone_url":"https://github.com/the8472/bittorrent.org.git","svn_url":"https://github.com/the8472/bittorrent.org","homepage":"","size":1148,"stargazers_count":0,"watchers_count":0,"language":"HTML","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":"bittorrent:master","ref":"master","sha":"ad4ee567f3a5de2678e93dc109099e9f4bdb2913","user":{"login":"bittorrent","id":142253,"avatar_url":"https://avatars.githubusercontent.com/u/142253?v=3","gravatar_id":"","url":"https://api.github.com/users/bittorrent","html_url":"https://github.com/bittorrent","followers_url":"https://api.github.com/users/bittorrent/followers","following_url":"https://api.github.com/users/bittorrent/following{/other_user}","gists_url":"https://api.github.com/users/bittorrent/gists{/gist_id}","starred_url":"https://api.github.com/users/bittorrent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bittorrent/subscriptions","organizations_url":"https://api.github.com/users/bittorrent/orgs","repos_url":"https://api.github.com/users/bittorrent/repos","events_url":"https://api.github.com/users/bittorrent/events{/privacy}","received_events_url":"https://api.github.com/users/bittorrent/received_events","type":"Organization","site_admin":false},"repo":{"id":1543812,"name":"bittorrent.org","full_name":"bittorrent/bittorrent.org","owner":{"login":"bittorrent","id":142253,"avatar_url":"https://avatars.githubusercontent.com/u/142253?v=3","gravatar_id":"","url":"https://api.github.com/users/bittorrent","html_url":"https://github.com/bittorrent","followers_url":"https://api.github.com/users/bittorrent/followers","following_url":"https://api.github.com/users/bittorrent/following{/other_user}","gists_url":"https://api.github.com/users/bittorrent/gists{/gist_id}","starred_url":"https://api.github.com/users/bittorrent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bittorrent/subscriptions","organizations_url":"https://api.github.com/users/bittorrent/orgs","repos_url":"https://api.github.com/users/bittorrent/repos","events_url":"https://api.github.com/users/bittorrent/events{/privacy}","received_events_url":"https://api.github.com/users/bittorrent/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bittorrent/bittorrent.org","description":"","fork":false,"url":"https://api.github.com/repos/bittorrent/bittorrent.org","forks_url":"https://api.github.com/repos/bittorrent/bittorrent.org/forks","keys_url":"https://api.github.com/repos/bittorrent/bittorrent.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bittorrent/bittorrent.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bittorrent/bittorrent.org/teams","hooks_url":"https://api.github.com/repos/bittorrent/bittorrent.org/hooks","issue_events_url":"https://api.github.com/repos/bittorrent/bittorrent.org/issues/events{/number}","events_url":"https://api.github.com/repos/bittorrent/bittorrent.org/events","assignees_url":"https://api.github.com/repos/bittorrent/bittorrent.org/assignees{/user}","branches_url":"https://api.github.com/repos/bittorrent/bittorrent.org/branches{/branch}","tags_url":"https://api.github.com/repos/bittorrent/bittorrent.org/tags","blobs_url":"https://api.github.com/repos/bittorrent/bittorrent.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bittorrent/bittorrent.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bittorrent/bittorrent.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/bittorrent/bittorrent.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bittorrent/bittorrent.org/statuses/{sha}","languages_url":"https://api.github.com/repos/bittorrent/bittorrent.org/languages","stargazers_url":"https://api.github.com/repos/bittorrent/bittorrent.org/stargazers","contributors_url":"https://api.github.com/repos/bittorrent/bittorrent.org/contributors","subscribers_url":"https://api.github.com/repos/bittorrent/bittorrent.org/subscribers","subscription_url":"https://api.github.com/repos/bittorrent/bittorrent.org/subscription","commits_url":"https://api.github.com/repos/bittorrent/bittorrent.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/bittorrent/bittorrent.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/bittorrent/bittorrent.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/bittorrent/bittorrent.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/bittorrent/bittorrent.org/contents/{+path}","compare_url":"https://api.github.com/repos/bittorrent/bittorrent.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bittorrent/bittorrent.org/merges","archive_url":"https://api.github.com/repos/bittorrent/bittorrent.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bittorrent/bittorrent.org/downloads","issues_url":"https://api.github.com/repos/bittorrent/bittorrent.org/issues{/number}","pulls_url":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls{/number}","milestones_url":"https://api.github.com/repos/bittorrent/bittorrent.org/milestones{/number}","notifications_url":"https://api.github.com/repos/bittorrent/bittorrent.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bittorrent/bittorrent.org/labels{/name}","releases_url":"https://api.github.com/repos/bittorrent/bittorrent.org/releases{/id}","deployments_url":"https://api.github.com/repos/bittorrent/bittorrent.org/deployments","created_at":"2011-03-29T22:52:47Z","updated_at":"2016-08-05T17:20:57Z","pushed_at":"2016-08-07T16:28:32Z","git_url":"git://github.com/bittorrent/bittorrent.org.git","ssh_url":"git@github.com:bittorrent/bittorrent.org.git","clone_url":"https://github.com/bittorrent/bittorrent.org.git","svn_url":"https://github.com/bittorrent/bittorrent.org","homepage":"","size":1768,"stargazers_count":63,"watchers_count":63,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":29,"mirror_url":null,"open_issues_count":13,"forks":29,"open_issues":13,"watchers":63,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/20"},"html":{"href":"https://github.com/bittorrent/bittorrent.org/pull/20"},"issue":{"href":"https://api.github.com/repos/bittorrent/bittorrent.org/issues/20"},"comments":{"href":"https://api.github.com/repos/bittorrent/bittorrent.org/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bittorrent/bittorrent.org/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/bittorrent/bittorrent.org/statuses/675c7aa4eb51e2107262eaadf6044b07d0b20a75"}}}}
{"actor":{"display_login":"the8472"}}