Skip to content

Commit

Permalink
enable h2 for native-tls https
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Dec 30, 2020
1 parent 2bcc40c commit 38b5f83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/shadowsocks-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ rand = { version = "0.8", optional = true }
futures = "0.3"
tokio = { version = "1.0", features = ["full"] }
tokio-native-tls = { version = "0.3", optional = true }
native-tls = { version = "0.2", optional = true }
native-tls = { version = "0.2.7", optional = true, features = ["alpn"] }
tokio-rustls = { version = "0.22", optional = true }
webpki-roots = { version = "0.21", optional = true }
rustls-native-certs = { version = "0.5", optional = true }
Expand Down
15 changes: 11 additions & 4 deletions crates/shadowsocks-service/src/local/http/http_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ProxyHttpStream {
pub async fn connect_https(stream: AutoProxyClientStream, domain: &str) -> io::Result<ProxyHttpStream> {
use native_tls::TlsConnector;

let cx = match TlsConnector::builder().build() {
let cx = match TlsConnector::builder().request_alpns(&["h2", "http/1.1"]).build() {
Ok(c) => c,
Err(err) => {
return Err(io::Error::new(ErrorKind::Other, format!("tls build: {}", err)));
Expand All @@ -40,9 +40,16 @@ impl ProxyHttpStream {

match cx.connect(domain, stream).await {
Ok(s) => {
// FIXME: There is no API to set ALPN for negociating H2
// https://github.com/sfackler/rust-native-tls/issues/49
Ok(ProxyHttpStream::Https(s, false))
let negociated_h2 = match s.get_ref().negotiated_alpn() {
Ok(Some(alpn)) => alpn == b"h2",
Ok(None) => false,
Err(err) => {
let ierr = io::Error::new(ErrorKind::Other, format!("tls alpn negociate: {}", err));
return Err(ierr);
}
};

Ok(ProxyHttpStream::Https(s, negociated_h2))
}
Err(err) => {
let ierr = io::Error::new(ErrorKind::Other, format!("tls connect: {}", err));
Expand Down

0 comments on commit 38b5f83

Please sign in to comment.