{"action":"created","comment":{"url":"https://api.github.com/repos/owncloud/core/pulls/comments/26662288","id":26662288,"diff_hunk":"@@ -0,0 +1,355 @@\n+<?php\n+/**\n+ * @author Clark Tomlinson  <clark@owncloud.com>\n+ * @since 2/19/15, 1:42 PM\n+ * @copyright Copyright (c) 2015, ownCloud, Inc.\n+ * @license AGPL-3.0\n+ *\n+ * This code is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU Affero General Public License, version 3,\n+ * as published by the Free Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+ * GNU Affero General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Affero General Public License, version 3,\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>\n+ *\n+ */\n+\n+namespace OCA\\Encryption\\Crypto;\n+\n+\n+use OC\\Encryption\\Exceptions\\DecryptionFailedException;\n+use OC\\Encryption\\Exceptions\\EncryptionFailedException;\n+use OC\\Encryption\\Exceptions\\GenericEncryptionException;\n+use OCP\\IConfig;\n+use OCP\\ILogger;\n+use OCP\\IUser;\n+use OCP\\IUserSession;\n+\n+class Crypt {\n+\n+\tconst ENCRYPTION_UKNOWN_ERROR = -1;\n+\tconst ENCRYPTION_NOT_INIALIZED_ERROR = 1;\n+\tconst ENCRYPTIION_PRIVATE_KEY_NOT_VALID_ERROR = 2;\n+\tconst ENCRYPTION_NO_SHARE_KEY_FOUND = 3;\n+\n+\tconst BLOCKSIZE = 8192;\n+\tconst DEFAULT_CIPHER = 'AES-256-CFB';\n+\n+\tconst HEADERSTART = 'HBEGIN';\n+\tconst HEADEREND = 'HEND';\n+\t/**\n+\t * @var ILogger\n+\t */\n+\tprivate $logger;\n+\t/**\n+\t * @var IUser\n+\t */\n+\tprivate $user;\n+\t/**\n+\t * @var IConfig\n+\t */\n+\tprivate $config;\n+\n+\t/**\n+\t * @param ILogger $logger\n+\t * @param IUserSession $userSession\n+\t * @param IConfig $config\n+\t */\n+\tpublic function __construct(ILogger $logger, IUserSession $userSession, IConfig $config) {\n+\t\t$this->logger = $logger;\n+\t\t$this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser() : false;\n+\t\t$this->config = $config;\n+\t}\n+\n+\t/**\n+\t * @param null $user\n+\t * @return string\n+\t */\n+\tpublic function mode($user = null) {\n+\t\treturn 'server';\n+\t}\n+\n+\t/**\n+\t *\n+\t */\n+\tpublic function createKeyPair() {\n+\n+\t\t$log = $this->logger;\n+\t\t$res = $this->getOpenSSLPKey();\n+\n+\t\tif (!$res) {\n+\t\t\t$log->error(\"Encryption Library could'nt generate users key-pair for {$this->user->getUID()}\", ['app' => 'encryption']);\n+\n+\t\t\tif (openssl_error_string()) {\n+\t\t\t\t$log->error('Encryption library openssl_pkey_new() fails: ' . openssl_error_string(), ['app' => 'encryption']);\n+\t\t\t}\n+\t\t} elseif (openssl_pkey_export($res, $privateKey, null, $this->getOpenSSLConfig())) {\n+\t\t\t$keyDetails = openssl_pkey_get_details($res);\n+\t\t\t$publicKey = $keyDetails['key'];\n+\n+\t\t\treturn [\n+\t\t\t\t'publicKey' => $publicKey,\n+\t\t\t\t'privateKey' => $privateKey\n+\t\t\t];\n+\t\t}\n+\t\t$log->error('Encryption library couldn\\'t export users private key, please check your servers openSSL configuration.' . $user->getUID(), ['app' => 'encryption']);\n+\t\tif (openssl_error_string()) {\n+\t\t\t$log->error('Encryption Library:' . openssl_error_string(), ['app' => 'encryption']);\n+\t\t}\n+\n+\t\treturn false;\n+\t}\n+\n+\t/**\n+\t * @return resource\n+\t */\n+\tpublic function getOpenSSLPKey() {\n+\t\t$config = $this->getOpenSSLConfig();\n+\t\treturn openssl_pkey_new($config);\n+\t}\n+\n+\t/**\n+\t * @return array\n+\t */\n+\tprivate function getOpenSSLConfig() {\n+\t\t$config = ['private_key_bits' => 4096];\n+\t\t$config = array_merge(\\OC::$server->getConfig()->getSystemValue('openssl', []), $config);\n+\t\treturn $config;\n+\t}\n+\n+\t/**\n+\t * @param $plainContent\n+\t * @param $passphrase\n+\t * @return bool|string\n+\t * @throws GenericEncryptionException\n+\t */\n+\tpublic function symmetricEncryptFileContent($plainContent, $passphrase) {\n+\n+\t\tif (!$plainContent) {\n+\t\t\t$this->logger->error('Encryption Library, symmetrical encryption failed no content given', ['app' => 'encryption']);\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\t$iv = $this->generateIv();\n+\n+\t\ttry {\n+\t\t\t$encryptedContent = $this->encrypt($plainContent, $iv, $passphrase, $this->getCipher());\n+\t\t\t// combine content to encrypt the IV identifier and actual IV\n+\t\t\t$catFile = $this->concatIV($encryptedContent, $iv);\n+\t\t\t$padded = $this->addPadding($catFile);\n+\n+\t\t\treturn $padded;\n+\t\t} catch (EncryptionFailedException $e) {\n+\t\t\t$message = 'Could not encrypt file content (code: ' . $e->getCode() . '): ';\n+\t\t\t$this->logger->error('files_encryption' . $message . $e->getMessage(), ['app' => 'encryption']);\n+\t\t\treturn false;\n+\t\t}\n+\n+\t}\n+\n+\t/**\n+\t * @param $plainContent\n+\t * @param $iv","path":"apps/encryption/lib/crypto/crypt.php","position":157,"original_position":157,"commit_id":"b2c7224f4556c9644a2621f63de654f55d93766f","original_commit_id":"b2c7224f4556c9644a2621f63de654f55d93766f","user":{"login":"LukasReschke","id":878997,"avatar_url":"https://avatars.githubusercontent.com/u/878997?v=3","gravatar_id":"","url":"https://api.github.com/users/LukasReschke","html_url":"https://github.com/LukasReschke","followers_url":"https://api.github.com/users/LukasReschke/followers","following_url":"https://api.github.com/users/LukasReschke/following{/other_user}","gists_url":"https://api.github.com/users/LukasReschke/gists{/gist_id}","starred_url":"https://api.github.com/users/LukasReschke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LukasReschke/subscriptions","organizations_url":"https://api.github.com/users/LukasReschke/orgs","repos_url":"https://api.github.com/users/LukasReschke/repos","events_url":"https://api.github.com/users/LukasReschke/events{/privacy}","received_events_url":"https://api.github.com/users/LukasReschke/received_events","type":"User","site_admin":false},"body":"`string`?","created_at":"2015-03-18T13:34:02Z","updated_at":"2015-03-18T13:34:02Z","html_url":"https://github.com/owncloud/core/pull/14472#discussion_r26662288","pull_request_url":"https://api.github.com/repos/owncloud/core/pulls/14472","_links":{"self":{"href":"https://api.github.com/repos/owncloud/core/pulls/comments/26662288"},"html":{"href":"https://github.com/owncloud/core/pull/14472#discussion_r26662288"},"pull_request":{"href":"https://api.github.com/repos/owncloud/core/pulls/14472"}}},"pull_request":{"url":"https://api.github.com/repos/owncloud/core/pulls/14472","id":29920996,"html_url":"https://github.com/owncloud/core/pull/14472","diff_url":"https://github.com/owncloud/core/pull/14472.diff","patch_url":"https://github.com/owncloud/core/pull/14472.patch","issue_url":"https://api.github.com/repos/owncloud/core/issues/14472","number":14472,"state":"open","locked":false,"title":"[WIP] encryption 2.0 app","user":{"login":"th3fallen","id":291859,"avatar_url":"https://avatars.githubusercontent.com/u/291859?v=3","gravatar_id":"","url":"https://api.github.com/users/th3fallen","html_url":"https://github.com/th3fallen","followers_url":"https://api.github.com/users/th3fallen/followers","following_url":"https://api.github.com/users/th3fallen/following{/other_user}","gists_url":"https://api.github.com/users/th3fallen/gists{/gist_id}","starred_url":"https://api.github.com/users/th3fallen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/th3fallen/subscriptions","organizations_url":"https://api.github.com/users/th3fallen/orgs","repos_url":"https://api.github.com/users/th3fallen/repos","events_url":"https://api.github.com/users/th3fallen/events{/privacy}","received_events_url":"https://api.github.com/users/th3fallen/received_events","type":"User","site_admin":false},"body":"Depends on https://github.com/owncloud/core/pull/14376\r\n\r\nVery much in development. Please point out any missed opportunities to use new methods/interfaces @schiesbn \r\n\r\n- [ ] The encryption module needs a upgrade script to migrate the keys from the old encryption app to the new one, unfortunately we had to make some small changes to the folder structure (added by @schiesbn)","created_at":"2015-02-24T18:06:34Z","updated_at":"2015-03-18T13:34:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dce3cc54f2d43bd4be95eeb55455002ffeb1cba7","assignee":null,"milestone":{"url":"https://api.github.com/repos/owncloud/core/milestones/31","html_url":"https://github.com/owncloud/core/milestones/8.1-current","labels_url":"https://api.github.com/repos/owncloud/core/milestones/31/labels","id":912160,"number":31,"title":"8.1-current","description":"","creator":{"login":"MorrisJobke","id":245432,"avatar_url":"https://avatars.githubusercontent.com/u/245432?v=3","gravatar_id":"","url":"https://api.github.com/users/MorrisJobke","html_url":"https://github.com/MorrisJobke","followers_url":"https://api.github.com/users/MorrisJobke/followers","following_url":"https://api.github.com/users/MorrisJobke/following{/other_user}","gists_url":"https://api.github.com/users/MorrisJobke/gists{/gist_id}","starred_url":"https://api.github.com/users/MorrisJobke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MorrisJobke/subscriptions","organizations_url":"https://api.github.com/users/MorrisJobke/orgs","repos_url":"https://api.github.com/users/MorrisJobke/repos","events_url":"https://api.github.com/users/MorrisJobke/events{/privacy}","received_events_url":"https://api.github.com/users/MorrisJobke/received_events","type":"User","site_admin":false},"open_issues":286,"closed_issues":398,"state":"open","created_at":"2014-12-22T12:04:01Z","updated_at":"2015-03-18T13:32:51Z","due_on":"2015-04-02T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/owncloud/core/pulls/14472/commits","review_comments_url":"https://api.github.com/repos/owncloud/core/pulls/14472/comments","review_comment_url":"https://api.github.com/repos/owncloud/core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/owncloud/core/issues/14472/comments","statuses_url":"https://api.github.com/repos/owncloud/core/statuses/b2c7224f4556c9644a2621f63de654f55d93766f","head":{"label":"owncloud:feature/wipencryptionapp","ref":"feature/wipencryptionapp","sha":"b2c7224f4556c9644a2621f63de654f55d93766f","user":{"login":"owncloud","id":1645051,"avatar_url":"https://avatars.githubusercontent.com/u/1645051?v=3","gravatar_id":"","url":"https://api.github.com/users/owncloud","html_url":"https://github.com/owncloud","followers_url":"https://api.github.com/users/owncloud/followers","following_url":"https://api.github.com/users/owncloud/following{/other_user}","gists_url":"https://api.github.com/users/owncloud/gists{/gist_id}","starred_url":"https://api.github.com/users/owncloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owncloud/subscriptions","organizations_url":"https://api.github.com/users/owncloud/orgs","repos_url":"https://api.github.com/users/owncloud/repos","events_url":"https://api.github.com/users/owncloud/events{/privacy}","received_events_url":"https://api.github.com/users/owncloud/received_events","type":"Organization","site_admin":false},"repo":{"id":5550552,"name":"core","full_name":"owncloud/core","owner":{"login":"owncloud","id":1645051,"avatar_url":"https://avatars.githubusercontent.com/u/1645051?v=3","gravatar_id":"","url":"https://api.github.com/users/owncloud","html_url":"https://github.com/owncloud","followers_url":"https://api.github.com/users/owncloud/followers","following_url":"https://api.github.com/users/owncloud/following{/other_user}","gists_url":"https://api.github.com/users/owncloud/gists{/gist_id}","starred_url":"https://api.github.com/users/owncloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owncloud/subscriptions","organizations_url":"https://api.github.com/users/owncloud/orgs","repos_url":"https://api.github.com/users/owncloud/repos","events_url":"https://api.github.com/users/owncloud/events{/privacy}","received_events_url":"https://api.github.com/users/owncloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/owncloud/core","description":"The ownCloud core","fork":false,"url":"https://api.github.com/repos/owncloud/core","forks_url":"https://api.github.com/repos/owncloud/core/forks","keys_url":"https://api.github.com/repos/owncloud/core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/owncloud/core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/owncloud/core/teams","hooks_url":"https://api.github.com/repos/owncloud/core/hooks","issue_events_url":"https://api.github.com/repos/owncloud/core/issues/events{/number}","events_url":"https://api.github.com/repos/owncloud/core/events","assignees_url":"https://api.github.com/repos/owncloud/core/assignees{/user}","branches_url":"https://api.github.com/repos/owncloud/core/branches{/branch}","tags_url":"https://api.github.com/repos/owncloud/core/tags","blobs_url":"https://api.github.com/repos/owncloud/core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/owncloud/core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/owncloud/core/git/refs{/sha}","trees_url":"https://api.github.com/repos/owncloud/core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/owncloud/core/statuses/{sha}","languages_url":"https://api.github.com/repos/owncloud/core/languages","stargazers_url":"https://api.github.com/repos/owncloud/core/stargazers","contributors_url":"https://api.github.com/repos/owncloud/core/contributors","subscribers_url":"https://api.github.com/repos/owncloud/core/subscribers","subscription_url":"https://api.github.com/repos/owncloud/core/subscription","commits_url":"https://api.github.com/repos/owncloud/core/commits{/sha}","git_commits_url":"https://api.github.com/repos/owncloud/core/git/commits{/sha}","comments_url":"https://api.github.com/repos/owncloud/core/comments{/number}","issue_comment_url":"https://api.github.com/repos/owncloud/core/issues/comments{/number}","contents_url":"https://api.github.com/repos/owncloud/core/contents/{+path}","compare_url":"https://api.github.com/repos/owncloud/core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/owncloud/core/merges","archive_url":"https://api.github.com/repos/owncloud/core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/owncloud/core/downloads","issues_url":"https://api.github.com/repos/owncloud/core/issues{/number}","pulls_url":"https://api.github.com/repos/owncloud/core/pulls{/number}","milestones_url":"https://api.github.com/repos/owncloud/core/milestones{/number}","notifications_url":"https://api.github.com/repos/owncloud/core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/owncloud/core/labels{/name}","releases_url":"https://api.github.com/repos/owncloud/core/releases{/id}","created_at":"2012-08-25T10:32:48Z","updated_at":"2015-03-18T13:17:00Z","pushed_at":"2015-03-18T13:19:35Z","git_url":"git://github.com/owncloud/core.git","ssh_url":"git@github.com:owncloud/core.git","clone_url":"https://github.com/owncloud/core.git","svn_url":"https://github.com/owncloud/core","homepage":null,"size":956716,"stargazers_count":3141,"watchers_count":3141,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1007,"mirror_url":null,"open_issues_count":1823,"forks":1007,"open_issues":1823,"watchers":3141,"default_branch":"master"}},"base":{"label":"owncloud:master","ref":"master","sha":"093efa458c16ea4a7f7fcaf3f98e1e0fb96624c4","user":{"login":"owncloud","id":1645051,"avatar_url":"https://avatars.githubusercontent.com/u/1645051?v=3","gravatar_id":"","url":"https://api.github.com/users/owncloud","html_url":"https://github.com/owncloud","followers_url":"https://api.github.com/users/owncloud/followers","following_url":"https://api.github.com/users/owncloud/following{/other_user}","gists_url":"https://api.github.com/users/owncloud/gists{/gist_id}","starred_url":"https://api.github.com/users/owncloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owncloud/subscriptions","organizations_url":"https://api.github.com/users/owncloud/orgs","repos_url":"https://api.github.com/users/owncloud/repos","events_url":"https://api.github.com/users/owncloud/events{/privacy}","received_events_url":"https://api.github.com/users/owncloud/received_events","type":"Organization","site_admin":false},"repo":{"id":5550552,"name":"core","full_name":"owncloud/core","owner":{"login":"owncloud","id":1645051,"avatar_url":"https://avatars.githubusercontent.com/u/1645051?v=3","gravatar_id":"","url":"https://api.github.com/users/owncloud","html_url":"https://github.com/owncloud","followers_url":"https://api.github.com/users/owncloud/followers","following_url":"https://api.github.com/users/owncloud/following{/other_user}","gists_url":"https://api.github.com/users/owncloud/gists{/gist_id}","starred_url":"https://api.github.com/users/owncloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owncloud/subscriptions","organizations_url":"https://api.github.com/users/owncloud/orgs","repos_url":"https://api.github.com/users/owncloud/repos","events_url":"https://api.github.com/users/owncloud/events{/privacy}","received_events_url":"https://api.github.com/users/owncloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/owncloud/core","description":"The ownCloud core","fork":false,"url":"https://api.github.com/repos/owncloud/core","forks_url":"https://api.github.com/repos/owncloud/core/forks","keys_url":"https://api.github.com/repos/owncloud/core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/owncloud/core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/owncloud/core/teams","hooks_url":"https://api.github.com/repos/owncloud/core/hooks","issue_events_url":"https://api.github.com/repos/owncloud/core/issues/events{/number}","events_url":"https://api.github.com/repos/owncloud/core/events","assignees_url":"https://api.github.com/repos/owncloud/core/assignees{/user}","branches_url":"https://api.github.com/repos/owncloud/core/branches{/branch}","tags_url":"https://api.github.com/repos/owncloud/core/tags","blobs_url":"https://api.github.com/repos/owncloud/core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/owncloud/core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/owncloud/core/git/refs{/sha}","trees_url":"https://api.github.com/repos/owncloud/core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/owncloud/core/statuses/{sha}","languages_url":"https://api.github.com/repos/owncloud/core/languages","stargazers_url":"https://api.github.com/repos/owncloud/core/stargazers","contributors_url":"https://api.github.com/repos/owncloud/core/contributors","subscribers_url":"https://api.github.com/repos/owncloud/core/subscribers","subscription_url":"https://api.github.com/repos/owncloud/core/subscription","commits_url":"https://api.github.com/repos/owncloud/core/commits{/sha}","git_commits_url":"https://api.github.com/repos/owncloud/core/git/commits{/sha}","comments_url":"https://api.github.com/repos/owncloud/core/comments{/number}","issue_comment_url":"https://api.github.com/repos/owncloud/core/issues/comments{/number}","contents_url":"https://api.github.com/repos/owncloud/core/contents/{+path}","compare_url":"https://api.github.com/repos/owncloud/core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/owncloud/core/merges","archive_url":"https://api.github.com/repos/owncloud/core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/owncloud/core/downloads","issues_url":"https://api.github.com/repos/owncloud/core/issues{/number}","pulls_url":"https://api.github.com/repos/owncloud/core/pulls{/number}","milestones_url":"https://api.github.com/repos/owncloud/core/milestones{/number}","notifications_url":"https://api.github.com/repos/owncloud/core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/owncloud/core/labels{/name}","releases_url":"https://api.github.com/repos/owncloud/core/releases{/id}","created_at":"2012-08-25T10:32:48Z","updated_at":"2015-03-18T13:17:00Z","pushed_at":"2015-03-18T13:19:35Z","git_url":"git://github.com/owncloud/core.git","ssh_url":"git@github.com:owncloud/core.git","clone_url":"https://github.com/owncloud/core.git","svn_url":"https://github.com/owncloud/core","homepage":null,"size":956716,"stargazers_count":3141,"watchers_count":3141,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1007,"mirror_url":null,"open_issues_count":1823,"forks":1007,"open_issues":1823,"watchers":3141,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/owncloud/core/pulls/14472"},"html":{"href":"https://github.com/owncloud/core/pull/14472"},"issue":{"href":"https://api.github.com/repos/owncloud/core/issues/14472"},"comments":{"href":"https://api.github.com/repos/owncloud/core/issues/14472/comments"},"review_comments":{"href":"https://api.github.com/repos/owncloud/core/pulls/14472/comments"},"review_comment":{"href":"https://api.github.com/repos/owncloud/core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/owncloud/core/pulls/14472/commits"},"statuses":{"href":"https://api.github.com/repos/owncloud/core/statuses/b2c7224f4556c9644a2621f63de654f55d93766f"}}}}