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
{
122 sub get_supported_plugins
{
123 return $plugin_names;
129 description
=> "API plugin name",
131 enum
=> $plugin_names,
135 description
=> 'DNS plugin data.',
137 'validation-delay' => {
139 description
=> 'Extra delay in seconds to wait before requesting validation.'
140 .' Allows to cope with a long TTL of DNS records.',
141 # low default, but our bet is that the acme-challenge domain isn't
142 # cached at all, so it hopefully shouldn't run into TTL issues
146 maximum
=> 2 * 24 * 60 * 60,
154 data
=> { optional
=> 1 },
155 nodes
=> { optional
=> 1 },
156 disable
=> { optional
=> 1 },
157 'validation-delay' => { optional
=> 1 },
161 my $proxmox_acme_command = sub {
162 my ($self, $acme, $auth, $data, $action) = @_;
164 die "No plugin data for DNSChallenge\n" if !defined($data->{plugin
});
166 my $alias = $data->{alias
};
167 my $domain = $auth->{identifier
}->{value
};
169 my $challenge = $self->extract_challenge($auth->{challenges
});
170 my $key_auth = $acme->key_authorization($challenge->{token
});
172 my $txtvalue = PVE
::ACME
::encode
(sha256
($key_auth));
173 my $dnsplugin = $data->{plugin
}->{api
};
174 my $plugin_conf_string = $data->{plugin
}->{data
};
176 # for security reasons, we execute the command as nobody
177 # we can't verify that the code of the DNSPlugins are harmless.
178 my $cmd = ["setpriv", "--reuid", "nobody", "--regid", "nogroup", "--clear-groups", "--reset-env", "--"];
180 # The order of the parameters passed to proxmox-acme is important
181 # proxmox-acme <setup|teardown> $plugin <$domain|$alias> $txtvalue [$plugin_conf_string]
182 push @$cmd, "/bin/bash", $ACME_PATH, $action, $dnsplugin;
188 my $input = "$txtvalue\n";
189 $input .= "$plugin_conf_string\n" if $plugin_conf_string;
191 PVE
::Tools
::run_command
($cmd, input
=> $input);
193 $data->{url
} = $challenge->{url
};
199 my ($self, $acme, $auth, $data) = @_;
201 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'setup');
202 print "Add TXT record: _acme-challenge.$domain\n";
204 # FIXME: probe ourself for propagation of TXT record, while not 100%
205 # failsafe it's good enough of a heuristic to do away with fixed sleep
206 # intervalls - original acme.sh employs that heuristic too.
207 my $delay = $data->{'validation-delay'} // 30;
209 print "Sleeping $delay seconds to wait for TXT record propagation\n";
210 sleep($delay); # don't care for EINTR
215 my ($self, $acme, $auth, $data) = @_;
217 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'teardown');
218 print "Remove TXT record: _acme-challenge.$domain\n";