update to openssl 0.9 (#31)
This commit is contained in:
parent
39f889430b
commit
89a8d0eaf3
4 changed files with 15 additions and 13 deletions
|
|
@ -16,7 +16,7 @@ name = "imap"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
openssl = "0.8"
|
openssl = "0.9"
|
||||||
regex = "0.2"
|
regex = "0.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
extern crate imap;
|
extern crate imap;
|
||||||
extern crate openssl;
|
extern crate openssl;
|
||||||
|
|
||||||
use openssl::ssl::{SslContext, SslMethod};
|
use openssl::ssl::{SslConnectorBuilder, SslMethod};
|
||||||
use imap::client::Client;
|
use imap::client::Client;
|
||||||
|
|
||||||
// To connect to the gmail IMAP server with this you will need to allow unsecure apps access.
|
// To connect to the gmail IMAP server with this you will need to allow unsecure apps access.
|
||||||
// See: https://support.google.com/accounts/answer/6010255?hl=en
|
// See: https://support.google.com/accounts/answer/6010255?hl=en
|
||||||
// Look at the gmail_oauth2.rs example on how to connect to a gmail server securely.
|
// Look at the gmail_oauth2.rs example on how to connect to a gmail server securely.
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut imap_socket = Client::secure_connect(("imap.gmail.com", 993), SslContext::new(SslMethod::Sslv23).unwrap()).unwrap();
|
let mut imap_socket = Client::secure_connect(("imap.gmail.com", 993), "imap.gmail.com",SslConnectorBuilder::new(SslMethod::tls()).unwrap().build()).unwrap();
|
||||||
|
|
||||||
imap_socket.login("username", "password").unwrap();
|
imap_socket.login("username", "password").unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ extern crate imap;
|
||||||
extern crate openssl;
|
extern crate openssl;
|
||||||
extern crate base64;
|
extern crate base64;
|
||||||
|
|
||||||
use openssl::ssl::{SslContext, SslMethod};
|
use openssl::ssl::{SslConnectorBuilder, SslMethod};
|
||||||
use base64::{encode};
|
use base64::{encode};
|
||||||
use imap::client::Client;
|
use imap::client::Client;
|
||||||
use imap::authenticator::Authenticator;
|
use imap::authenticator::Authenticator;
|
||||||
|
|
@ -24,7 +24,7 @@ fn main() {
|
||||||
user: String::from("sombody@gmail.com"),
|
user: String::from("sombody@gmail.com"),
|
||||||
access_token: String::from("<access_token>")
|
access_token: String::from("<access_token>")
|
||||||
};
|
};
|
||||||
let mut imap_socket = Client::secure_connect(("imap.gmail.com", 993), SslContext::new(SslMethod::Sslv23).unwrap()).unwrap();
|
let mut imap_socket = Client::secure_connect(("imap.gmail.com", 993),"imap.gmail.com", SslConnectorBuilder::new(SslMethod::tls()).unwrap().build()).unwrap();
|
||||||
|
|
||||||
imap_socket.authenticate("XOAUTH2", gmail_auth).unwrap();
|
imap_socket.authenticate("XOAUTH2", gmail_auth).unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use std::net::{TcpStream, ToSocketAddrs};
|
use std::net::{TcpStream, ToSocketAddrs};
|
||||||
use openssl::ssl::{SslContext, SslStream};
|
use openssl::ssl::{SslConnector, SslStream};
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
|
@ -178,21 +178,23 @@ impl Client<TcpStream> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This will upgrade a regular TCP connection to use SSL.
|
/// This will upgrade a regular TCP connection to use SSL.
|
||||||
pub fn secure(mut self, ssl_context: SslContext) -> Result<Client<SslStream<TcpStream>>> {
|
///
|
||||||
|
/// Use the domain parameter for openssl's SNI and hostname verification.
|
||||||
|
pub fn secure(mut self, domain: &str,ssl_connector: SslConnector) -> Result<Client<SslStream<TcpStream>>> {
|
||||||
// TODO This needs to be tested
|
// TODO This needs to be tested
|
||||||
try!(self.run_command_and_check_ok("STARTTLS"));
|
self.run_command_and_check_ok("STARTTLS")?;
|
||||||
SslStream::connect(&ssl_context, self.stream)
|
SslConnector::connect(&ssl_connector,domain, self.stream)
|
||||||
.map(|s| Client::new(s))
|
.map(Client::new)
|
||||||
.map_err(|e| Error::Ssl(e))
|
.map_err(Error::Ssl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client<SslStream<TcpStream>> {
|
impl Client<SslStream<TcpStream>> {
|
||||||
/// Creates a client with an SSL wrapper.
|
/// Creates a client with an SSL wrapper.
|
||||||
pub fn secure_connect<A: ToSocketAddrs>(addr: A, ssl_context: SslContext) -> Result<Client<SslStream<TcpStream>>> {
|
pub fn secure_connect<A: ToSocketAddrs>(addr: A, domain: &str,ssl_connector: SslConnector) -> Result<Client<SslStream<TcpStream>>> {
|
||||||
match TcpStream::connect(addr) {
|
match TcpStream::connect(addr) {
|
||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
let ssl_stream = match SslStream::connect(&ssl_context, stream) {
|
let ssl_stream = match SslConnector::connect(&ssl_connector, domain,stream) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => return Err(Error::Ssl(e))
|
Err(e) => return Err(Error::Ssl(e))
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue