switch from rustls to native-tls

This commit is contained in:
Astro 2017-06-06 02:03:38 +02:00
commit 0bae1ce336
5 changed files with 29 additions and 37 deletions

View file

@ -1,16 +1,11 @@
extern crate futures;
extern crate tokio_core;
extern crate tokio_xmpp;
extern crate rustls;
use std::sync::Arc;
use std::io::BufReader;
use std::fs::File;
use tokio_core::reactor::Core;
use futures::{Future, Stream};
use tokio_xmpp::TcpClient;
use tokio_xmpp::xmpp_codec::Packet;
use rustls::ClientConfig;
fn main() {
use std::net::ToSocketAddrs;
@ -18,23 +13,18 @@ fn main() {
.to_socket_addrs().unwrap()
.next().unwrap();
let mut config = ClientConfig::new();
let mut certfile = BufReader::new(File::open("/usr/share/ca-certificates/CAcert/root.crt").unwrap());
config.root_store.add_pem_file(&mut certfile).unwrap();
let arc_config = Arc::new(config);
let mut core = Core::new().unwrap();
let client = TcpClient::connect(
&addr,
&core.handle()
).map_err(|e| format!("{}", e)
).and_then(|stream| {
if stream.can_starttls() {
stream.starttls(arc_config)
stream.starttls()
} else {
panic!("No STARTTLS")
}
}).map_err(|e| format!("{}", e)
).and_then(|stream| {
}).and_then(|stream| {
stream.auth("astrobot", "").expect("auth")
}).and_then(|stream| {
stream.for_each(|event| {