Search in sources :

Example 1 with PeerSessionsStorage

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;
}
Also used : PeerSession(im.actor.core.entity.encryption.PeerSession) RatchetPrivateKey(im.actor.runtime.crypto.ratchet.RatchetPrivateKey) ArrayList(java.util.ArrayList) RatchetPublicKey(im.actor.runtime.crypto.ratchet.RatchetPublicKey) PeerSessionsStorage(im.actor.core.entity.encryption.PeerSessionsStorage)

Example 2 with PeerSessionsStorage

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;
            }
        }
    };
}
Also used : IOException(java.io.IOException) PeerSessionsStorage(im.actor.core.entity.encryption.PeerSessionsStorage)

Aggregations

PeerSessionsStorage (im.actor.core.entity.encryption.PeerSessionsStorage)2 PeerSession (im.actor.core.entity.encryption.PeerSession)1 RatchetPrivateKey (im.actor.runtime.crypto.ratchet.RatchetPrivateKey)1 RatchetPublicKey (im.actor.runtime.crypto.ratchet.RatchetPublicKey)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1