Properly verify OTK signature
This commit is contained in:
parent
8444683271
commit
8b3d0c14d0
34
src/Olm.cpp
34
src/Olm.cpp
@ -1208,22 +1208,40 @@ send_encrypted_to_device_messages(const std::map<std::string, std::vector<std::s
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Verify signatures
|
|
||||||
auto otk = rd.second.begin()->at("key");
|
auto otk = rd.second.begin()->at("key");
|
||||||
|
|
||||||
auto id_key = pks.at(user_id).at(device_id).curve25519;
|
auto sign_key = pks.at(user_id).at(device_id).ed25519;
|
||||||
|
auto id_key = pks.at(user_id).at(device_id).curve25519;
|
||||||
|
|
||||||
|
// Verify signature
|
||||||
|
{
|
||||||
|
auto signedKey = *rd.second.begin();
|
||||||
|
std::string signature =
|
||||||
|
signedKey["signatures"][user_id].value(
|
||||||
|
"ed25519:" + device_id, "");
|
||||||
|
|
||||||
|
if (signature.empty() ||
|
||||||
|
!mtx::crypto::ed25519_verify_signature(
|
||||||
|
sign_key, signedKey, signature)) {
|
||||||
|
nhlog::net()->warn(
|
||||||
|
"Skipping device {} as its one time key "
|
||||||
|
"has an invalid signature.",
|
||||||
|
device_id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto session =
|
auto session =
|
||||||
olm::client()->create_outbound_session(id_key, otk);
|
olm::client()->create_outbound_session(id_key, otk);
|
||||||
|
|
||||||
messages[mtx::identifiers::parse<mtx::identifiers::User>(
|
messages[mtx::identifiers::parse<mtx::identifiers::User>(
|
||||||
user_id)][device_id] =
|
user_id)][device_id] =
|
||||||
olm::client()
|
olm::client()
|
||||||
->create_olm_encrypted_content(
|
->create_olm_encrypted_content(session.get(),
|
||||||
session.get(),
|
ev_json,
|
||||||
ev_json,
|
UserId(user_id),
|
||||||
UserId(user_id),
|
sign_key,
|
||||||
pks.at(user_id).at(device_id).ed25519,
|
id_key)
|
||||||
id_key)
|
|
||||||
.get<mtx::events::msg::OlmEncrypted>();
|
.get<mtx::events::msg::OlmEncrypted>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user