1 package PVE
::ACME
::StandAlone
;
9 use base
qw(PVE::ACME::Challenge);
11 sub supported_challenge_types
{
12 return { 'http-01' => 1 };
25 nodes
=> { optional
=> 1 },
26 disable
=> { optional
=> 1 },
30 sub extract_challenge
{
31 my ($self, $challenge) = @_;
33 return PVE
::ACME
::Challenge-
>extract_challenge($challenge, 'http-01');
41 my ($self, $acme, $auth, $data) = @_;
43 print "Setting up webserver\n";
45 my $challenge = $self->extract_challenge($auth->{challenges
});
46 my $key_auth = $acme->key_authorization($challenge->{token
});
48 my $server = HTTP
::Daemon-
>new(
51 ) or die "Failed to initialize HTTP daemon\n";
52 my $pid = fork() // die "Failed to fork HTTP daemon - $!\n";
54 $data->{server
} = $server;
56 $data->{url
} = $challenge->{url
};
58 while (my $c = $server->accept()) {
59 while (my $r = $c->get_request()) {
60 if ($r->method() eq 'GET' and
61 $r->uri->path eq "/.well-known/acme-challenge/$challenge->{token}") {
62 my $resp = HTTP
::Response-
>new(200, 'OK', undef, $key_auth);
64 $c->send_response($resp);
66 $c->send_error(404, 'Not found.')
76 my ($self, $acme, $auth, $data) = @_;
78 eval { $data->{server
}->close() };
79 kill('KILL', $data->{pid
});
80 waitpid($data->{pid
}, 0);