Skip to content

Commit 06edcfa

Browse files
committed
use rustls-pki-types pem api
Signed-off-by: tottoto <[email protected]>
1 parent 0bcc625 commit 06edcfa

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ proc-macro2 = "1.0.29"
7070
quote = "1.0.10"
7171
rand = "0.9.0"
7272
rustls = { version = "0.23.16", default-features = false }
73-
rustls-pemfile = "2.0.0"
7473
schemars = "0.8.6"
7574
secrecy = "0.10.2"
7675
serde = "1.0.130"

kube-client/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ categories = ["web-programming::http-client", "network-programming", "api-bindin
1313

1414
[features]
1515
default = ["client"]
16-
rustls-tls = ["rustls", "rustls-pemfile", "hyper-rustls", "hyper-http-proxy?/rustls-tls-native-roots"]
16+
rustls-tls = ["rustls", "hyper-rustls", "hyper-http-proxy?/rustls-tls-native-roots"]
1717
webpki-roots = ["hyper-rustls/webpki-roots"]
1818
aws-lc-rs = ["rustls?/aws-lc-rs"]
1919
openssl-tls = ["openssl", "hyper-openssl"]
@@ -57,7 +57,6 @@ futures = { workspace = true, optional = true, features = ["std"] }
5757
pem = { workspace = true, optional = true }
5858
openssl = { workspace = true, optional = true }
5959
rustls = { workspace = true, optional = true }
60-
rustls-pemfile = { workspace = true, optional = true }
6160
bytes = { workspace = true, optional = true }
6261
tokio = { workspace = true, features = ["time", "signal", "sync"], optional = true }
6362
kube-core = { path = "../kube-core", version = "=0.98.0" }

kube-client/src/client/tls.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub mod rustls_tls {
1414
pub enum Error {
1515
/// Identity PEM is invalid
1616
#[error("identity PEM is invalid: {0}")]
17-
InvalidIdentityPem(#[source] std::io::Error),
17+
InvalidIdentityPem(#[source] rustls::pki_types::pem::Error),
1818

1919
/// Identity PEM is missing a private key: the key must be PKCS8 or RSA/PKCS1
2020
#[error("identity PEM is missing a private key: the key must be PKCS8 or RSA/PKCS1")]
@@ -96,22 +96,19 @@ pub mod rustls_tls {
9696
}
9797

9898
fn client_auth(data: &[u8]) -> Result<(Vec<CertificateDer<'static>>, PrivateKeyDer<'static>), Error> {
99-
use rustls_pemfile::Item;
99+
use rustls::pki_types::pem::{self, PemObject, SectionKind};
100100

101101
let mut cert_chain = Vec::new();
102102
let mut pkcs8_key = None;
103103
let mut pkcs1_key = None;
104104
let mut sec1_key = None;
105105
let mut reader = std::io::Cursor::new(data);
106-
for item in rustls_pemfile::read_all(&mut reader)
107-
.collect::<Result<Vec<_>, _>>()
108-
.map_err(Error::InvalidIdentityPem)?
109-
{
110-
match item {
111-
Item::X509Certificate(cert) => cert_chain.push(cert),
112-
Item::Pkcs8Key(key) => pkcs8_key = Some(PrivateKeyDer::Pkcs8(key)),
113-
Item::Pkcs1Key(key) => pkcs1_key = Some(PrivateKeyDer::from(key)),
114-
Item::Sec1Key(key) => sec1_key = Some(PrivateKeyDer::from(key)),
106+
while let Some((kind, der)) = pem::from_buf(&mut reader).map_err(Error::InvalidIdentityPem)? {
107+
match kind {
108+
SectionKind::Certificate => cert_chain.push(der.into()),
109+
SectionKind::PrivateKey => pkcs8_key = PrivateKeyDer::from_pem(kind, der),
110+
SectionKind::RsaPrivateKey => pkcs1_key = PrivateKeyDer::from_pem(kind, der),
111+
SectionKind::EcPrivateKey => sec1_key = PrivateKeyDer::from_pem(kind, der),
115112
_ => return Err(Error::UnknownPrivateKeyFormat),
116113
}
117114
}

0 commit comments

Comments
 (0)