Commit 7b43ba8f authored by johan's avatar johan
Browse files

Avoid using raw pointer

parent 35b37b8f
......@@ -146,7 +146,7 @@ namespace lime {
* @param[in] RNG_context A Random Number Generator context used for any rndom generation needed by this session
*/
template <typename Curve>
DR<Curve>::DR(lime::Db *localStorage, const DRChainKey &SK, const SharedADBuffer &AD, const X<Curve, lime::Xtype::publicKey> &peerPublicKey, long int peerDid, const std::string &peerDeviceId, const DSA<Curve, lime::DSAtype::publicKey> &peerIk, long int selfDid, const std::vector<uint8_t> &X3DH_initMessage, std::shared_ptr<RNG> RNG_context)
DR<Curve>::DR(std::shared_ptr<lime::Db> localStorage, const DRChainKey &SK, const SharedADBuffer &AD, const X<Curve, lime::Xtype::publicKey> &peerPublicKey, long int peerDid, const std::string &peerDeviceId, const DSA<Curve, lime::DSAtype::publicKey> &peerIk, long int selfDid, const std::vector<uint8_t> &X3DH_initMessage, std::shared_ptr<RNG> RNG_context)
:m_DHr{peerPublicKey},m_DHr_valid{true}, m_DHs{},m_RK(SK),m_CKs{},m_CKr{},m_Ns(0),m_Nr(0),m_PN(0),m_sharedAD(AD),m_mkskipped{},
m_RNG{RNG_context},m_dbSessionId{0},m_usedNr{0},m_usedDHid{0},m_localStorage{localStorage},m_dirty{DRSessionDbStatus::dirty},m_peerDid{peerDid},m_peerDeviceId{},m_peerIk{},m_db_Uid{selfDid},
m_active_status{true}, m_X3DH_initMessage{X3DH_initMessage}
......@@ -189,7 +189,7 @@ namespace lime {
* @param[in] RNG_context A Random Number Generator context used for any rndom generation needed by this session
*/
template <typename Curve>
DR<Curve>::DR(lime::Db *localStorage, const DRChainKey &SK, const SharedADBuffer &AD, const Xpair<Curve> &selfKeyPair, long int peerDid, const std::string &peerDeviceId, const DSA<Curve, lime::DSAtype::publicKey> &peerIk, long int selfDid, std::shared_ptr<RNG> RNG_context)
DR<Curve>::DR(std::shared_ptr<lime::Db> localStorage, const DRChainKey &SK, const SharedADBuffer &AD, const Xpair<Curve> &selfKeyPair, long int peerDid, const std::string &peerDeviceId, const DSA<Curve, lime::DSAtype::publicKey> &peerIk, long int selfDid, std::shared_ptr<RNG> RNG_context)
:m_DHr{},m_DHr_valid{false},m_DHs{selfKeyPair},m_RK(SK),m_CKs{},m_CKr{},m_Ns(0),m_Nr(0),m_PN(0),m_sharedAD(AD),m_mkskipped{},
m_RNG{RNG_context},m_dbSessionId{0},m_usedNr{0},m_usedDHid{0},m_localStorage{localStorage},m_dirty{DRSessionDbStatus::dirty},m_peerDid{peerDid},m_peerDeviceId{},m_peerIk{},m_db_Uid{selfDid},
m_active_status{true}, m_X3DH_initMessage{}
......@@ -212,7 +212,7 @@ namespace lime {
* @param[in] RNG_context A Random Number Generator context used for any rndom generation needed by this session
*/
template <typename Curve>
DR<Curve>::DR(lime::Db *localStorage, long sessionId, std::shared_ptr<RNG> RNG_context)
DR<Curve>::DR(std::shared_ptr<lime::Db> localStorage, long sessionId, std::shared_ptr<RNG> RNG_context)
:m_DHr{},m_DHr_valid{true},m_DHs{},m_RK{},m_CKs{},m_CKr{},m_Ns(0),m_Nr(0),m_PN(0),m_sharedAD{},m_mkskipped{},
m_RNG{RNG_context},m_dbSessionId{sessionId},m_usedNr{0},m_usedDHid{0},m_localStorage{localStorage},m_dirty{DRSessionDbStatus::clean},m_peerDid{0},m_peerDeviceId{},m_peerIk{},m_db_Uid{0},
m_active_status{false}, m_X3DH_initMessage{}
......
......@@ -98,7 +98,7 @@ namespace lime {
long int m_dbSessionId; // used to store row id from Database Storage
uint16_t m_usedNr; // store the index of message key used for decryption if it came from mkskipped db
long m_usedDHid; // store the index of DHr message key used for decryption if it came from mkskipped db(not zero only if used)
lime::Db *m_localStorage; // enable access to the database holding sessions and skipped message keys, no need to use smart pointers here, Db is not owned by DRsession, it must persist even if no session exists
std::shared_ptr<lime::Db> m_localStorage; // enable access to the database holding sessions and skipped message keys
DRSessionDbStatus m_dirty; // status of the object regarding its instance in local storage, could be: clean, dirty_encrypt, dirty_decrypt or dirty
long int m_peerDid; // used during session creation only to hold the peer device id in DB as we need it to insert the session in local Storage
std::string m_peerDeviceId; // used during session creation only, if the deviceId is not yet in local storage, to hold the peer device Id so we can insert it in DB when session is saved for the first time
......@@ -117,9 +117,9 @@ namespace lime {
public:
DR() = delete; // make sure the Double Ratchet is not initialised without parameters
DR(lime::Db *localStorage, const DRChainKey &SK, const SharedADBuffer &AD, const X<Curve, lime::Xtype::publicKey> &peerPublicKey, const long int peerDid, const std::string &peerDeviceId, const DSA<Curve, lime::DSAtype::publicKey> &peerIk, long int selfDeviceId, const std::vector<uint8_t> &X3DH_initMessage, std::shared_ptr<RNG> RNG_context); // call to initialise a session for sender: we have Shared Key and peer Public key
DR(lime::Db *localStorage, const DRChainKey &SK, const SharedADBuffer &AD, const Xpair<Curve> &selfKeyPair, long int peerDid, const std::string &peerDeviceId, const DSA<Curve, lime::DSAtype::publicKey> &peerIk, long int selfDeviceId, std::shared_ptr<RNG> RNG_context); // call at initialisation of a session for receiver: we have Share Key and self key pair
DR(lime::Db *localStorage, long sessionId, std::shared_ptr<RNG> RNG_context); // load session from DB
DR(std::shared_ptr<lime::Db> localStorage, const DRChainKey &SK, const SharedADBuffer &AD, const X<Curve, lime::Xtype::publicKey> &peerPublicKey, const long int peerDid, const std::string &peerDeviceId, const DSA<Curve, lime::DSAtype::publicKey> &peerIk, long int selfDeviceId, const std::vector<uint8_t> &X3DH_initMessage, std::shared_ptr<RNG> RNG_context); // call to initialise a session for sender: we have Shared Key and peer Public key
DR(std::shared_ptr<lime::Db> localStorage, const DRChainKey &SK, const SharedADBuffer &AD, const Xpair<Curve> &selfKeyPair, long int peerDid, const std::string &peerDeviceId, const DSA<Curve, lime::DSAtype::publicKey> &peerIk, long int selfDeviceId, std::shared_ptr<RNG> RNG_context); // call at initialisation of a session for receiver: we have Share Key and self key pair
DR(std::shared_ptr<lime::Db> localStorage, long sessionId, std::shared_ptr<RNG> RNG_context); // load session from DB
DR(DR<Curve> &a) = delete; // can't copy a session, force usage of shared pointers
DR<Curve> &operator=(DR<Curve> &a) = delete; // can't copy a session
~DR();
......
......@@ -1170,7 +1170,7 @@ void Lime<Curve>::cache_DR_sessions(std::vector<RecipientInfos<Curve>> &internal
auto sessionId = r.get<int>(0);
auto peerDeviceId = r.get<std::string>(1);
auto DRsession = std::make_shared<DR<Curve>>(m_localStorage.get(), sessionId, m_RNG); // load session from local storage
auto DRsession = std::make_shared<DR<Curve>>(m_localStorage, sessionId, m_RNG); // load session from local storage
requestedDevices[peerDeviceId] = DRsession; // store found session in a our temp container
m_DR_sessions_cache[peerDeviceId] = DRsession; // session is also stored in cache
}
......@@ -1196,7 +1196,7 @@ void Lime<Curve>::get_DRSessions(const std::string &senderDeviceId, const long i
for (const auto &sessionId : rs) {
/* load session in cache DRSessions */
DRSessions.push_back(make_shared<DR<Curve>>(m_localStorage.get(), sessionId, m_RNG)); // load session from cache
DRSessions.push_back(make_shared<DR<Curve>>(m_localStorage, sessionId, m_RNG)); // load session from cache
}
};
......
......@@ -122,7 +122,7 @@ namespace lime {
m_DR_sessions_cache.erase(peerBundle.deviceId); // will just do nothing if this peerDeviceId is not in cache
}
m_DR_sessions_cache.emplace(peerBundle.deviceId, make_shared<DR<Curve>>(m_localStorage.get(), SK, AD, peerBundle.SPk, peerDid, peerBundle.deviceId, peerBundle.Ik, m_db_Uid, X3DH_initMessage, m_RNG)); // will just do nothing if this peerDeviceId is already in cache
m_DR_sessions_cache.emplace(peerBundle.deviceId, make_shared<DR<Curve>>(m_localStorage, SK, AD, peerBundle.SPk, peerDid, peerBundle.deviceId, peerBundle.Ik, m_db_Uid, X3DH_initMessage, m_RNG)); // will just do nothing if this peerDeviceId is already in cache
LIME_LOGI<<"X3DH created session with device "<<peerBundle.deviceId;
}
......@@ -211,7 +211,7 @@ namespace lime {
// check the new peer device Id in Storage, if it is not found, the DR session will add it when it saves itself after successful decryption
auto peerDid = m_localStorage->check_peerDevice(senderDeviceId, peerIk);
auto DRSession = make_shared<DR<Curve>>(m_localStorage.get(), SK, AD, SPk, peerDid, senderDeviceId, peerIk, m_db_Uid, m_RNG);
auto DRSession = make_shared<DR<Curve>>(m_localStorage, SK, AD, SPk, peerDid, senderDeviceId, peerIk, m_db_Uid, m_RNG);
return DRSession;
}
......
......@@ -214,8 +214,8 @@ void dr_sessionsInit(std::shared_ptr<DR<Curve>> &alice, std::shared_ptr<DR<Curve
// create DR sessions
std::vector<uint8_t> X3DH_initMessage{};
DSA<Curve, lime::DSAtype::publicKey> dummyPeerIk{}; // DR session creation gets the peerDeviceId and peerIk but uses it only if peerDid is 0, give dummy, we're focusing on DR here
alice = std::make_shared<DR<Curve>>(localStorageAlice.get(), SK, AD, bobKeyPair.publicKey(), aliceDid, "dummyPeerDevice", dummyPeerIk, aliceUid, X3DH_initMessage, RNG_context);
bob = std::make_shared<DR<Curve>>(localStorageBob.get(), SK, AD, bobKeyPair, bobDid, "dummyPeerDevice", dummyPeerIk, bobUid, RNG_context);
alice = std::make_shared<DR<Curve>>(localStorageAlice, SK, AD, bobKeyPair.publicKey(), aliceDid, "dummyPeerDevice", dummyPeerIk, aliceUid, X3DH_initMessage, RNG_context);
bob = std::make_shared<DR<Curve>>(localStorageBob, SK, AD, bobKeyPair, bobDid, "dummyPeerDevice", dummyPeerIk, bobUid, RNG_context);
}
......
......@@ -257,7 +257,7 @@ static void dr_long_exchange_test(uint8_t period=1, std::string db_filename="dr_
/* destroy and reload bob sessions */
auto bobSessionId=bob->dbSessionId();
bob = nullptr; // release and destroy bob DR context
bob = make_shared<DR<Curve>>(bobLocalStorage.get(), bobSessionId, RNG_context);
bob = make_shared<DR<Curve>>(bobLocalStorage, bobSessionId, RNG_context);
}
} else {
// bob replies
......@@ -281,7 +281,7 @@ static void dr_long_exchange_test(uint8_t period=1, std::string db_filename="dr_
/* destroy and reload alice sessions */
auto aliceSessionId=alice->dbSessionId();
alice = nullptr; // release and destroy alice DR context
alice = make_shared<DR<Curve>>(aliceLocalStorage.get(), aliceSessionId, RNG_context);
alice = make_shared<DR<Curve>>(aliceLocalStorage, aliceSessionId, RNG_context);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment