1 package PVE
::ACME
::DNSChallenge
;
6 use Digest
::SHA
qw(sha256);
9 use base
qw(PVE::ACME::Challenge);
11 my $ACME_PATH = '/usr/share/proxmox-acme/proxmox-acme';
13 sub supported_challenge_types
{
21 # describe the data schema of the supported plugins
59 'gandi_livedns' => {},
100 'openprovider' => {},
104 description
=> "The OVH endpoint",
108 description
=> "The application key.",
112 description
=> "The application secret.",
118 description
=> "The PowerDNS API endpoint.",
151 sub get_supported_plugins
{
158 description
=> "API plugin name",
160 enum
=> [sort keys %$plugins],
164 description
=> 'DNS plugin data.',
166 'validation-delay' => {
168 description
=> 'Extra delay in seconds to wait before requesting validation.'
169 .' Allows to cope with a long TTL of DNS records.',
170 # low default, but our bet is that the acme-challenge domain isn't
171 # cached at all, so it hopefully shouldn't run into TTL issues
175 maximum
=> 2 * 24 * 60 * 60,
183 data
=> { optional
=> 1 },
184 nodes
=> { optional
=> 1 },
185 disable
=> { optional
=> 1 },
186 'validation-delay' => { optional
=> 1 },
190 my $proxmox_acme_command = sub {
191 my ($self, $acme, $auth, $data, $action) = @_;
193 die "No plugin data for DNSChallenge\n" if !defined($data->{plugin
});
195 my $alias = $data->{alias
};
196 my $domain = $auth->{identifier
}->{value
};
198 my $challenge = $self->extract_challenge($auth->{challenges
});
199 my $key_auth = $acme->key_authorization($challenge->{token
});
201 my $txtvalue = PVE
::ACME
::encode
(sha256
($key_auth));
202 my $dnsplugin = $data->{plugin
}->{api
};
203 my $plugin_conf_string = $data->{plugin
}->{data
};
205 # for security reasons, we execute the command as nobody
206 # we can't verify that the code of the DNSPlugins are harmless.
207 my $cmd = ["setpriv", "--reuid", "nobody", "--regid", "nogroup", "--clear-groups", "--reset-env", "--"];
209 # The order of the parameters passed to proxmox-acme is important
210 # proxmox-acme <setup|teardown> $plugin <$domain|$alias> $txtvalue [$plugin_conf_string]
211 push @$cmd, "/bin/bash", $ACME_PATH, $action, $dnsplugin;
217 my $input = "$txtvalue\n";
218 $input .= "$plugin_conf_string\n" if $plugin_conf_string;
220 PVE
::Tools
::run_command
($cmd, input
=> $input);
222 $data->{url
} = $challenge->{url
};
228 my ($self, $acme, $auth, $data) = @_;
230 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'setup');
231 print "Add TXT record: _acme-challenge.$domain\n";
233 # FIXME: probe ourself for propagation of TXT record, while not 100%
234 # failsafe it's good enough of a heuristic to do away with fixed sleep
235 # intervalls - original acme.sh employs that heuristic too.
236 my $delay = $data->{'validation-delay'} // 30;
238 print "Sleeping $delay seconds to wait for TXT record propagation\n";
239 sleep($delay); # don't care for EINTR
244 my ($self, $acme, $auth, $data) = @_;
246 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'teardown');
247 print "Remove TXT record: _acme-challenge.$domain\n";