Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kubert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["kubernetes", "client", "runtime", "server"]

[features]
_tls = [
"dep:rustls-pemfile",
"dep:rustls-pki-types",
"dep:tokio-rustls",
"kube-client?/rustls-tls",
]
Expand Down Expand Up @@ -194,7 +194,7 @@ once_cell = { version = "1", optional = true }
parking_lot = { version = "0.12", optional = true }
pin-project-lite = { version = "0.2", optional = true }
prometheus-client = { workspace = true, optional = true }
rustls-pemfile = { version = "2", optional = true }
rustls-pki-types = { version = "1", optional = true }
serde = { version = "1", optional = true }
serde_json = { version = "1", optional = true }
sha2 = { version = "0.10", optional = true }
Expand Down
15 changes: 10 additions & 5 deletions kubert/src/server/tls_rustls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use rustls_pki_types::{pem::PemObject, PrivatePkcs1KeyDer, PrivatePkcs8KeyDer};
use std::sync::Arc;
use tokio_rustls::{
rustls::{
Expand Down Expand Up @@ -39,19 +40,23 @@ async fn load_certs(
TlsCertPath(cp): &TlsCertPath,
) -> std::io::Result<Vec<CertificateDer<'static>>> {
let pem = tokio::fs::read(cp).await?;
rustls_pemfile::certs(&mut pem.as_slice()).collect()
CertificateDer::pem_slice_iter(pem.as_slice())
.collect::<Result<Vec<_>, _>>()
.map_err(std::io::Error::other)
}

async fn load_private_key(TlsKeyPath(kp): &TlsKeyPath) -> std::io::Result<PrivateKeyDer<'static>> {
let pem = tokio::fs::read(kp).await?;

let mut keys = rustls_pemfile::pkcs8_private_keys(&mut pem.as_slice())
let mut keys = PrivatePkcs8KeyDer::pem_slice_iter(pem.as_slice())
.map(|res| res.map(PrivateKeyDer::from))
.collect::<Result<Vec<_>, _>>()?;
.collect::<Result<Vec<_>, _>>()
.map_err(std::io::Error::other)?;
if keys.is_empty() {
keys = rustls_pemfile::rsa_private_keys(&mut pem.as_slice())
keys = PrivatePkcs1KeyDer::pem_slice_iter(pem.as_slice())
.map(|res| res.map(PrivateKeyDer::from))
.collect::<Result<Vec<_>, _>>()?;
.collect::<Result<Vec<_>, _>>()
.map_err(std::io::Error::other)?;
}

let key = keys
Expand Down
Loading