Crate blaze_ssl_async

source ·
Expand description

Blaze SSL Async

BlazeSSL Async is an implementation of the SSLv3 protocol and the TLS_RSA_WITH_RC4_128_SHA, and TLS_RSA_WITH_RC4_128_MD5 ciphers.

This library does not implement the entirety of the protocol it only implements client auth through x509 certificates and server auth through the self signed key.pem and cert.pem stored in the src directory.

This is used by the Pocket Relay project to allow the server to accept connections that would normally go to gosredirector.ea.com and also connect to the official servers for both MITM logic and Origin authentication.

Usage

Add dependency to your cargo dependencies

blaze-ssl-async = "^0.3"

Connecting to a server

The example below if for connecting to a server as a client

// BlazeStream is a wrapper over tokios TcpStream
use blaze_ssl_async::stream::BlazeStream;

// Tokio read write extensions used for read_exact and write_all
use tokio::io::{AsyncReadExt, AsyncWriteExt};

// BlazeStream::connect takes in any value that implements ToSocketAddrs
// some common implementations are "HOST:PORT" and ("HOST", PORT)
let mut stream = BlazeStream::connect(("159.153.64.175", 42127))
    .await
    .expect("Failed to create blaze stream");

// TODO... Read from the stream as you would a normal TcpStream
let mut buf = [0u8; 12];
stream.read_exact(&mut buf)
    .await
    .expect("Failed to read 12 bytes");
// Write the bytes back
stream.write_all(&buf)
    .await
    .expect("Failed to write 12 by tes");
// You **MUST** flush BlazeSSL streams or else the data will never
// be sent to the client (If you don't flush the data won't be written till the next read)
stream.flush()
    .await
    .expect("Failed to flush");

Binding a server

The example below is an example for creating a server that accepts clients

// BlazeListener is wrapper over tokios TcpListener
use crate::stream::BlazeListener;

// Tokio read write extensions used for read_exact and write_all
use tokio::io::{AsyncReadExt, AsyncWriteExt};

// Bind a listener accepts the same address values as the tokio TcpListener
let listener = BlazeListener::bind(("0.0.0.0", 42127))
        .await
        .expect("Failed to bind blaze listener");

// Accept new connections
loop {
    // Accept the initial TcpStream without SSL
    let (stream, _) = listener
        .accept()
        .await
        .expect("Failed to accept stream");
    tokio::spawn(async move {
        // Complete the SSL handshake process in a spawned task
        let stream = stream.finish_accept()
            .await
            .expect("Failed to finish accepting stream");

        // Read and write to the stream the same as in the client example
    });
}

Note: This accept and finish_accept system is in place as to not prevent accepting new connections while a handshake is being completed. If you want to block new connections and do the handshaking portion in the accept you can use blocking_accept instead of accept and the finish_accept call is no longer necessary

Re-exports

Modules