diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2015-12-08 19:12:33 +0100 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2015-12-08 19:25:20 +0100 |
commit | e1d918aaf4f643eb4ebab9bd1258ef99d8f5517a (patch) | |
tree | a803819a4e450f90e7a3c83d5997688e71f57286 /acme-webserver | |
parent | 99ebd3d32e5a158b6ca5b2248dc67e67e4789bdd (diff) |
First attempt.
Diffstat (limited to 'acme-webserver')
-rwxr-xr-x | acme-webserver | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/acme-webserver b/acme-webserver new file mode 100755 index 0000000..57ea789 --- /dev/null +++ b/acme-webserver @@ -0,0 +1,32 @@ +#!/usr/bin/perl -T + +use strict; +use warnings; + +my $ROOT = '/.well-known/acme-challenge'; + +$_ = <STDIN> // exit; +my $proto = s/ HTTP\/(1\.[01])\r\n\z// ? $1 : die "Error: Bad request\n"; +my $method = s/\A(GET|HEAD) // ? $1 : die "Error: Bad request\n"; + +# Consume the headers (and ignore them) +while (defined (my $h = <STDIN>)) { last if $h eq "\r\n" }; + +my ($status_line, $content_type, $content); +if (/\A\Q$ROOT\E\/([A-Za-z0-9_-]+)\z/ and -f $1) { + if (open my $fh, '<', $1) { + ($status_line, $content_type) = ('200 OK', 'application/jose+json'); + $content = do { local $/ = undef; <$fh> }; + close $fh; + } + else { + $status_line = '403 Forbidden'; + } +} + +print "HTTP/$proto ", ($status_line // '404 Not Found'), "\r\n"; +print "Content-Type: $content_type\r\n" if defined $content_type; +print "Content-Length: ".length($content)."\r\n" if defined $content; +print "Connection: close\r\n"; +print "\r\n"; +print $content if defined $content and $method eq 'GET'; |