Skip to content

Commit 6af1417

Browse files
committed
Make certificate/private key configuration fallible
1 parent b119ef7 commit 6af1417

4 files changed

Lines changed: 47 additions & 17 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_chain(cert_chain)?;
184184
ActionResult::Applied
185185
}
186186
State::ApplyingToSsl(_) => {

src/entry.rs

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

286-
ctx.get_mut().stage_certificate_chain(chain);
287-
C_INT_SUCCESS as i64
286+
match ctx.get_mut().stage_certificate_chain(chain) {
287+
Err(e) => e.raise().into(),
288+
Ok(()) => C_INT_SUCCESS as i64,
289+
}
288290
}
289291
Ok(SslCtrl::SetTlsExtServerNameArg) => {
290292
ctx.get_mut().set_servername_callback_context(parg);
@@ -479,8 +481,10 @@ entry! {
479481
Err(err) => return err.raise().into(),
480482
};
481483

482-
ctx.get_mut().stage_certificate_chain(chain);
483-
C_INT_SUCCESS
484+
match ctx.get_mut().stage_certificate_chain(chain) {
485+
Ok(()) => C_INT_SUCCESS,
486+
Err(e) => e.raise().into(),
487+
}
484488
}
485489
}
486490

@@ -523,8 +527,10 @@ entry! {
523527
let x509 = OwnedX509::new_incref(x);
524528
let ee = CertificateDer::from(x509.der_bytes());
525529

526-
ctx.get_mut().stage_certificate_end_entity(ee);
527-
C_INT_SUCCESS
530+
match ctx.get_mut().stage_certificate_end_entity(ee) {
531+
Ok(()) => C_INT_SUCCESS,
532+
Err(e) => e.raise().into(),
533+
}
528534
}
529535
}
530536

@@ -958,8 +964,10 @@ entry! {
958964
}
959965
};
960966

961-
ssl.get_mut().stage_certificate_chain(chain);
962-
C_INT_SUCCESS as i64
967+
match ssl.get_mut().stage_certificate_chain(chain) {
968+
Ok(()) => C_INT_SUCCESS as i64,
969+
Err(e) => e.raise().into(),
970+
}
963971
}
964972
Ok(SslCtrl::GetNegotiatedGroup) => ssl
965973
.get()
@@ -1448,8 +1456,10 @@ entry! {
14481456
let x509 = OwnedX509::new_incref(x);
14491457
let ee = CertificateDer::from(x509.der_bytes());
14501458

1451-
ssl.get_mut().stage_certificate_end_entity(ee);
1452-
C_INT_SUCCESS
1459+
match ssl.get_mut().stage_certificate_end_entity(ee) {
1460+
Ok(()) => C_INT_SUCCESS,
1461+
Err(e) => e.raise().into(),
1462+
}
14531463
}
14541464
}
14551465

src/lib.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,17 @@ impl SslContext {
678678
self.cert_callback = callbacks::CertCallbackConfig { cb, context };
679679
}
680680

681-
fn stage_certificate_end_entity(&mut self, end: CertificateDer<'static>) {
681+
fn stage_certificate_end_entity(
682+
&mut self,
683+
end: CertificateDer<'static>,
684+
) -> Result<(), error::Error> {
682685
self.auth_keys.stage_certificate_end_entity(end)
683686
}
684687

685-
fn stage_certificate_chain(&mut self, chain: Vec<CertificateDer<'static>>) {
688+
fn stage_certificate_chain(
689+
&mut self,
690+
chain: Vec<CertificateDer<'static>>,
691+
) -> Result<(), error::Error> {
686692
self.auth_keys.stage_certificate_chain(chain)
687693
}
688694

@@ -933,11 +939,17 @@ impl Ssl {
933939
self.mode == ConnMode::Server
934940
}
935941

936-
fn stage_certificate_end_entity(&mut self, end: CertificateDer<'static>) {
942+
fn stage_certificate_end_entity(
943+
&mut self,
944+
end: CertificateDer<'static>,
945+
) -> Result<(), error::Error> {
937946
self.auth_keys.stage_certificate_end_entity(end)
938947
}
939948

940-
fn stage_certificate_chain(&mut self, chain: Vec<CertificateDer<'static>>) {
949+
fn stage_certificate_chain(
950+
&mut self,
951+
chain: Vec<CertificateDer<'static>>,
952+
) -> Result<(), error::Error> {
941953
self.auth_keys.stage_certificate_chain(chain)
942954
}
943955

src/sign.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,20 @@ pub struct CertifiedKeySet {
3434
}
3535

3636
impl CertifiedKeySet {
37-
pub fn stage_certificate_chain(&mut self, chain: Vec<CertificateDer<'static>>) {
37+
pub fn stage_certificate_chain(
38+
&mut self,
39+
chain: Vec<CertificateDer<'static>>,
40+
) -> Result<(), error::Error> {
3841
self.pending_cert_chain = Some(chain);
42+
Ok(())
3943
}
4044

41-
pub fn stage_certificate_end_entity(&mut self, end: CertificateDer<'static>) {
45+
pub fn stage_certificate_end_entity(
46+
&mut self,
47+
end: CertificateDer<'static>,
48+
) -> Result<(), error::Error> {
4249
self.pending_cert_end_entity = Some(end);
50+
Ok(())
4351
}
4452

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

0 commit comments

Comments
 (0)