From ffce814c1f2d0f2b8070f4755f7448e08d00e32b Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Wed, 3 Oct 2012 14:35:12 +0200 Subject: setup.sh ==> setup.pl. --- README.md | 1 + setup.pl | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.sh | 24 ------------------------ 3 files changed, 58 insertions(+), 24 deletions(-) create mode 100755 setup.pl delete mode 100755 setup.sh diff --git a/README.md b/README.md index 05b7176..d077f94 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ The following CPAN modules need to be installed: * `Mail::IMAPTalk` * `Modern::Perl` * `Time::HiRes` + * `LWP::Simple` (for the setup process only) ### Key Setup and jQuery Download diff --git a/setup.pl b/setup.pl new file mode 100755 index 0000000..5df84a0 --- /dev/null +++ b/setup.pl @@ -0,0 +1,57 @@ +#! /usr/bin/env perl + +use common::sense; +use Modern::Perl; +use JSON; +use Crypt::OpenSSL::RSA; +use File::Slurp; +use File::Path qw(make_path); +use File::Copy; +use LWP::Simple qw(getstore); + +sub printspec($$) { + my ($outfile, $pemfile) = @_; + my $key = Crypt::OpenSSL::RSA->new_private_key(scalar read_file($pemfile)); + my ($n, $e, @stuff) = $key->get_key_parameters; + say $outfile + encode_json({"public-key" => {e => $e->to_decimal, n => $n->to_decimal, algorithm => "RS"}, + "authentication" => "/browserid/authenticate.html", + "provisioning" => "/browserid/provision.html"}); +}; + +my $wwwuser = "www"; +my $configpath = "etc/mulkid"; + +# Download jQuery. +make_path("www/jquery"); +say "Fetching jQuery..."; +getstore("http://code.jquery.com/jquery-1.7.2.min.js", "www/jquery/jquery.js"); + +# Generate the private key. +say "Generating private key..."; +#FIXME: Don't do this if the private key already exists! +system "openssl genpkey -algorithm rsa -out rsa2048.pem -pkeyopt rsa_keygen_bits:2048"; + +# Install the private key. +make_path($configpath); +my $pemfile = "$configpath/rsa2048.pem"; +move("rsa2048.pem", $pemfile) or die "Could not move rsa2048.pem to $configpath"; +system "chmod go= $pemfile"; +system "chown $wwwuser $pemfile"; + +# Generate spec file. +open(my $out, ">", "browserid.json") + or die "Cannot open browserid.json for writing: $!"; +printspec $out, $pemfile; +close($out); + +say "\n"; +say "******************************************************************"; +say "* FINISHED. *"; +say "* *"; +say "* Please put browserid.json where it will be served as *"; +say "* https:///.well-known/browserid *"; +say "* with a content type of *"; +say "* application/json *"; +say "* . *"; +say "******************************************************************"; diff --git a/setup.sh b/setup.sh deleted file mode 100755 index 727e3ad..0000000 --- a/setup.sh +++ /dev/null @@ -1,24 +0,0 @@ -#! /bin/sh - -WWWUSER=www - -# Download jQuery. -mkdir -p jquery -wget -O jquery/jquery.js http://code.jquery.com/jquery-1.7.2.min.js - -# Generate the private key. -openssl genpkey -algorithm rsa -out rsa2048.pem -pkeyopt rsa_keygen_bits:2048 - -# Install the private key. -mkdir -p /etc/mulkid -mv rsa2048.pem /etc/mulkid/ -chmod go= /etc/mulkid/rsa2048.pem -chown $WWWUSER /etc/mulkid/rsa2048.pem - -# Generate spec file. -./generate_specfile.pl >browserid.json -echo "Please put browserid.json where it will be served as" -echo " https:///.well-known/browserid" -echo "with a content type of" -echo " application/json" -echo "." -- cgit v1.2.3