Skip to content

Commit 8846adf

Browse files
committed
fixup! ACME: alternative chains support.
1 parent edbe668 commit 8846adf

File tree

2 files changed

+52
-56
lines changed

2 files changed

+52
-56
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -237,24 +237,6 @@ Accepted values:
237237
The generated account keys are preserved across reloads,
238238
but will be lost on restart unless [state_path](#state_path) is configured.
239239

240-
### chain
241-
242-
**Syntax:** **`chain`** `issuer`=_`name`_
243-
244-
**Default:** -
245-
246-
**Context:** acme_issuer
247-
248-
_This directive appeared in version 0.3.0._
249-
250-
Specifies the preferred certificate chain.
251-
252-
If the ACME issuer offers multiple certificate chains,
253-
prefer the chain with the topmost certificate issued from the
254-
Subject Common Name _`name`_.
255-
256-
If no matches, the default chain will be used.
257-
258240
### challenge
259241

260242
**Syntax:** **`challenge`** _`type`_
@@ -308,6 +290,24 @@ In both cases, the key is expected to be encoded in
308290

309291
[RFC8555#eab]: https://datatracker.ietf.org/doc/html/rfc8555#section-7.3.4
310292

293+
### preferred_chain
294+
295+
**Syntax:** **`preferred_chain`** _`issuer name`_
296+
297+
**Default:** -
298+
299+
**Context:** acme_issuer
300+
301+
_This directive appeared in version 0.3.0._
302+
303+
Specifies the preferred certificate chain.
304+
305+
If the ACME issuer offers multiple certificate chains,
306+
prefer the chain with the topmost certificate issued from the
307+
Subject Common Name _`issuer name`_.
308+
309+
If no matches, the default chain will be used.
310+
311311
### profile
312312

313313
**Syntax:** **`profile`** _`name`_ \[`require`]

src/conf.rs

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,6 @@ static mut NGX_HTTP_ACME_ISSUER_COMMANDS: [ngx_command_t; 12] = [
101101
offset: 0,
102102
post: ptr::null_mut(),
103103
},
104-
ngx_command_t {
105-
name: ngx_string!("chain"),
106-
type_: NGX_CONF_TAKE1 as ngx_uint_t,
107-
set: Some(cmd_issuer_set_chain),
108-
conf: 0,
109-
offset: 0,
110-
post: ptr::null_mut(),
111-
},
112104
ngx_command_t {
113105
name: ngx_string!("challenge"),
114106
type_: NGX_CONF_TAKE1 as ngx_uint_t,
@@ -133,6 +125,14 @@ static mut NGX_HTTP_ACME_ISSUER_COMMANDS: [ngx_command_t; 12] = [
133125
offset: 0,
134126
post: ptr::null_mut(),
135127
},
128+
ngx_command_t {
129+
name: ngx_string!("preferred_chain"),
130+
type_: NGX_CONF_TAKE1 as ngx_uint_t,
131+
set: Some(cmd_issuer_set_preferred_chain),
132+
conf: 0,
133+
offset: 0,
134+
post: ptr::null_mut(),
135+
},
136136
ngx_command_t {
137137
name: ngx_string!("profile"),
138138
type_: nginx_sys::NGX_CONF_TAKE12 as ngx_uint_t,
@@ -351,36 +351,6 @@ extern "C" fn cmd_add_certificate(
351351
NGX_CONF_OK
352352
}
353353

354-
extern "C" fn cmd_issuer_set_chain(
355-
cf: *mut ngx_conf_t,
356-
_cmd: *mut ngx_command_t,
357-
conf: *mut c_void,
358-
) -> *mut c_char {
359-
let cf = unsafe { cf.as_mut().expect("cf") };
360-
let issuer = unsafe { conf.cast::<Issuer>().as_mut().expect("issuer conf") };
361-
362-
if issuer.chain.is_some() {
363-
return NGX_CONF_DUPLICATE;
364-
}
365-
366-
for value in &cf.args()[1..] {
367-
// SAFETY: the value is well aligned, and the conversion result is assigned to an object in
368-
// the same pool.
369-
let Ok(value) = (unsafe { conf_value_to_str(value) }) else {
370-
return NGX_CONF_INVALID_VALUE;
371-
};
372-
373-
if let Some(name) = value.strip_prefix("issuer=") {
374-
issuer.chain = Some(issuer::CertificateChainMatcher::new(name));
375-
continue;
376-
}
377-
378-
return NGX_CONF_INVALID_VALUE;
379-
}
380-
381-
NGX_CONF_OK
382-
}
383-
384354
extern "C" fn cmd_issuer_set_challenge(
385355
cf: *mut ngx_conf_t,
386356
_cmd: *mut ngx_command_t,
@@ -552,6 +522,32 @@ extern "C" fn cmd_issuer_set_external_account_key(
552522
NGX_CONF_OK
553523
}
554524

525+
extern "C" fn cmd_issuer_set_preferred_chain(
526+
cf: *mut ngx_conf_t,
527+
_cmd: *mut ngx_command_t,
528+
conf: *mut c_void,
529+
) -> *mut c_char {
530+
let cf = unsafe { cf.as_mut().expect("cf") };
531+
let issuer = unsafe { conf.cast::<Issuer>().as_mut().expect("issuer conf") };
532+
533+
if issuer.chain.is_some() {
534+
return NGX_CONF_DUPLICATE;
535+
}
536+
537+
// NGX_CONF_TAKE1 ensures that args contains 2 elements
538+
let args = cf.args();
539+
540+
// SAFETY: the value is well aligned, and the conversion result is assigned to an object in
541+
// the same pool.
542+
let Ok(issuer_name) = (unsafe { conf_value_to_str(&args[1]) }) else {
543+
return NGX_CONF_INVALID_VALUE;
544+
};
545+
546+
issuer.chain = Some(issuer::CertificateChainMatcher::new(issuer_name));
547+
548+
NGX_CONF_OK
549+
}
550+
555551
extern "C" fn cmd_issuer_set_profile(
556552
cf: *mut ngx_conf_t,
557553
_cmd: *mut ngx_command_t,

0 commit comments

Comments
 (0)