MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / GetNetworkKey

Method GetNetworkKey

cpp/src/Driver.cpp:7006–7037  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Get the Network Key we will use for Security Command Class -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

7004// Get the Network Key we will use for Security Command Class
7005//-----------------------------------------------------------------------------
7006uint8 *Driver::GetNetworkKey() {
7007 std::string networkKey;
7008 std::vector<std::string> elems;
7009 unsigned int tempkey[16];
7010 static uint8 keybytes[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
7011 static bool keySet = false;
7012 if (keySet == false) {
7013 Options::Get()->GetOptionAsString("NetworkKey", &networkKey );
7014 OpenZWave::split(elems, networkKey, ",", true);
7015 if (elems.size() != 16) {
7016 Log::Write(LogLevel_Warning, "Invalid Network Key. Does not contain 16 Bytes - Contains %d", elems.size());
7017 Log::Write(LogLevel_Warning, "Raw Key: %s", networkKey.c_str());
7018 Log::Write(LogLevel_Warning, "Parsed Key:");
7019 int i = 0;
7020 for (std::vector<std::string>::iterator it = elems.begin(); it != elems.end(); it++)
7021 Log::Write(LogLevel_Warning, "%d) - %s", ++i, (*it).c_str());
7022 OZW_FATAL_ERROR(OZWException::OZWEXCEPTION_SECURITY_FAILED, "Failed to Read Network Key");
7023 }
7024 int i = 0;
7025 for (std::vector<std::string>::iterator it = elems.begin(); it != elems.end(); it++) {
7026 if (0 == sscanf(OpenZWave::trim(*it).c_str(), "%x", &tempkey[i])) {
7027 Log::Write(LogLevel_Warning, "Cannot Convert Network Key Byte %s to Key", (*it).c_str());
7028 OZW_FATAL_ERROR(OZWException::OZWEXCEPTION_SECURITY_FAILED, "Failed to Convert Network Key");
7029 } else {
7030 keybytes[i] = (tempkey[i] & 0xFF);
7031 }
7032 i++;
7033 }
7034 keySet = true;
7035 }
7036 return keybytes;
7037}
7038
7039//-----------------------------------------------------------------------------
7040// <Driver::SendEncryptedMessage>

Callers 2

initNetworkKeysMethod · 0.95
HandleMsgMethod · 0.80

Calls 7

WriteFunction · 0.85
GetOptionAsStringMethod · 0.80
GetFunction · 0.70
sizeMethod · 0.45
c_strMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected