ensure FNE key req/rsp handle variable length keys properly (fixes an issue with sending DES and ARC4 keys as 32-byte length keys);

pull/86/head
Bryan Biedenkapp 11 months ago
parent 9806ece4f5
commit 3dd7871ee6

@ -91,21 +91,31 @@ public:
/**
* @brief Gets the encryption key.
* @param[out] key Buffer containing the key.
* @returns uint8_t Length of encryption key.
*/
void getKey(uint8_t* key) const
uint8_t getKey(uint8_t* key) const
{
assert(key != nullptr);
const char* rawKey = m_keyMaterial.c_str();
::memset(key, 0x00U, 32U);
uint8_t len = 32U, charPos = 0U;
for (uint8_t i = 0U; i < 32U; i++) {
char t[4] = {rawKey[0], rawKey[1], 0};
key[i] = (uint8_t)::strtoul(t, NULL, 16);
if (i + 2U > m_keyMaterial.size())
if (charPos + 2U > m_keyMaterial.size()) {
len = i;
break;
}
rawKey += 2 * sizeof(char);
charPos += 2U;
}
return len;
}
public:

@ -1099,6 +1099,14 @@ void* FNENetwork::threadedNetworkRx(void* arg)
modifyKey->getAlgId(), modifyKey->getKId());
::KeyItem keyItem = network->m_cryptoLookup->find(modifyKey->getKId());
if (!keyItem.isInvalid()) {
uint8_t key[P25DEF::MAX_ENC_KEY_LENGTH_BYTES];
::memset(key, 0x00U, P25DEF::MAX_ENC_KEY_LENGTH_BYTES);
uint8_t keyLength = keyItem.getKey(key);
LogDebugEx(LOG_HOST, "FNENetwork::threadedNetworkRx()", "keyLength = %u", keyLength);
Utils::dump(1U, "Key", key, P25DEF::MAX_ENC_KEY_LENGTH_BYTES);
// build response buffer
uint8_t buffer[DATA_PACKET_LENGTH];
::memset(buffer, 0x00U, DATA_PACKET_LENGTH);
@ -1110,17 +1118,13 @@ void* FNENetwork::threadedNetworkRx(void* arg)
KeysetItem ks = KeysetItem();
ks.keysetId(1U);
ks.algId(modifyKey->getAlgId());
ks.keyLength(P25DEF::MAX_ENC_KEY_LENGTH_BYTES); // bryanb: this --- will be problematic and should be properly calculated
ks.keyLength(keyLength);
p25::kmm::KeyItem ki = p25::kmm::KeyItem();
ki.keyFormat(KEY_FORMAT_TEK);
ki.kId((uint16_t)keyItem.kId());
ki.sln((uint16_t)keyItem.sln());
uint8_t key[P25DEF::MAX_ENC_KEY_LENGTH_BYTES];
::memset(key, 0x00U, P25DEF::MAX_ENC_KEY_LENGTH_BYTES);
keyItem.getKey(key);
ki.setKey(key, P25DEF::MAX_ENC_KEY_LENGTH_BYTES); // bryanb: this --- will be problematic and should be properly calculated
ki.setKey(key, keyLength);
ks.push_back(ki);
modifyKeyRsp.setKeysetItem(ks);

Loading…
Cancel
Save

Powered by TurnKey Linux.