]> git.proxmox.com Git - proxmox-acme.git/commitdiff
Use the caller's data instead of extracting it yourself.
authorWolfgang Link <w.link@proxmox.com>
Mon, 6 Apr 2020 06:35:06 +0000 (08:35 +0200)
committerWolfgang Link <w.link@proxmox.com>
Thu, 16 Apr 2020 06:43:23 +0000 (08:43 +0200)
Add the server in the data structure to return it.

Signed-off-by: Wolfgang Link <w.link@proxmox.com>
src/PVE/ACME/StandAlone.pm

index 0b4aaae0cd9618077a882bb7562d7bcf88e0e909..73caef698cdc1220191743a315b94e36dbc184fb 100644 (file)
@@ -34,41 +34,26 @@ sub extract_challenge {
 }
 
 sub setup {
 }
 
 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,
 
     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 $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()) {
     } 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 {
                    $resp->request($r);
                    $c->send_response($resp);
                } else {
@@ -82,11 +67,11 @@ sub setup {
 }
 
 sub teardown {
 }
 
 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;
 }
 
 1;