[pve-devel] [Patch V3 acme 10/13] Use the caller's data instead of extracting it yourself.
Wolfgang Link
w.link at proxmox.com
Thu Apr 16 07:18:37 CEST 2020
Add the server in the data structure to return it.
Signed-off-by: Wolfgang Link <w.link at proxmox.com>
---
src/PVE/ACME/StandAlone.pm | 41 ++++++++++++--------------------------
1 file changed, 13 insertions(+), 28 deletions(-)
diff --git a/src/PVE/ACME/StandAlone.pm b/src/PVE/ACME/StandAlone.pm
index 0b4aaae..73caef6 100644
--- a/src/PVE/ACME/StandAlone.pm
+++ b/src/PVE/ACME/StandAlone.pm
@@ -34,41 +34,26 @@ sub extract_challenge {
}
sub setup {
- my ($class, $acme, $authorization) = @_;
+ my ($class, $data) = @_;
- my $challenges = $authorization->{challenges};
- die "no challenges defined in authorization\n" if !$challenges;
+ print "Setting up webserver\n";
- my $http_challenges = [ grep {$_->{type} eq 'http-01'} @$challenges ];
- die "no http-01 challenge defined in authorization\n"
- if ! scalar $http_challenges;
-
- my $http_challenge = $http_challenges->[0];
-
- die "no token found in http-01 challenge\n" if !$http_challenge->{token};
-
- my $key_authorization = $acme->key_authorization($http_challenge->{token});
+ my $key_auth = $data->{key_authorization};
my $server = HTTP::Daemon->new(
LocalPort => 80,
ReuseAddr => 1,
- ) or die "Failed to initialize HTTP daemon\n";
+ ) or die "Failed to initialize HTTP daemon\n";
my $pid = fork() // die "Failed to fork HTTP daemon - $!\n";
if ($pid) {
- my $self = {
- server => $server,
- pid => $pid,
- authorization => $authorization,
- key_auth => $key_authorization,
- url => $http_challenge->{url},
- };
-
- return bless $self, $class;
+ $data->{server} = $server;
+ $data->{pid} = $pid;
} 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/$http_challenge->{token}") {
- my $resp = HTTP::Response->new(200, 'OK', undef, $key_authorization);
+ if ($r->method() eq 'GET' and
+ $r->uri->path eq "/.well-known/acme-challenge/$data->{token}") {
+ my $resp = HTTP::Response->new(200, 'OK', undef, $key_auth);
$resp->request($r);
$c->send_response($resp);
} else {
@@ -82,11 +67,11 @@ sub setup {
}
sub teardown {
- my ($self) = @_;
+ my ($self, $data) = @_;
- eval { $self->{server}->close() };
- kill('KILL', $self->{pid});
- waitpid($self->{pid}, 0);
+ eval { $data->{server}->close() };
+ kill('KILL', $data->{pid});
+ waitpid($data->{pid}, 0);
}
1;
--
2.20.1
More information about the pve-devel
mailing list