Skip to content

Commit

Permalink
main.conf: Add SecureConnections option
Browse files Browse the repository at this point in the history
This introduces SecureConnections option to main.conf that can be used to
configure this on adapter initialization.

This is useful for:
- disable for adapters that have a problems with SecureConnections enabled
- if you want to disable CTKD (cross transport key derivation)
- add option to enable only SecureConnections
  • Loading branch information
stream-sim authored and Vudentz committed Nov 22, 2022
1 parent 5a872af commit 9f50368
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -10146,7 +10146,8 @@ static void read_info_complete(uint8_t status, uint16_t length,
}

if (missing_settings & MGMT_SETTING_SECURE_CONN)
set_mode(adapter, MGMT_OP_SET_SECURE_CONN, 0x01);
set_mode(adapter, MGMT_OP_SET_SECURE_CONN,
btd_opts.secure_conn);

if (adapter->supported_settings & MGMT_SETTING_PRIVACY)
set_privacy(adapter, btd_opts.privacy);
Expand Down
7 changes: 7 additions & 0 deletions src/btd.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ enum mps_mode_t {
MPS_MULTIPLE,
};

enum sc_mode_t {
SC_OFF,
SC_ON,
SC_ONLY,
};

struct btd_br_defaults {
uint16_t page_scan_type;
uint16_t page_scan_interval;
Expand Down Expand Up @@ -105,6 +111,7 @@ struct btd_opts {
uint8_t privacy;
bool device_privacy;
uint32_t name_request_retry_delay;
uint8_t secure_conn;

struct btd_defaults defaults;

Expand Down
15 changes: 15 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static const char *supported_options[] = {
"MaxControllers"
"MultiProfile",
"FastConnectable",
"SecureConnections",
"Privacy",
"JustWorksRepairing",
"TemporaryTimeout",
Expand Down Expand Up @@ -881,6 +882,19 @@ static void parse_config(GKeyFile *config)
btd_opts.name_request_retry_delay = val;
}

str = g_key_file_get_string(config, "General",
"SecureConnections", &err);
if (err)
g_clear_error(&err);
else {
if (!strcmp(str, "off"))
btd_opts.secure_conn = SC_OFF;
else if (!strcmp(str, "on"))
btd_opts.secure_conn = SC_ON;
else if (!strcmp(str, "only"))
btd_opts.secure_conn = SC_ONLY;
}

str = g_key_file_get_string(config, "GATT", "Cache", &err);
if (err) {
DBG("%s", err->message);
Expand Down Expand Up @@ -993,6 +1007,7 @@ static void init_defaults(void)
btd_opts.debug_keys = FALSE;
btd_opts.refresh_discovery = TRUE;
btd_opts.name_request_retry_delay = DEFAULT_NAME_REQUEST_RETRY_DELAY;
btd_opts.secure_conn = SC_ON;

btd_opts.defaults.num_entries = 0;
btd_opts.defaults.br.page_scan_type = 0xFFFF;
Expand Down
11 changes: 11 additions & 0 deletions src/main.conf
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@
# profile is connected. Defaults to true.
#RefreshDiscovery = true

# Default Secure Connections setting.
# Enables the Secure Connections setting for adapters that support it. It
# provides better crypto algorithms for BT links and also enables CTKD (cross
# transport key derivation) during pairing on any link.
# Possible values: "off", "on", "only"
# - "off": Secure Connections are disabled
# - "on": Secure Connections are enabled when peer device supports them
# - "only": we allow only Secure Connections
# Defaults to "on"
#SecureConnections = on

# Enables D-Bus experimental interfaces
# Possible values: true or false
#Experimental = false
Expand Down

0 comments on commit 9f50368

Please sign in to comment.