Skip to content

Commit b555c4e

Browse files
committed
Conf: allow unversioned challenge names.
Simplify "challenge" directive parsing.
1 parent 52ce8d7 commit b555c4e

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,11 @@ restart unless [state_path](#state_path) is configured.
201201

202202
Sets challenge type used for this issuer. Allowed values:
203203

204-
- `http-01`
205-
- `tls-alpn-01`
204+
- `http-01` (`http`)
205+
- `tls-alpn-01` (`tls-alpn`)
206+
207+
ACME challenges are versioned, but if you specify an unversioned name,
208+
the module will select the latest implemented version automatically.
206209

207210
### contact
208211

src/acme/types.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,6 @@ pub enum ChallengeKind {
157157
Other(String),
158158
}
159159

160-
impl From<&str> for ChallengeKind {
161-
fn from(s: &str) -> Self {
162-
match s {
163-
"http-01" => ChallengeKind::Http01,
164-
"dns-01" => ChallengeKind::Dns01,
165-
"tls-alpn-01" => ChallengeKind::TlsAlpn01,
166-
_ => ChallengeKind::Other(s.to_string()),
167-
}
168-
}
169-
}
170-
171160
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
172161
#[serde(rename_all = "camelCase")]
173162
pub enum ChallengeStatus {

src/conf.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,15 @@ extern "C" fn cmd_issuer_set_challenge(
338338
}
339339

340340
// NGX_CONF_TAKE1 ensures that args contains 2 elements
341-
let args = cf.args();
341+
let val = cf.args()[1];
342342

343-
let Ok(val) = core::str::from_utf8(args[1].as_bytes()) else {
344-
return NGX_CONF_ERROR;
345-
};
346-
let val = ChallengeKind::from(val);
347-
if !matches!(val, ChallengeKind::Http01 | ChallengeKind::TlsAlpn01) {
348-
ngx_conf_log_error!(NGX_LOG_EMERG, cf, "unsupported challenge type: {val:?}");
349-
return NGX_CONF_ERROR;
343+
let val = match val.as_bytes() {
344+
b"http" | b"http-01" => ChallengeKind::Http01,
345+
b"tls-alpn" | b"tls-alpn-01" => ChallengeKind::TlsAlpn01,
346+
_ => {
347+
ngx_conf_log_error!(NGX_LOG_EMERG, cf, "unsupported challenge: {val}");
348+
return NGX_CONF_ERROR;
349+
}
350350
};
351351

352352
issuer.challenge = Some(val);

t/acme_conf_issuer.t

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use Test::Nginx;
2424
select STDERR; $| = 1;
2525
select STDOUT; $| = 1;
2626

27-
my $t = Test::Nginx->new()->has(qw/http http_ssl/)->plan(7);
27+
my $t = Test::Nginx->new()->has(qw/http http_ssl/)->plan(8);
2828

2929
use constant TEMPLATE_CONF => <<'EOF';
3030
@@ -67,6 +67,7 @@ acme_shared_zone zone=ngx_acme_shared:1M;
6767
acme_issuer example {
6868
uri https://localhost:%%PORT_9000%%/dir;
6969
account_key ecdsa:256;
70+
challenge http;
7071
7172
ssl_verify off;
7273
state_path %%TESTDIR%%;
@@ -161,6 +162,20 @@ resolver 127.0.0.1:%%PORT_8980_UDP%%;
161162
162163
EOF
163164

165+
166+
like(check($t, <<'EOF' ), qr/\[emerg].*unsupported challenge/, 'bad challenge');
167+
168+
acme_issuer example {
169+
uri https://localhost:%%PORT_9000%%/dir;
170+
challenge bad-value;
171+
ssl_verify off;
172+
state_path %%TESTDIR%%;
173+
}
174+
175+
resolver 127.0.0.1:%%PORT_8980_UDP%%;
176+
177+
EOF
178+
164179
# stop and clear the log to avoid triggering sanitizer checks
165180

166181
$t->stop()->write_file('error.log', '');

0 commit comments

Comments
 (0)