-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose API to enable certificate compression.
- Loading branch information
1 parent
2b75e1e
commit 2245501
Showing
6 changed files
with
286 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,4 @@ tower = "0.4" | |
tower-layer = "0.3" | ||
tower-service = "0.3" | ||
autocfg = "1.3.0" | ||
brotli = "6.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
use std::io::Write as _; | ||
|
||
use super::server::Server; | ||
use crate::ssl::CertificateCompressor; | ||
use crate::x509::store::X509StoreBuilder; | ||
use crate::x509::X509; | ||
|
||
struct BrotliCompressor { | ||
q: u32, | ||
lgwin: u32, | ||
} | ||
|
||
impl Default for BrotliCompressor { | ||
fn default() -> Self { | ||
Self { q: 11, lgwin: 32 } | ||
} | ||
} | ||
|
||
impl CertificateCompressor for BrotliCompressor { | ||
fn algorithm(&self) -> crate::ssl::CertificateCompressionAlgorithm { | ||
crate::ssl::CertificateCompressionAlgorithm(1234) | ||
} | ||
|
||
fn can_compress(&self) -> bool { | ||
true | ||
} | ||
|
||
fn can_decompress(&self) -> bool { | ||
true | ||
} | ||
|
||
fn compress<W>(&self, input: &[u8], output: &mut W) -> std::io::Result<()> | ||
where | ||
W: std::io::Write, | ||
{ | ||
let mut writer = brotli::CompressorWriter::new(output, 1024, self.q, self.lgwin); | ||
writer.write_all(&input)?; | ||
Ok(()) | ||
} | ||
|
||
fn decompress<W>(&self, input: &[u8], output: &mut W) -> std::io::Result<()> | ||
where | ||
W: std::io::Write, | ||
{ | ||
brotli::BrotliDecompress(&mut std::io::Cursor::new(input), output)?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[test] | ||
fn server_only_cert_compression() { | ||
let mut server_builder = Server::builder(); | ||
server_builder | ||
.ctx() | ||
.add_certificate_compression_algorithm(BrotliCompressor::default()) | ||
.unwrap(); | ||
|
||
let server = server_builder.build(); | ||
|
||
let mut store = X509StoreBuilder::new().unwrap(); | ||
let x509 = X509::from_pem(super::ROOT_CERT).unwrap(); | ||
store.add_cert(x509).unwrap(); | ||
|
||
let client = server.client(); | ||
|
||
client.connect(); | ||
} | ||
|
||
#[test] | ||
fn client_only_cert_compression() { | ||
let server_builder = Server::builder().build(); | ||
|
||
let mut store = X509StoreBuilder::new().unwrap(); | ||
let x509 = X509::from_pem(super::ROOT_CERT).unwrap(); | ||
store.add_cert(x509).unwrap(); | ||
|
||
let mut client = server_builder.client(); | ||
client | ||
.ctx() | ||
.add_certificate_compression_algorithm(BrotliCompressor::default()) | ||
.unwrap(); | ||
|
||
client.connect(); | ||
} | ||
|
||
#[test] | ||
fn client_and_server_cert_compression() { | ||
let mut server = Server::builder(); | ||
server | ||
.ctx() | ||
.add_certificate_compression_algorithm(BrotliCompressor::default()) | ||
.unwrap(); | ||
|
||
let server = server.build(); | ||
|
||
let mut store = X509StoreBuilder::new().unwrap(); | ||
let x509 = X509::from_pem(super::ROOT_CERT).unwrap(); | ||
store.add_cert(x509).unwrap(); | ||
|
||
let mut client = server.client(); | ||
client | ||
.ctx() | ||
.add_certificate_compression_algorithm(BrotliCompressor::default()) | ||
.unwrap(); | ||
|
||
client.connect(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters