Skip to content

Commit e06f99a

Browse files
committed
Updated to latest rustls changes, fixed compilation and added feature flags
1 parent aedb23b commit e06f99a

File tree

5 files changed

+24
-30
lines changed

5 files changed

+24
-30
lines changed

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ no-default-features = true
1717

1818
[dependencies]
1919
rustls = { git = "https://github.com/rustls/rustls.git", default-features = false, features = ["std"] }
20+
rustls-pki-types = "1"
2021
windows-sys = { version = "0.60", features = ["Win32_Foundation", "Win32_Security_Cryptography"] }
2122

2223
[dev-dependencies]
@@ -25,9 +26,11 @@ clap = { version = "4", features = ["derive"] }
2526
rustls-pki-types = "1"
2627

2728
[features]
28-
default = ["logging", "tls12", "aws-lc-rs"]
29-
aws-lc-rs = ["rustls/aws_lc_rs"]
29+
default = ["log", "tls12", "aws-lc-rs"]
30+
aws-lc-rs = ["rustls/aws-lc-rs"]
3031
fips = ["rustls/fips"]
31-
logging = ["rustls/logging"]
32+
log = ["rustls/log"]
3233
ring = ["rustls/ring"]
3334
tls12 = ["rustls/tls12"]
35+
brotli = ["rustls/brotli"]
36+
zlib = ["rustls/zlib"]

examples/client.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@ impl ResolvesClientCert for ClientCertResolver {
5757
}
5858
for scheme in signing_key.supported_schemes() {
5959
if sigschemes.contains(scheme) {
60-
return Some(Arc::new(CertifiedKey {
61-
cert: chain,
62-
key: Arc::new(signing_key),
63-
ocsp: None,
64-
}));
60+
return CertifiedKey::new(chain, Arc::new(signing_key))
61+
.ok()
62+
.map(Arc::new);
6563
}
6664
}
6765
None

examples/server.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct ServerCertResolver {
5454
}
5555

5656
impl ResolvesServerCert for ServerCertResolver {
57-
fn resolve(&self, client_hello: ClientHello) -> Option<Arc<CertifiedKey>> {
57+
fn resolve(&self, client_hello: &ClientHello) -> Option<Arc<CertifiedKey>> {
5858
println!("Client hello server name: {:?}", client_hello.server_name());
5959
let name = client_hello.server_name()?;
6060

@@ -78,11 +78,7 @@ impl ResolvesServerCert for ServerCertResolver {
7878
let certs = chain.into_iter().map(Into::into).collect();
7979

8080
// return CertifiedKey instance
81-
Some(Arc::new(CertifiedKey {
82-
cert: certs,
83-
key: Arc::new(key),
84-
ocsp: None,
85-
}))
81+
CertifiedKey::new(certs, Arc::new(key)).ok().map(Arc::new)
8682
}
8783
}
8884

src/signer.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ use rustls::{
66
sign::{Signer, SigningKey},
77
Error, OtherError, SignatureAlgorithm, SignatureScheme,
88
};
9-
10-
use crate::key::{AlgorithmGroup, NCryptKey, SignaturePadding};
11-
12-
use windows_sys::Win32::Security::Cryptography::BCryptHash;
9+
use rustls_pki_types::SubjectPublicKeyInfoDer;
1310
use windows_sys::Win32::Security::Cryptography::{
14-
BCRYPT_SHA256_ALG_HANDLE, BCRYPT_SHA384_ALG_HANDLE, BCRYPT_SHA512_ALG_HANDLE,
11+
BCryptHash, BCRYPT_SHA256_ALG_HANDLE, BCRYPT_SHA384_ALG_HANDLE, BCRYPT_SHA512_ALG_HANDLE,
1512
};
1613

14+
use crate::key::{AlgorithmGroup, NCryptKey, SignaturePadding};
15+
1716
// Convert IEEE-P1363 signature format to DER encoding.
1817
// We assume the length of the r and s parts is less than 256 bytes.
1918
fn p1363_to_der(data: &[u8]) -> Vec<u8> {
@@ -193,6 +192,10 @@ impl SigningKey for CngSigningKey {
193192
None
194193
}
195194

195+
fn public_key(&self) -> Option<SubjectPublicKeyInfoDer<'_>> {
196+
None
197+
}
198+
196199
fn algorithm(&self) -> SignatureAlgorithm {
197200
match self.algorithm_group {
198201
AlgorithmGroup::Rsa => SignatureAlgorithm::RSA,

tests/test_client_server.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ mod client {
4848
let (chain, signing_key) = get_chain(&self.0, &self.1).ok()?;
4949
for scheme in signing_key.supported_schemes() {
5050
if sigschemes.contains(scheme) {
51-
return Some(Arc::new(CertifiedKey {
52-
cert: chain,
53-
key: Arc::new(signing_key),
54-
ocsp: None,
55-
}));
51+
return CertifiedKey::new(chain, Arc::new(signing_key))
52+
.ok()
53+
.map(Arc::new);
5654
}
5755
}
5856
None
@@ -117,7 +115,7 @@ mod server {
117115
pub struct ServerCertResolver(CertStore);
118116

119117
impl ResolvesServerCert for ServerCertResolver {
120-
fn resolve(&self, client_hello: ClientHello) -> Option<Arc<CertifiedKey>> {
118+
fn resolve(&self, client_hello: &ClientHello) -> Option<Arc<CertifiedKey>> {
121119
let name = client_hello.server_name()?;
122120

123121
let contexts = self.0.find_by_subject_str(name).ok()?;
@@ -130,11 +128,7 @@ mod server {
130128
let chain = context.as_chain_der().ok()?;
131129
let certs = chain.into_iter().map(Into::into).collect();
132130

133-
Some(Arc::new(CertifiedKey {
134-
cert: certs,
135-
key: Arc::new(key),
136-
ocsp: None,
137-
}))
131+
CertifiedKey::new(certs, Arc::new(key)).ok().map(Arc::new)
138132
}
139133
}
140134

0 commit comments

Comments
 (0)