Skip to content

Commit

Permalink
Use SHA hash to make token harder to guess (#5258)
Browse files Browse the repository at this point in the history
* Use SHA hash to make token harder to guess

Use hashlib SHA256 to encode object id instead of using it directly.

* Cache access token

Instead of generating a token on the fly cache it in the constructor.

* Fix lint
  • Loading branch information
valentinalexeev authored and nordlead2005 committed Jan 10, 2017
1 parent 43b6dff commit 922308b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion homeassistant/components/camera/__init__.py
Expand Up @@ -8,6 +8,7 @@
import asyncio
from datetime import timedelta
import logging
import hashlib

from aiohttp import web

Expand Down Expand Up @@ -47,11 +48,13 @@ class Camera(Entity):
def __init__(self):
"""Initialize a camera."""
self.is_streaming = False
self._access_token = hashlib.sha256(
str.encode(str(id(self)))).hexdigest()

@property
def access_token(self):
"""Access token for this camera."""
return str(id(self))
return self._access_token

@property
def should_poll(self):
Expand Down

0 comments on commit 922308b

Please sign in to comment.