sfackler / rust-native-tls

Apache License 2.0
475 stars 200 forks source link

Windows unexpected or badly formatted, MacOS bad protocol version #305

Open fufesou opened 1 week ago

fufesou commented 1 week ago

version: 0.2.12

We're currently facing this issue https://github.com/rustdesk/rustdesk-server-pro/issues/417

It's the same to https://github.com/seanmonstar/reqwest/issues/2004 and https://github.com/seanmonstar/reqwest/discussions/2411

Sample code

use native_tls::TlsConnector;
use std::io::{Read, Write};
use std::net::TcpStream;

fn main() {
    let connector = TlsConnector::new().unwrap();

    let stream = TcpStream::connect("test.com:443").unwrap();
    let mut stream = connector.connect("test.com", stream).unwrap();

    stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap();
    let mut res = vec![];
    stream.read_to_end(&mut res).unwrap();
    println!("{}", String::from_utf8_lossy(&res));
}

Output

Trace log on Windows ``` called `Result::unwrap()` on an `Err` value: Failure(Os { code: -2146893018, kind: Uncategorized, message: "The message received was unexpected or badly formatted." }) ```
Trace log on MacOS ``` called `Result::unwrap()` on an `Err` value: Failure(Error { code: -9836, message: "bad protocol version" }) ```
Curl -vv ``` * Connected to test.com (54.36.110.163) port 443 (#0) * ALPN: offers h2,http/1.1 } [5 bytes data] * TLSv1.3 (OUT), TLS handshake, Client hello (1): } [512 bytes data] * CAfile: D:/Program Files/Git/mingw64/etc/ssl/certs/ca-bundle.crt * CApath: none { [5 bytes data] * TLSv1.3 (IN), TLS handshake, Server hello (2): { [122 bytes data] * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8): { [15 bytes data] * TLSv1.3 (IN), TLS handshake, Certificate (11): { [2838 bytes data] * TLSv1.3 (IN), TLS handshake, CERT verify (15): { [520 bytes data] * TLSv1.3 (IN), TLS handshake, Finished (20): { [36 bytes data] * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1): } [1 bytes data] * TLSv1.3 (OUT), TLS handshake, Finished (20): } [36 bytes data] * SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256 * ALPN: server accepted h2 * Server certificate: * subject: CN=test.com * start date: Oct 15 13:29:24 2024 GMT * expire date: Jan 13 13:29:23 2025 GMT * subjectAltName: host "test.com" matched cert's "*.test.com" * issuer: C=US; O=Let's Encrypt; CN=R10 * SSL certificate verify ok. } [5 bytes data] * using HTTP/2 * h2h3 [:method: GET] * h2h3 [:path: /api/oidc/auth] * h2h3 [:scheme: https] * h2h3 [:authority: test.com] * h2h3 [user-agent: curl/7.88.1] * h2h3 [accept: */*] * Using Stream ID: 1 (easy handle 0x1f41c451480) } [5 bytes data] > GET /api/oidc/auth HTTP/2 > Host: test.com > user-agent: curl/7.88.1 > accept: */* > { [5 bytes data] * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): { [122 bytes data] < HTTP/2 405 < allow: POST < date: Wed, 16 Oct 2024 03:38:35 GMT < content-length: 0 ```

The most possible reason. https://github.com/rustdesk/rustdesk-server-pro/issues/417#issuecomment-2415843704

fufesou commented 2 days ago

https://github.com/rustdesk/rustdesk-server-pro/issues/417#issuecomment-2436798604

Hi, sorry to bother, but is there any progress?