Skip to content

Commit

Permalink
Supply some entropy in /info url
Browse files Browse the repository at this point in the history
  • Loading branch information
majek committed Jan 17, 2012
1 parent 584152e commit a0f2d84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -6,7 +6,8 @@
"url": "https://github.com/sockjs/sockjs-node.git"},
"dependencies": {
"node-uuid": "1.2.0",
"faye-websocket": "0.3.x"
"faye-websocket": "0.3.x",
"rbytes": "0.0.2"
},
"devDependencies": {
"coffee-script": "1.1.1"
Expand Down
1 change: 1 addition & 0 deletions src/chunking-test.coffee
Expand Up @@ -29,6 +29,7 @@ exports.app =
websocket: @options.disabled_transports.indexOf('websocket') is -1,
origins: @options.origins,
cookie_needed: not not @options.jsessionid,
entropy: utils.random32(),
}
res.setHeader('Content-Type', 'application/json; charset=UTF-8')
res.writeHead(200)
Expand Down
16 changes: 16 additions & 0 deletions src/utils.coffee
@@ -1,5 +1,10 @@
crypto = require('crypto')

try
rbytes = require('rbytes')
catch x
null

exports.array_intersection = array_intersection = (arr_a, arr_b) ->
r = []
for a in arr_a
Expand Down Expand Up @@ -121,3 +126,14 @@ exports.parseCookie = (cookie_header) ->
parts = cookie.split('=')
cookies[ parts[0].trim() ] = ( parts[1] || '' ).trim()
return cookies

exports.random32 = () ->
if rbytes
x = rbytes.randomBytes(4)
v = [x[0], x[1], x[2], x[3]]
else
foo = -> Math.floor(Math.random()*256)
v = [foo(), foo(), foo(), foo()]

x = v[0] + (v[1]*256 ) + (v[2]*256*256) + (v[3]*256*256*256)
return x

0 comments on commit a0f2d84

Please sign in to comment.