Skip to content

Commit 80b79cd

Browse files
authored
Merge pull request #37 from hrvolapeter/rustls-0.20
Upgrade to rustls 0.20
2 parents 92f45b0 + dd7e5dd commit 80b79cd

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ webpki-roots = ["hyper-rustls/webpki-roots"]
1919
base64 = "0.13"
2020
time = { version = "0.3.5", features = ["serde"] }
2121
hyper = { version = "0.14.2", features = ["client", "runtime", "http2"] }
22-
hyper-rustls = { version = "0.22.1", default-features = false, features = ["tokio-runtime"] }
22+
hyper-rustls = { version = "0.23.0", default-features = false, features = ["native-tokio", "http1", "http2"] }
2323
log = "0.4"
24-
rustls = "0.19.0"
24+
rustls = "0.20.2"
25+
rustls-pemfile = "0.2.1"
2526
serde = {version = "1.0", features = ["derive"]}
2627
serde_json = "1.0"
2728
tokio = { version = "1.1", features = ["fs"] }

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub enum Error {
1818
/// Error in underlying RustTLS library.
1919
/// Might signal problem with establishing secure connection using trusted certificates
2020
#[error("TLS error")]
21-
TLSError(rustls::TLSError),
21+
TLSError(rustls::Error),
2222

2323
/// Error when establishing connection to OAuth server
2424
#[error("Could not establish connection with OAuth server")]

src/jwt.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::io;
44

55
use rustls::{
66
self,
7-
internal::pemfile,
87
sign::{self, SigningKey},
98
PrivateKey,
109
};
@@ -23,12 +22,12 @@ fn append_base64<T: AsRef<[u8]> + ?Sized>(s: &T, out: &mut String) {
2322

2423
/// Decode a PKCS8 formatted RSA key.
2524
fn decode_rsa_key(pem_pkcs8: &str) -> Result<PrivateKey, io::Error> {
26-
let private_keys = pemfile::pkcs8_private_keys(&mut pem_pkcs8.as_bytes());
25+
let private_keys = rustls_pemfile::pkcs8_private_keys(&mut pem_pkcs8.as_bytes());
2726

2827
match private_keys {
2928
Ok(mut keys) if !keys.is_empty() => {
3029
keys.truncate(1);
31-
Ok(keys.remove(0))
30+
Ok(PrivateKey(keys.remove(0)))
3231
}
3332
Ok(_) => Err(io::Error::new(
3433
io::ErrorKind::InvalidInput,
@@ -89,14 +88,14 @@ pub(crate) struct JwtSigner {
8988
impl JwtSigner {
9089
pub(crate) fn new(private_key: &str) -> Result<Self, Error> {
9190
let key = decode_rsa_key(private_key)?;
92-
let signing_key = sign::RSASigningKey::new(&key).map_err(|_| Error::SignerInit)?;
91+
let signing_key = sign::RsaSigningKey::new(&key).map_err(|_| Error::SignerInit)?;
9392
let signer = signing_key
9493
.choose_scheme(&[rustls::SignatureScheme::RSA_PKCS1_SHA256])
9594
.ok_or(Error::SignerSchemeError)?;
9695
Ok(JwtSigner { signer })
9796
}
9897

99-
pub(crate) fn sign_claims(&self, claims: &Claims) -> Result<String, rustls::TLSError> {
98+
pub(crate) fn sign_claims(&self, claims: &Claims) -> Result<String, rustls::Error> {
10099
let mut jwt_head = Self::encode_claims(claims);
101100
let signature = self.signer.sign(jwt_head.as_bytes())?;
102101
jwt_head.push('.');

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub use types::Token;
8080
use std::path::Path;
8181

8282
use hyper::Client;
83-
use hyper_rustls::HttpsConnector;
83+
use hyper_rustls::HttpsConnectorBuilder;
8484

8585
/// Initialize GCP authentication based on a credentials file
8686
///
@@ -95,11 +95,12 @@ async fn get_authentication_manager(
9595
credential_path: Option<&Path>,
9696
) -> Result<AuthenticationManager, Error> {
9797
#[cfg(feature = "webpki-roots")]
98-
let https = HttpsConnector::with_webpki_roots();
98+
let https = HttpsConnectorBuilder::new().with_webpki_roots();
9999
#[cfg(not(feature = "webpki-roots"))]
100-
let https = HttpsConnector::with_native_roots();
100+
let https = HttpsConnectorBuilder::new().with_native_roots();
101101

102-
let client = Client::builder().build::<_, hyper::Body>(https);
102+
let client =
103+
Client::builder().build::<_, hyper::Body>(https.https_only().enable_http2().build());
103104

104105
let custom = match credential_path {
105106
Some(path) => CustomServiceAccount::from_file(path).await,

0 commit comments

Comments
 (0)