Search in sources :

Example 1 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class SessionUtil method hasSession.

public static boolean hasSession(Context context, MasterSecret masterSecret, @NonNull String number) {
    SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
    SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(number, SignalServiceAddress.DEFAULT_DEVICE_ID);
    return sessionStore.containsSession(axolotlAddress);
}
Also used : TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 2 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class TextSecureSessionStore method migrateSessions.

public void migrateSessions() {
    synchronized (FILE_LOCK) {
        File directory = getSessionDirectory();
        for (File session : directory.listFiles()) {
            if (session.isFile()) {
                SignalProtocolAddress address = getAddressName(session);
                if (address != null) {
                    SessionRecord sessionRecord = loadSession(address);
                    storeSession(address, sessionRecord);
                }
            }
        }
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) SessionRecord(org.whispersystems.libsignal.state.SessionRecord)

Example 3 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by WhisperSystems.

the class TextSecureSessionStore method deleteAllSessions.

@Override
public void deleteAllSessions(String name) {
    List<Integer> devices = getSubDeviceSessions(name);
    deleteSession(new SignalProtocolAddress(name, SignalServiceAddress.DEFAULT_DEVICE_ID));
    for (int device : devices) {
        deleteSession(new SignalProtocolAddress(name, device));
    }
}
Also used : SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 4 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by signalapp.

the class SessionUtil method hasSession.

public static boolean hasSession(Context context, @NonNull Address address) {
    SessionStore sessionStore = new TextSecureSessionStore(context);
    SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(address.serialize(), SignalServiceAddress.DEFAULT_DEVICE_ID);
    return sessionStore.containsSession(axolotlAddress);
}
Also used : TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 5 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by signalapp.

the class TextSecureIdentityKeyStore method saveIdentity.

public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey, boolean nonBlockingApproval) {
    synchronized (LOCK) {
        IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
        Address signalAddress = Address.fromExternal(context, address.getName());
        Optional<IdentityRecord> identityRecord = identityDatabase.getIdentity(signalAddress);
        if (!identityRecord.isPresent()) {
            Log.w(TAG, "Saving new identity...");
            identityDatabase.saveIdentity(signalAddress, identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval);
            return false;
        }
        if (!identityRecord.get().getIdentityKey().equals(identityKey)) {
            Log.w(TAG, "Replacing existing identity...");
            VerifiedStatus verifiedStatus;
            if (identityRecord.get().getVerifiedStatus() == VerifiedStatus.VERIFIED || identityRecord.get().getVerifiedStatus() == VerifiedStatus.UNVERIFIED) {
                verifiedStatus = VerifiedStatus.UNVERIFIED;
            } else {
                verifiedStatus = VerifiedStatus.DEFAULT;
            }
            identityDatabase.saveIdentity(signalAddress, identityKey, verifiedStatus, false, System.currentTimeMillis(), nonBlockingApproval);
            IdentityUtil.markIdentityUpdate(context, Recipient.from(context, signalAddress, true));
            SessionUtil.archiveSiblingSessions(context, address);
            return true;
        }
        if (isNonBlockingApprovalRequired(identityRecord.get())) {
            Log.w(TAG, "Setting approval status...");
            identityDatabase.setApproval(signalAddress, nonBlockingApproval);
            return false;
        }
        return false;
    }
}
Also used : IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) VerifiedStatus(org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus) Address(org.thoughtcrime.securesms.database.Address) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) IdentityRecord(org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord)

Aggregations

SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)57 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)7 HashMap (java.util.HashMap)6 Recipient (org.thoughtcrime.securesms.recipients.Recipient)6 IdentityKey (org.whispersystems.libsignal.IdentityKey)6 IOException (java.io.IOException)5 SessionBuilder (org.whispersystems.libsignal.SessionBuilder)5 SessionRecord (org.whispersystems.libsignal.state.SessionRecord)5 Optional (org.whispersystems.libsignal.util.guava.Optional)5 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)5 File (java.io.File)4 List (java.util.List)4 Map (java.util.Map)4 SessionStore (org.whispersystems.libsignal.state.SessionStore)4 DistributionId (org.whispersystems.signalservice.api.push.DistributionId)4 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)4 ByteString (com.google.protobuf.ByteString)3