Skip to content

Instantly share code, notes, and snippets.

@UndeRus
Created November 12, 2015 09:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UndeRus/4086d8d12e780b5c76db to your computer and use it in GitHub Desktop.
Save UndeRus/4086d8d12e780b5c76db to your computer and use it in GitHub Desktop.
Openssl minimal rust example
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