]> git.proxmox.com Git - proxmox-acme.git/blobdiff - src/PVE/ACME/StandAlone.pm
fix #3390: standalone: explicitly bind to '::'
[proxmox-acme.git] / src / PVE / ACME / StandAlone.pm
index 73caef698cdc1220191743a315b94e36dbc184fb..c054c5a9e003b3bb43e9b7eca9769d91dad779f3 100644 (file)
@@ -9,7 +9,7 @@ use HTTP::Response;
 use base qw(PVE::ACME::Challenge);
 
 sub supported_challenge_types {
-    return { 'http-01' => 1 };
+    return ['http-01'];
 }
 
 sub type {
@@ -27,32 +27,32 @@ sub options {
     };
 }
 
-sub extract_challenge {
-    my ($self, $challenge) = @_;
-
-    return PVE::ACME::Challenge->extract_challenge($challenge, 'http-01');
-}
-
 sub setup {
-    my ($class, $data) = @_;
+    my ($self, $acme, $auth, $data) = @_;
 
     print "Setting up webserver\n";
 
-    my $key_auth = $data->{key_authorization};
+    my $challenge = $self->extract_challenge($auth->{challenges});
+    my $key_auth = $acme->key_authorization($challenge->{token});
 
-    my $server = HTTP::Daemon->new(
+    my %sockopts = (
        LocalPort => 80,
        ReuseAddr => 1,
-       ) or die "Failed to initialize HTTP daemon\n";
+       );
+    my $server = HTTP::Daemon->new( LocalHost => '::', V6Only => 0, %sockopts) //
+           HTTP::Daemon->new( LocalHost => '0.0.0.0', %sockopts)
+           or die "Failed to initialize HTTP daemon\n";
+
     my $pid = fork() // die "Failed to fork HTTP daemon - $!\n";
     if ($pid) {
        $data->{server} = $server;
        $data->{pid} = $pid;
+       $data->{url} = $challenge->{url};
     } else {
        while (my $c = $server->accept()) {
            while (my $r = $c->get_request()) {
                if ($r->method() eq 'GET' and
-                   $r->uri->path eq "/.well-known/acme-challenge/$data->{token}") {
+                   $r->uri->path eq "/.well-known/acme-challenge/$challenge->{token}") {
                    my $resp = HTTP::Response->new(200, 'OK', undef, $key_auth);
                    $resp->request($r);
                    $c->send_response($resp);
@@ -67,7 +67,7 @@ sub setup {
 }
 
 sub teardown {
-    my ($self, $data) = @_;
+    my ($self, $acme, $auth, $data) = @_;
 
     eval { $data->{server}->close() };
     kill('KILL', $data->{pid});