use of im.actor.core.entity.encryption.PeerSessionsStorage in project actor-platform by actorapp.
the class SessionManagerActor method spawnSession.
/**
* Spawn new session
*
* @param uid user's id
* @param ownKeyGroup own key group id
* @param theirKeyGroup their key group Id
* @param ownIdentity own identity private key
* @param theirIdentity their identity public key
* @param ownPreKey own pre key
* @param theirPreKey their pre key
* @return spawned session
*/
private PeerSession spawnSession(int uid, int ownKeyGroup, int theirKeyGroup, PrivateKey ownIdentity, PublicKey theirIdentity, PrivateKey ownPreKey, PublicKey theirPreKey) {
//
// Calculating Master Secret
//
byte[] masterSecret = RatchetMasterSecret.calculateMasterSecret(new RatchetPrivateKey(ownIdentity.getKey()), new RatchetPrivateKey(ownPreKey.getKey()), new RatchetPublicKey(theirIdentity.getPublicKey()), new RatchetPublicKey(theirPreKey.getPublicKey()));
//
// Building Session
//
PeerSession peerSession = new PeerSession(RandomUtils.nextRid(), uid, ownKeyGroup, theirKeyGroup, ownPreKey.getKeyId(), theirPreKey.getKeyId(), masterSecret);
//
// Saving session in sessions storage
//
PeerSessionsStorage sessionsStorage = peerSessions.getValue(uid);
if (sessionsStorage == null) {
sessionsStorage = new PeerSessionsStorage(uid, new ArrayList<PeerSession>());
}
sessionsStorage = sessionsStorage.addSession(peerSession);
peerSessions.addOrUpdateItem(sessionsStorage);
return peerSession;
}
use of im.actor.core.entity.encryption.PeerSessionsStorage in project actor-platform by actorapp.
the class SessionManagerActor method preStart.
@Override
public void preStart() {
super.preStart();
keyManager = context().getEncryption().getKeyManagerInt();
peerSessions = new BaseKeyValueEngine<PeerSessionsStorage>(Storage.createKeyValue("encryption_sessions")) {
@Override
protected byte[] serialize(PeerSessionsStorage value) {
return value.toByteArray();
}
@Override
protected PeerSessionsStorage deserialize(byte[] data) {
try {
return new PeerSessionsStorage(data);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
};
}
Aggregations