summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-10-27 19:33:15 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-10-27 19:33:15 +0300
commit41372b6061bbd20c702c54d65a9f1719a4906249 (patch)
tree22060f333aa932f10280d52c6594a55ad5c1cc8a /protocols
parent0a641111470bf1910bed3fe1cd57f31c6c1ecfce (diff)
code cleaning
Diffstat (limited to 'protocols')
-rw-r--r--protocols/JabberG/src/jabber_omemo.cpp67
-rw-r--r--protocols/JabberG/src/jabber_proto.h2
-rw-r--r--protocols/JabberG/src/jabber_util.cpp2
3 files changed, 32 insertions, 39 deletions
diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp
index 1b2fd188ce..81bc0a43a5 100644
--- a/protocols/JabberG/src/jabber_omemo.cpp
+++ b/protocols/JabberG/src/jabber_omemo.cpp
@@ -280,7 +280,7 @@ complete:
result = SG_ERR_UNKNOWN;
goto complete;
}
-
+
result = EVP_DecryptInit_ex(ctx, evp_cipher, nullptr, key, iv);
if (!result) {
result = SG_ERR_UNKNOWN;
@@ -339,16 +339,16 @@ complete:
struct outgoing_message
{
- outgoing_message(MCONTACT h, char* p)
+ outgoing_message(MCONTACT h, char *p)
{
hContact = h;
pszSrc = p;
}
MCONTACT hContact;
- char* pszSrc;
+ char *pszSrc;
};
-
+
omemo_impl::omemo_impl(CJabberProto *p) :
proto(p)
{
@@ -460,7 +460,7 @@ complete:
}
signal_protocol_key_helper_key_list_free(keys_root);
- if(proto->m_bJabberOnline)
+ if (proto->m_bJabberOnline)
proto->OmemoSendBundle();
}
@@ -469,7 +469,7 @@ complete:
ptrA id_buf((char*)mir_alloc(address->name_len + sizeof(int32_t)));
memcpy(id_buf, address->name, address->name_len);
memcpy(id_buf.get() + address->name_len, &address->device_id, sizeof(int32_t));
-
+
ptrA id_str(mir_base64_encode(id_buf, address->name_len + sizeof(int32_t)));
return CMStringA("OmemoSignalSession_") + id_str;
}
@@ -630,8 +630,8 @@ complete:
struct db_enum_settings_del_all_cb_data
{
- CJabberProto* proto;
std::list<char*> settings;
+ CJabberProto *proto;
const char *name;
size_t name_len;
};
@@ -650,6 +650,7 @@ complete:
return 0;//?
}
+
int delete_all_sessions_func(const char *name, size_t name_len, void *user_data)
{
/**
@@ -937,7 +938,7 @@ complete:
return 0;
}
- int is_trusted_identity(const signal_protocol_address * address, uint8_t * key_data, size_t key_len, void * user_data)
+ int is_trusted_identity(const signal_protocol_address *address, uint8_t *key_data, size_t key_len, void *user_data)
{
/**
* Verify a remote client's identity key.
@@ -965,7 +966,7 @@ complete:
if (val == FP_ABSENT) {
uint32_t count = 0;
db_enum_settings(hContact, omemo::db_enum_settings_fps_cb, proto->m_szModuleName, &count);
- if(count)
+ if (count)
proto->MsgPopup(hContact, omemo::FormatFingerprint(fp_hex), TranslateT("Unknown device added"));
}
@@ -1024,7 +1025,7 @@ complete:
{
// Instantiate a session_builder for a recipient address.
int32_t dev_id_int = strtol(dev_id, nullptr, 10);
- signal_protocol_address address = {jid, mir_strlen(jid), dev_id_int};
+ signal_protocol_address address = { jid, mir_strlen(jid), dev_id_int };
session_builder *builder;
if (session_builder_create(&builder, store_context, &address, global_context) < 0) {
@@ -1112,13 +1113,13 @@ complete:
proto->OmemoSendBundle();
}
- CMStringW FormatFingerprint(const char* pszHexString)
+ CMStringW FormatFingerprint(const char *pszHexString)
{
CMStringW buf;
- if(pszHexString) {
+ if (pszHexString) {
int i = 0;
const char *p = pszHexString;
- if(*p && *(p+1)) p+=2;
+ if (*p && *(p + 1)) p += 2;
for (; *p; p++) {
buf.AppendChar(toupper(*p));
i++;
@@ -1163,7 +1164,7 @@ complete:
return CMStringA(suffix);
}
- CMStringA hex_string(const uint8_t* pData, const size_t length)
+ CMStringA hex_string(const uint8_t *pData, const size_t length)
{
CMStringA hexstr;
if (pData) {
@@ -1202,7 +1203,7 @@ void CJabberProto::OmemoInitDevice()
SIGNAL_UNREF(device_key);
}
-void CJabberProto::OmemoPutMessageToOutgoingQueue(MCONTACT hContact, const char* pszSrc)
+void CJabberProto::OmemoPutMessageToOutgoingQueue(MCONTACT hContact, const char *pszSrc)
{
char *msg = mir_strdup(pszSrc);
m_omemo.outgoing_messages.push_back(omemo::outgoing_message(hContact, msg));
@@ -1232,15 +1233,15 @@ bool CJabberProto::OmemoHandleMessage(const TiXmlElement *node, const char *jid,
Netlib_Log(nullptr, "Jabber OMEMO: error: failed to get iv data");
return true;
}
-
+
const char *sender_dev_id = XmlGetAttr(header_node, "sid");
if (!sender_dev_id) {
debugLogA("Jabber OMEMO: error: failed to get sender device id");
return true;
}
-
+
int32_t sender_dev_id_int = strtol(sender_dev_id, nullptr, 10);
-
+
uint32_t own_id = m_omemo.GetOwnDeviceId();
const char *encrypted_key_base64 = nullptr;
bool isprekey = false;
@@ -1265,7 +1266,7 @@ bool CJabberProto::OmemoHandleMessage(const TiXmlElement *node, const char *jid,
session_cipher *cipher;
char szBareJid[JABBER_MAX_JID_LEN];
JabberStripJid(isCarbon ? m_szJabberJID : jid, szBareJid, _countof(szBareJid));
- signal_protocol_address address = {szBareJid, mir_strlen(szBareJid), sender_dev_id_int};
+ signal_protocol_address address = { szBareJid, mir_strlen(szBareJid), sender_dev_id_int };
if (session_cipher_create(&cipher, m_omemo.store_context, &address, m_omemo.global_context) != SG_SUCCESS)
debugLogA("Jabber OMEMO: error: Cannot create session cipher for decrypt");
@@ -1492,9 +1493,9 @@ void CJabberProto::OmemoSendBundle()
XmlNodeIq iq("set", SerialNext());
iq << XATTR("from", JabberStripJid(m_ThreadInfo->fullJID, szBareJid, _countof(szBareJid)));
- TiXmlElement *publish_node = iq << XCHILDNS("pubsub", "http://jabber.org/protocol/pubsub")
+ TiXmlElement *publish_node = iq << XCHILDNS("pubsub", "http://jabber.org/protocol/pubsub")
<< XCHILD("publish") << XATTR("node", CMStringA(FORMAT, "%s.bundles:%u", JABBER_FEAT_OMEMO, own_id));
-
+
TiXmlElement *bundle_node = publish_node << XCHILD("item") << XATTR("id", "current") << XCHILDNS("bundle", JABBER_FEAT_OMEMO);
session_signed_pre_key *sspk;
@@ -1562,12 +1563,10 @@ bool CJabberProto::OmemoCheckSession(MCONTACT hContact, bool requestBundles)
if (device_id == 0)
break;
- signal_protocol_address address = {jid, mir_strlen(jid), device_id};
+ signal_protocol_address address = { jid, mir_strlen(jid), device_id };
if (!signal_protocol_session_contains_session(m_omemo.store_context, &address)) {
- bool *autotrust = new bool;
- *autotrust = !count;
if (requestBundles) {
- XmlNodeIq iq(AddIQ(&CJabberProto::OmemoOnIqResultGetBundle, JABBER_IQ_TYPE_GET, nullptr, autotrust));
+ XmlNodeIq iq(AddIQ(&CJabberProto::OmemoOnIqResultGetBundle, JABBER_IQ_TYPE_GET, nullptr, (void *)!count));
char szBareJid[JABBER_MAX_JID_LEN];
iq << XATTR("from", JabberStripJid(m_ThreadInfo->fullJID, szBareJid, _countof(szBareJid))) << XATTR("to", jid);
@@ -1580,7 +1579,7 @@ bool CJabberProto::OmemoCheckSession(MCONTACT hContact, bool requestBundles)
ok = false;
}
else {
- if(count == 0) {
+ if (count == 0) {
MBinBuffer fp(getBlob(_hContact, omemo::IdentityPrefix + m_omemo.dbGetSuffix(_hContact, device_id)));
CMStringA fp_hex(omemo::hex_string(fp.data(), fp.length()));
setByte(hContact, "OmemoFingerprintTrusted_" + fp_hex, FP_TOFU);
@@ -1598,12 +1597,6 @@ bool CJabberProto::OmemoCheckSession(MCONTACT hContact, bool requestBundles)
void CJabberProto::OmemoOnIqResultGetBundle(const TiXmlElement *iqNode, CJabberIqInfo *IqInfo)
{
- bool autotrust = 0;
- if (bool *ud = (bool *)IqInfo->GetUserData()) {
- autotrust = *ud;
- delete ud;
- }
-
if (iqNode == nullptr || !m_bUseOMEMO)
return;
@@ -1639,7 +1632,7 @@ void CJabberProto::OmemoOnIqResultGetBundle(const TiXmlElement *iqNode, CJabberI
const char *items_node_val = XmlGetAttr(items, "node");
const char *device_id = items_node_val;
device_id += mir_wstrlen(JABBER_FEAT_OMEMO L".bundles:");
-
+
auto *bundle = XmlFirstChild(XmlFirstChild(items, "item"), "bundle");
if (!bundle) {
debugLogA("Jabber OMEMO: error: device bundle does not contain bundle node");
@@ -1665,7 +1658,7 @@ void CJabberProto::OmemoOnIqResultGetBundle(const TiXmlElement *iqNode, CJabberI
debugLogA("Jabber OMEMO: error: device bundle does not contain identityKey node");
return;
}
-
+
auto *prekeys = XmlFirstChild(bundle, "prekeys");
if (!prekeys) {
debugLogA("Jabber OMEMO: error: device bundle does not contain prekeys node");
@@ -1695,7 +1688,7 @@ void CJabberProto::OmemoOnIqResultGetBundle(const TiXmlElement *iqNode, CJabberI
return;
}
- if (autotrust) {
+ if (IqInfo->GetUserData()) {
size_t key_len;
uint8_t *key_buf = (uint8_t *)mir_base64_decode(identityKey->GetText(), &key_len);
CMStringA fp_hex(omemo::hex_string(key_buf, key_len));
@@ -1746,7 +1739,7 @@ int CJabberProto::OmemoEncryptMessage(XmlNode &msg, const char *msg_text, MCONTA
TiXmlElement *header = encrypted << XCHILD("header");
header << XATTRI64("sid", m_omemo.GetOwnDeviceId());
-
+
int session_count = 0;
char key_plus_tag[32];
memcpy(key_plus_tag, key, 16);
@@ -1768,7 +1761,7 @@ int CJabberProto::OmemoEncryptMessage(XmlNode &msg, const char *msg_text, MCONTA
continue;
session_cipher *scipher;
- signal_protocol_address address = {jid, mir_strlen(jid), device_id};
+ signal_protocol_address address = { jid, mir_strlen(jid), device_id };
if (session_cipher_create(&scipher, m_omemo.store_context, &address, m_omemo.global_context) != SG_SUCCESS) {
debugLogA("Jabber OMEMO: error: Cannot create session cipher for encrypt");
continue;
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index 073a6de91f..f1e0f97f44 100644
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -888,7 +888,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
bool IsMyOwnJID(const char *szJID);
bool IsSendAck(MCONTACT hContact);
- void ConfigurePepNode(const char * nodename, const char * access_model, const char * max_items = nullptr);
+ void ConfigurePepNode(const char *nodename, const char *access_model, const char *max_items = nullptr);
void __cdecl LoadHttpAvatars(void* param);
CMStringA MyNick(MCONTACT hContact = 0);
diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp
index c7f6a1fd4a..6fcedc0a1c 100644
--- a/protocols/JabberG/src/jabber_util.cpp
+++ b/protocols/JabberG/src/jabber_util.cpp
@@ -872,7 +872,7 @@ bool CJabberProto::IsSendAck(MCONTACT hContact)
return m_bMsgAck;
}
-void CJabberProto::ConfigurePepNode(const char* nodename, const char* access_model, const char* max_items)
+void CJabberProto::ConfigurePepNode(const char *nodename, const char *access_model, const char *max_items)
{
char szBareJid[JABBER_MAX_JID_LEN];
XmlNodeIq iq("set", SerialNext());