{"action":"created","issue":{"url":"https://api.github.com/repos/d11wtq/dockerpty-restored-2/issues/65","labels_url":"https://api.github.com/repos/d11wtq/dockerpty-restored-2/issues/65/labels{/name}","comments_url":"https://api.github.com/repos/d11wtq/dockerpty-restored-2/issues/65/comments","events_url":"https://api.github.com/repos/d11wtq/dockerpty-restored-2/issues/65/events","html_url":"https://github.com/d11wtq/dockerpty-restored-2/issues/65","id":107835671,"number":65,"title":"Attaching over TLS produces raw output","user":{"login":"d11wtq","id":37948,"avatar_url":"https://avatars.githubusercontent.com/u/37948?v=3","gravatar_id":"","url":"https://api.github.com/users/d11wtq","html_url":"https://github.com/d11wtq","followers_url":"https://api.github.com/users/d11wtq/followers","following_url":"https://api.github.com/users/d11wtq/following{/other_user}","gists_url":"https://api.github.com/users/d11wtq/gists{/gist_id}","starred_url":"https://api.github.com/users/d11wtq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/d11wtq/subscriptions","organizations_url":"https://api.github.com/users/d11wtq/orgs","repos_url":"https://api.github.com/users/d11wtq/repos","events_url":"https://api.github.com/users/d11wtq/events{/privacy}","received_events_url":"https://api.github.com/users/d11wtq/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-23T01:45:31Z","updated_at":"2015-09-23T01:45:40Z","closed_at":"2015-09-23T01:45:34Z","body":"#18 Issue by __aanand__, created on: 2014-10-15T16:57:44Z\n\nWhen I pass a docker-py client into dockerpty that's communicating over TLS, I get junk in my terminal when I try to stream output from a container. My guess is that it's raw (un-decrypted) socket output, and that anything I write is similarly going over the connection unencrypted (and thus treated as junk data on the other end).\r\n\r\nI believe the problem is with `Stream`'s `read()` and `write()` methods, which use `os.read()` and `os.write()` on the socket's `fileno`. This works fine for plain HTTP, but appear to bypass the TLS encoding/decoding when used on an `ssl.SSLSocket`.\r\n\r\nI've gotten as far as fixing *output* in a hacky way by special-casing `SSLSocket`:\r\n\r\n```python\r\ndef read(self, n=4096):\r\n    \"\"\"\r\n    Return `n` bytes of data from the Stream, or None at end of stream.\r\n    \"\"\"\r\n\r\n    try:\r\n        from ssl import SSLSocket\r\n        if type(self.fd) is SSLSocket:\r\n            return self.fd.recv(n)\r\n        else:\r\n            return os.read(self.fd.fileno(), n)\r\n    except EnvironmentError as e:\r\n        if e.errno not in Stream.ERRNO_RECOVERABLE:\r\n            raise e\r\n```\r\n\r\nThe equivalent hack in `write()` isn't fixing container input though - I'm still investigating. In any case, this bug is a blocker for Fig and boot2docker 1.3, and I'm not sure what the \"correct\" fix is."},"comment":{"url":"https://api.github.com/repos/d11wtq/dockerpty-restored-2/issues/comments/142469966","html_url":"https://github.com/d11wtq/dockerpty-restored-2/issues/65#issuecomment-142469966","issue_url":"https://api.github.com/repos/d11wtq/dockerpty-restored-2/issues/65","id":142469966,"user":{"login":"d11wtq","id":37948,"avatar_url":"https://avatars.githubusercontent.com/u/37948?v=3","gravatar_id":"","url":"https://api.github.com/users/d11wtq","html_url":"https://github.com/d11wtq","followers_url":"https://api.github.com/users/d11wtq/followers","following_url":"https://api.github.com/users/d11wtq/following{/other_user}","gists_url":"https://api.github.com/users/d11wtq/gists{/gist_id}","starred_url":"https://api.github.com/users/d11wtq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/d11wtq/subscriptions","organizations_url":"https://api.github.com/users/d11wtq/orgs","repos_url":"https://api.github.com/users/d11wtq/repos","events_url":"https://api.github.com/users/d11wtq/events{/privacy}","received_events_url":"https://api.github.com/users/d11wtq/received_events","type":"User","site_admin":false},"created_at":"2015-09-23T01:45:40Z","updated_at":"2015-09-23T01:45:40Z","body":"Comment by __aanand__, created on: 2014-10-16T13:21:31Z\n\nOK - overall, this was less hacky than I feared it was going to be: #19 "}}