Skip to content

Commit 219044f

Browse files
authored
Merge pull request #19 from LiberalArtist/crypto-random-id-cookie
Uses crypto-random-bytes for make-secret-salt/file
2 parents 2d34fd2 + c7c67c9 commit 219044f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

web-server-doc/web-server/scribblings/http.scrbl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#lang scribble/doc
2-
@(require "web-server.rkt")
2+
@(require "web-server.rkt"
3+
(for-label racket/random
4+
))
35

46
@title[#:tag "http"]{HTTP: Hypertext Transfer Protocol}
57

@@ -329,7 +331,7 @@ is fully controlled by the user, and thus cannot be trusted.
329331
This module provides functions for creating and verifying
330332
authenticated cookies that are intrinsically timestamped. It is based
331333
on the algorithm proposed by the
332-
@link["http://cookies.lcs.mit.edu/"]{MIT Cookie Eaters}: if you store
334+
@link["https://pdos.csail.mit.edu/archive/cookies/"]{MIT Cookie Eaters}: if you store
333335
the data @racket[_data] at thime @racket[_authored-seconds], then the
334336
user will receive @litchar{digest&authored-seconds&data}, where
335337
@racket[_digest] is an HMAC-SHA1 digest of @racket[_authored-seconds]
@@ -343,8 +345,8 @@ to generate this is by using random bytes from something like OpenSSL
343345
or
344346
@tt{/dev/random}. @link["http://www.madboa.com/geek/openssl/#random-generate"]{This
345347
FAQ} lists a few options. A convenient purely Racket-based option is
346-
available (@racket[make-secret-salt/file]), but it will not have as
347-
good entropy, if you care about that sort of thing.
348+
available (@racket[make-secret-salt/file]),
349+
which is implemented using @racket[crypto-random-bytes].
348350

349351
@defproc[(make-id-cookie
350352
[name cookie-name?]

web-server-lib/web-server/http/id-cookie.rkt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
net/cookie
44
racket/match
55
racket/file
6+
racket/random
67
racket/contract
78
web-server/http
89
web-server/stuffers/hmac-sha1
@@ -21,8 +22,7 @@
2122
(unless (file-exists? secret-salt-path)
2223
(with-output-to-file secret-salt-path
2324
(λ ()
24-
(for ([i (in-range 128)])
25-
(write-byte (random 256))))))
25+
(write-bytes (crypto-random-bytes 128)))))
2626
(file->bytes secret-salt-path))
2727

2828
(define (id-cookie? name c)

0 commit comments

Comments
 (0)