{"action":"created","comment":{"url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/comments/201697851","pull_request_review_id":136249240,"id":201697851,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMTY5Nzg1MQ==","diff_hunk":"@@ -103,13 +106,67 @@ public final class EncryptionSessionsDirectory : NSObject {\n     deinit {\n         self.commitCache()\n     }\n+    \n+    private func hash(for data: Data, recepient: EncryptionSessionIdentifier) -> GenericHash {\n+        let builder = GenericHashBuilder()","path":"WireCryptobox/EncryptionSessionsDirectory.swift","position":null,"original_position":27,"commit_id":"1df9c9bafe200f2bcf8ee2e6177d87b771e127a6","original_commit_id":"5cd906d317626c02b30251c117985008788e837f","user":{"login":"mikeger","id":715129,"node_id":"MDQ6VXNlcjcxNTEyOQ==","avatar_url":"https://avatars3.githubusercontent.com/u/715129?v=4","gravatar_id":"","url":"https://api.github.com/users/mikeger","html_url":"https://github.com/mikeger","followers_url":"https://api.github.com/users/mikeger/followers","following_url":"https://api.github.com/users/mikeger/following{/other_user}","gists_url":"https://api.github.com/users/mikeger/gists{/gist_id}","starred_url":"https://api.github.com/users/mikeger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikeger/subscriptions","organizations_url":"https://api.github.com/users/mikeger/orgs","repos_url":"https://api.github.com/users/mikeger/repos","events_url":"https://api.github.com/users/mikeger/events{/privacy}","received_events_url":"https://api.github.com/users/mikeger/received_events","type":"User","site_admin":false},"body":"@daehn the benefits of `GenericHashBuilder` are: variable hash value size (16 to 64 bit, we use 32 or 64 depending on the CPU architecture) and possibility to append the data to hash, so no need to build the joint data and keep it in the memory.","created_at":"2018-07-11T13:54:33Z","updated_at":"2018-07-11T13:54:34Z","html_url":"https://github.com/wireapp/wire-ios-cryptobox/pull/22#discussion_r201697851","pull_request_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/22","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/comments/201697851"},"html":{"href":"https://github.com/wireapp/wire-ios-cryptobox/pull/22#discussion_r201697851"},"pull_request":{"href":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/22"}},"in_reply_to_id":201627371},"pull_request":{"url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/22","id":200108525,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAwMTA4NTI1","html_url":"https://github.com/wireapp/wire-ios-cryptobox/pull/22","diff_url":"https://github.com/wireapp/wire-ios-cryptobox/pull/22.diff","patch_url":"https://github.com/wireapp/wire-ios-cryptobox/pull/22.patch","issue_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/issues/22","number":22,"state":"open","locked":false,"title":"Caching of the encrypted payloads","user":{"login":"mikeger","id":715129,"node_id":"MDQ6VXNlcjcxNTEyOQ==","avatar_url":"https://avatars3.githubusercontent.com/u/715129?v=4","gravatar_id":"","url":"https://api.github.com/users/mikeger","html_url":"https://github.com/mikeger","followers_url":"https://api.github.com/users/mikeger/followers","following_url":"https://api.github.com/users/mikeger/following{/other_user}","gists_url":"https://api.github.com/users/mikeger/gists{/gist_id}","starred_url":"https://api.github.com/users/mikeger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikeger/subscriptions","organizations_url":"https://api.github.com/users/mikeger/orgs","repos_url":"https://api.github.com/users/mikeger/repos","events_url":"https://api.github.com/users/mikeger/events{/privacy}","received_events_url":"https://api.github.com/users/mikeger/received_events","type":"User","site_admin":false},"body":"## What's new in this PR?\r\n\r\n### Issues\r\n\r\nOther clients (Web) noticed that sometimes they cannot decrypt the message from the iOS client.\r\n\r\nhttps://github.com/wireapp/ios-architecture/issues/34\r\n\r\n### Causes\r\n\r\nWhen the iOS device is online, but the requests cannot go through, each time Wire app is trying to send the request for the message upload we are encrypting the message payload.\r\n\r\nThe problem is that with every encryption we advance the encryption key forward, so if device is offline long enough, the receiver would reject the message (it's too far in the future).\r\n\r\n### Solutions\r\n\r\nI introduced the property `cachingEncryptor` on `EncryptionSessionsDirectory` that returns the `Encryptor` that is caching the payload using the key of plaintext message text hash + session ID.\r\n\r\nWhen the request is generated, we'll encrypt using `cachingEncryptor` and automatically get the old payload if we encrypt the same message for the same receiver. \r\n\r\nWhen the request is successful, we reset the cache with `flushEncryptionCache()`.\r\n\r\n## Notes\r\n\r\nI moved the methods of `EncryptionSessionsDirectory` to the protocols, so it allows the implementation of the `Encryptor` variant as well as the mock encryptor in tests.\r\n\r\n## Requirements\r\n\r\n- [ ] https://github.com/wireapp/wire-ios-system/pull/28","created_at":"2018-07-09T13:58:20Z","updated_at":"2018-07-11T13:54:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"02089bf033f2f3fad490f4ad0e7c50597863e9a5","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/22/commits","review_comments_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/22/comments","review_comment_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/issues/22/comments","statuses_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/statuses/1df9c9bafe200f2bcf8ee2e6177d87b771e127a6","head":{"label":"wireapp:feature/caching","ref":"feature/caching","sha":"1df9c9bafe200f2bcf8ee2e6177d87b771e127a6","user":{"login":"wireapp","id":16047324,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2MDQ3MzI0","avatar_url":"https://avatars3.githubusercontent.com/u/16047324?v=4","gravatar_id":"","url":"https://api.github.com/users/wireapp","html_url":"https://github.com/wireapp","followers_url":"https://api.github.com/users/wireapp/followers","following_url":"https://api.github.com/users/wireapp/following{/other_user}","gists_url":"https://api.github.com/users/wireapp/gists{/gist_id}","starred_url":"https://api.github.com/users/wireapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wireapp/subscriptions","organizations_url":"https://api.github.com/users/wireapp/orgs","repos_url":"https://api.github.com/users/wireapp/repos","events_url":"https://api.github.com/users/wireapp/events{/privacy}","received_events_url":"https://api.github.com/users/wireapp/received_events","type":"Organization","site_admin":false},"repo":{"id":53574465,"node_id":"MDEwOlJlcG9zaXRvcnk1MzU3NDQ2NQ==","name":"wire-ios-cryptobox","full_name":"wireapp/wire-ios-cryptobox","owner":{"login":"wireapp","id":16047324,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2MDQ3MzI0","avatar_url":"https://avatars3.githubusercontent.com/u/16047324?v=4","gravatar_id":"","url":"https://api.github.com/users/wireapp","html_url":"https://github.com/wireapp","followers_url":"https://api.github.com/users/wireapp/followers","following_url":"https://api.github.com/users/wireapp/following{/other_user}","gists_url":"https://api.github.com/users/wireapp/gists{/gist_id}","starred_url":"https://api.github.com/users/wireapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wireapp/subscriptions","organizations_url":"https://api.github.com/users/wireapp/orgs","repos_url":"https://api.github.com/users/wireapp/repos","events_url":"https://api.github.com/users/wireapp/events{/privacy}","received_events_url":"https://api.github.com/users/wireapp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wireapp/wire-ios-cryptobox","description":null,"fork":false,"url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox","forks_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/forks","keys_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/teams","hooks_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/hooks","issue_events_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/issues/events{/number}","events_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/events","assignees_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/assignees{/user}","branches_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/branches{/branch}","tags_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/tags","blobs_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/git/refs{/sha}","trees_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/statuses/{sha}","languages_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/languages","stargazers_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/stargazers","contributors_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/contributors","subscribers_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/subscribers","subscription_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/subscription","commits_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/commits{/sha}","git_commits_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/git/commits{/sha}","comments_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/comments{/number}","issue_comment_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/issues/comments{/number}","contents_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/contents/{+path}","compare_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/merges","archive_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/downloads","issues_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/issues{/number}","pulls_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls{/number}","milestones_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/milestones{/number}","notifications_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/labels{/name}","releases_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/releases{/id}","deployments_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/deployments","created_at":"2016-03-10T10:04:06Z","updated_at":"2018-06-22T13:46:29Z","pushed_at":"2018-07-11T13:49:45Z","git_url":"git://github.com/wireapp/wire-ios-cryptobox.git","ssh_url":"git@github.com:wireapp/wire-ios-cryptobox.git","clone_url":"https://github.com/wireapp/wire-ios-cryptobox.git","svn_url":"https://github.com/wireapp/wire-ios-cryptobox","homepage":"https://wire.com","size":24618,"stargazers_count":25,"watchers_count":25,"language":"Swift","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":6,"open_issues":1,"watchers":25,"default_branch":"develop"}},"base":{"label":"wireapp:develop","ref":"develop","sha":"f94a7bb63f5c7f948dfce6819ab98422bc54635a","user":{"login":"wireapp","id":16047324,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2MDQ3MzI0","avatar_url":"https://avatars3.githubusercontent.com/u/16047324?v=4","gravatar_id":"","url":"https://api.github.com/users/wireapp","html_url":"https://github.com/wireapp","followers_url":"https://api.github.com/users/wireapp/followers","following_url":"https://api.github.com/users/wireapp/following{/other_user}","gists_url":"https://api.github.com/users/wireapp/gists{/gist_id}","starred_url":"https://api.github.com/users/wireapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wireapp/subscriptions","organizations_url":"https://api.github.com/users/wireapp/orgs","repos_url":"https://api.github.com/users/wireapp/repos","events_url":"https://api.github.com/users/wireapp/events{/privacy}","received_events_url":"https://api.github.com/users/wireapp/received_events","type":"Organization","site_admin":false},"repo":{"id":53574465,"node_id":"MDEwOlJlcG9zaXRvcnk1MzU3NDQ2NQ==","name":"wire-ios-cryptobox","full_name":"wireapp/wire-ios-cryptobox","owner":{"login":"wireapp","id":16047324,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2MDQ3MzI0","avatar_url":"https://avatars3.githubusercontent.com/u/16047324?v=4","gravatar_id":"","url":"https://api.github.com/users/wireapp","html_url":"https://github.com/wireapp","followers_url":"https://api.github.com/users/wireapp/followers","following_url":"https://api.github.com/users/wireapp/following{/other_user}","gists_url":"https://api.github.com/users/wireapp/gists{/gist_id}","starred_url":"https://api.github.com/users/wireapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wireapp/subscriptions","organizations_url":"https://api.github.com/users/wireapp/orgs","repos_url":"https://api.github.com/users/wireapp/repos","events_url":"https://api.github.com/users/wireapp/events{/privacy}","received_events_url":"https://api.github.com/users/wireapp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wireapp/wire-ios-cryptobox","description":null,"fork":false,"url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox","forks_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/forks","keys_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/teams","hooks_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/hooks","issue_events_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/issues/events{/number}","events_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/events","assignees_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/assignees{/user}","branches_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/branches{/branch}","tags_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/tags","blobs_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/git/refs{/sha}","trees_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/statuses/{sha}","languages_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/languages","stargazers_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/stargazers","contributors_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/contributors","subscribers_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/subscribers","subscription_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/subscription","commits_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/commits{/sha}","git_commits_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/git/commits{/sha}","comments_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/comments{/number}","issue_comment_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/issues/comments{/number}","contents_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/contents/{+path}","compare_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/merges","archive_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/downloads","issues_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/issues{/number}","pulls_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls{/number}","milestones_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/milestones{/number}","notifications_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/labels{/name}","releases_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/releases{/id}","deployments_url":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/deployments","created_at":"2016-03-10T10:04:06Z","updated_at":"2018-06-22T13:46:29Z","pushed_at":"2018-07-11T13:49:45Z","git_url":"git://github.com/wireapp/wire-ios-cryptobox.git","ssh_url":"git@github.com:wireapp/wire-ios-cryptobox.git","clone_url":"https://github.com/wireapp/wire-ios-cryptobox.git","svn_url":"https://github.com/wireapp/wire-ios-cryptobox","homepage":"https://wire.com","size":24618,"stargazers_count":25,"watchers_count":25,"language":"Swift","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":6,"open_issues":1,"watchers":25,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/22"},"html":{"href":"https://github.com/wireapp/wire-ios-cryptobox/pull/22"},"issue":{"href":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/issues/22"},"comments":{"href":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/wireapp/wire-ios-cryptobox/statuses/1df9c9bafe200f2bcf8ee2e6177d87b771e127a6"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"mikeger"}}