{"action":"created","comment":{"url":"https://api.github.com/repos/kaaproject/kaa/pulls/comments/77978946","id":77978946,"diff_hunk":"@@ -0,0 +1,186 @@\n+/*\n+ *  Copyright 2014-2016 CyberVision, Inc.\n+ *\n+ *  Licensed under the Apache License, Version 2.0 (the \"License\");\n+ *  you may not use this file except in compliance with the License.\n+ *  You may obtain a copy of the License at\n+ *\n+ *       http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ *  Unless required by applicable law or agreed to in writing, software\n+ *  distributed under the License is distributed on an \"AS IS\" BASIS,\n+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ *  See the License for the specific language governing permissions and\n+ *  limitations under the License.\n+ */\n+\n+#include \"platform/ext_encryption_utils.h\"\n+#include \"platform/ext_key_utils.h\"\n+\n+#include <assert.h>\n+#include <stdbool.h>\n+#include <string.h>\n+\n+#include <utilities/kaa_aes_rsa.h>\n+\n+#include <mbedtls/pk.h>\n+#include <mbedtls/entropy.h>\n+#include <mbedtls/ctr_drbg.h>\n+#include <mbedtls/md.h>\n+\n+#define ENC_SESSION_KEY_LENGTH         256\n+#define KAA_SIGNATURE_LENGTH           256\n+#define AES_ECB_ENCRYPTION_CHUNCK_SIZE 16\n+\n+extern mbedtls_pk_context pk_context_;\n+\n+/**\n+ * Contains Endpoint keys.\n+ *\n+ * The main purpose of the structure is\n+ * caching calculated keys.\n+ */\n+static struct {\n+    uint8_t session_key[KAA_SESSION_KEY_LENGTH];\n+    uint8_t encrypted_session_key[ENC_SESSION_KEY_LENGTH];\n+    uint8_t signature[KAA_SIGNATURE_LENGTH];\n+    size_t  encrypted_session_key_length;\n+    size_t  session_key_length;\n+} keys;\n+\n+kaa_error_t kaa_init_session_key(void)\n+{\n+    /* Initialization should be performed only once */\n+    static bool initialized = false;\n+    if (!initialized) {\n+        /* Generate session key */\n+        if (init_aes_key(keys.session_key, KAA_SESSION_KEY_LENGTH)) {\n+            return KAA_ERR_BADDATA;\n+        }\n+\n+        keys.session_key_length = KAA_SESSION_KEY_LENGTH;\n+        initialized = true;\n+    }\n+\n+    return KAA_ERR_NONE;\n+}\n+\n+void ext_get_endpoint_session_key(uint8_t **buffer, size_t *buffer_size)\n+{\n+    if (!buffer || !buffer_size) {\n+        return;\n+    }\n+    *buffer = keys.session_key;\n+    *buffer_size = keys.session_key_length;\n+}\n+\n+/* Get encrypted session key (enctypted with remote key) */\n+kaa_error_t ext_get_encrypted_session_key(uint8_t **buffer, size_t *buffer_size,\n+        const uint8_t *remote_key, size_t remote_key_size)\n+{\n+    if (!buffer || !buffer_size || !remote_key || !remote_key_size) {","path":"client/client-multi/client-c/src/kaa/platform-impl/common/encryption_utils.c","position":81,"original_position":81,"commit_id":"baa5c841bc09bfb372d031b0e2d21e620f97118a","original_commit_id":"baa5c841bc09bfb372d031b0e2d21e620f97118a","user":{"login":"rasendubi","id":1366419,"avatar_url":"https://avatars.githubusercontent.com/u/1366419?v=3","gravatar_id":"","url":"https://api.github.com/users/rasendubi","html_url":"https://github.com/rasendubi","followers_url":"https://api.github.com/users/rasendubi/followers","following_url":"https://api.github.com/users/rasendubi/following{/other_user}","gists_url":"https://api.github.com/users/rasendubi/gists{/gist_id}","starred_url":"https://api.github.com/users/rasendubi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rasendubi/subscriptions","organizations_url":"https://api.github.com/users/rasendubi/orgs","repos_url":"https://api.github.com/users/rasendubi/repos","events_url":"https://api.github.com/users/rasendubi/events{/privacy}","received_events_url":"https://api.github.com/users/rasendubi/received_events","type":"User","site_admin":false},"body":"```c\r\nif (buffer == NULL || buffer_size == 0 || remote_key == NULL || remote_key_size == 0)\r\n```","created_at":"2016-09-08T10:09:10Z","updated_at":"2016-09-08T10:09:10Z","html_url":"https://github.com/kaaproject/kaa/pull/1004#discussion_r77978946","pull_request_url":"https://api.github.com/repos/kaaproject/kaa/pulls/1004","_links":{"self":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/comments/77978946"},"html":{"href":"https://github.com/kaaproject/kaa/pull/1004#discussion_r77978946"},"pull_request":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/1004"}}},"pull_request":{"url":"https://api.github.com/repos/kaaproject/kaa/pulls/1004","id":82007770,"html_url":"https://github.com/kaaproject/kaa/pull/1004","diff_url":"https://github.com/kaaproject/kaa/pull/1004.diff","patch_url":"https://github.com/kaaproject/kaa/pull/1004.patch","issue_url":"https://api.github.com/repos/kaaproject/kaa/issues/1004","number":1004,"state":"open","locked":false,"title":"KAA-1364: [C SDK] Fix undefined references when encryption is disabled","user":{"login":"RostakaGmfun","id":5872727,"avatar_url":"https://avatars.githubusercontent.com/u/5872727?v=3","gravatar_id":"","url":"https://api.github.com/users/RostakaGmfun","html_url":"https://github.com/RostakaGmfun","followers_url":"https://api.github.com/users/RostakaGmfun/followers","following_url":"https://api.github.com/users/RostakaGmfun/following{/other_user}","gists_url":"https://api.github.com/users/RostakaGmfun/gists{/gist_id}","starred_url":"https://api.github.com/users/RostakaGmfun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RostakaGmfun/subscriptions","organizations_url":"https://api.github.com/users/RostakaGmfun/orgs","repos_url":"https://api.github.com/users/RostakaGmfun/repos","events_url":"https://api.github.com/users/RostakaGmfun/events{/privacy}","received_events_url":"https://api.github.com/users/RostakaGmfun/received_events","type":"User","site_admin":false},"body":"/cc @vadimol","created_at":"2016-08-19T16:22:53Z","updated_at":"2016-09-08T10:09:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c77f5b4a9bf0f22b101c039ec760851315dd1988","assignee":{"login":"vadimol","id":5074479,"avatar_url":"https://avatars.githubusercontent.com/u/5074479?v=3","gravatar_id":"","url":"https://api.github.com/users/vadimol","html_url":"https://github.com/vadimol","followers_url":"https://api.github.com/users/vadimol/followers","following_url":"https://api.github.com/users/vadimol/following{/other_user}","gists_url":"https://api.github.com/users/vadimol/gists{/gist_id}","starred_url":"https://api.github.com/users/vadimol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vadimol/subscriptions","organizations_url":"https://api.github.com/users/vadimol/orgs","repos_url":"https://api.github.com/users/vadimol/repos","events_url":"https://api.github.com/users/vadimol/events{/privacy}","received_events_url":"https://api.github.com/users/vadimol/received_events","type":"User","site_admin":false},"assignees":[{"login":"vadimol","id":5074479,"avatar_url":"https://avatars.githubusercontent.com/u/5074479?v=3","gravatar_id":"","url":"https://api.github.com/users/vadimol","html_url":"https://github.com/vadimol","followers_url":"https://api.github.com/users/vadimol/followers","following_url":"https://api.github.com/users/vadimol/following{/other_user}","gists_url":"https://api.github.com/users/vadimol/gists{/gist_id}","starred_url":"https://api.github.com/users/vadimol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vadimol/subscriptions","organizations_url":"https://api.github.com/users/vadimol/orgs","repos_url":"https://api.github.com/users/vadimol/repos","events_url":"https://api.github.com/users/vadimol/events{/privacy}","received_events_url":"https://api.github.com/users/vadimol/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/kaaproject/kaa/pulls/1004/commits","review_comments_url":"https://api.github.com/repos/kaaproject/kaa/pulls/1004/comments","review_comment_url":"https://api.github.com/repos/kaaproject/kaa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kaaproject/kaa/issues/1004/comments","statuses_url":"https://api.github.com/repos/kaaproject/kaa/statuses/baa5c841bc09bfb372d031b0e2d21e620f97118a","head":{"label":"RostakaGmfun:KAA-1364","ref":"KAA-1364","sha":"baa5c841bc09bfb372d031b0e2d21e620f97118a","user":{"login":"RostakaGmfun","id":5872727,"avatar_url":"https://avatars.githubusercontent.com/u/5872727?v=3","gravatar_id":"","url":"https://api.github.com/users/RostakaGmfun","html_url":"https://github.com/RostakaGmfun","followers_url":"https://api.github.com/users/RostakaGmfun/followers","following_url":"https://api.github.com/users/RostakaGmfun/following{/other_user}","gists_url":"https://api.github.com/users/RostakaGmfun/gists{/gist_id}","starred_url":"https://api.github.com/users/RostakaGmfun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RostakaGmfun/subscriptions","organizations_url":"https://api.github.com/users/RostakaGmfun/orgs","repos_url":"https://api.github.com/users/RostakaGmfun/repos","events_url":"https://api.github.com/users/RostakaGmfun/events{/privacy}","received_events_url":"https://api.github.com/users/RostakaGmfun/received_events","type":"User","site_admin":false},"repo":{"id":55242302,"name":"kaa","full_name":"RostakaGmfun/kaa","owner":{"login":"RostakaGmfun","id":5872727,"avatar_url":"https://avatars.githubusercontent.com/u/5872727?v=3","gravatar_id":"","url":"https://api.github.com/users/RostakaGmfun","html_url":"https://github.com/RostakaGmfun","followers_url":"https://api.github.com/users/RostakaGmfun/followers","following_url":"https://api.github.com/users/RostakaGmfun/following{/other_user}","gists_url":"https://api.github.com/users/RostakaGmfun/gists{/gist_id}","starred_url":"https://api.github.com/users/RostakaGmfun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RostakaGmfun/subscriptions","organizations_url":"https://api.github.com/users/RostakaGmfun/orgs","repos_url":"https://api.github.com/users/RostakaGmfun/repos","events_url":"https://api.github.com/users/RostakaGmfun/events{/privacy}","received_events_url":"https://api.github.com/users/RostakaGmfun/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/RostakaGmfun/kaa","description":"Kaa open-source middleware platform for building, managing, and integrating connected products with the Internet of Everything.","fork":true,"url":"https://api.github.com/repos/RostakaGmfun/kaa","forks_url":"https://api.github.com/repos/RostakaGmfun/kaa/forks","keys_url":"https://api.github.com/repos/RostakaGmfun/kaa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RostakaGmfun/kaa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RostakaGmfun/kaa/teams","hooks_url":"https://api.github.com/repos/RostakaGmfun/kaa/hooks","issue_events_url":"https://api.github.com/repos/RostakaGmfun/kaa/issues/events{/number}","events_url":"https://api.github.com/repos/RostakaGmfun/kaa/events","assignees_url":"https://api.github.com/repos/RostakaGmfun/kaa/assignees{/user}","branches_url":"https://api.github.com/repos/RostakaGmfun/kaa/branches{/branch}","tags_url":"https://api.github.com/repos/RostakaGmfun/kaa/tags","blobs_url":"https://api.github.com/repos/RostakaGmfun/kaa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RostakaGmfun/kaa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RostakaGmfun/kaa/git/refs{/sha}","trees_url":"https://api.github.com/repos/RostakaGmfun/kaa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RostakaGmfun/kaa/statuses/{sha}","languages_url":"https://api.github.com/repos/RostakaGmfun/kaa/languages","stargazers_url":"https://api.github.com/repos/RostakaGmfun/kaa/stargazers","contributors_url":"https://api.github.com/repos/RostakaGmfun/kaa/contributors","subscribers_url":"https://api.github.com/repos/RostakaGmfun/kaa/subscribers","subscription_url":"https://api.github.com/repos/RostakaGmfun/kaa/subscription","commits_url":"https://api.github.com/repos/RostakaGmfun/kaa/commits{/sha}","git_commits_url":"https://api.github.com/repos/RostakaGmfun/kaa/git/commits{/sha}","comments_url":"https://api.github.com/repos/RostakaGmfun/kaa/comments{/number}","issue_comment_url":"https://api.github.com/repos/RostakaGmfun/kaa/issues/comments{/number}","contents_url":"https://api.github.com/repos/RostakaGmfun/kaa/contents/{+path}","compare_url":"https://api.github.com/repos/RostakaGmfun/kaa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RostakaGmfun/kaa/merges","archive_url":"https://api.github.com/repos/RostakaGmfun/kaa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RostakaGmfun/kaa/downloads","issues_url":"https://api.github.com/repos/RostakaGmfun/kaa/issues{/number}","pulls_url":"https://api.github.com/repos/RostakaGmfun/kaa/pulls{/number}","milestones_url":"https://api.github.com/repos/RostakaGmfun/kaa/milestones{/number}","notifications_url":"https://api.github.com/repos/RostakaGmfun/kaa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RostakaGmfun/kaa/labels{/name}","releases_url":"https://api.github.com/repos/RostakaGmfun/kaa/releases{/id}","deployments_url":"https://api.github.com/repos/RostakaGmfun/kaa/deployments","created_at":"2016-04-01T15:28:29Z","updated_at":"2016-04-01T15:28:38Z","pushed_at":"2016-08-23T10:13:33Z","git_url":"git://github.com/RostakaGmfun/kaa.git","ssh_url":"git@github.com:RostakaGmfun/kaa.git","clone_url":"https://github.com/RostakaGmfun/kaa.git","svn_url":"https://github.com/RostakaGmfun/kaa","homepage":"http://www.kaaproject.org","size":137922,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"kaaproject:develop","ref":"develop","sha":"0a86b5f7bbd66be1075291ec600d1d68c7a00ef0","user":{"login":"kaaproject","id":6984613,"avatar_url":"https://avatars.githubusercontent.com/u/6984613?v=3","gravatar_id":"","url":"https://api.github.com/users/kaaproject","html_url":"https://github.com/kaaproject","followers_url":"https://api.github.com/users/kaaproject/followers","following_url":"https://api.github.com/users/kaaproject/following{/other_user}","gists_url":"https://api.github.com/users/kaaproject/gists{/gist_id}","starred_url":"https://api.github.com/users/kaaproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaaproject/subscriptions","organizations_url":"https://api.github.com/users/kaaproject/orgs","repos_url":"https://api.github.com/users/kaaproject/repos","events_url":"https://api.github.com/users/kaaproject/events{/privacy}","received_events_url":"https://api.github.com/users/kaaproject/received_events","type":"Organization","site_admin":false},"repo":{"id":17839346,"name":"kaa","full_name":"kaaproject/kaa","owner":{"login":"kaaproject","id":6984613,"avatar_url":"https://avatars.githubusercontent.com/u/6984613?v=3","gravatar_id":"","url":"https://api.github.com/users/kaaproject","html_url":"https://github.com/kaaproject","followers_url":"https://api.github.com/users/kaaproject/followers","following_url":"https://api.github.com/users/kaaproject/following{/other_user}","gists_url":"https://api.github.com/users/kaaproject/gists{/gist_id}","starred_url":"https://api.github.com/users/kaaproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaaproject/subscriptions","organizations_url":"https://api.github.com/users/kaaproject/orgs","repos_url":"https://api.github.com/users/kaaproject/repos","events_url":"https://api.github.com/users/kaaproject/events{/privacy}","received_events_url":"https://api.github.com/users/kaaproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kaaproject/kaa","description":"Kaa open-source middleware platform for building, managing, and integrating connected products with the Internet of Everything.","fork":false,"url":"https://api.github.com/repos/kaaproject/kaa","forks_url":"https://api.github.com/repos/kaaproject/kaa/forks","keys_url":"https://api.github.com/repos/kaaproject/kaa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kaaproject/kaa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kaaproject/kaa/teams","hooks_url":"https://api.github.com/repos/kaaproject/kaa/hooks","issue_events_url":"https://api.github.com/repos/kaaproject/kaa/issues/events{/number}","events_url":"https://api.github.com/repos/kaaproject/kaa/events","assignees_url":"https://api.github.com/repos/kaaproject/kaa/assignees{/user}","branches_url":"https://api.github.com/repos/kaaproject/kaa/branches{/branch}","tags_url":"https://api.github.com/repos/kaaproject/kaa/tags","blobs_url":"https://api.github.com/repos/kaaproject/kaa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kaaproject/kaa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kaaproject/kaa/git/refs{/sha}","trees_url":"https://api.github.com/repos/kaaproject/kaa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kaaproject/kaa/statuses/{sha}","languages_url":"https://api.github.com/repos/kaaproject/kaa/languages","stargazers_url":"https://api.github.com/repos/kaaproject/kaa/stargazers","contributors_url":"https://api.github.com/repos/kaaproject/kaa/contributors","subscribers_url":"https://api.github.com/repos/kaaproject/kaa/subscribers","subscription_url":"https://api.github.com/repos/kaaproject/kaa/subscription","commits_url":"https://api.github.com/repos/kaaproject/kaa/commits{/sha}","git_commits_url":"https://api.github.com/repos/kaaproject/kaa/git/commits{/sha}","comments_url":"https://api.github.com/repos/kaaproject/kaa/comments{/number}","issue_comment_url":"https://api.github.com/repos/kaaproject/kaa/issues/comments{/number}","contents_url":"https://api.github.com/repos/kaaproject/kaa/contents/{+path}","compare_url":"https://api.github.com/repos/kaaproject/kaa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kaaproject/kaa/merges","archive_url":"https://api.github.com/repos/kaaproject/kaa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kaaproject/kaa/downloads","issues_url":"https://api.github.com/repos/kaaproject/kaa/issues{/number}","pulls_url":"https://api.github.com/repos/kaaproject/kaa/pulls{/number}","milestones_url":"https://api.github.com/repos/kaaproject/kaa/milestones{/number}","notifications_url":"https://api.github.com/repos/kaaproject/kaa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kaaproject/kaa/labels{/name}","releases_url":"https://api.github.com/repos/kaaproject/kaa/releases{/id}","deployments_url":"https://api.github.com/repos/kaaproject/kaa/deployments","created_at":"2014-03-17T18:48:31Z","updated_at":"2016-09-08T01:43:03Z","pushed_at":"2016-09-08T09:48:29Z","git_url":"git://github.com/kaaproject/kaa.git","ssh_url":"git@github.com:kaaproject/kaa.git","clone_url":"https://github.com/kaaproject/kaa.git","svn_url":"https://github.com/kaaproject/kaa","homepage":"http://www.kaaproject.org","size":152274,"stargazers_count":440,"watchers_count":440,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":157,"mirror_url":null,"open_issues_count":32,"forks":157,"open_issues":32,"watchers":440,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/1004"},"html":{"href":"https://github.com/kaaproject/kaa/pull/1004"},"issue":{"href":"https://api.github.com/repos/kaaproject/kaa/issues/1004"},"comments":{"href":"https://api.github.com/repos/kaaproject/kaa/issues/1004/comments"},"review_comments":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/1004/comments"},"review_comment":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kaaproject/kaa/pulls/1004/commits"},"statuses":{"href":"https://api.github.com/repos/kaaproject/kaa/statuses/baa5c841bc09bfb372d031b0e2d21e620f97118a"}}}}
{"actor":{"display_login":"rasendubi"}}