Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(websocket): Allow wss connections on IP addresses #5525

Merged
merged 8 commits into from
Aug 7, 2024

Conversation

oblique
Copy link
Contributor

@oblique oblique commented Aug 3, 2024

Description

Notes & open questions

It is completely valid to establish TLS connection with just an IP if:

  1. You add your self-sign certificate via add_trust.
  2. You create a valid certificate for an IP. For example 1.1.1.1 has a valid certificate.

Example with rustls:

use rustls::{ClientConfig, ClientConnection, RootCertStore, Stream};
use std::io::{Read, Write};
use std::net::TcpStream;
use std::sync::Arc;
use webpki_roots::TLS_SERVER_ROOTS;

fn main() {
    let provider = rustls::crypto::ring::default_provider();
    let cert_store = TLS_SERVER_ROOTS.iter().cloned().collect::<RootCertStore>();

    let client = ClientConfig::builder_with_provider(provider.into())
        .with_safe_default_protocol_versions()
        .unwrap()
        .with_root_certificates(cert_store)
        .with_no_client_auth();

    let server_name = "1.1.1.1".try_into().unwrap();
    let mut conn = ClientConnection::new(Arc::new(client), server_name).unwrap();
    let mut sock = TcpStream::connect("1.1.1.1:443").unwrap();

    let mut io = Stream::new(&mut conn, &mut sock);

    io.write_all(b"GET / HTTP/1.1\r\n\r\n").unwrap();

    let mut resp = Vec::new();
    io.read_to_end(&mut resp).unwrap();

    println!("{}", String::from_utf8(resp).unwrap());
}

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

Copy link
Contributor

mergify bot commented Aug 3, 2024

This pull request has merge conflicts. Could you please resolve them @oblique? 🙏

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Yiannis

transports/websocket/src/framed.rs Show resolved Hide resolved
transports/websocket/src/framed.rs Show resolved Hide resolved
@jxs jxs added the send-it label Aug 7, 2024
@mergify mergify bot merged commit 98da34a into libp2p:master Aug 7, 2024
72 checks passed
@oblique oblique deleted the feat/tls-ip branch August 7, 2024 09:43
TimTinkers pushed a commit to unattended-backpack/rust-libp2p that referenced this pull request Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants