summaryrefslogtreecommitdiff
path: root/src/session.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/session.rs')
-rw-r--r--src/session.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/session.rs b/src/session.rs
index e3566d1..c9dd266 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -5,6 +5,8 @@ use std::path::Path;
use std::slice;
use std::str;
use libc::{self, c_uint, c_int, c_void, c_long};
+#[cfg(unix)]
+use libc::size_t;
use {raw, Error, DisconnectCode, ByApplication, HostKeyType};
use {MethodType, Agent, Channel, Listener, HashType, KnownHosts, Sftp};
@@ -219,6 +221,40 @@ impl Session {
})
}
+ /// Attempt public key authentication using a PEM encoded private key from
+ /// memory. Public key is computed from private key if none passed.
+ /// This is available only for `unix` targets, as it relies on openssl.
+ /// It is therefore recommended to use `#[cfg(unix)]` or otherwise test for
+ /// the `unix` compliation target when using this function.
+ #[cfg(unix)]
+ pub fn userauth_pubkey_memory(&self,
+ username: &str,
+ pubkeydata: Option<&str>,
+ privatekeydata: &str,
+ passphrase: Option<&str>) -> Result<(), Error> {
+ let (pubkeydata, pubkeydata_len) = match pubkeydata {
+ Some(s) => (Some(try!(CString::new(s))), s.len()),
+ None => (None, 0),
+ };
+ let privatekeydata_len = privatekeydata.len();
+ let privatekeydata = try!(CString::new(privatekeydata));
+ let passphrase = match passphrase {
+ Some(s) => Some(try!(CString::new(s))),
+ None => None,
+ };
+ self.rc(unsafe {
+ raw::libssh2_userauth_publickey_frommemory(self.raw,
+ username.as_ptr() as *const _,
+ username.len() as size_t,
+ pubkeydata.as_ref().map(|s| s.as_ptr()).unwrap_or(0 as *const _),
+ pubkeydata_len as size_t,
+ privatekeydata.as_ptr(),
+ privatekeydata_len as size_t,
+ passphrase.as_ref().map(|s| s.as_ptr())
+ .unwrap_or(0 as *const _))
+ })
+ }
+
// Umm... I wish this were documented in libssh2?
#[allow(missing_docs)]
pub fn userauth_hostbased_file(&self,