Merge pull request #806 from sfackler/servername-param
Add a parameter to servername
This commit is contained in:
commit
afec43351c
|
|
@ -333,6 +333,25 @@ impl StatusType {
|
||||||
pub const OCSP: StatusType = StatusType(ffi::TLSEXT_STATUSTYPE_ocsp);
|
pub const OCSP: StatusType = StatusType(ffi::TLSEXT_STATUSTYPE_ocsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An identifier of a session name type.
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct NameType(c_int);
|
||||||
|
|
||||||
|
impl NameType {
|
||||||
|
/// Constructs a `StatusType` from a raw OpenSSL value.
|
||||||
|
pub fn from_raw(raw: c_int) -> StatusType {
|
||||||
|
StatusType(raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the raw OpenSSL value represented by this type.
|
||||||
|
pub fn as_raw(&self) -> c_int {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A host name.
|
||||||
|
pub const HOST_NAME: NameType = NameType(ffi::TLSEXT_NAMETYPE_host_name);
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref INDEXES: Mutex<HashMap<TypeId, c_int>> = Mutex::new(HashMap::new());
|
static ref INDEXES: Mutex<HashMap<TypeId, c_int>> = Mutex::new(HashMap::new());
|
||||||
static ref SSL_INDEXES: Mutex<HashMap<TypeId, c_int>> = Mutex::new(HashMap::new());
|
static ref SSL_INDEXES: Mutex<HashMap<TypeId, c_int>> = Mutex::new(HashMap::new());
|
||||||
|
|
@ -505,7 +524,6 @@ impl SslContextBuilder {
|
||||||
/// [`SSL_CTX_set_verify`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_CTX_set_verify.html
|
/// [`SSL_CTX_set_verify`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_CTX_set_verify.html
|
||||||
pub fn set_verify_callback<F>(&mut self, mode: SslVerifyMode, verify: F)
|
pub fn set_verify_callback<F>(&mut self, mode: SslVerifyMode, verify: F)
|
||||||
where
|
where
|
||||||
// FIXME should take a mutable reference to the store
|
|
||||||
F: Fn(bool, &mut X509StoreContextRef) -> bool + 'static + Sync + Send,
|
F: Fn(bool, &mut X509StoreContextRef) -> bool + 'static + Sync + Send,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
@ -1498,7 +1516,6 @@ impl SslRef {
|
||||||
/// [`SSL_set_verify`]: https://www.openssl.org/docs/man1.0.2/ssl/SSL_set_verify.html
|
/// [`SSL_set_verify`]: https://www.openssl.org/docs/man1.0.2/ssl/SSL_set_verify.html
|
||||||
pub fn set_verify_callback<F>(&mut self, mode: SslVerifyMode, verify: F)
|
pub fn set_verify_callback<F>(&mut self, mode: SslVerifyMode, verify: F)
|
||||||
where
|
where
|
||||||
// FIXME should take a mutable reference to the x509 store
|
|
||||||
F: Fn(bool, &mut X509StoreContextRef) -> bool + 'static + Sync + Send,
|
F: Fn(bool, &mut X509StoreContextRef) -> bool + 'static + Sync + Send,
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
@ -1801,17 +1818,16 @@ impl SslRef {
|
||||||
/// This corresponds to [`SSL_get_servername`].
|
/// This corresponds to [`SSL_get_servername`].
|
||||||
///
|
///
|
||||||
/// [`SSL_get_servername`]: https://www.openssl.org/docs/manmaster/man3/SSL_get_servername.html
|
/// [`SSL_get_servername`]: https://www.openssl.org/docs/manmaster/man3/SSL_get_servername.html
|
||||||
// FIXME add name parameter
|
pub fn servername(&self, type_: NameType) -> Option<&str> {
|
||||||
pub fn servername(&self) -> Option<&str> {
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let name = ffi::SSL_get_servername(self.as_ptr(), ffi::TLSEXT_NAMETYPE_host_name);
|
let name = ffi::SSL_get_servername(self.as_ptr(), type_.0);
|
||||||
if name == ptr::null() {
|
if name == ptr::null() {
|
||||||
return None;
|
None
|
||||||
}
|
} else {
|
||||||
|
|
||||||
Some(str::from_utf8(CStr::from_ptr(name as *const _).to_bytes()).unwrap())
|
Some(str::from_utf8(CStr::from_ptr(name as *const _).to_bytes()).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Changes the context corresponding to the current connection.
|
/// Changes the context corresponding to the current connection.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -605,7 +605,7 @@ fn test_alpn_server_select_none_fatal() {
|
||||||
// Have the listener wait on the connection in a different thread.
|
// Have the listener wait on the connection in a different thread.
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let (stream, _) = listener.accept().unwrap();
|
let (stream, _) = listener.accept().unwrap();
|
||||||
Ssl::new(&listener_ctx).unwrap().accept(stream).unwrap();
|
Ssl::new(&listener_ctx).unwrap().accept(stream).unwrap_err();
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut ctx = SslContext::builder(SslMethod::tls()).unwrap();
|
let mut ctx = SslContext::builder(SslMethod::tls()).unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue