Skip to content

Commit 23a2ab7

Browse files
committed
feat: expert option to disable TLS cert validation of HA WS server
Users are still using self-signed certificates in 2025... A quick fix to disable certificate validation. DISCOURAGED AND NOT RECOMMENDED! Please use Let's Encrpyt instead.
1 parent 9ba6ed8 commit 23a2ab7

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
_Changes in the next release_
1010

11+
### Added
12+
- Expert option to disable certificate validation of the Home Assistant WebSocket server connection.
13+
1114
---
1215

1316
## v0.12.2 - 2025-04-17
1417
### Added
15-
- Propagate media player attribute `media_position_updated_at`.
18+
- Propagate media player attribute `media_position_updated_at` ([feature-and-bug-tracker#443](https://github.com/unfoldedcircle/feature-and-bug-tracker/issues/443)).
19+
1620
### Fixed
1721
- Media player `media_type` attribute value should be upper case to match entity documentation.
1822
### Changed

src/configuration.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ pub struct HomeAssistantSettings {
141141
// for data migration of existing configurations
142142
#[serde(default = "default_disconnect_in_standby")]
143143
pub disconnect_in_standby: bool,
144+
/// Disables certificate verification for the Home Assistant WS connection.
145+
// for data migration of existing configurations
146+
#[serde(default = "default_disable_cert_validation")]
147+
pub disable_cert_validation: bool,
144148
}
145149

146150
impl Default for HomeAssistantSettings {
@@ -154,6 +158,7 @@ impl Default for HomeAssistantSettings {
154158
reconnect: Default::default(),
155159
heartbeat: Default::default(),
156160
disconnect_in_standby: default_disconnect_in_standby(),
161+
disable_cert_validation: default_disable_cert_validation(),
157162
}
158163
}
159164
}
@@ -236,6 +241,9 @@ fn default_request_timeout() -> u8 {
236241
fn default_disconnect_in_standby() -> bool {
237242
true
238243
}
244+
fn default_disable_cert_validation() -> bool {
245+
false
246+
}
239247

240248
#[serde_as]
241249
#[derive(Clone, serde::Deserialize, serde::Serialize)]

src/controller/handler/ha_connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl Handler<ConnectMsg> for Controller {
141141
Ok((r, f)) => (r, f),
142142
Err(e) => {
143143
warn!("Could not connect to {url}: {e:?}");
144-
return Err(Error::new(ErrorKind::Other, e.to_string()));
144+
return Err(Error::other(e.to_string()));
145145
}
146146
};
147147
info!("Connected to: {url} ({heartbeat})");

src/controller/handler/setup.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ impl Handler<SetDriverUserDataMsg> for Controller {
158158
if let Some(value) = parse_value(&values, "ping_frames") {
159159
cfg.heartbeat.ping_frames = value;
160160
}
161+
if let Some(value) = parse_value(&values, "disable_cert_validation") {
162+
cfg.disable_cert_validation = value;
163+
}
161164
if let Some(value) = parse_value(&values, "reconnect.attempts") {
162165
cfg.reconnect.attempts = value;
163166
}
@@ -501,6 +504,19 @@ impl Handler<RequestExpertOptionsMsg> for Controller {
501504
"value": self.settings.hass.heartbeat.ping_frames
502505
}
503506
}
507+
},
508+
{
509+
"id": "disable_cert_validation",
510+
"label": {
511+
"en": "Disable certificate verification",
512+
"de": "Zertifikatsüberprüfung deaktivieren",
513+
"fr": "Désactiver la vérification des certificats"
514+
},
515+
"field": {
516+
"checkbox": {
517+
"value": self.settings.hass.disable_cert_validation
518+
}
519+
}
504520
}
505521
]
506522
}

src/controller/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ impl Controller {
145145
Duration::from_secs(settings.hass.connection_timeout as u64),
146146
Duration::from_secs(settings.hass.request_timeout as u64),
147147
matches!(url.scheme(), "wss" | "https"),
148+
settings.hass.disable_cert_validation,
148149
),
149150
ha_reconnect_duration: settings.hass.reconnect.duration,
150151
settings,

src/util/network.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn new_websocket_client(
3030
connection_timeout: Duration,
3131
request_timeout: Duration,
3232
tls: bool,
33+
disable_cert_validation: bool,
3334
) -> awc::Client {
3435
if tls {
3536
// TLS configuration: https://github.com/actix/actix-web/blob/master/awc/tests/test_rustls_client.rs
@@ -44,7 +45,7 @@ pub fn new_websocket_client(
4445

4546
// Disable TLS verification
4647
// Requires: rustls = { ... optional = true, features = ["dangerous_configuration"] }
47-
if bool_from_env(ENV_DISABLE_CERT_VERIFICATION) {
48+
if disable_cert_validation || bool_from_env(ENV_DISABLE_CERT_VERIFICATION) {
4849
config
4950
.dangerous()
5051
.set_certificate_verifier(Arc::new(danger::NoCertificateVerification {}));

0 commit comments

Comments
 (0)