Skip to content

Commit eb4304a

Browse files
committed
Add precision to certificate chain operations
We were convolving functions that operate only on the tail of a certificate chain (eg, `SSL_CTX_set0_chain`) and those that provide the entire chain in one (eg, `SSL_CTX_use_certificate_chain_file` or the `Certificate` conf directive).
1 parent 6af1417 commit eb4304a

4 files changed

Lines changed: 36 additions & 9 deletions

File tree

src/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl SslConfigCtx {
180180
State::ApplyingToCtx(ctx) => {
181181
// the "Certificate" command after `SSL_CONF_CTX_set_ssl_ctx` is documented as using
182182
// `SSL_CTX_use_certificate_chain_file`.
183-
ctx.get_mut().stage_certificate_chain(cert_chain)?;
183+
ctx.get_mut().stage_certificate_full_chain(cert_chain)?;
184184
ActionResult::Applied
185185
}
186186
State::ApplyingToSsl(_) => {

src/entry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ entry! {
283283
}
284284
};
285285

286-
match ctx.get_mut().stage_certificate_chain(chain) {
286+
match ctx.get_mut().stage_certificate_chain_tail(chain) {
287287
Err(e) => e.raise().into(),
288288
Ok(()) => C_INT_SUCCESS as i64,
289289
}
@@ -481,7 +481,7 @@ entry! {
481481
Err(err) => return err.raise().into(),
482482
};
483483

484-
match ctx.get_mut().stage_certificate_chain(chain) {
484+
match ctx.get_mut().stage_certificate_full_chain(chain) {
485485
Ok(()) => C_INT_SUCCESS,
486486
Err(e) => e.raise().into(),
487487
}
@@ -964,7 +964,7 @@ entry! {
964964
}
965965
};
966966

967-
match ssl.get_mut().stage_certificate_chain(chain) {
967+
match ssl.get_mut().stage_certificate_chain_tail(chain) {
968968
Ok(()) => C_INT_SUCCESS as i64,
969969
Err(e) => e.raise().into(),
970970
}

src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,18 @@ impl SslContext {
685685
self.auth_keys.stage_certificate_end_entity(end)
686686
}
687687

688-
fn stage_certificate_chain(
688+
fn stage_certificate_full_chain(
689689
&mut self,
690690
chain: Vec<CertificateDer<'static>>,
691691
) -> Result<(), error::Error> {
692-
self.auth_keys.stage_certificate_chain(chain)
692+
self.auth_keys.stage_certificate_full_chain(chain)
693+
}
694+
695+
fn stage_certificate_chain_tail(
696+
&mut self,
697+
chain: Vec<CertificateDer<'static>>,
698+
) -> Result<(), error::Error> {
699+
self.auth_keys.stage_certificate_chain_tail(chain)
693700
}
694701

695702
fn commit_private_key(&mut self, key: evp_pkey::EvpPkey) -> Result<(), error::Error> {
@@ -946,11 +953,11 @@ impl Ssl {
946953
self.auth_keys.stage_certificate_end_entity(end)
947954
}
948955

949-
fn stage_certificate_chain(
956+
fn stage_certificate_chain_tail(
950957
&mut self,
951958
chain: Vec<CertificateDer<'static>>,
952959
) -> Result<(), error::Error> {
953-
self.auth_keys.stage_certificate_chain(chain)
960+
self.auth_keys.stage_certificate_chain_tail(chain)
954961
}
955962

956963
fn commit_private_key(&mut self, key: evp_pkey::EvpPkey) -> Result<(), error::Error> {

src/sign.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,27 @@ pub struct CertifiedKeySet {
3434
}
3535

3636
impl CertifiedKeySet {
37-
pub fn stage_certificate_chain(
37+
/// Set the entirety of the current certificate chain to `chain`.
38+
///
39+
/// `chain[0]` is the end-entity cert.
40+
pub fn stage_certificate_full_chain(
41+
&mut self,
42+
mut chain: Vec<CertificateDer<'static>>,
43+
) -> Result<(), error::Error> {
44+
match chain.is_empty() {
45+
false => {
46+
self.stage_certificate_end_entity(chain.remove(0))?;
47+
self.stage_certificate_chain_tail(chain)
48+
}
49+
true => Err(error::Error::bad_data("empty certificate full chain")),
50+
}
51+
}
52+
53+
/// Set the "bottom part" of the current certificate chain to `chain`.
54+
///
55+
/// This does not contain the end-entity certificate. That must be provided separately
56+
/// with `stage_certificate_end_entity()`.
57+
pub fn stage_certificate_chain_tail(
3858
&mut self,
3959
chain: Vec<CertificateDer<'static>>,
4060
) -> Result<(), error::Error> {

0 commit comments

Comments
 (0)