Search in sources :

Example 1 with RatchetPrivateKey

use of im.actor.runtime.crypto.ratchet.RatchetPrivateKey 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)

Aggregations

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