ClientCtx

Struct ClientCtx 

Source
pub struct ClientCtx(/* private fields */);
Expand description

A Kerberos client context

Implementations§

Source§

impl ClientCtx

Source

pub fn new( flags: InitiateFlags, principal: Option<&str>, target_principal: &str, channel_bindings: Option<&[u8]>, ) -> Result<(PendingClientCtx, impl Deref<Target = [u8]>)>

create a new client context for speaking to target_principal. If principal is None then the credentials of the user running current process will be used. target_principal must be the service principal name of the service you intend to communicate with. This should be an spn as described by GSSAPI, e.g. service/host@REALM. If present, channel_bindings is a service-specific channel binding token which will be part of the initial communication with the server.

On success a PendingClientCtx and a token to be sent to the server will be returned. The server and client may generate multiple additional tokens, which must be passed to the their respective step methods until the initialization is complete.

Examples found in repository?
examples/auth.rs (line 41)
39fn client(spn: &str, input: mpsc::Receiver<Msg>, output: mpsc::Sender<Msg>) {
40    let (mut client, token) =
41        ClientCtx::new(InitiateFlags::empty(), None, spn, None).expect("new");
42    output.send(Msg::Token(Bytes::copy_from_slice(&*token))).expect("send");
43    let mut client = loop {
44        let token = match input.recv().expect("expected data") {
45            Msg::Msg(_) => panic!("client not finished initializing"),
46            Msg::Token(t) => t,
47        };
48        match client.step(&*token).expect("step") {
49            Step::Finished((ctx, token)) => {
50                if let Some(token) = token {
51                    output.send(Msg::Token(Bytes::copy_from_slice(&*token))).expect("send");
52                }
53                break ctx
54            },
55            Step::Continue((ctx, token)) => {
56                output.send(Msg::Token(Bytes::copy_from_slice(&*token))).expect("send");
57                client = ctx;
58            }
59        }
60    };
61    let msg = client.wrap(true, b"super secret message").expect("wrap");
62    output.send(Msg::Msg(Bytes::copy_from_slice(&*msg))).expect("send");
63}
Source

pub fn new_with_cred( cred: Cred, target_principal: &str, channel_bindings: Option<&[u8]>, ) -> Result<(PendingClientCtx, impl Deref<Target = [u8]>)>

Trait Implementations§

Source§

impl Debug for ClientCtx

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl K5Ctx for ClientCtx

Source§

type Buffer = <ClientCtx as K5Ctx>::Buffer

Source§

type IOVBuffer = <ClientCtx as K5Ctx>::IOVBuffer

Source§

fn wrap(&mut self, encrypt: bool, msg: &[u8]) -> Result<Self::Buffer>

Wrap the specified message for sending to the other side. If encrypt is true then the contents will be encrypted. Even if encrypt is false the integrity of the contents are protected, if the message is altered in transit the other side will know.
Source§

fn wrap_iov(&mut self, encrypt: bool, msg: BytesMut) -> Result<Self::IOVBuffer>

Wrap data in place using the underlying wrap_iov facility. If encrypt is true then the contents of data will be encrypted in place. The returned buffer is NOT contiguous, and as such you must use some kind of writev implementation to properly send it. You can use tokio’s write_buf directly, or you can extract the iovecs for a direct call to writev using bytes::Buf::chunks_vectored. Read more
Source§

fn unwrap(&mut self, msg: &[u8]) -> Result<Self::Buffer>

Unwrap the specified message returning it’s decrypted and verified contents
Source§

fn unwrap_iov(&mut self, len: usize, msg: &mut BytesMut) -> Result<BytesMut>

Unwrap in place the message at the beginning of the specified BytesMut and then split it off and return it. This won’t copy or allocate, it just looks that way because the bytes crate is awesome.
Source§

fn ttl(&mut self) -> Result<Duration>

Return the remaining time this session has to live

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.