1 package PVE
::ACME
::StandAlone
;
9 use base
qw(PVE::ACME::Challenge);
11 sub supported_challenge_types
{
25 nodes
=> { optional
=> 1 },
26 disable
=> { optional
=> 1 },
31 my ($self, $acme, $auth, $data) = @_;
33 print "Setting up webserver\n";
35 my $challenge = $self->extract_challenge($auth->{challenges
});
36 my $key_auth = $acme->key_authorization($challenge->{token
});
42 my $server = HTTP
::Daemon-
>new( LocalHost
=> '::', V6Only
=> 0, %sockopts) //
43 HTTP
::Daemon-
>new( LocalHost
=> '0.0.0.0', %sockopts)
44 or die "Failed to initialize HTTP daemon\n";
46 my $pid = fork() // die "Failed to fork HTTP daemon - $!\n";
48 $data->{server
} = $server;
50 $data->{url
} = $challenge->{url
};
52 while (my $c = $server->accept()) {
53 while (my $r = $c->get_request()) {
54 if ($r->method() eq 'GET' and
55 $r->uri->path eq "/.well-known/acme-challenge/$challenge->{token}") {
56 my $resp = HTTP
::Response-
>new(200, 'OK', undef, $key_auth);
58 $c->send_response($resp);
60 $c->send_error(404, 'Not found.')
70 my ($self, $acme, $auth, $data) = @_;
72 eval { $data->{server
}->close() };
73 kill('KILL', $data->{pid
});
74 waitpid($data->{pid
}, 0);