mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 11:56:25 +01:00
Enable api transport encryption for new projects (#3142)
* Enable api transport encryption for new projects * Format
This commit is contained in:
parent
c569f5ddcf
commit
0b69f72315
@ -1,5 +1,6 @@
|
|||||||
# pylint: disable=wrong-import-position
|
# pylint: disable=wrong-import-position
|
||||||
|
|
||||||
|
import base64
|
||||||
import codecs
|
import codecs
|
||||||
import collections
|
import collections
|
||||||
import functools
|
import functools
|
||||||
@ -378,6 +379,8 @@ class WizardRequestHandler(BaseHandler):
|
|||||||
if k in ("name", "platform", "board", "ssid", "psk", "password")
|
if k in ("name", "platform", "board", "ssid", "psk", "password")
|
||||||
}
|
}
|
||||||
kwargs["ota_password"] = secrets.token_hex(16)
|
kwargs["ota_password"] = secrets.token_hex(16)
|
||||||
|
noise_psk = secrets.token_bytes(32)
|
||||||
|
kwargs["api_encryption_key"] = base64.b64encode(noise_psk).decode()
|
||||||
destination = settings.rel_path(f"{kwargs['name']}.yaml")
|
destination = settings.rel_path(f"{kwargs['name']}.yaml")
|
||||||
wizard.wizard_write(path=destination, **kwargs)
|
wizard.wizard_write(path=destination, **kwargs)
|
||||||
self.set_status(200)
|
self.set_status(200)
|
||||||
|
@ -111,6 +111,8 @@ def wizard_file(**kwargs):
|
|||||||
# Configure API
|
# Configure API
|
||||||
if "password" in kwargs:
|
if "password" in kwargs:
|
||||||
config += f" password: \"{kwargs['password']}\"\n"
|
config += f" password: \"{kwargs['password']}\"\n"
|
||||||
|
if "api_encryption_key" in kwargs:
|
||||||
|
config += f" encryption:\n key: \"{kwargs['api_encryption_key']}\"\n"
|
||||||
|
|
||||||
# Configure OTA
|
# Configure OTA
|
||||||
config += "\nota:\n"
|
config += "\nota:\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user