Apparently I'm behind the times on this constructor

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-05-03 14:37:08 -07:00
parent 6fce69bbac
commit 54f25358eb
9 changed files with 26 additions and 46 deletions

View File

@ -38,12 +38,8 @@ public class AuthenticationCredentials {
}
public AuthenticationCredentials(String authenticationToken) {
try {
this.salt = Math.abs(SecureRandom.getInstance("SHA1PRNG").nextInt()) + "";
this.hashedAuthenticationToken = getHashedValue(salt, authenticationToken);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
this.salt = Math.abs(new SecureRandom().nextInt()) + "";
this.hashedAuthenticationToken = getHashedValue(salt, authenticationToken);
}
public String getHashedAuthenticationToken() {

View File

@ -25,7 +25,7 @@ public class TurnTokenGenerator {
try {
Mac mac = Mac.getInstance("HmacSHA1");
long validUntilSeconds = (System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1)) / 1000;
long user = Math.abs(SecureRandom.getInstance("SHA1PRNG").nextInt());
long user = Math.abs(new SecureRandom().nextInt());
String userTime = validUntilSeconds + ":" + user;
mac.init(new SecretKeySpec(key, "HmacSHA1"));

View File

@ -360,16 +360,12 @@ public class AccountController {
}
@VisibleForTesting protected VerificationCode generateVerificationCode(String number) {
try {
if (testDevices.containsKey(number)) {
return new VerificationCode(testDevices.get(number));
}
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
int randomInt = 100000 + random.nextInt(900000);
return new VerificationCode(randomInt);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
if (testDevices.containsKey(number)) {
return new VerificationCode(testDevices.get(number));
}
SecureRandom random = new SecureRandom();
int randomInt = 100000 + random.nextInt(900000);
return new VerificationCode(randomInt);
}
}

View File

@ -103,14 +103,10 @@ public class AttachmentController {
}
private long generateAttachmentId() {
try {
byte[] attachmentBytes = new byte[8];
SecureRandom.getInstance("SHA1PRNG").nextBytes(attachmentBytes);
byte[] attachmentBytes = new byte[8];
new SecureRandom().nextBytes(attachmentBytes);
attachmentBytes[0] = (byte)(attachmentBytes[0] & 0x7F);
return Conversions.byteArrayToLong(attachmentBytes);
} catch (NoSuchAlgorithmException nsae) {
throw new AssertionError(nsae);
}
attachmentBytes[0] = (byte)(attachmentBytes[0] & 0x7F);
return Conversions.byteArrayToLong(attachmentBytes);
}
}

View File

@ -205,12 +205,8 @@ public class DeviceController {
}
@VisibleForTesting protected VerificationCode generateVerificationCode() {
try {
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
int randomInt = 100000 + random.nextInt(900000);
return new VerificationCode(randomInt);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
SecureRandom random = new SecureRandom();
int randomInt = 100000 + random.nextInt(900000);
return new VerificationCode(randomInt);
}
}

View File

@ -222,7 +222,7 @@ public class FederatedClient {
trustManagerFactory.init(initializeTrustStore(peer.getName(), peer.getCertificate()));
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagerFactory.getTrustManagers(), SecureRandom.getInstance("SHA1PRNG"));
sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, new DefaultHostnameVerifier());
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", sslConnectionSocketFactory).build();

View File

@ -22,11 +22,11 @@ public class ProvisioningAddress extends WebsocketAddress {
public static ProvisioningAddress generate() {
try {
byte[] random = new byte[16];
SecureRandom.getInstance("SHA1PRNG").nextBytes(random);
new SecureRandom().nextBytes(random);
return new ProvisioningAddress(Base64.encodeBytesWithoutPadding(random)
.replace('+', '-').replace('/', '_'), 0);
} catch (NoSuchAlgorithmException | InvalidWebsocketAddressException e) {
} catch (InvalidWebsocketAddressException e) {
throw new AssertionError(e);
}
}

View File

@ -86,7 +86,7 @@ public class DeleteUserCommand extends EnvironmentCommand<WhisperServerConfigura
if (device.isPresent()) {
byte[] random = new byte[16];
SecureRandom.getInstance("SHA1PRNG").nextBytes(random);
new SecureRandom().nextBytes(random);
device.get().setGcmId(null);
device.get().setFetchesMessages(false);

View File

@ -244,18 +244,14 @@ public class PubSubConnectionTest {
}
public int read(byte[] input, int offset, int length) {
try {
int maxCopy = Math.min(data.length - index, length);
int randomCopy = SecureRandom.getInstance("SHA1PRNG").nextInt(maxCopy) + 1;
int copyAmount = Math.min(maxCopy, randomCopy);
int maxCopy = Math.min(data.length - index, length);
int randomCopy = new SecureRandom().nextInt(maxCopy) + 1;
int copyAmount = Math.min(maxCopy, randomCopy);
System.arraycopy(data, index, input, offset, copyAmount);
index += copyAmount;
System.arraycopy(data, index, input, offset, copyAmount);
index += copyAmount;
return copyAmount;
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
return copyAmount;
}
}