Skip to content

Commit

Permalink
Merge 9971773 into 1287510
Browse files Browse the repository at this point in the history
  • Loading branch information
TimonPost committed Dec 28, 2019
2 parents 1287510 + 9971773 commit 5865415
Show file tree
Hide file tree
Showing 71 changed files with 4,930 additions and 3,696 deletions.
2 changes: 2 additions & 0 deletions admin/pipelines/cargo-steps.yml
Expand Up @@ -15,3 +15,5 @@ steps:
workingDirectory: rustls
- script: cargo test --release --no-run
displayName: "cargo test (release; no run)"
- script: cargo fmt --all -- --check
displayName: "cargo fmt (all; check)"
14 changes: 7 additions & 7 deletions rustls-mio/examples/simple_0rtt_client.rs
@@ -1,12 +1,14 @@
use std::sync::Arc;

use std::io::{stdout, Read, Write};
use std::net::TcpStream;
use std::{
io::{stdout, Read, Write},
net::TcpStream,
};

use env_logger;
use rustls;
use webpki;
use webpki_roots;
use env_logger;

fn start_session(config: &Arc<rustls::ClientConfig>, domain_name: &str) {
let dns_name = webpki::DNSNameRef::try_from_ascii_str(domain_name).unwrap();
Expand All @@ -26,15 +28,13 @@ fn start_session(config: &Arc<rustls::ClientConfig>, domain_name: &str) {
// will yield Some(WriteEarlyData) and WriteEarlyData implements
// io::Write. Use this to send the request.
if let Some(mut early_data) = sess.early_data() {
early_data.write(request.as_bytes())
.unwrap();
early_data.write(request.as_bytes()).unwrap();
}

let mut stream = rustls::Stream::new(&mut sess, &mut sock);

// Complete handshake.
stream.flush()
.unwrap();
stream.flush().unwrap();

// If we didn't send early data, or the server didn't accept it,
// then send the request as normal.
Expand Down
35 changes: 24 additions & 11 deletions rustls-mio/examples/simpleclient.rs
@@ -1,7 +1,9 @@
use std::sync::Arc;

use std::net::TcpStream;
use std::io::{Read, Write, stdout};
use std::{
io::{stdout, Read, Write},
net::TcpStream,
};

use rustls;
use webpki;
Expand All @@ -11,21 +13,32 @@ use rustls::Session;

fn main() {
let mut config = rustls::ClientConfig::new();
config.root_store.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
config
.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);

let dns_name = webpki::DNSNameRef::try_from_ascii_str("google.com").unwrap();
let mut sess = rustls::ClientSession::new(&Arc::new(config), dns_name);
let mut sock = TcpStream::connect("google.com:443").unwrap();
let mut tls = rustls::Stream::new(&mut sess, &mut sock);
tls.write(concat!("GET / HTTP/1.1\r\n",
"Host: google.com\r\n",
"Connection: close\r\n",
"Accept-Encoding: identity\r\n",
"\r\n")
.as_bytes())
.unwrap();
tls.write(
concat!(
"GET / HTTP/1.1\r\n",
"Host: google.com\r\n",
"Connection: close\r\n",
"Accept-Encoding: identity\r\n",
"\r\n"
)
.as_bytes(),
)
.unwrap();
let ciphersuite = tls.sess.get_negotiated_ciphersuite().unwrap();
writeln!(&mut std::io::stderr(), "Current ciphersuite: {:?}", ciphersuite.suite).unwrap();
writeln!(
&mut std::io::stderr(),
"Current ciphersuite: {:?}",
ciphersuite.suite
)
.unwrap();
let mut plaintext = Vec::new();
tls.read_to_end(&mut plaintext).unwrap();
stdout().write_all(&plaintext).unwrap();
Expand Down

0 comments on commit 5865415

Please sign in to comment.