Skip to content

Commit abcc5db

Browse files
fix setting default values which were overriding even when unset
1 parent 975544f commit abcc5db

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ ble_error_t GenericSecurityManager::requestPairing(connection_handle_t connectio
119119
update_oob_presence(connection);
120120

121121
AuthenticationMask link_authentication(_default_authentication);
122-
link_authentication.set_mitm(cb->mitm_requested);
122+
123+
if (cb->mitm_requested) {
124+
link_authentication.set_mitm(true);
125+
}
123126

124127
/* by default the initiator doesn't send any keys other then identity */
125128
KeyDistribution initiator_distribution(
@@ -133,9 +136,12 @@ ble_error_t GenericSecurityManager::requestPairing(connection_handle_t connectio
133136
}
134137

135138
/* override default if requested */
136-
initiator_distribution.set_signing(
137-
cb->signing_override_default ? cb->signing_requested : _default_key_distribution.get_signing()
138-
);
139+
if (cb->signing_override_default) {
140+
initiator_distribution.set_signing(cb->signing_requested);
141+
} else {
142+
/* because _master_sends_keys might be false so we need to set this */
143+
initiator_distribution.set_signing(_default_key_distribution.get_signing());
144+
}
139145

140146
KeyDistribution responder_distribution(_default_key_distribution);
141147

@@ -161,7 +167,9 @@ ble_error_t GenericSecurityManager::acceptPairingRequest(connection_handle_t con
161167
update_oob_presence(connection);
162168

163169
AuthenticationMask link_authentication(_default_authentication);
164-
link_authentication.set_mitm(cb->mitm_requested);
170+
if (cb->mitm_requested) {
171+
link_authentication.set_mitm(true);
172+
}
165173

166174
KeyDistribution initiator_dist = cb->get_initiator_key_distribution();
167175

@@ -172,20 +180,22 @@ ble_error_t GenericSecurityManager::acceptPairingRequest(connection_handle_t con
172180
}
173181

174182
/* signing has to be offered and enabled on the link */
175-
initiator_dist.set_signing(
176-
initiator_dist.get_signing()
177-
&& (
178-
cb->signing_override_default ? cb->signing_requested : _default_key_distribution.get_signing())
179-
);
183+
if (initiator_dist.get_signing()) {
184+
initiator_dist.set_signing(
185+
cb->signing_override_default ? cb->signing_requested : _default_key_distribution.get_signing()
186+
);
187+
}
180188

181-
KeyDistribution responder_dist = cb->get_responder_key_distribution();
189+
KeyDistribution responder_dist(cb->get_responder_key_distribution());
182190

183191
responder_dist &= _default_key_distribution;
192+
184193
/* signing has to be requested and enabled on the link */
185-
responder_dist.set_signing(
186-
responder_dist.get_signing()
187-
&& (cb->signing_override_default ? cb->signing_requested : _default_key_distribution.get_signing())
188-
);
194+
if (responder_dist.get_signing()) {
195+
responder_dist.set_signing(
196+
cb->signing_override_default ? cb->signing_requested : _default_key_distribution.get_signing()
197+
);
198+
}
189199

190200
return _pal.send_pairing_response(
191201
connection,

0 commit comments

Comments
 (0)