ApacheCookieEncrypted
view release on metacpan or search on metacpan
Revision history for Perl extension Apache::Cookie::Encrypted.
0.03 Mon June 4 15:00:00 2001
- changed the key retrieval system. This makes this module for use with
mod_perl only. I guess I'll have to work on one for plain CGI using
CGI::Cookie just to be fair. :)
0.02 Sat June 2 23:30:00 2001
- fixed inheritance. It just wasn't working for some reason.
0.01 Thu May 31 23:00:22 2001
- original version;
Encrypted.pm view on Meta::CPAN
package Apache::Cookie::Encrypted;
#use Apache::Cookie;
use base qw(Apache::Cookie);
require Apache;
use strict;
use warnings;
use Crypt::CBC;
use Carp;
use vars qw($VERSION $key);
$VERSION = '0.03';
Encrypted.pm view on Meta::CPAN
foreach my $arg (@args) {
if (ref($arg) eq "Apache::Request" || ref($arg) eq "Apache") {
$r = $arg;
} else {
push(@new_args, $arg);
}
}
# load in options supplied to new()
for (my $x = 0; $x <= $#new_args; $x += 2) {
defined($args[($x + 1)]) or croak("Apache::Cookie::Encrypted->new() called with odd number of".
" option parameters - should be of the form -option => value");
$params->{lc($new_args[$x])} = $new_args[($x + 1)];
}
# check for the key and place it in the proper variable
unless ($key) {
if (exists($params->{-key})) {
$key = $params->{-key};
delete $params->{-key};
} else {
croak "No key defined - key must be defined for Apache::Cookie::Encrypted to work\n";
}
}
my $self = $class->SUPER::new($r);
if (exists($params->{-name})) {
$self->name($params->{-name});
}
if (exists($params->{-value})) {
Encrypted.pm view on Meta::CPAN
if (exists($params->{-secure})) {
$self->secure($params->{-secure});
}
# return the blessed object
return bless $self, $class;
}
sub Apache::Cookie::Encrypted::value {
my $self = shift;
my $data = shift || undef;
if ($data) {
$data = &_encrypt_data($data) if $data ne '';
$self->SUPER::value($data);
} else {
my @cookie_data = $self->SUPER::value();
my $data_in;
if (scalar(@cookie_data) > 1) {
$data_in = \@cookie_data;
} else {
$data_in = $cookie_data[0];
}
my $data_out = &_decrypt_data( $data_in );
return wantarray ? @$data_out : $data_out;
}
}
sub Apache::Cookie::Encrypted::parse {
my $self = shift;
my $data = shift || undef;
my %parsed;
if ($data) {
%parsed = SUPER::parse($data);
} else {
%parsed = SUPER::parse();
}
my %new_parsed;
foreach (keys %parsed) {
$new_parsed{$_} = bless $parsed{$_}, $self;
}
return wantarray ? %new_parsed : \%new_parsed;
}
sub Apache::Cookie::Encrypted::fetch {
my $self = shift;
my %fetched = $self->SUPER::fetch();
my %enc_fetch_translated;
foreach (keys %fetched) {
$enc_fetch_translated{$_} = bless $fetched{$_}, $self;
}
Encrypted.pm view on Meta::CPAN
}
}
}
1;
__END__
=head1 NAME
Apache::Cookie::Encrypted - Encrypted HTTP Cookies Class
=head1 SYNOPSIS
use Apache::Cookie::Encrypted;
my $cookie = Apache::Cookie::Encrypted->new($r, ...);
=head1 DESCRIPTION
The Apache::Cookie::Encrypted module is a class derived from Apache::Cookie.
It creates a cookie with its contents encrypted with Crypt::Blowfish.
=head1 METHODS
This interface is identical to the I<Apache::Cookie> interface with a couple of
exceptions. Refer to the I<Apache::Cookie> documentation while these docs
are being refined.
You'll notice that the documentation is pretty much the same as I<Apache::Cookie's>.
It is. I took most of the documentation and put it here for your convienience.
=over 4
=item new
Just like Apache::Cookie->new(), it also requires an I<Apache> object
but also can take an I<Apache::Request> object:
my $cookie = Apache::Cookie::Encrypted->new($r,
-key => $key,
-name => 'foo',
-value => 'bar',
-expires => '+3M',
-domain => '.myeboard.com',
-path => '/',
-secure => 1
);
The key doesn't have to be defined in the constructor if you set it in
your httpd.conf as a PerlSetVar.
PerlSetVar COOKIE_KEY <Blowfish key>
B<Make sure you do define a key or else the module will croak.>
=item bake
This is the same bake method in I<Apache::Cookie>.
$cookie->bake;
=item parse
This method parses the given string if present, otherwise, the incoming Cookie header:
my $cookies = $cookie->parse; #hash ref
my %cookies = $cookie->parse;
my %cookies = $cookie->parse($cookie_string);
=item fetch
Fetch and parse incoming I<Cookie> header:
my $cookies = Apache::Cookie::Encrypted->fetch; # hash ref
my %cookies = Apache::Cookie::Encrypted->fetch; # plain hash
The value will be decrypted upon call to $cookie->value.
=item as_string
Format the cookie object as a string:
#same as $cookie->bake
$r->err_headers_out->add("Set-Cookie" => $cookie->as_string);
=item name
Get or set the name of the cookie:
my $name = $cookie->name;
$cookie->name("Foo");
=item value
Get or set the values of the cookie:
my $value = $cookie->value;
my @value = $cookie->value;
$cookie->value("string");
$cookie->value(\@array);
Just like in I<Apache::Cookie> except that the contents are encrypted
and decrypted automaticaly with the key defined in the constructor or
set within httpd.conf as a PerlSetVar.
B<Remember the key must be set in the constructor or in the httpd.conf
file for this module to work. It wil complain if its not set.>
=item domain
Get or set the domain for the cookie:
Encrypted.pm view on Meta::CPAN
Get or set the secure flag for the cookie:
my $secure = $cookie->secure;
$cookie->secure(1);
=back
=head1 SEE ALSO
I<Apache>(3), I<Apache::Cookie>(3), I<Apache::Request>(3)
=head1 AUTHOR
Jamie Krasnoo<jkrasnoo@socal.rr.com>
=head1 CREDITS
Apache::Cookie - docs and modules - Doug MacEachern
Crypt::CBC - Lincoln Stein, lstein@cshl.org
Crypt::Blowfish - Dave Paris <amused@pobox.com> and those mentioned in the module.
=cut
Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'NAME' => 'Apache::Cookie::Encrypted',
'VERSION_FROM' => 'Encrypted.pm', # finds $VERSION
'PREREQ_PM' => { Crypt::CBC => 1.25, Crypt::Blowfish => 2.06, Apache::Cookie => 0.01 }, # e.g., Module::Name => 1.1
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'Encrypted.pm', # retrieve abstract from module
AUTHOR => 'Jamie Krasnoo <jkrasnoo@socal.rr.com>') : ()),
);
Apache/Cookie/Encrypted version 0.02
====================================
Apache::Cookie::Encrypted is a subclass of Apache::Cookie.
It takes the value you put in to the cookie and automaticaly
encrypts it. It automaticaly decrypts it when the value is
retrieved. Other than that it behaves just like Apache::Cookie.
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make install
DEPENDENCIES
This module requires these other modules and libraries:
Apache()
Apache::Cookie
Crypt::CBC
Crypt::Blowfish
Apache::Cookie is bundled with Apache::Request.
This module is meant to be used with mod_perl.
Suggested Modules
Crypt::Random
Math::Pari - needed by Crypt::Random
makes creating 448 bit keys much easier.
COPYRIGHT AND LICENCE
This is under the same license as Apache::Cookie or perl.
Copyright (C) 2001 Jamie Krasnoo
( run in 0.893 second using v1.01-cache-2.11-cpan-e9199f4ba4c )