| 1 | ############################################################################# | ||
| 2 | # | ||
| 3 | # Apache::Session::Generate::DBMS; | ||
| 4 | # Generates session identifier tokens using MD5 and validate them using | ||
| 5 | # Apache::Session::DBMS extended syntax | ||
| 6 | # | ||
| 7 | # Copyright(c) 2005 Asemantics S.r.l. | ||
| 8 | # Alberto Reggiori (alberto@asemantics.com) | ||
| 9 | # Distribute under a BSD license (see LICENSE file in main dir) | ||
| 10 | # | ||
| 11 | ############################################################################ | ||
| 12 | |||
| 13 | package Apache::Session::Generate::DBMS; | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use vars qw($VERSION); | ||
| 17 | |||
| 18 | use Apache::Session::Generate::MD5; | ||
| 19 | |||
| 20 | $VERSION = '0.1'; | ||
| 21 | |||
| 22 | sub generate { | ||
| 23 | my $session = shift; | ||
| 24 | |||
| 25 | &Apache::Session::Generate::MD5::generate( $session ); | ||
| 26 | }; | ||
| 27 | |||
| 28 | sub validate { | ||
| 29 | my $session = shift; | ||
| 30 | |||
| 31 | die | ||
| 32 | unless( $session->{isObjectPerKey} or | ||
| 33 | $session->{data}->{_session_id} =~ /^[a-fA-F0-9]+$/ ); | ||
| 34 | }; | ||
| 35 | |||
| 36 | 1; | ||
| 37 | |||
| 38 | =pod | ||
| 39 | |||
| 40 | =head1 NAME | ||
| 41 | |||
| 42 | Apache::Session::Generate::DBMS - Use MD5 to create random object IDs | ||
| 43 | |||
| 44 | =head1 SYNOPSIS | ||
| 45 | |||
| 46 | use Apache::Session::Generate::DBMS; | ||
| 47 | |||
| 48 | $id = Apache::Session::Generate::DBMS::generate(); | ||
| 49 | |||
| 50 | =head1 DESCRIPTION | ||
| 51 | |||
| 52 | This module fulfills the ID generation interface of Apache::Session. The | ||
| 53 | IDs are generated using a two-round MD5 of a random number, the time since the | ||
| 54 | epoch, the process ID, and the address of an anonymous hash. The resultant ID | ||
| 55 | number is highly entropic on Linux and other platforms that have good | ||
| 56 | random number generators. You are encouraged to investigate the quality of | ||
| 57 | your system's random number generator if you are using the generated ID | ||
| 58 | numbers in a secure environment. | ||
| 59 | |||
| 60 | This module can also examine session IDs to ensure that they are, indeed, | ||
| 61 | session ID numbers and not evil attacks. The reader is encouraged to | ||
| 62 | consider the effect of bogus session ID numbers in a system which uses | ||
| 63 | these ID numbers to access disks and databases. | ||
| 64 | |||
| 65 | This modules takes one argument in the usual Apache::Session style. The | ||
| 66 | argument is IDLength, and the value, between 0 and 32, tells this module | ||
| 67 | where to truncate the session ID. Without this argument, the session ID will | ||
| 68 | be 32 hexadecimal characters long, equivalent to a 128-bit key. | ||
| 69 | |||
| 70 | The validation code has been modified to support extended object-per-key | ||
| 71 | mode for Apache::Session::DBMS module. | ||
| 72 | |||
| 73 | =head1 AUTHOR | ||
| 74 | |||
| 75 | This module was written by Alberto Reggiori <alberto@asemantics.com> | ||
| 76 | |||
| 77 | =head1 SEE ALSO | ||
| 78 | |||
| 79 | L<Apache::Session::DBMS> |