Skip to content

Commit

Permalink
Merge pull request #43 from NabuCasa/dev
Browse files Browse the repository at this point in the history
Release 0.10
  • Loading branch information
pvizeli authored Mar 21, 2019
2 parents 8940148 + 4dbd2c3 commit be292c7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
19 changes: 19 additions & 0 deletions hass_nabucasa/acme.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def _generate_csr(self) -> bytes:
key_pem = OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, key)

self.path_private_key.write_bytes(key_pem)
self.path_private_key.chmod(0o600)

return crypto_util.make_csr(key_pem, [self._domain])

Expand Down Expand Up @@ -377,3 +378,21 @@ async def reset_acme(self) -> None:
self._acme_client = None
self._account_jwk = None
self._x509 = None

async def hardening_files(self) -> None:
"""Control permission on files."""
def _control():
# Set file permission to 0600
if self.path_account_key.exists():
self.path_account_key.chmod(0o600)
if self.path_registration_info.exists():
self.path_registration_info.chmod(0o600)
if self.path_fullchain.exists():
self.path_fullchain.chmod(0o600)
if self.path_private_key.exists():
self.path_private_key.chmod(0o600)

try:
await self.cloud.run_executor(_control)
except OSError:
_LOGGER.warning("Can't check and hardening file permission")
9 changes: 6 additions & 3 deletions hass_nabucasa/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ async def load_backend(self) -> None:
"Home Assistant Cloud",
const.MESSAGE_REMOTE_READY,
)
await self._acme.hardening_files()

# Setup snitun / aiohttp wrapper
context = await self._create_context()
Expand Down Expand Up @@ -236,7 +237,7 @@ async def _refresh_snitun_token(self) -> None:
aes_key,
aes_iv,
utils.utc_from_timestamp(data["valid"]),
data["throttling"]
data["throttling"],
)

async def connect(self) -> None:
Expand All @@ -252,8 +253,10 @@ async def connect(self) -> None:
try:
await self._refresh_snitun_token()
await self._snitun.connect(
self._token.fernet, self._token.aes_key, self._token.aes_iv,
throttling=self._token.throttling
self._token.fernet,
self._token.aes_key,
self._token.aes_iv,
throttling=self._token.throttling,
)

self.cloud.client.dispatcher_message(const.DISPATCH_REMOTE_CONNECT)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = "0.9"
VERSION = "0.10"

setup(
name="hass-nabucasa",
Expand Down
5 changes: 5 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def __init__(self):
self.call_issue = False
self.call_reset = False
self.call_load = False
self.call_hardening = False
self.init_args = None

self.common_name = None
Expand Down Expand Up @@ -144,6 +145,10 @@ async def load_certificate(self):
"""Load certificate."""
self.call_load = True

async def hardening_files(self):
"""Hardening files."""
self.call_hardening = True

def __call__(self, *args):
"""Init."""
self.init_args = args
Expand Down
5 changes: 5 additions & 0 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ async def test_load_backend_exists_cert(
"test.dui.nabu.casa",
"[email protected]",
)
assert acme_mock.call_hardening
assert snitun_mock.call_start
assert snitun_mock.init_args == (None, None)
assert snitun_mock.init_kwarg == {
Expand Down Expand Up @@ -141,6 +142,7 @@ async def test_load_backend_not_exists_cert(
"test.dui.nabu.casa",
"[email protected]",
)
assert acme_mock.call_hardening
assert snitun_mock.call_start
assert snitun_mock.init_args == (None, None)
assert snitun_mock.init_kwarg == {
Expand Down Expand Up @@ -192,6 +194,7 @@ async def test_load_and_unload_backend(
"test.dui.nabu.casa",
"[email protected]",
)
assert acme_mock.call_hardening
assert snitun_mock.call_start
assert not snitun_mock.call_stop
assert snitun_mock.init_args == (None, None)
Expand Down Expand Up @@ -251,6 +254,7 @@ async def test_load_backend_exists_wrong_cert(
"test.dui.nabu.casa",
"[email protected]",
)
assert acme_mock.call_hardening
assert snitun_mock.call_start
assert snitun_mock.init_args == (None, None)
assert snitun_mock.init_kwarg == {
Expand Down Expand Up @@ -332,6 +336,7 @@ async def test_load_backend_no_autostart(

assert remote.snitun_server == "rest-remote.nabu.casa"
assert not acme_mock.call_issue
assert acme_mock.call_hardening
assert snitun_mock.call_start

assert not snitun_mock.call_connect
Expand Down

0 comments on commit be292c7

Please sign in to comment.