diff options
author | Sven Gothel <[email protected]> | 2021-02-09 06:03:04 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-02-09 06:03:04 +0100 |
commit | 9d183a87e84e0f7d71683769653933b5a909f0a4 (patch) | |
tree | 69fdb98a5cc967c8ae022321e3a573f62db1318f /src/direct_bt/SMPKeyBin.cpp | |
parent | 7ce8651a5737f5a66c8be3f4cb975e134a7a0699 (diff) |
SMPKeyBin (C++/Java): Add 'apply(BTDevice&)' method, setting Security params and uploading available LTKs
Moving the SMPKeyBin setup and key-upload for the BTDevice to public SMPKeyBin,
providing the proper setup and upload method.
One change compared to removed coding in Scanner10 example occured:
"BTSecurityLevel::ENC_ONLY is set to avoid a new SMP PairingMode negotiation,
which is undesired as this instances' stored LTK shall be used for PairingMode::PRE_PAIRED."
i.e.: 'device.setConnSecurity(BTSecurityLevel.ENC_ONLY, SMPIOCapability.NO_INPUT_NO_OUTPUT);'
This has been evaluate with a Secure Connections capable LE device
using BTSecurityLevel::ENC_AUTH_FIPS and SMPIOCapability::KEYBOARD_ONLY.
After initial pairing using a dynamic generated passkey,
we connected successfully and stored the LTKs and CSRKs with this connection parameter.
Thereafter reconnect after setting (BTSecurityLevel.ENC_ONLY, SMPIOCapability.NO_INPUT_NO_OUTPUT)
and uploading stored keys succeeded with Linux Kernel-BlueZ host implementation.
Diffstat (limited to 'src/direct_bt/SMPKeyBin.cpp')
-rw-r--r-- | src/direct_bt/SMPKeyBin.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/direct_bt/SMPKeyBin.cpp b/src/direct_bt/SMPKeyBin.cpp index a726e118..03d837eb 100644 --- a/src/direct_bt/SMPKeyBin.cpp +++ b/src/direct_bt/SMPKeyBin.cpp @@ -198,3 +198,52 @@ bool SMPKeyBin::read(const std::string path, const std::string basename) { } return isValid(); } + +HCIStatusCode SMPKeyBin::apply(BTDevice & device) const noexcept { + HCIStatusCode res = HCIStatusCode::SUCCESS; + + if( !isValid() || ( !hasLTKInit() && !hasLTKResp() ) ) { + res = HCIStatusCode::INVALID_PARAMS; + if( verbose ) { + fprintf(stderr, "****** APPLY SMPKeyBin failed: SMPKeyBin Status: %s, %s\n", + getHCIStatusCodeString(res).c_str(), this->toString().c_str()); + } + return res; + } + if( !device.isValid() ) { + res = HCIStatusCode::INVALID_PARAMS; + if( verbose ) { + fprintf(stderr, "****** APPLY SMPKeyBin failed: Device Invalid: %s, %s, %s\n", + getHCIStatusCodeString(res).c_str(), this->toString().c_str(), device.toString().c_str()); + } + return res; + } + + if( !device.setConnSecurity(BTSecurityLevel::ENC_ONLY, SMPIOCapability::NO_INPUT_NO_OUTPUT) ) { + res = HCIStatusCode::CONNECTION_ALREADY_EXISTS; + if( verbose ) { + fprintf(stderr, "****** APPLY SMPKeyBin failed: Device Connected/ing: %s, %s, %s\n", + getHCIStatusCodeString(res).c_str(), this->toString().c_str(), device.toString().c_str()); + } + return res; + } + + if( hasLTKInit() ) { + res = device.setLongTermKeyInfo( getLTKInit() ); + if( HCIStatusCode::SUCCESS != res && verbose ) { + fprintf(stderr, "****** APPLY SMPKeyBin failed: Init-LTK Upload: %s, %s, %s\n", + getHCIStatusCodeString(res).c_str(), this->toString().c_str(), device.toString().c_str()); + } + } + + if( HCIStatusCode::SUCCESS == res && hasLTKResp() ) { + res = device.setLongTermKeyInfo( getLTKResp() ); + if( HCIStatusCode::SUCCESS != res && verbose ) { + fprintf(stderr, "****** APPLY SMPKeyBin failed: Resp-LTK Upload: %s, %s, %s\n", + getHCIStatusCodeString(res).c_str(), this->toString().c_str(), device.toString().c_str()); + } + } + + return res; +} + |