Created
May 14, 2016 06:09
-
-
Save cite-reader/0f7e57ca56078ea747bc85451e910ad0 to your computer and use it in GitHub Desktop.
OpenSSL from Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.