1 package PVE
::ACME
::StandAlone
;
9 use base
qw(PVE::ACME::Challenge);
11 sub supported_challenge_types
{
12 return { 'http-01' => 1 };
16 my ($class, $acme, $authorization) = @_;
18 my $challenges = $authorization->{challenges
};
19 die "no challenges defined in authorization\n" if !$challenges;
21 my $http_challenges = [ grep {$_->{type
} eq 'http-01'} @$challenges ];
22 die "no http-01 challenge defined in authorization\n"
23 if ! scalar $http_challenges;
25 my $http_challenge = $http_challenges->[0];
27 die "no token found in http-01 challenge\n" if !$http_challenge->{token
};
29 my $key_authorization = $acme->key_authorization($http_challenge->{token
});
31 my $server = HTTP
::Daemon-
>new(
34 ) or die "Failed to initialize HTTP daemon\n";
35 my $pid = fork() // die "Failed to fork HTTP daemon - $!\n";
40 authorization
=> $authorization,
41 key_auth
=> $key_authorization,
42 url
=> $http_challenge->{url
},
45 return bless $self, $class;
47 while (my $c = $server->accept()) {
48 while (my $r = $c->get_request()) {
49 if ($r->method() eq 'GET' and $r->uri->path eq "/.well-known/acme-challenge/$http_challenge->{token}") {
50 my $resp = HTTP
::Response-
>new(200, 'OK', undef, $key_authorization);
52 $c->send_response($resp);
54 $c->send_error(404, 'Not found.')
66 eval { $self->{server
}->close() };
67 kill('KILL', $self->{pid
});
68 waitpid($self->{pid
}, 0);