use base qw(PVE::ACME::Challenge);
sub supported_challenge_types {
- return { 'http-01' => 1 };
+ return ['http-01'];
}
sub type {
};
}
-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);
}
sub teardown {
- my ($self, $data) = @_;
+ my ($self, $acme, $auth, $data) = @_;
eval { $data->{server}->close() };
kill('KILL', $data->{pid});