Skip to content

Commit ee9f3b8

Browse files
authored
Changing WebSocket Masking Key to use SecureRandom #255 (#259)
* Fixing typo in IMqttClient.java Signed-off-by: James Sutton <james.sutton@uk.ibm.com> * Issue #213 Signed-off-by: James Sutton <james.sutton@uk.ibm.com> * Issue #249: Null Check for reconnect timer & Connect options Signed-off-by: James Sutton <james.sutton@uk.ibm.com> * Changing WebSocket Masking Key to use SecureRandom Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
1 parent e717536 commit ee9f3b8

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

  • org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/websocket

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/websocket/WebSocketFrame.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.io.IOException;
1919
import java.io.InputStream;
2020
import java.nio.ByteBuffer;
21-
import java.util.Random;
21+
import java.security.SecureRandom;
2222

2323
public class WebSocketFrame {
2424

@@ -291,11 +291,11 @@ public static void appendFinAndOpCode(ByteBuffer buffer, byte opcode, boolean fi
291291
* @return ByteArray containing the key;
292292
*/
293293
public static byte[] generateMaskingKey(){
294-
Random randomGenerator = new Random();
295-
int a = randomGenerator.nextInt(255);
296-
int b = randomGenerator.nextInt(255);
297-
int c = randomGenerator.nextInt(255);
298-
int d = randomGenerator.nextInt(255);
294+
SecureRandom secureRandomGenerator = new SecureRandom();
295+
int a = secureRandomGenerator.nextInt(255);
296+
int b = secureRandomGenerator.nextInt(255);
297+
int c = secureRandomGenerator.nextInt(255);
298+
int d = secureRandomGenerator.nextInt(255);
299299
return new byte[] {(byte) a,(byte) b,(byte) c,(byte) d};
300300
}
301301

0 commit comments

Comments
 (0)