if(bctbx_aes_gcm_encrypt_and_tag(randomKey.data(),lime::settings::DRMessageKeySize,// key buffer also hold the IV
...
...
@@ -464,12 +464,12 @@ namespace lime {
// Loop on each session, given Associated Data to Double Ratchet encryption is: auth tag of cipherMessage AEAD || sourceDeviceId || recipient device Id(gruu)
// build the common part to AD given to DR Session encryption
// fetch all the verified devices (we don't directly fetch unverified device as some devices may not be in local storage at all)
rowset<row>rs_devices=(m_localStorage->sql.prepare<<"SELECT d.DeviceId FROM lime_PeerDevices as d WHERE d.Verified = 1 AND d.DeviceId IN ("<<sqlString_allDevices<<");");
std::vector<std::string>verifiedDevices{};// vector of verified deviceId
for(auto&r:rs_devices){
for(constauto&r:rs_devices){
verifiedDevices.push_back(r.get<string>(0));
}
// loop on internal recipient and mark the one verified as verified
rowset<row>rs=(m_localStorage->sql.prepare<<"SELECT s.sessionId, d.DeviceId FROM DR_sessions as s INNER JOIN lime_PeerDevices as d ON s.Did=d.Did WHERE s.Uid= :Uid AND s.Status=1 AND d.DeviceId IN ("<<sqlString_requestedDevices<<");",use(m_db_Uid));
std::unordered_map<std::string,std::shared_ptr<DR<Curve>>>requestedDevices;// found session will be loaded and temp stored in this
rowset<int>rs=(m_localStorage->sql.prepare<<"SELECT s.sessionId FROM DR_sessions as s INNER JOIN lime_PeerDevices as d ON s.Did=d.Did WHERE d.DeviceId = :senderDeviceId AND s.Uid = :Uid AND s.sessionId <> :ignoreThisDRSessionId ORDER BY s.Status DESC, timeStamp ASC;",use(senderDeviceId),use(m_db_Uid),use(ignoreThisDRSessionId));
for(autosessionId:rs){
for(constauto&sessionId:rs){
/* load session in cache DRSessions */
DRSessions.push_back(make_shared<DR<Curve>>(m_localStorage.get(),sessionId));// load session from cache
// Generate DR_Session and put it in cache(but not in localStorage yet, that would be done when first message generation will be complete)
...
...
@@ -239,10 +239,10 @@ namespace lime {
// Generate the shared AD used in DR session
SharedADBufferAD;// AD is HKDF(session Initiator Ik || session receiver Ik || session Initiator device Id || session receiver device Id), we are receiver on this one