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
});
38 my $server = HTTP
::Daemon-
>new(
41 ) or die "Failed to initialize HTTP daemon\n";
42 my $pid = fork() // die "Failed to fork HTTP daemon - $!\n";
44 $data->{server
} = $server;
46 $data->{url
} = $challenge->{url
};
48 while (my $c = $server->accept()) {
49 while (my $r = $c->get_request()) {
50 if ($r->method() eq 'GET' and
51 $r->uri->path eq "/.well-known/acme-challenge/$challenge->{token}") {
52 my $resp = HTTP
::Response-
>new(200, 'OK', undef, $key_auth);
54 $c->send_response($resp);
56 $c->send_error(404, 'Not found.')
66 my ($self, $acme, $auth, $data) = @_;
68 eval { $data->{server
}->close() };
69 kill('KILL', $data->{pid
});
70 waitpid($data->{pid
}, 0);