-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
Allow random to be passed in and can default to a weak pseudo random.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,6 @@ | |
|
||
package org.eclipse.jetty.plus.webapp; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.Random; | ||
import javax.naming.Context; | ||
import javax.naming.InitialContext; | ||
import javax.naming.NameNotFoundException; | ||
|
@@ -40,7 +38,6 @@ | |
public class PlusConfiguration extends AbstractConfiguration | ||
{ | ||
private static final Logger LOG = Log.getLogger(PlusConfiguration.class); | ||
private static final Random __random = new SecureRandom(); | ||
This comment has been minimized.
Sorry, something went wrong.
joakime
Contributor
|
||
|
||
private Integer _key; | ||
|
||
|
@@ -101,7 +98,7 @@ protected void lockCompEnv(WebAppContext wac) | |
{ | ||
try (ThreadClassLoaderScope scope = new ThreadClassLoaderScope(wac.getClassLoader())) | ||
{ | ||
_key = __random.nextInt(); | ||
_key = (int)(this.hashCode() ^ System.nanoTime()); | ||
Context context = new InitialContext(); | ||
Context compCtx = (Context)context.lookup("java:comp"); | ||
compCtx.addToEnvironment(NamingContext.LOCK_PROPERTY, _key); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
|
||
package org.eclipse.jetty.websocket.client.masks; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.Random; | ||
|
||
import org.eclipse.jetty.websocket.common.WebSocketFrame; | ||
|
@@ -29,7 +28,7 @@ public class RandomMasker implements Masker | |
|
||
public RandomMasker() | ||
{ | ||
this(new SecureRandom()); | ||
this(null); | ||
} | ||
|
||
public RandomMasker(Random random) | ||
|
@@ -40,8 +39,27 @@ public RandomMasker(Random random) | |
@Override | ||
public void setMask(WebSocketFrame frame) | ||
{ | ||
byte[] mask = new byte[4]; | ||
random.nextBytes(mask); | ||
byte[] mask; | ||
if (random != null) | ||
{ | ||
mask = new byte[4]; | ||
random.nextBytes(mask); | ||
} | ||
else | ||
{ | ||
// This is a weak random, but sufficient for a mask. | ||
// Using a SecureRandom would result in lock contention | ||
// Using a Random is as more predictable than this algorithm | ||
// Using a onetime random is essentially a system time. | ||
int pseudoRandom = (int)(System.identityHashCode(frame.hashCode()) ^ System.nanoTime()); | ||
mask = new byte[] | ||
{ | ||
(byte)pseudoRandom, | ||
(byte)(pseudoRandom >> 8), | ||
(byte)(pseudoRandom >> 16), | ||
(byte)(pseudoRandom >> 24), | ||
}; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
joakime
Contributor
|
||
frame.setMask(mask); | ||
} | ||
} |
This pseudo random isn't sufficient for client multipart boundary.
See similar discussion at firefox about this as well ...
In short, it needs to be using SecureRandom (like it was before).
The only change this file needs is to remove the
static
from (the left-hand) line 73