Skip to content

Instantly share code, notes, and snippets.

@cite-reader
Created May 14, 2016 06:09
Show Gist options
  • Save cite-reader/0f7e57ca56078ea747bc85451e910ad0 to your computer and use it in GitHub Desktop.
Save cite-reader/0f7e57ca56078ea747bc85451e910ad0 to your computer and use it in GitHub Desktop.
OpenSSL from Rust
[package]
name = "openssl-ex"
version = "0.1.0"
authors = ["Alex Hill <alexander.d.hill.89@gmail.com>"]
[dependencies.openssl]
version = "0.7"
features = ["tlsv1_2"]
extern crate openssl;
use openssl::ssl::SslMethod::Tlsv1_2;
use openssl::ssl::SslContext;
use openssl::ssl::SslStream;
use std::net::TcpStream;
use std::io::{self, Write, Read};
fn main() {
let context = SslContext::new(Tlsv1_2).unwrap();
let client = TcpStream::connect("google.com:443").unwrap();
let mut secure_client = SslStream::connect(&context, client).unwrap();
write!(secure_client,
concat!(
"HEAD / HTTP/1.1\r\n",
"Host: google.com\r\n",
"User-Agent: Artisinally hand-crafted HTTP\r\n",
"Accept: */*\r\n\r\n"
)).unwrap();
let mut buffer = [0; 500];
let total = secure_client.read(&mut buffer).unwrap();
io::stdout().write(&buffer[.. total]).unwrap();
}
@cite-reader
Copy link
Author

CC0
To the extent possible under law, Alex Hill has waived all copyright and related or neighboring rights to OpenSSL Rust client example. This work is published from: United States.

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