{"action":"created","comment":{"url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/comments/28778817","id":28778817,"diff_hunk":"@@ -0,0 +1,151 @@\n+//\n+//  CDTEncryptionKeychainUtils.m\n+//\n+//\n+//  Created by Enrique de la Torre Fernandez on 09/04/2015.\n+//\n+//\n+//  Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file\n+//  except in compliance with the License. You may obtain a copy of the License at\n+//  http://www.apache.org/licenses/LICENSE-2.0\n+//  Unless required by applicable law or agreed to in writing, software distributed under the\n+//  License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\n+//  either express or implied. See the License for the specific language governing permissions\n+//  and limitations under the License.\n+//\n+\n+#import \"CDTEncryptionKeychainUtils.h\"\n+#import \"CDTEncryptionKeychainUtils+AES.h\"\n+#import \"CDTEncryptionKeychainUtils+PBKDF2.h\"\n+\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_KEYGEN_LABEL = @\"KEYGEN_ERROR\";\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_KEYGEN_MSG_INVALID_ITERATIONS =\n+    @\"Number of iterations must greater than 0\";\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_KEYGEN_MSG_INVALID_LENGTH =\n+    @\"Length must greater than 0\";\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_KEYGEN_MSG_EMPTY_PASSWORD =\n+    @\"Password cannot be nil/empty\";\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_KEYGEN_MSG_EMPTY_SALT =\n+    @\"Salt cannot be nil/empty\";\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_KEYGEN_MSG_PASS_NOT_DERIVED =\n+    @\"Password not derived\";\n+\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_ENCRYPT_LABEL = @\"ENCRYPT_ERROR\";\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_ENCRYPT_MSG_EMPTY_DATA =\n+    @\"Cannot encrypt empty/nil data\";\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_ENCRYPT_MSG_EMPTY_KEY =\n+    @\"Cannot work with an empty/nil key\";\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_ENCRYPT_MSG_EMPTY_IV =\n+    @\"Cannot encrypt with empty/nil iv\";\n+\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_DECRYPT_LABEL = @\"DECRYPT_ERROR\";\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_DECRYPT_MSG_EMPTY_CIPHER =\n+    @\"Cannot decrypt empty/nil cipher\";\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_DECRYPT_MSG_EMPTY_KEY =\n+    @\"Cannot work with an empty/nil key\";\n+NSString *const CDTENCRYPTION_KEYCHAIN_UTILS_ERROR_DECRYPT_MSG_EMPTY_IV =\n+    @\"Cannot decrypt with empty/nil iv\";\n+\n+@interface CDTEncryptionKeychainUtils ()\n+\n+@end\n+\n+@implementation CDTEncryptionKeychainUtils\n+\n+#pragma mark - Public class methods\n++ (NSData *)generateRandomBytesInBufferWithLength:(NSUInteger)length\n+{\n+    uint8_t randBytes[length];\n+    \n+    int rc = SecRandomCopyBytes(kSecRandomDefault, (size_t)length, randBytes);","path":"Classes/common/Encryption/Keychain/CDTEncryptionKeychainUtils.m","position":null,"original_position":60,"commit_id":"7bb8c2aa293486556b11994de1fe1b3c67f7cb6d","original_commit_id":"5be696b182f75e627a4248686682c6eb74587795","user":{"login":"indisoluble","id":472832,"avatar_url":"https://avatars.githubusercontent.com/u/472832?v=3","gravatar_id":"","url":"https://api.github.com/users/indisoluble","html_url":"https://github.com/indisoluble","followers_url":"https://api.github.com/users/indisoluble/followers","following_url":"https://api.github.com/users/indisoluble/following{/other_user}","gists_url":"https://api.github.com/users/indisoluble/gists{/gist_id}","starred_url":"https://api.github.com/users/indisoluble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indisoluble/subscriptions","organizations_url":"https://api.github.com/users/indisoluble/orgs","repos_url":"https://api.github.com/users/indisoluble/repos","events_url":"https://api.github.com/users/indisoluble/events{/privacy}","received_events_url":"https://api.github.com/users/indisoluble/received_events","type":"User","site_admin":false},"body":"Fixed in 7bb8c2a","created_at":"2015-04-21T13:49:50Z","updated_at":"2015-04-21T13:49:50Z","html_url":"https://github.com/cloudant/CDTDatastore/pull/126#discussion_r28778817","pull_request_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/126","_links":{"self":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/comments/28778817"},"html":{"href":"https://github.com/cloudant/CDTDatastore/pull/126#discussion_r28778817"},"pull_request":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/126"}}},"pull_request":{"url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/126","id":33742159,"html_url":"https://github.com/cloudant/CDTDatastore/pull/126","diff_url":"https://github.com/cloudant/CDTDatastore/pull/126.diff","patch_url":"https://github.com/cloudant/CDTDatastore/pull/126.patch","issue_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/126","number":126,"state":"open","locked":false,"title":"45570 Generate, retrieve & store a key: AES & PBKDF2","user":{"login":"indisoluble","id":472832,"avatar_url":"https://avatars.githubusercontent.com/u/472832?v=3","gravatar_id":"","url":"https://api.github.com/users/indisoluble","html_url":"https://github.com/indisoluble","followers_url":"https://api.github.com/users/indisoluble/followers","following_url":"https://api.github.com/users/indisoluble/following{/other_user}","gists_url":"https://api.github.com/users/indisoluble/gists{/gist_id}","starred_url":"https://api.github.com/users/indisoluble/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/indisoluble/subscriptions","organizations_url":"https://api.github.com/users/indisoluble/orgs","repos_url":"https://api.github.com/users/indisoluble/repos","events_url":"https://api.github.com/users/indisoluble/events{/privacy}","received_events_url":"https://api.github.com/users/indisoluble/received_events","type":"User","site_admin":false},"body":"*What:*\r\nAdd classes to apply AES to a NSData and generate a key with PBKDF2.\r\n\r\n*Why:*\r\nThis PR is part of a bigger development to provide a mechanism to generate a key and safely store it.\r\n\r\n*How:*\r\nThese classes are essentially a wrapper around the methods offered by Security framework.\r\n\r\n*Tests:*\r\nOnly to be sure that we get what we expect, using some hardcoded values we check that the results we get are as expected.\r\n\r\nreviewer @mikerhodes \r\nreviewer @rhyshort \r\n","created_at":"2015-04-21T09:13:51Z","updated_at":"2015-04-21T13:49:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"af34151aecca81dec98654e55f0337713990db05","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/126/commits","review_comments_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/126/comments","review_comment_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/126/comments","statuses_url":"https://api.github.com/repos/cloudant/CDTDatastore/statuses/7bb8c2aa293486556b11994de1fe1b3c67f7cb6d","head":{"label":"cloudant:45570-generate-retrieve-store-key-utils","ref":"45570-generate-retrieve-store-key-utils","sha":"7bb8c2aa293486556b11994de1fe1b3c67f7cb6d","user":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"repo":{"id":15022868,"name":"CDTDatastore","full_name":"cloudant/CDTDatastore","owner":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudant/CDTDatastore","description":"Cloudant Sync iOS datastore library.","fork":false,"url":"https://api.github.com/repos/cloudant/CDTDatastore","forks_url":"https://api.github.com/repos/cloudant/CDTDatastore/forks","keys_url":"https://api.github.com/repos/cloudant/CDTDatastore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudant/CDTDatastore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudant/CDTDatastore/teams","hooks_url":"https://api.github.com/repos/cloudant/CDTDatastore/hooks","issue_events_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/events{/number}","events_url":"https://api.github.com/repos/cloudant/CDTDatastore/events","assignees_url":"https://api.github.com/repos/cloudant/CDTDatastore/assignees{/user}","branches_url":"https://api.github.com/repos/cloudant/CDTDatastore/branches{/branch}","tags_url":"https://api.github.com/repos/cloudant/CDTDatastore/tags","blobs_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudant/CDTDatastore/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudant/CDTDatastore/languages","stargazers_url":"https://api.github.com/repos/cloudant/CDTDatastore/stargazers","contributors_url":"https://api.github.com/repos/cloudant/CDTDatastore/contributors","subscribers_url":"https://api.github.com/repos/cloudant/CDTDatastore/subscribers","subscription_url":"https://api.github.com/repos/cloudant/CDTDatastore/subscription","commits_url":"https://api.github.com/repos/cloudant/CDTDatastore/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudant/CDTDatastore/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudant/CDTDatastore/contents/{+path}","compare_url":"https://api.github.com/repos/cloudant/CDTDatastore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudant/CDTDatastore/merges","archive_url":"https://api.github.com/repos/cloudant/CDTDatastore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudant/CDTDatastore/downloads","issues_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues{/number}","pulls_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudant/CDTDatastore/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudant/CDTDatastore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudant/CDTDatastore/labels{/name}","releases_url":"https://api.github.com/repos/cloudant/CDTDatastore/releases{/id}","created_at":"2013-12-08T11:59:05Z","updated_at":"2015-04-21T13:22:05Z","pushed_at":"2015-04-21T13:49:38Z","git_url":"git://github.com/cloudant/CDTDatastore.git","ssh_url":"git@github.com:cloudant/CDTDatastore.git","clone_url":"https://github.com/cloudant/CDTDatastore.git","svn_url":"https://github.com/cloudant/CDTDatastore","homepage":null,"size":8095,"stargazers_count":70,"watchers_count":70,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":5,"forks":13,"open_issues":5,"watchers":70,"default_branch":"master"}},"base":{"label":"cloudant:feature-encryption","ref":"feature-encryption","sha":"c67f4a8f8ce17f53b07e411592c92ac233a897c2","user":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"repo":{"id":15022868,"name":"CDTDatastore","full_name":"cloudant/CDTDatastore","owner":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudant/CDTDatastore","description":"Cloudant Sync iOS datastore library.","fork":false,"url":"https://api.github.com/repos/cloudant/CDTDatastore","forks_url":"https://api.github.com/repos/cloudant/CDTDatastore/forks","keys_url":"https://api.github.com/repos/cloudant/CDTDatastore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudant/CDTDatastore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudant/CDTDatastore/teams","hooks_url":"https://api.github.com/repos/cloudant/CDTDatastore/hooks","issue_events_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/events{/number}","events_url":"https://api.github.com/repos/cloudant/CDTDatastore/events","assignees_url":"https://api.github.com/repos/cloudant/CDTDatastore/assignees{/user}","branches_url":"https://api.github.com/repos/cloudant/CDTDatastore/branches{/branch}","tags_url":"https://api.github.com/repos/cloudant/CDTDatastore/tags","blobs_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudant/CDTDatastore/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudant/CDTDatastore/languages","stargazers_url":"https://api.github.com/repos/cloudant/CDTDatastore/stargazers","contributors_url":"https://api.github.com/repos/cloudant/CDTDatastore/contributors","subscribers_url":"https://api.github.com/repos/cloudant/CDTDatastore/subscribers","subscription_url":"https://api.github.com/repos/cloudant/CDTDatastore/subscription","commits_url":"https://api.github.com/repos/cloudant/CDTDatastore/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudant/CDTDatastore/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudant/CDTDatastore/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudant/CDTDatastore/contents/{+path}","compare_url":"https://api.github.com/repos/cloudant/CDTDatastore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudant/CDTDatastore/merges","archive_url":"https://api.github.com/repos/cloudant/CDTDatastore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudant/CDTDatastore/downloads","issues_url":"https://api.github.com/repos/cloudant/CDTDatastore/issues{/number}","pulls_url":"https://api.github.com/repos/cloudant/CDTDatastore/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudant/CDTDatastore/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudant/CDTDatastore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudant/CDTDatastore/labels{/name}","releases_url":"https://api.github.com/repos/cloudant/CDTDatastore/releases{/id}","created_at":"2013-12-08T11:59:05Z","updated_at":"2015-04-21T13:22:05Z","pushed_at":"2015-04-21T13:49:38Z","git_url":"git://github.com/cloudant/CDTDatastore.git","ssh_url":"git@github.com:cloudant/CDTDatastore.git","clone_url":"https://github.com/cloudant/CDTDatastore.git","svn_url":"https://github.com/cloudant/CDTDatastore","homepage":null,"size":8095,"stargazers_count":70,"watchers_count":70,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":5,"forks":13,"open_issues":5,"watchers":70,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/126"},"html":{"href":"https://github.com/cloudant/CDTDatastore/pull/126"},"issue":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/issues/126"},"comments":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/issues/126/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/126/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/pulls/126/commits"},"statuses":{"href":"https://api.github.com/repos/cloudant/CDTDatastore/statuses/7bb8c2aa293486556b11994de1fe1b3c67f7cb6d"}}}}