|
22 | 22 | 'use strict'; /* eslint no-underscore-dangle: 0 */ |
23 | 23 | // Our equivalent of '_debugger' in node itthis |
24 | 24 | const assert = require('assert'); |
25 | | -// const crypto = require('crypto'); |
| 25 | +const crypto = require('crypto'); |
26 | 26 | const events = require('events'); |
27 | 27 | const http = require('http'); |
28 | 28 | const Repl = require('repl'); |
@@ -59,51 +59,6 @@ exports.port = process.debugPort; |
59 | 59 |
|
60 | 60 | function ignoreError() {} |
61 | 61 |
|
62 | | -// Generate a Sec-WebSocket-* value |
63 | | -function createSecretKey() { |
64 | | - // How many spaces will we be inserting? |
65 | | - var numSpaces = 1 + Math.floor(Math.random() * 12); |
66 | | - assert.ok(1 <= numSpaces && numSpaces <= 12); |
67 | | - |
68 | | - // What is the numerical value of our key? |
69 | | - var keyVal = (Math.floor( |
70 | | - Math.random() * (4294967295 / numSpaces) |
71 | | - ) * numSpaces); |
72 | | - |
73 | | - // Our string starts with a string representation of our key |
74 | | - var s = keyVal.toString(); |
75 | | - |
76 | | - // Insert 'numChars' worth of noise in the character ranges |
77 | | - // [0x21, 0x2f] (14 characters) and [0x3a, 0x7e] (68 characters) |
78 | | - var numChars = 1 + Math.floor(Math.random() * 12); |
79 | | - assert.ok(1 <= numChars && numChars <= 12); |
80 | | - |
81 | | - for (var i = 0; i < numChars; i++) { |
82 | | - var pos = Math.floor(Math.random() * s.length + 1); |
83 | | - |
84 | | - var c = Math.floor(Math.random() * (14 + 68)); |
85 | | - c = (c <= 14) ? |
86 | | - String.fromCharCode(c + 0x21) : |
87 | | - String.fromCharCode((c - 14) + 0x3a); |
88 | | - |
89 | | - s = s.substring(0, pos) + c + s.substring(pos, s.length); |
90 | | - } |
91 | | - |
92 | | - // We shoudln't have any spaces in our value until we insert them |
93 | | - assert.equal(s.indexOf(' '), -1); |
94 | | - |
95 | | - // Insert 'numSpaces' worth of spaces |
96 | | - for (var i = 0; i < numSpaces; i++) { |
97 | | - var pos = Math.floor(Math.random() * (s.length - 1)) + 1; |
98 | | - s = s.substring(0, pos) + ' ' + s.substring(pos, s.length); |
99 | | - } |
100 | | - |
101 | | - assert.notEqual(s.charAt(0), ' '); |
102 | | - assert.notEqual(s.charAt(s.length), ' '); |
103 | | - |
104 | | - return s; |
105 | | -} |
106 | | - |
107 | 62 | function encodeFrameHybi17(payload) { |
108 | 63 | const dataLength = payload.length; |
109 | 64 |
|
@@ -295,7 +250,7 @@ class Client extends events.EventEmitter { |
295 | 250 | } |
296 | 251 |
|
297 | 252 | connect(port, host) { |
298 | | - const key1 = createSecretKey(); |
| 253 | + const key1 = crypto.randomBytes(16).toString('base64'); |
299 | 254 |
|
300 | 255 | const httpReq = this._http = http.request({ |
301 | 256 | host, port, |
|
0 commit comments