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
{
126 description
=> "API plugin name",
128 enum
=> $api_name_list,
132 description
=> 'DNS plugin data.',
140 data
=> { optional
=> 1 },
141 nodes
=> { optional
=> 1 },
142 disable
=> { optional
=> 1 },
146 my $proxmox_acme_command = sub {
147 my ($self, $acme, $auth, $data, $action) = @_;
149 die "No plugin data for DNSChallenge\n" if !defined($data->{plugin
});
151 my $alias = $data->{alias
};
152 my $domain = $auth->{identifier
}->{value
};
154 my $challenge = $self->extract_challenge($auth->{challenges
});
155 my $key_auth = $acme->key_authorization($challenge->{token
});
157 my $txtvalue = PVE
::ACME
::encode
(sha256
($key_auth));
158 my $dnsplugin = $data->{plugin
}->{api
};
159 my $plugin_conf_string = $data->{plugin
}->{data
};
161 # for security reasons, we execute the command as nobody
162 # we can't verify that the code of the DNSPlugins are harmless.
163 my $cmd = ["setpriv", "--reuid", "nobody", "--regid", "nogroup", "--clear-groups", "--reset-env", "--"];
165 # The order of the parameters passed to proxmox-acme is important
166 # proxmox-acme <setup|teardown> $plugin <$domain|$alias> $txtvalue [$plugin_conf_string]
167 push @$cmd, "/bin/bash", $ACME_PATH, $action, $dnsplugin;
173 my $input = "$txtvalue\n";
174 $input .= "$plugin_conf_string\n" if $plugin_conf_string;
176 PVE
::Tools
::run_command
($cmd, input
=> $input);
178 $data->{url
} = $challenge->{url
};
184 my ($self, $acme, $auth, $data) = @_;
186 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'setup');
187 print "Add TXT record: _acme-challenge.$domain\n";
191 my ($self, $acme, $auth, $data) = @_;
193 my $domain = $proxmox_acme_command->($self, $acme, $auth, $data, 'teardown');
194 print "Remove TXT record: _acme-challenge.$domain\n";