Skip to content

CloseNotify alert received when using rustls/examples/simpleclient.rs #380

Closed

Description

@volfco

I'm trying to figure out how to write my own HTTP client using rustls/examples/simpleclient.rs as a base.

The code in master works when using it against google.com:443 or oracle.com, but fails on other popular sites such as reddit.com, twitter.com, github.com with the following error (this was against twitter.com):

Current ciphersuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: ConnectionAborted, error: "CloseNotify alert received" }', src/main.rs:40:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Not sure where in the pipeline this error is happening.

Activity

  1. ctz commented on Jun 28, 2020

    @ctz
    Member

    This is a normal and expected error: I've ensure it's mentioned in the docs as of a5e1488. TLDR: it signifies clean connection closure by the peer. close_notify does not have universal support in TLS libraries/applications, so that's why you see variance between hosts. In your application you should respond by tearing down the underlying TCP connection.

  2. volfco commented on Jun 28, 2020

    @volfco
    Author

    I still think the example should be fixed so it's handled.

    I can open up an MR throwing in a check to prevent a panic like this:

    let reader = tls.read_to_end(&mut plaintext);
    if reader.is_err() {
        let err = reader.err().unwrap();
        if err.kind() != ErrorKind::ConnectionAborted && !err.to_string().contains("CloseNotify") {
            reader.unwrap()
        }
    }

    But there has to be a better solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions