Chromium Code Reviews| Index: runtime/bin/websocket_impl.dart |
| diff --git a/runtime/bin/websocket_impl.dart b/runtime/bin/websocket_impl.dart |
| index cd53226174f094b79e99c08a669d0150ec72a3db..3801a91522eb2edc905b60c30bc396b82009009d 100644 |
| --- a/runtime/bin/websocket_impl.dart |
| +++ b/runtime/bin/websocket_impl.dart |
| @@ -455,6 +455,8 @@ class _WebSocketConnectionBase { |
| _closeSent = true; |
| } |
| + int hashCode() => _hash; |
| + |
| _onWebSocketMessageStart(int type) { |
| _currentMessageType = type; |
| if (_currentMessageType == _WebSocketMessageType.TEXT) { |
| @@ -546,6 +548,7 @@ class _WebSocketConnectionBase { |
| Socket _socket; |
| Timer _closeTimer; |
| + int _hash; |
| Function _onMessage; |
| Function _onClosed; |
| @@ -562,6 +565,7 @@ class _WebSocketConnectionBase { |
| class _WebSocketConnection |
| extends _WebSocketConnectionBase implements WebSocketConnection { |
| _WebSocketConnection(DetachedSocket detached) { |
| + _hash = detached.socket.hashCode(); |
| _socketConnected(detached.socket); |
| _startProcessing(detached.unparsedData); |
| } |
| @@ -635,6 +639,9 @@ class _WebSocketClientConnection |
| _conn.onRequest = _onHttpClientRequest; |
| _conn.onResponse = _onHttpClientResponse; |
| _conn.onError = (e) => _reportError(e); |
| + |
| + // Generate the nonce now as it is also used to set the hash code. |
|
Mads Ager (google)
2012/05/14 09:19:39
I don't actually know if it would be a security is
Søren Gjesse
2012/05/14 15:52:41
Done.
|
| + _generateNonceAndHash(); |
| } |
| void set onRequest(void callback(HttpClientRequest request)) { |
| @@ -654,7 +661,6 @@ class _WebSocketClientConnection |
| _onRequest(request); |
| } |
| // Setup the initial handshake. |
| - _generateNonce(); |
| request.headers.add(HttpHeaders.CONNECTION, "upgrade"); |
| request.headers.set(HttpHeaders.UPGRADE, "websocket"); |
| request.headers.set("Sec-WebSocket-Key", _nonce); |
| @@ -687,7 +693,7 @@ class _WebSocketClientConnection |
| _startProcessing(detached.unparsedData); |
| } |
| - void _generateNonce() { |
| + void _generateNonceAndHash() { |
| assert(_nonce == null); |
| void intToBigEndianBytes(int value, List<int> bytes, int offset) { |
| bytes[offset] = (value >> 24) & 0xFF; |
| @@ -696,13 +702,15 @@ class _WebSocketClientConnection |
| bytes[offset + 3] = value & 0xFF; |
| } |
| - // Generate 16 random bytes. |
| + // Generate 16 random bytes. Use the last four bytes for the hash code. |
| List<int> nonce = new List<int>(16); |
| + int r; |
| for (int i = 0; i < 4; i++) { |
| - int r = (Math.random() * 0x100000000).toInt(); |
| + r = (Math.random() * 0x100000000).toInt(); |
| intToBigEndianBytes(r, nonce, i * 4); |
| } |
| _nonce = _Base64._encode(nonce); |
| + _hash = r; |
| } |
| bool _isWebSocketUpgrade(HttpClientResponse response) { |