{"action":"created","comment":{"url":"https://api.github.com/repos/solettaproject/soletta/pulls/comments/73922117","id":73922117,"diff_hunk":"@@ -0,0 +1,470 @@\n+/*\n+ * This file is part of the Soletta (TM) Project\n+ *\n+ * Copyright (C) 2016 Intel Corporation. All rights reserved.\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+#define SOL_LOG_DOMAIN &_lwm2m_security_domain\n+\n+#include \"sol-log-internal.h\"\n+#include \"sol-util-internal.h\"\n+#include \"sol-coap.h\"\n+#include \"sol-lwm2m-security.h\"\n+#include \"sol-platform.h\"\n+#include \"sol-socket-dtls.h\"\n+#include \"sol-socket.h\"\n+#include \"sol-str-slice.h\"\n+#include \"sol-util-internal.h\"\n+#include \"sol-vector.h\"\n+\n+SOL_LOG_INTERNAL_DECLARE(_lwm2m_security_domain, \"lwm2m-security\");\n+\n+#ifdef DTLS\n+\n+struct sol_socket *sol_coap_server_get_socket(const struct sol_coap_server *server);\n+\n+static ssize_t\n+get_psk_from_server_or_bs_server(const void *data, struct sol_str_slice id,\n+    char *psk, size_t psk_len)\n+{\n+    const struct sol_lwm2m_security *ctx = data;\n+    struct sol_lwm2m_server *lwm2m_server;\n+    struct sol_lwm2m_bootstrap_server *lwm2m_bs_server;\n+    struct sol_vector *known_psks;\n+    struct sol_lwm2m_security_psk *stored_psk;\n+    uint16_t i;\n+\n+    SOL_DBG(\"Looking for PSK with ID=%.*s\", SOL_STR_SLICE_PRINT(id));\n+\n+    //If the caller expects a PSK_LEN less than 16 bytes\n+    if (psk_len < SOL_DTLS_PSK_KEY_LEN)\n+        return -ENOBUFS;\n+\n+    if (ctx->type == LWM2M_SERVER) {\n+        SOL_DBG(\"ctx->type = LWM2M_SERVER\");\n+        lwm2m_server = ctx->entity;\n+        known_psks = lwm2m_server->known_psks;\n+    } else {\n+        SOL_DBG(\"ctx->type = LWM2M_BOOTSTRAP_SERVER\");\n+        lwm2m_bs_server = ctx->entity;\n+        known_psks = lwm2m_bs_server->known_psks;\n+    }\n+\n+    SOL_VECTOR_FOREACH_IDX (known_psks, stored_psk, i) {\n+        if (sol_str_slice_eq(sol_str_slice_from_blob(stored_psk->id), id)) {\n+            if (stored_psk->key->size != SOL_DTLS_PSK_KEY_LEN) {\n+                SOL_WRN(\"The PSK '%.*s' is %zu-bytes long; expecting a %d-bytes long PSK\",\n+                    SOL_STR_SLICE_PRINT(sol_str_slice_from_blob(stored_psk->key)),\n+                    stored_psk->key->size, SOL_DTLS_PSK_KEY_LEN);\n+                return -EINVAL;\n+            }\n+\n+            memcpy(psk, stored_psk->key->mem, stored_psk->key->size);\n+            return (ssize_t)SOL_DTLS_PSK_KEY_LEN;\n+        }\n+    }\n+\n+    return -ENOENT;\n+}\n+\n+static ssize_t\n+get_psk_from_client(const void *data, struct sol_str_slice id,\n+    char *psk, size_t psk_len)\n+{\n+    const struct sol_lwm2m_security *ctx = data;\n+    struct sol_lwm2m_client *lwm2m_client = ctx->entity;\n+    struct obj_ctx *obj_ctx;\n+    struct obj_instance *instance;\n+    struct sol_lwm2m_resource res[3] = { };\n+    uint16_t i;\n+    int r;\n+\n+    SOL_DBG(\"Looking for PSK with ID=%.*s\", SOL_STR_SLICE_PRINT(id));\n+\n+    //If the caller expects a PSK_LEN less than 16 bytes\n+    if (psk_len < SOL_DTLS_PSK_KEY_LEN)\n+        return -ENOBUFS;\n+\n+    obj_ctx = find_object_ctx_by_id(lwm2m_client, SECURITY_OBJECT_ID);\n+    if (!obj_ctx) {\n+        SOL_WRN(\"LWM2M Security object not provided!\");\n+        return -ENOENT;\n+    }\n+\n+    if (!obj_ctx->instances.len) {\n+        SOL_WRN(\"There are no Security Server instances\");\n+        return -ENOENT;\n+    }\n+\n+    SOL_VECTOR_FOREACH_IDX (&obj_ctx->instances, instance, i) {\n+        r = read_resources(lwm2m_client, obj_ctx, instance, res, 3,\n+            SECURITY_SECURITY_MODE,\n+            SECURITY_PUBLIC_KEY_OR_IDENTITY,\n+            SECURITY_SECRET_KEY);\n+        SOL_INT_CHECK_GOTO(r, < 0, err_clear);\n+\n+        //If -ENOENT when reading SECURITY_SECRET_KEY or","path":"src/lib/comms/sol-lwm2m-security.c","position":118,"original_position":118,"commit_id":"91ab3f6f50f86073aca9eb0afdbb37b709a14e79","original_commit_id":"7d8eabe5b52fae7aafa0ea00bccf3790969faf95","user":{"login":"cabelitos","id":984610,"avatar_url":"https://avatars.githubusercontent.com/u/984610?v=3","gravatar_id":"","url":"https://api.github.com/users/cabelitos","html_url":"https://github.com/cabelitos","followers_url":"https://api.github.com/users/cabelitos/followers","following_url":"https://api.github.com/users/cabelitos/following{/other_user}","gists_url":"https://api.github.com/users/cabelitos/gists{/gist_id}","starred_url":"https://api.github.com/users/cabelitos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cabelitos/subscriptions","organizations_url":"https://api.github.com/users/cabelitos/orgs","repos_url":"https://api.github.com/users/cabelitos/repos","events_url":"https://api.github.com/users/cabelitos/events{/privacy}","received_events_url":"https://api.github.com/users/cabelitos/received_events","type":"User","site_admin":false},"body":"watch it out, because if `-ENOENT` is returned the `SOL_INT_CHECK_GOTO` above will jump to `err_clear`","created_at":"2016-08-08T17:56:46Z","updated_at":"2016-08-08T17:56:46Z","html_url":"https://github.com/solettaproject/soletta/pull/2272#discussion_r73922117","pull_request_url":"https://api.github.com/repos/solettaproject/soletta/pulls/2272","_links":{"self":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/comments/73922117"},"html":{"href":"https://github.com/solettaproject/soletta/pull/2272#discussion_r73922117"},"pull_request":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/2272"}}},"pull_request":{"url":"https://api.github.com/repos/solettaproject/soletta/pulls/2272","id":79977516,"html_url":"https://github.com/solettaproject/soletta/pull/2272","diff_url":"https://github.com/solettaproject/soletta/pull/2272.diff","patch_url":"https://github.com/solettaproject/soletta/pull/2272.patch","issue_url":"https://api.github.com/repos/solettaproject/soletta/issues/2272","number":2272,"state":"open","locked":false,"title":"LWM2M: Support for DTLS with Pre-Shared Key security mode","user":{"login":"bsmelo","id":15204241,"avatar_url":"https://avatars.githubusercontent.com/u/15204241?v=3","gravatar_id":"","url":"https://api.github.com/users/bsmelo","html_url":"https://github.com/bsmelo","followers_url":"https://api.github.com/users/bsmelo/followers","following_url":"https://api.github.com/users/bsmelo/following{/other_user}","gists_url":"https://api.github.com/users/bsmelo/gists{/gist_id}","starred_url":"https://api.github.com/users/bsmelo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsmelo/subscriptions","organizations_url":"https://api.github.com/users/bsmelo/orgs","repos_url":"https://api.github.com/users/bsmelo/repos","events_url":"https://api.github.com/users/bsmelo/events{/privacy}","received_events_url":"https://api.github.com/users/bsmelo/received_events","type":"User","site_admin":false},"body":"This patch adds support for CoAP Data Encryption using DTLS with Pre-Shared Key mode (using `TLS_PSK_WITH_AES_128_CCM_8` Cipher Suite).\r\n\r\nIt includes modifications on the LWM2M Samples to demonstrate the support as well.\r\n\r\nThis patch depends on #2271.\r\n\r\nSigned-off-by: Bruno Melo bsilva.melo@gmail.com","created_at":"2016-08-03T20:56:20Z","updated_at":"2016-08-08T17:56:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a3b425e79bb8eb6f808e8c45ce92cbd7688f4f27","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/solettaproject/soletta/pulls/2272/commits","review_comments_url":"https://api.github.com/repos/solettaproject/soletta/pulls/2272/comments","review_comment_url":"https://api.github.com/repos/solettaproject/soletta/pulls/comments{/number}","comments_url":"https://api.github.com/repos/solettaproject/soletta/issues/2272/comments","statuses_url":"https://api.github.com/repos/solettaproject/soletta/statuses/91ab3f6f50f86073aca9eb0afdbb37b709a14e79","head":{"label":"bsmelo:lwm2m-dtls_psk-v1","ref":"lwm2m-dtls_psk-v1","sha":"91ab3f6f50f86073aca9eb0afdbb37b709a14e79","user":{"login":"bsmelo","id":15204241,"avatar_url":"https://avatars.githubusercontent.com/u/15204241?v=3","gravatar_id":"","url":"https://api.github.com/users/bsmelo","html_url":"https://github.com/bsmelo","followers_url":"https://api.github.com/users/bsmelo/followers","following_url":"https://api.github.com/users/bsmelo/following{/other_user}","gists_url":"https://api.github.com/users/bsmelo/gists{/gist_id}","starred_url":"https://api.github.com/users/bsmelo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsmelo/subscriptions","organizations_url":"https://api.github.com/users/bsmelo/orgs","repos_url":"https://api.github.com/users/bsmelo/repos","events_url":"https://api.github.com/users/bsmelo/events{/privacy}","received_events_url":"https://api.github.com/users/bsmelo/received_events","type":"User","site_admin":false},"repo":{"id":54440906,"name":"soletta","full_name":"bsmelo/soletta","owner":{"login":"bsmelo","id":15204241,"avatar_url":"https://avatars.githubusercontent.com/u/15204241?v=3","gravatar_id":"","url":"https://api.github.com/users/bsmelo","html_url":"https://github.com/bsmelo","followers_url":"https://api.github.com/users/bsmelo/followers","following_url":"https://api.github.com/users/bsmelo/following{/other_user}","gists_url":"https://api.github.com/users/bsmelo/gists{/gist_id}","starred_url":"https://api.github.com/users/bsmelo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsmelo/subscriptions","organizations_url":"https://api.github.com/users/bsmelo/orgs","repos_url":"https://api.github.com/users/bsmelo/repos","events_url":"https://api.github.com/users/bsmelo/events{/privacy}","received_events_url":"https://api.github.com/users/bsmelo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bsmelo/soletta","description":"Soletta Project is a framework for making IoT devices.  With Soletta Project's libraries developers can easily write software for devices that control actuators/sensors and communicate using standard technologies. It enables adding smartness even on the smallest edge devices.  ","fork":true,"url":"https://api.github.com/repos/bsmelo/soletta","forks_url":"https://api.github.com/repos/bsmelo/soletta/forks","keys_url":"https://api.github.com/repos/bsmelo/soletta/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bsmelo/soletta/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bsmelo/soletta/teams","hooks_url":"https://api.github.com/repos/bsmelo/soletta/hooks","issue_events_url":"https://api.github.com/repos/bsmelo/soletta/issues/events{/number}","events_url":"https://api.github.com/repos/bsmelo/soletta/events","assignees_url":"https://api.github.com/repos/bsmelo/soletta/assignees{/user}","branches_url":"https://api.github.com/repos/bsmelo/soletta/branches{/branch}","tags_url":"https://api.github.com/repos/bsmelo/soletta/tags","blobs_url":"https://api.github.com/repos/bsmelo/soletta/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bsmelo/soletta/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bsmelo/soletta/git/refs{/sha}","trees_url":"https://api.github.com/repos/bsmelo/soletta/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bsmelo/soletta/statuses/{sha}","languages_url":"https://api.github.com/repos/bsmelo/soletta/languages","stargazers_url":"https://api.github.com/repos/bsmelo/soletta/stargazers","contributors_url":"https://api.github.com/repos/bsmelo/soletta/contributors","subscribers_url":"https://api.github.com/repos/bsmelo/soletta/subscribers","subscription_url":"https://api.github.com/repos/bsmelo/soletta/subscription","commits_url":"https://api.github.com/repos/bsmelo/soletta/commits{/sha}","git_commits_url":"https://api.github.com/repos/bsmelo/soletta/git/commits{/sha}","comments_url":"https://api.github.com/repos/bsmelo/soletta/comments{/number}","issue_comment_url":"https://api.github.com/repos/bsmelo/soletta/issues/comments{/number}","contents_url":"https://api.github.com/repos/bsmelo/soletta/contents/{+path}","compare_url":"https://api.github.com/repos/bsmelo/soletta/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bsmelo/soletta/merges","archive_url":"https://api.github.com/repos/bsmelo/soletta/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bsmelo/soletta/downloads","issues_url":"https://api.github.com/repos/bsmelo/soletta/issues{/number}","pulls_url":"https://api.github.com/repos/bsmelo/soletta/pulls{/number}","milestones_url":"https://api.github.com/repos/bsmelo/soletta/milestones{/number}","notifications_url":"https://api.github.com/repos/bsmelo/soletta/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bsmelo/soletta/labels{/name}","releases_url":"https://api.github.com/repos/bsmelo/soletta/releases{/id}","deployments_url":"https://api.github.com/repos/bsmelo/soletta/deployments","created_at":"2016-03-22T03:04:07Z","updated_at":"2016-03-22T03:04:11Z","pushed_at":"2016-08-07T17:47:51Z","git_url":"git://github.com/bsmelo/soletta.git","ssh_url":"git@github.com:bsmelo/soletta.git","clone_url":"https://github.com/bsmelo/soletta.git","svn_url":"https://github.com/bsmelo/soletta","homepage":"http://solettaproject.org","size":21979,"stargazers_count":0,"watchers_count":0,"language":"C","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":"solettaproject:master","ref":"master","sha":"2bbca90f033e6321451a40505199dd2bb602cd40","user":{"login":"solettaproject","id":12736897,"avatar_url":"https://avatars.githubusercontent.com/u/12736897?v=3","gravatar_id":"","url":"https://api.github.com/users/solettaproject","html_url":"https://github.com/solettaproject","followers_url":"https://api.github.com/users/solettaproject/followers","following_url":"https://api.github.com/users/solettaproject/following{/other_user}","gists_url":"https://api.github.com/users/solettaproject/gists{/gist_id}","starred_url":"https://api.github.com/users/solettaproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solettaproject/subscriptions","organizations_url":"https://api.github.com/users/solettaproject/orgs","repos_url":"https://api.github.com/users/solettaproject/repos","events_url":"https://api.github.com/users/solettaproject/events{/privacy}","received_events_url":"https://api.github.com/users/solettaproject/received_events","type":"Organization","site_admin":false},"repo":{"id":37087063,"name":"soletta","full_name":"solettaproject/soletta","owner":{"login":"solettaproject","id":12736897,"avatar_url":"https://avatars.githubusercontent.com/u/12736897?v=3","gravatar_id":"","url":"https://api.github.com/users/solettaproject","html_url":"https://github.com/solettaproject","followers_url":"https://api.github.com/users/solettaproject/followers","following_url":"https://api.github.com/users/solettaproject/following{/other_user}","gists_url":"https://api.github.com/users/solettaproject/gists{/gist_id}","starred_url":"https://api.github.com/users/solettaproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solettaproject/subscriptions","organizations_url":"https://api.github.com/users/solettaproject/orgs","repos_url":"https://api.github.com/users/solettaproject/repos","events_url":"https://api.github.com/users/solettaproject/events{/privacy}","received_events_url":"https://api.github.com/users/solettaproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/solettaproject/soletta","description":"Soletta Project is a framework for making IoT devices.  With Soletta Project's libraries developers can easily write software for devices that control actuators/sensors and communicate using standard technologies. It enables adding smartness even on the smallest edge devices.  ","fork":false,"url":"https://api.github.com/repos/solettaproject/soletta","forks_url":"https://api.github.com/repos/solettaproject/soletta/forks","keys_url":"https://api.github.com/repos/solettaproject/soletta/keys{/key_id}","collaborators_url":"https://api.github.com/repos/solettaproject/soletta/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/solettaproject/soletta/teams","hooks_url":"https://api.github.com/repos/solettaproject/soletta/hooks","issue_events_url":"https://api.github.com/repos/solettaproject/soletta/issues/events{/number}","events_url":"https://api.github.com/repos/solettaproject/soletta/events","assignees_url":"https://api.github.com/repos/solettaproject/soletta/assignees{/user}","branches_url":"https://api.github.com/repos/solettaproject/soletta/branches{/branch}","tags_url":"https://api.github.com/repos/solettaproject/soletta/tags","blobs_url":"https://api.github.com/repos/solettaproject/soletta/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/solettaproject/soletta/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/solettaproject/soletta/git/refs{/sha}","trees_url":"https://api.github.com/repos/solettaproject/soletta/git/trees{/sha}","statuses_url":"https://api.github.com/repos/solettaproject/soletta/statuses/{sha}","languages_url":"https://api.github.com/repos/solettaproject/soletta/languages","stargazers_url":"https://api.github.com/repos/solettaproject/soletta/stargazers","contributors_url":"https://api.github.com/repos/solettaproject/soletta/contributors","subscribers_url":"https://api.github.com/repos/solettaproject/soletta/subscribers","subscription_url":"https://api.github.com/repos/solettaproject/soletta/subscription","commits_url":"https://api.github.com/repos/solettaproject/soletta/commits{/sha}","git_commits_url":"https://api.github.com/repos/solettaproject/soletta/git/commits{/sha}","comments_url":"https://api.github.com/repos/solettaproject/soletta/comments{/number}","issue_comment_url":"https://api.github.com/repos/solettaproject/soletta/issues/comments{/number}","contents_url":"https://api.github.com/repos/solettaproject/soletta/contents/{+path}","compare_url":"https://api.github.com/repos/solettaproject/soletta/compare/{base}...{head}","merges_url":"https://api.github.com/repos/solettaproject/soletta/merges","archive_url":"https://api.github.com/repos/solettaproject/soletta/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/solettaproject/soletta/downloads","issues_url":"https://api.github.com/repos/solettaproject/soletta/issues{/number}","pulls_url":"https://api.github.com/repos/solettaproject/soletta/pulls{/number}","milestones_url":"https://api.github.com/repos/solettaproject/soletta/milestones{/number}","notifications_url":"https://api.github.com/repos/solettaproject/soletta/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/solettaproject/soletta/labels{/name}","releases_url":"https://api.github.com/repos/solettaproject/soletta/releases{/id}","deployments_url":"https://api.github.com/repos/solettaproject/soletta/deployments","created_at":"2015-06-08T19:13:18Z","updated_at":"2016-08-03T06:37:55Z","pushed_at":"2016-08-08T07:27:25Z","git_url":"git://github.com/solettaproject/soletta.git","ssh_url":"git@github.com:solettaproject/soletta.git","clone_url":"https://github.com/solettaproject/soletta.git","svn_url":"https://github.com/solettaproject/soletta","homepage":"http://solettaproject.org","size":31063,"stargazers_count":118,"watchers_count":118,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":92,"mirror_url":null,"open_issues_count":111,"forks":92,"open_issues":111,"watchers":118,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/2272"},"html":{"href":"https://github.com/solettaproject/soletta/pull/2272"},"issue":{"href":"https://api.github.com/repos/solettaproject/soletta/issues/2272"},"comments":{"href":"https://api.github.com/repos/solettaproject/soletta/issues/2272/comments"},"review_comments":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/2272/comments"},"review_comment":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/solettaproject/soletta/pulls/2272/commits"},"statuses":{"href":"https://api.github.com/repos/solettaproject/soletta/statuses/91ab3f6f50f86073aca9eb0afdbb37b709a14e79"}}}}
{"actor":{"display_login":"cabelitos"}}