Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
It looks like the author copied the idea from Apache::Session::Generate::MD5.

Perhaps the idea, but neither algorithm nor source. Apache::Session::Generate::MD5 uses substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, $length), with $length initialised to 32. It has the same problems with time(), $$, and rand(). Due to the use of the concat operator, rand() returns a string, where most of the bits are constant (0-9 differ only in the last four bits), but it returns a lot more bits. This difference should not really matter for MD5 hashing, rand() will give about 2RANDBITS different values, perhaps only 2RANDBITS-1 due to runding. (Ab-)using the address of an anonymous reference as another entropy source is a nice idea, but how does perl (and the OS) randomize the address? Running perl -e 'print "".{}' on my Strawberry installation returns ZERO random bits, the value is constantly HASH(0x3f9b9c). On Slackware 13.0, I see differnt values, perl -e 'system $^X,-E=>q[say "".{}] for 1..1000'|sort -u|wc -l gives 936. Not too bad. But from where comes the entropy used to randomize the address? From the same source used for rand()? That would be pretty bad.

Because md5_hex() always returns 32 chars, substr is pretty useless. But the surrounding code may reduce $length, making colliding IDs more probably.

CGI::Session::ID::uuid appears to use better algorithms.

At least, there are short comments in the code about the external UUID generators used. Too bad they aren't shown in the documentation.

Using time-based UUIDs (v1 and v2) gives a new, unique ID every 100 ns, that should be sufficient for a session ID. <update>Of course, most bits of those UUIDs can be guessed by an attacker, so using them directly as a session ID would be a bad idea.</update> The other UUID variants are either constant (name-based, v3 and v5) or depend on a random number generator (v4). When that generator is a pseudo-random number generator, the quality of the UUID depends on the quality of the pseudo-random number generator implementation.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^6: Randomness encountered with CGI Session by afoken
in thread Randomness encountered with CGI Session by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-19 02:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found