mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 02:53:50 +00:00
Simplify access to SecureRandom
This shouldn't matter at all, but it's more "correct," and shows my age less.
This commit is contained in:
parent
8aa185070b
commit
a52c295a38
@ -879,24 +879,20 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleInviteLink() {
|
private void handleInviteLink() {
|
||||||
try {
|
String inviteText;
|
||||||
String inviteText;
|
|
||||||
|
|
||||||
boolean a = SecureRandom.getInstance("SHA1PRNG").nextBoolean();
|
boolean a = new SecureRandom().nextBoolean();
|
||||||
if (a) inviteText = getString(R.string.ConversationActivity_lets_switch_to_signal, "https://sgnl.link/1LoIMUl");
|
if (a) inviteText = getString(R.string.ConversationActivity_lets_switch_to_signal, "https://sgnl.link/1LoIMUl");
|
||||||
else inviteText = getString(R.string.ConversationActivity_lets_use_this_to_chat, "https://sgnl.link/1MF56H1");
|
else inviteText = getString(R.string.ConversationActivity_lets_use_this_to_chat, "https://sgnl.link/1MF56H1");
|
||||||
|
|
||||||
if (isDefaultSms) {
|
if (isDefaultSms) {
|
||||||
composeText.appendInvite(inviteText);
|
composeText.appendInvite(inviteText);
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(Intent.ACTION_SENDTO);
|
Intent intent = new Intent(Intent.ACTION_SENDTO);
|
||||||
intent.setData(Uri.parse("smsto:" + recipient.getAddress().serialize()));
|
intent.setData(Uri.parse("smsto:" + recipient.getAddress().serialize()));
|
||||||
intent.putExtra("sms_body", inviteText);
|
intent.putExtra("sms_body", inviteText);
|
||||||
intent.putExtra(Intent.EXTRA_TEXT, inviteText);
|
intent.putExtra(Intent.EXTRA_TEXT, inviteText);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,8 +264,8 @@ public class MasterSecretUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] generateSalt() throws NoSuchAlgorithmException {
|
private static byte[] generateSalt() {
|
||||||
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
|
SecureRandom random = new SecureRandom();
|
||||||
byte[] salt = new byte[16];
|
byte[] salt = new byte[16];
|
||||||
random.nextBytes(salt);
|
random.nextBytes(salt);
|
||||||
|
|
||||||
|
@ -308,13 +308,9 @@ public class GroupDatabase extends Database {
|
|||||||
|
|
||||||
|
|
||||||
public byte[] allocateGroupId() {
|
public byte[] allocateGroupId() {
|
||||||
try {
|
byte[] groupId = new byte[16];
|
||||||
byte[] groupId = new byte[16];
|
new SecureRandom().nextBytes(groupId);
|
||||||
SecureRandom.getInstance("SHA1PRNG").nextBytes(groupId);
|
return groupId;
|
||||||
return groupId;
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Reader implements Closeable {
|
public static class Reader implements Closeable {
|
||||||
|
@ -71,7 +71,6 @@ import org.whispersystems.libsignal.util.guava.Optional;
|
|||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -1279,13 +1278,9 @@ public class MmsDatabase extends MessagingDatabase {
|
|||||||
private final long threadId;
|
private final long threadId;
|
||||||
|
|
||||||
public OutgoingMessageReader(OutgoingMediaMessage message, long threadId) {
|
public OutgoingMessageReader(OutgoingMediaMessage message, long threadId) {
|
||||||
try {
|
this.message = message;
|
||||||
this.message = message;
|
this.id = new SecureRandom().nextLong();
|
||||||
this.id = SecureRandom.getInstance("SHA1PRNG").nextLong();
|
this.threadId = threadId;
|
||||||
this.threadId = threadId;
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageRecord getCurrent() {
|
public MessageRecord getCurrent() {
|
||||||
|
@ -47,7 +47,6 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -818,13 +817,9 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
private final long threadId;
|
private final long threadId;
|
||||||
|
|
||||||
public OutgoingMessageReader(OutgoingTextMessage message, long threadId) {
|
public OutgoingMessageReader(OutgoingTextMessage message, long threadId) {
|
||||||
try {
|
this.message = message;
|
||||||
this.message = message;
|
this.threadId = threadId;
|
||||||
this.threadId = threadId;
|
this.id = new SecureRandom().nextLong();
|
||||||
this.id = SecureRandom.getInstance("SHA1PRNG").nextLong();
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageRecord getCurrent() {
|
public MessageRecord getCurrent() {
|
||||||
|
@ -144,24 +144,20 @@ public abstract class Slide {
|
|||||||
boolean voiceNote,
|
boolean voiceNote,
|
||||||
boolean quote)
|
boolean quote)
|
||||||
{
|
{
|
||||||
try {
|
String resolvedType = Optional.fromNullable(MediaUtil.getMimeType(context, uri)).or(defaultMime);
|
||||||
String resolvedType = Optional.fromNullable(MediaUtil.getMimeType(context, uri)).or(defaultMime);
|
String fastPreflightId = String.valueOf(new SecureRandom().nextLong());
|
||||||
String fastPreflightId = String.valueOf(SecureRandom.getInstance("SHA1PRNG").nextLong());
|
return new UriAttachment(uri,
|
||||||
return new UriAttachment(uri,
|
hasThumbnail ? uri : null,
|
||||||
hasThumbnail ? uri : null,
|
resolvedType,
|
||||||
resolvedType,
|
AttachmentDatabase.TRANSFER_PROGRESS_STARTED,
|
||||||
AttachmentDatabase.TRANSFER_PROGRESS_STARTED,
|
size,
|
||||||
size,
|
width,
|
||||||
width,
|
height,
|
||||||
height,
|
fileName,
|
||||||
fileName,
|
fastPreflightId,
|
||||||
fastPreflightId,
|
voiceNote,
|
||||||
voiceNote,
|
quote,
|
||||||
quote,
|
caption);
|
||||||
caption);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -415,72 +415,68 @@ public class WebRtcCallService extends Service implements InjectableType,
|
|||||||
|
|
||||||
if (callState != CallState.STATE_IDLE) throw new IllegalStateException("Dialing from non-idle?");
|
if (callState != CallState.STATE_IDLE) throw new IllegalStateException("Dialing from non-idle?");
|
||||||
|
|
||||||
try {
|
this.callState = CallState.STATE_DIALING;
|
||||||
this.callState = CallState.STATE_DIALING;
|
this.recipient = getRemoteRecipient(intent);
|
||||||
this.recipient = getRemoteRecipient(intent);
|
this.callId = new SecureRandom().nextLong();
|
||||||
this.callId = SecureRandom.getInstance("SHA1PRNG").nextLong();
|
this.pendingOutgoingIceUpdates = new LinkedList<>();
|
||||||
this.pendingOutgoingIceUpdates = new LinkedList<>();
|
|
||||||
|
|
||||||
initializeVideo();
|
initializeVideo();
|
||||||
|
|
||||||
sendMessage(WebRtcViewModel.State.CALL_OUTGOING, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
sendMessage(WebRtcViewModel.State.CALL_OUTGOING, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
||||||
lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
|
lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
|
||||||
audioManager.initializeAudioForCall();
|
audioManager.initializeAudioForCall();
|
||||||
audioManager.startOutgoingRinger(OutgoingRinger.Type.RINGING);
|
audioManager.startOutgoingRinger(OutgoingRinger.Type.RINGING);
|
||||||
bluetoothStateManager.setWantsConnection(true);
|
bluetoothStateManager.setWantsConnection(true);
|
||||||
|
|
||||||
setCallInProgressNotification(TYPE_OUTGOING_RINGING, recipient);
|
setCallInProgressNotification(TYPE_OUTGOING_RINGING, recipient);
|
||||||
DatabaseFactory.getSmsDatabase(this).insertOutgoingCall(recipient.getAddress());
|
DatabaseFactory.getSmsDatabase(this).insertOutgoingCall(recipient.getAddress());
|
||||||
|
|
||||||
timeoutExecutor.schedule(new TimeoutRunnable(this.callId), 2, TimeUnit.MINUTES);
|
timeoutExecutor.schedule(new TimeoutRunnable(this.callId), 2, TimeUnit.MINUTES);
|
||||||
|
|
||||||
retrieveTurnServers().addListener(new SuccessOnlyListener<List<PeerConnection.IceServer>>(this.callState, this.callId) {
|
retrieveTurnServers().addListener(new SuccessOnlyListener<List<PeerConnection.IceServer>>(this.callState, this.callId) {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccessContinue(List<PeerConnection.IceServer> result) {
|
public void onSuccessContinue(List<PeerConnection.IceServer> result) {
|
||||||
try {
|
try {
|
||||||
boolean isAlwaysTurn = TextSecurePreferences.isTurnOnly(WebRtcCallService.this);
|
boolean isAlwaysTurn = TextSecurePreferences.isTurnOnly(WebRtcCallService.this);
|
||||||
|
|
||||||
WebRtcCallService.this.peerConnection = new PeerConnectionWrapper(WebRtcCallService.this, peerConnectionFactory, WebRtcCallService.this, localRenderer, result, WebRtcCallService.this, eglBase, isAlwaysTurn);
|
WebRtcCallService.this.peerConnection = new PeerConnectionWrapper(WebRtcCallService.this, peerConnectionFactory, WebRtcCallService.this, localRenderer, result, WebRtcCallService.this, eglBase, isAlwaysTurn);
|
||||||
WebRtcCallService.this.localCameraState = WebRtcCallService.this.peerConnection.getCameraState();
|
WebRtcCallService.this.localCameraState = WebRtcCallService.this.peerConnection.getCameraState();
|
||||||
WebRtcCallService.this.dataChannel = WebRtcCallService.this.peerConnection.createDataChannel(DATA_CHANNEL_NAME);
|
WebRtcCallService.this.dataChannel = WebRtcCallService.this.peerConnection.createDataChannel(DATA_CHANNEL_NAME);
|
||||||
WebRtcCallService.this.dataChannel.registerObserver(WebRtcCallService.this);
|
WebRtcCallService.this.dataChannel.registerObserver(WebRtcCallService.this);
|
||||||
|
|
||||||
SessionDescription sdp = WebRtcCallService.this.peerConnection.createOffer(new MediaConstraints());
|
SessionDescription sdp = WebRtcCallService.this.peerConnection.createOffer(new MediaConstraints());
|
||||||
WebRtcCallService.this.peerConnection.setLocalDescription(sdp);
|
WebRtcCallService.this.peerConnection.setLocalDescription(sdp);
|
||||||
|
|
||||||
Log.i(TAG, "Sending offer: " + sdp.description);
|
Log.i(TAG, "Sending offer: " + sdp.description);
|
||||||
|
|
||||||
ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forOffer(new OfferMessage(WebRtcCallService.this.callId, sdp.description)));
|
ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forOffer(new OfferMessage(WebRtcCallService.this.callId, sdp.description)));
|
||||||
|
|
||||||
listenableFutureTask.addListener(new FailureListener<Boolean>(callState, callId) {
|
listenableFutureTask.addListener(new FailureListener<Boolean>(callState, callId) {
|
||||||
@Override
|
@Override
|
||||||
public void onFailureContinue(Throwable error) {
|
public void onFailureContinue(Throwable error) {
|
||||||
Log.w(TAG, error);
|
Log.w(TAG, error);
|
||||||
|
|
||||||
if (error instanceof UntrustedIdentityException) {
|
if (error instanceof UntrustedIdentityException) {
|
||||||
sendMessage(WebRtcViewModel.State.UNTRUSTED_IDENTITY, recipient, ((UntrustedIdentityException)error).getIdentityKey(), localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
sendMessage(WebRtcViewModel.State.UNTRUSTED_IDENTITY, recipient, ((UntrustedIdentityException)error).getIdentityKey(), localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
||||||
} else if (error instanceof UnregisteredUserException) {
|
} else if (error instanceof UnregisteredUserException) {
|
||||||
sendMessage(WebRtcViewModel.State.NO_SUCH_USER, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
sendMessage(WebRtcViewModel.State.NO_SUCH_USER, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
||||||
} else if (error instanceof IOException) {
|
} else if (error instanceof IOException) {
|
||||||
sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
||||||
}
|
|
||||||
|
|
||||||
terminate();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (recipient != null) {
|
terminate();
|
||||||
sendMessage(viewModelStateFor(callState), recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
|
||||||
}
|
}
|
||||||
} catch (PeerConnectionException e) {
|
});
|
||||||
Log.w(TAG, e);
|
|
||||||
terminate();
|
if (recipient != null) {
|
||||||
|
sendMessage(viewModelStateFor(callState), recipient, localCameraState, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
|
||||||
}
|
}
|
||||||
|
} catch (PeerConnectionException e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
|
terminate();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} catch (NoSuchAlgorithmException e) {
|
});
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleResponseMessage(Intent intent) {
|
private void handleResponseMessage(Intent intent) {
|
||||||
|
@ -456,11 +456,7 @@ public class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T getRandomElement(T[] elements) {
|
public static <T> T getRandomElement(T[] elements) {
|
||||||
try {
|
return elements[new SecureRandom().nextInt(elements.length)];
|
||||||
return elements[SecureRandom.getInstance("SHA1PRNG").nextInt(elements.length)];
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean equals(@Nullable Object a, @Nullable Object b) {
|
public static boolean equals(@Nullable Object a, @Nullable Object b) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user