Skip to content

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

@fufesou

Description

@fufesou

version: 0.2.12

We're currently facing this issue rustdesk/rustdesk-server-pro#417

It's the same to seanmonstar/reqwest#2004 and seanmonstar/reqwest#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. rustdesk/rustdesk-server-pro#417 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions