{"action":"created","comment":{"url":"https://api.github.com/repos/diwanc/liota/pulls/comments/72946783","id":72946783,"diff_hunk":"@@ -48,25 +49,78 @@ def on_message(self, client, userdata, msg):\n     def on_publish(self, client, userdata, mid):\n         log.debug(\"mid: {0}\".format(str(mid)))\n \n-    def __init__(self, url, port):\n+    def on_connect(self, client, userdata, flags, rc):\n+        log.debug(\"Connected with result code \" + str(rc))\n+\n+    def __init__(self, gw_identity, TLSConf, url, port, tls_support=True):\n+        self.gw_identity = gw_identity\n+        self.TLSConf = TLSConf\n         self.url = url\n         self.port = port\n         self.client = paho.Client()\n         self.client.on_message = self.on_message\n         self.client.on_publish = self.on_publish\n         self.client.on_subscribe = self.on_subscribe\n+        self.tls_support = tls_support\n         self.connect_soc()\n         TransportLayer.__init__(self)\n \n     def connect_soc(self):\n-        self.client.connect_soc(host=self.url, port=self.port, keepalive=60)\n-        log.info(\"Connection Successful\")\n+        # Set up TLS support\n+        if self.tls_support:\n+\n+            # Validate CA certificate path\n+            if self.gw_identity.cacert:\n+                if not(os.path.exists(self.gw_identity.cacert)):\n+                    raise ValueError(\"Error : Wrong CA certificate path.\")\n+            else:\n+                raise ValueError(\"Error : CA certificate path is missing\")\n+\n+            # Validate client certificate path\n+            if self.gw_identity.certfile:\n+                if os.path.exists(self.gw_identity.certfile):\n+                    client_cert_available = True\n+                else:\n+                    raise ValueError(\"Error : Wrong client certificate path.\")\n+            else:\n+                client_cert_available = False\n+\n+            # Validate client key file path\n+            if self.gw_identity.keyfile:\n+                if os.path.exists(self.gw_identity.keyfile):\n+                    client_key_available = True\n+                else:\n+                    raise ValueError(\"Error : Wrong client key path.\")\n+            else:\n+                client_key_available = False\n+\n+            # Multiple conditions for certificate validations\n+                # 1. Both Client certificate and key file should be present\n+                # 2. If both are not there proceed without client certificate and key\n+                # 3. If one of them is not there throw an error to notify one of them is missing\n+            if client_cert_available != client_key_available:","path":"liota/transports/mqtt.py","position":67,"original_position":67,"commit_id":"49a45ddb34ac508c9507b816ce1be074185ba96f","original_commit_id":"49a45ddb34ac508c9507b816ce1be074185ba96f","user":{"login":"diwanc","id":4242007,"avatar_url":"https://avatars.githubusercontent.com/u/4242007?v=3","gravatar_id":"","url":"https://api.github.com/users/diwanc","html_url":"https://github.com/diwanc","followers_url":"https://api.github.com/users/diwanc/followers","following_url":"https://api.github.com/users/diwanc/following{/other_user}","gists_url":"https://api.github.com/users/diwanc/gists{/gist_id}","starred_url":"https://api.github.com/users/diwanc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diwanc/subscriptions","organizations_url":"https://api.github.com/users/diwanc/orgs","repos_url":"https://api.github.com/users/diwanc/repos","events_url":"https://api.github.com/users/diwanc/events{/privacy}","received_events_url":"https://api.github.com/users/diwanc/received_events","type":"User","site_admin":false},"body":"1) Boolean operator \"not\" preferable over \"!=\"\r\n2) Also, think of splitting the first case into two; a) \"Client cert file found. But key not found.\" b) \"Client key file found. But cert file not found.\"","created_at":"2016-08-01T09:19:33Z","updated_at":"2016-08-01T09:19:33Z","html_url":"https://github.com/diwanc/liota/pull/1#discussion_r72946783","pull_request_url":"https://api.github.com/repos/diwanc/liota/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/diwanc/liota/pulls/comments/72946783"},"html":{"href":"https://github.com/diwanc/liota/pull/1#discussion_r72946783"},"pull_request":{"href":"https://api.github.com/repos/diwanc/liota/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/diwanc/liota/pulls/1","id":79457792,"html_url":"https://github.com/diwanc/liota/pull/1","diff_url":"https://github.com/diwanc/liota/pull/1.diff","patch_url":"https://github.com/diwanc/liota/pull/1.patch","issue_url":"https://api.github.com/repos/diwanc/liota/issues/1","number":1,"state":"open","locked":false,"title":"TLS Feature","user":{"login":"ashish-vmware","id":20726257,"avatar_url":"https://avatars.githubusercontent.com/u/20726257?v=3","gravatar_id":"","url":"https://api.github.com/users/ashish-vmware","html_url":"https://github.com/ashish-vmware","followers_url":"https://api.github.com/users/ashish-vmware/followers","following_url":"https://api.github.com/users/ashish-vmware/following{/other_user}","gists_url":"https://api.github.com/users/ashish-vmware/gists{/gist_id}","starred_url":"https://api.github.com/users/ashish-vmware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashish-vmware/subscriptions","organizations_url":"https://api.github.com/users/ashish-vmware/orgs","repos_url":"https://api.github.com/users/ashish-vmware/repos","events_url":"https://api.github.com/users/ashish-vmware/events{/privacy}","received_events_url":"https://api.github.com/users/ashish-vmware/received_events","type":"User","site_admin":false},"body":"- Adding TLS support and certificate validations in current MQTT implementation\r\n- Adding identity layer to encapsulate gateway identity and TLS configurations\r\n","created_at":"2016-07-30T13:48:29Z","updated_at":"2016-08-01T09:19:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e3016beeb2a41be61b29cab464e3fad76c826e69","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/diwanc/liota/pulls/1/commits","review_comments_url":"https://api.github.com/repos/diwanc/liota/pulls/1/comments","review_comment_url":"https://api.github.com/repos/diwanc/liota/pulls/comments{/number}","comments_url":"https://api.github.com/repos/diwanc/liota/issues/1/comments","statuses_url":"https://api.github.com/repos/diwanc/liota/statuses/49a45ddb34ac508c9507b816ce1be074185ba96f","head":{"label":"ashish-vmware:TLS_feature","ref":"TLS_feature","sha":"49a45ddb34ac508c9507b816ce1be074185ba96f","user":{"login":"ashish-vmware","id":20726257,"avatar_url":"https://avatars.githubusercontent.com/u/20726257?v=3","gravatar_id":"","url":"https://api.github.com/users/ashish-vmware","html_url":"https://github.com/ashish-vmware","followers_url":"https://api.github.com/users/ashish-vmware/followers","following_url":"https://api.github.com/users/ashish-vmware/following{/other_user}","gists_url":"https://api.github.com/users/ashish-vmware/gists{/gist_id}","starred_url":"https://api.github.com/users/ashish-vmware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashish-vmware/subscriptions","organizations_url":"https://api.github.com/users/ashish-vmware/orgs","repos_url":"https://api.github.com/users/ashish-vmware/repos","events_url":"https://api.github.com/users/ashish-vmware/events{/privacy}","received_events_url":"https://api.github.com/users/ashish-vmware/received_events","type":"User","site_admin":false},"repo":{"id":64544861,"name":"liota","full_name":"ashish-vmware/liota","owner":{"login":"ashish-vmware","id":20726257,"avatar_url":"https://avatars.githubusercontent.com/u/20726257?v=3","gravatar_id":"","url":"https://api.github.com/users/ashish-vmware","html_url":"https://github.com/ashish-vmware","followers_url":"https://api.github.com/users/ashish-vmware/followers","following_url":"https://api.github.com/users/ashish-vmware/following{/other_user}","gists_url":"https://api.github.com/users/ashish-vmware/gists{/gist_id}","starred_url":"https://api.github.com/users/ashish-vmware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashish-vmware/subscriptions","organizations_url":"https://api.github.com/users/ashish-vmware/orgs","repos_url":"https://api.github.com/users/ashish-vmware/repos","events_url":"https://api.github.com/users/ashish-vmware/events{/privacy}","received_events_url":"https://api.github.com/users/ashish-vmware/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ashish-vmware/liota","description":null,"fork":true,"url":"https://api.github.com/repos/ashish-vmware/liota","forks_url":"https://api.github.com/repos/ashish-vmware/liota/forks","keys_url":"https://api.github.com/repos/ashish-vmware/liota/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ashish-vmware/liota/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ashish-vmware/liota/teams","hooks_url":"https://api.github.com/repos/ashish-vmware/liota/hooks","issue_events_url":"https://api.github.com/repos/ashish-vmware/liota/issues/events{/number}","events_url":"https://api.github.com/repos/ashish-vmware/liota/events","assignees_url":"https://api.github.com/repos/ashish-vmware/liota/assignees{/user}","branches_url":"https://api.github.com/repos/ashish-vmware/liota/branches{/branch}","tags_url":"https://api.github.com/repos/ashish-vmware/liota/tags","blobs_url":"https://api.github.com/repos/ashish-vmware/liota/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ashish-vmware/liota/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ashish-vmware/liota/git/refs{/sha}","trees_url":"https://api.github.com/repos/ashish-vmware/liota/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ashish-vmware/liota/statuses/{sha}","languages_url":"https://api.github.com/repos/ashish-vmware/liota/languages","stargazers_url":"https://api.github.com/repos/ashish-vmware/liota/stargazers","contributors_url":"https://api.github.com/repos/ashish-vmware/liota/contributors","subscribers_url":"https://api.github.com/repos/ashish-vmware/liota/subscribers","subscription_url":"https://api.github.com/repos/ashish-vmware/liota/subscription","commits_url":"https://api.github.com/repos/ashish-vmware/liota/commits{/sha}","git_commits_url":"https://api.github.com/repos/ashish-vmware/liota/git/commits{/sha}","comments_url":"https://api.github.com/repos/ashish-vmware/liota/comments{/number}","issue_comment_url":"https://api.github.com/repos/ashish-vmware/liota/issues/comments{/number}","contents_url":"https://api.github.com/repos/ashish-vmware/liota/contents/{+path}","compare_url":"https://api.github.com/repos/ashish-vmware/liota/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ashish-vmware/liota/merges","archive_url":"https://api.github.com/repos/ashish-vmware/liota/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ashish-vmware/liota/downloads","issues_url":"https://api.github.com/repos/ashish-vmware/liota/issues{/number}","pulls_url":"https://api.github.com/repos/ashish-vmware/liota/pulls{/number}","milestones_url":"https://api.github.com/repos/ashish-vmware/liota/milestones{/number}","notifications_url":"https://api.github.com/repos/ashish-vmware/liota/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ashish-vmware/liota/labels{/name}","releases_url":"https://api.github.com/repos/ashish-vmware/liota/releases{/id}","deployments_url":"https://api.github.com/repos/ashish-vmware/liota/deployments","created_at":"2016-07-30T13:14:07Z","updated_at":"2016-07-30T13:14:08Z","pushed_at":"2016-07-30T13:24:54Z","git_url":"git://github.com/ashish-vmware/liota.git","ssh_url":"git@github.com:ashish-vmware/liota.git","clone_url":"https://github.com/ashish-vmware/liota.git","svn_url":"https://github.com/ashish-vmware/liota","homepage":null,"size":125,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"diwanc:master","ref":"master","sha":"044051cd84655835a905e4fcbb8d4c38760c6b1e","user":{"login":"diwanc","id":4242007,"avatar_url":"https://avatars.githubusercontent.com/u/4242007?v=3","gravatar_id":"","url":"https://api.github.com/users/diwanc","html_url":"https://github.com/diwanc","followers_url":"https://api.github.com/users/diwanc/followers","following_url":"https://api.github.com/users/diwanc/following{/other_user}","gists_url":"https://api.github.com/users/diwanc/gists{/gist_id}","starred_url":"https://api.github.com/users/diwanc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diwanc/subscriptions","organizations_url":"https://api.github.com/users/diwanc/orgs","repos_url":"https://api.github.com/users/diwanc/repos","events_url":"https://api.github.com/users/diwanc/events{/privacy}","received_events_url":"https://api.github.com/users/diwanc/received_events","type":"User","site_admin":false},"repo":{"id":64391850,"name":"liota","full_name":"diwanc/liota","owner":{"login":"diwanc","id":4242007,"avatar_url":"https://avatars.githubusercontent.com/u/4242007?v=3","gravatar_id":"","url":"https://api.github.com/users/diwanc","html_url":"https://github.com/diwanc","followers_url":"https://api.github.com/users/diwanc/followers","following_url":"https://api.github.com/users/diwanc/following{/other_user}","gists_url":"https://api.github.com/users/diwanc/gists{/gist_id}","starred_url":"https://api.github.com/users/diwanc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diwanc/subscriptions","organizations_url":"https://api.github.com/users/diwanc/orgs","repos_url":"https://api.github.com/users/diwanc/repos","events_url":"https://api.github.com/users/diwanc/events{/privacy}","received_events_url":"https://api.github.com/users/diwanc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/diwanc/liota","description":null,"fork":true,"url":"https://api.github.com/repos/diwanc/liota","forks_url":"https://api.github.com/repos/diwanc/liota/forks","keys_url":"https://api.github.com/repos/diwanc/liota/keys{/key_id}","collaborators_url":"https://api.github.com/repos/diwanc/liota/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/diwanc/liota/teams","hooks_url":"https://api.github.com/repos/diwanc/liota/hooks","issue_events_url":"https://api.github.com/repos/diwanc/liota/issues/events{/number}","events_url":"https://api.github.com/repos/diwanc/liota/events","assignees_url":"https://api.github.com/repos/diwanc/liota/assignees{/user}","branches_url":"https://api.github.com/repos/diwanc/liota/branches{/branch}","tags_url":"https://api.github.com/repos/diwanc/liota/tags","blobs_url":"https://api.github.com/repos/diwanc/liota/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/diwanc/liota/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/diwanc/liota/git/refs{/sha}","trees_url":"https://api.github.com/repos/diwanc/liota/git/trees{/sha}","statuses_url":"https://api.github.com/repos/diwanc/liota/statuses/{sha}","languages_url":"https://api.github.com/repos/diwanc/liota/languages","stargazers_url":"https://api.github.com/repos/diwanc/liota/stargazers","contributors_url":"https://api.github.com/repos/diwanc/liota/contributors","subscribers_url":"https://api.github.com/repos/diwanc/liota/subscribers","subscription_url":"https://api.github.com/repos/diwanc/liota/subscription","commits_url":"https://api.github.com/repos/diwanc/liota/commits{/sha}","git_commits_url":"https://api.github.com/repos/diwanc/liota/git/commits{/sha}","comments_url":"https://api.github.com/repos/diwanc/liota/comments{/number}","issue_comment_url":"https://api.github.com/repos/diwanc/liota/issues/comments{/number}","contents_url":"https://api.github.com/repos/diwanc/liota/contents/{+path}","compare_url":"https://api.github.com/repos/diwanc/liota/compare/{base}...{head}","merges_url":"https://api.github.com/repos/diwanc/liota/merges","archive_url":"https://api.github.com/repos/diwanc/liota/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/diwanc/liota/downloads","issues_url":"https://api.github.com/repos/diwanc/liota/issues{/number}","pulls_url":"https://api.github.com/repos/diwanc/liota/pulls{/number}","milestones_url":"https://api.github.com/repos/diwanc/liota/milestones{/number}","notifications_url":"https://api.github.com/repos/diwanc/liota/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/diwanc/liota/labels{/name}","releases_url":"https://api.github.com/repos/diwanc/liota/releases{/id}","deployments_url":"https://api.github.com/repos/diwanc/liota/deployments","created_at":"2016-07-28T11:58:52Z","updated_at":"2016-07-28T11:58:53Z","pushed_at":"2016-07-30T13:48:29Z","git_url":"git://github.com/diwanc/liota.git","ssh_url":"git@github.com:diwanc/liota.git","clone_url":"https://github.com/diwanc/liota.git","svn_url":"https://github.com/diwanc/liota","homepage":null,"size":151,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/diwanc/liota/pulls/1"},"html":{"href":"https://github.com/diwanc/liota/pull/1"},"issue":{"href":"https://api.github.com/repos/diwanc/liota/issues/1"},"comments":{"href":"https://api.github.com/repos/diwanc/liota/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/diwanc/liota/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/diwanc/liota/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/diwanc/liota/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/diwanc/liota/statuses/49a45ddb34ac508c9507b816ce1be074185ba96f"}}}}
{"actor":{"display_login":"diwanc"}}