Stas Bekman wrote:
> Peter Rothermel wrote:
>
> >
> > PerlChildInitHandler Apache::foo->loadkey
> >
> > Will the genkey method get execute at the
> > initialization of each thread?
>
> Apache doesn't provide such a hook yet. May be in the future.
>
> child_init is for child process init, not threads.
>
>http://perl.apache.org/release/docs/2.0/user/handlers/handlers.html#PerlChildInitHandler
>
> what are you trying to do?
I'm encrypting/decrypting data within cookies that are holding session keys
for authentication purposes. I decrypt the session key within the cookie data,
whenever I get an http request that has a cookie in the header.
The RSA keys that I use for encrytion/decryption are regenerated when the Apache
server is started. My module has a load_key subroutine that I call before I do any
encryption or decryption. This returns a RSA object that is initialized with a global
var that hold a 2048 bit RSA key. If the global var is empty I generate a new key.
The code works OK but I seem to be generating a 2048 bit key the first time
that a user logs into my site. This key generation takes awhile. I would prefer
generating the key when server/thread/interupter is started. I was hoping that
a PerlClhildInitHandler could be used to call the gen_key subroutine to load
the data into global var $private_key_string.
my $self = shift;use vars qw($VERSION $private_key_string @ISA);
sub gen_key : method {
my ($self,$r) = @_;
my $rlog = $r->log;
my $tmprsa = Crypt::OpenSSL::RSA->new();
$rlog->notice("Generating a RSA key");
$tmprsa->generate_key(2048);
$private_key_string = $tmprsa->get_private_key_string();
}
sub load_key : method {
my ($self,$r) = @_;
my $rlog = $r->log;
my $rsa;
if (length($private_key_string)) {
$rsa = Crypt::OpenSSL::RSA->new();
$rsa->load_private_key( $private_key_string );
}
else {
$rsa = $self->gen_key;
}
return $rsa;
}
>
>
> You should try to write your code in mpm-agnostic way if possible. so
> the same code can run under various mpms.
>
> __________________________________________________________________
> Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/ mod_perl Guide ---> http://perl.apache.org
> mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org http://ticketmaster.com