Created
November 12, 2015 09:11
-
-
Save UndeRus/4086d8d12e780b5c76db to your computer and use it in GitHub Desktop.
Openssl minimal rust example
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 std::io::prelude::*; | |
use std::path::Path; | |
use std::net::TcpStream; | |
use openssl::ssl::{Ssl, SslMethod, SslContext, SslStream, SSL_VERIFY_NONE}; | |
use openssl::x509::{X509FileType}; | |
fn main() { | |
let mut ctx = SslContext::new(SslMethod::Sslv23).unwrap(); | |
let cert = Path::new("client.pem"); | |
let key = Path::new("client.key"); | |
ctx.set_cipher_list("DEFAULT"); | |
ctx.set_certificate_file(cert, X509FileType::PEM); | |
ctx.set_private_key_file(key, X509FileType::PEM); | |
ctx.set_verify(SSL_VERIFY_NONE, None); | |
//Ok(Openssl { context: Arc::new(ctx) }) | |
let ssl = Ssl::new(&ctx).unwrap(); | |
let mut stream = TcpStream::connect("127.0.0.1:64738").unwrap(); | |
let mut sslStream = SslStream::connect(ssl, stream).unwrap(); | |
let mut buffer = [0; 10]; | |
sslStream.write(b"some bytes"); | |
sslStream.read(&mut buffer[..]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment