aboutsummaryrefslogtreecommitdiffstats
path: root/webserver
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2015-12-18 01:45:34 +0100
committerGuilhem Moulin <guilhem@fripost.org>2015-12-18 01:45:34 +0100
commit4afa905f4b93331e592d9f7b614f709d5bda52e8 (patch)
treead4fcac2d404749c2dc8440c39b2e37f9f6e7075 /webserver
parentf6ac1ad1819d8aead2fdd9ed2d1159f1fcb8b992 (diff)
parent9b4e37696a8ae05650a2aec57ba294fc4785ae0d (diff)
Merge branch 'master' into debian
Diffstat (limited to 'webserver')
-rwxr-xr-xwebserver50
1 files changed, 50 insertions, 0 deletions
diff --git a/webserver b/webserver
new file mode 100755
index 0000000..e5e040d
--- /dev/null
+++ b/webserver
@@ -0,0 +1,50 @@
+#!/usr/bin/perl -T
+
+#----------------------------------------------------------------------
+# Let's Encrypt ACME client (minimal webserver for answering challenges)
+# Copyright © 2015 Guilhem Moulin <guilhem@fripost.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#----------------------------------------------------------------------
+
+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';