Mozilla-Persona
view release on metacpan or search on metacpan
lib/Mozilla/Persona/Server.pm view on Meta::CPAN
eval "require $class"; panic $@ if $@;
$self->{MP_validator} = $class->new(%$config);
}
sub privatePEM()
{ my $self = shift;
my $pem = read_file $self->{MP_pem_fn};
my $key = Crypt::OpenSSL::RSA->new_private_key($pem);
$key->use_pkcs1_padding;
$key->use_sha256_hash;
$key;
}
#------------------------
sub getSession($)
{ my ($self, $cgi) = @_;
my $cookie = $cgi->cookie($self->cookie)
lib/Mozilla/Persona/Setup.pm view on Meta::CPAN
use Mozilla::Persona::Server ();
use Crypt::OpenSSL::Bignum ();
use Crypt::OpenSSL::RSA ();
use LWP::UserAgent ();
my $ua;
my $latest_jquery = 'http://code.jquery.com/jquery.min.js';
my $restart;
sub get_jquery($$);
sub create_private_key($$);
sub publish_config($$);
sub publish_helpers($$$);
sub setup_persona(%)
{ my %args = @_;
### Configuration
my $docroot = $args{docroot} or panic;
lib/Mozilla/Persona/Setup.pm view on Meta::CPAN
-d $wk || mkdir $wk
or fault __x"cannot create directory {dir} for publish", dir => $wk;
my $publish = "$wk/browserid";
(my $setup_src = __FILE__) =~ s!Setup.pm$!setup!;
### Work
get_jquery $latest_jquery, $jquery;
create_private_key $privkey, $group;
publish_config $publish, $privkey;
my $persona = Mozilla::Persona::Server->new
( private_pem => $privkey
, cookie_name => 'persona'
, domain => $domain
, validator =>
{ class => 'Mozilla::Persona::Validate::Table'
, pwfile => "$secrets/passwords"
, domain => $domain
lib/Mozilla/Persona/Setup.pm view on Meta::CPAN
$ua ||= LWP::UserAgent->new;
my $resp = $ua->get($from_url);
$resp->is_success
or error __x"failed downloading jquery from {url}: {err}"
, url => $from_url. err => $resp->status_line;
write_file $to_fn, $resp->decoded_content || $resp->content;
}
sub create_private_key($$)
{ my ($outfn, $group) = @_;
my $gid = getpwnam $group
or error __x"unknown group {name}", name => $group;
if(-f $outfn && !$restart)
{ info __x"reusing private key in {fn}", fn => $outfn;
my $has_gid = (stat $outfn)[5];
$gid == $has_gid
lib/Mozilla/Persona/Setup.pm view on Meta::CPAN
return;
}
info __x"generating new private key at {fn}", fn => $outfn;
! -f $outfn || unlink $outfn
or fault __x"cannot replace existing pem file in {fn}", fn => $outfn;
my $key = Crypt::OpenSSL::RSA->generate_key(2048);
write_file $outfn, $key->get_private_key_string;
chmod 0440, $outfn;
chown -1, $gid, $outfn
or warning __x"please set group on {fn} to {group}"
, fn => $outfn, group => $group;
$key;
}
sub publish_config($$)
{ my ($outfn, $keyfn) = @_;
my $pem = read_file $keyfn;
my $key = Crypt::OpenSSL::RSA->new_private_key($pem);
my ($n, $e, @stuff) = $key->get_key_parameters;
write_file $outfn, encode_json
{ 'public-key' =>
{ e => $e->to_decimal
, n => $n->to_decimal
, algorithm => 'RS'
}
, authentication => '/persona/authenticate.html'
, provisioning => '/persona/provision.html'
( run in 0.355 second using v1.01-cache-2.11-cpan-4d50c553e7e )