pub struct ClientCtx { /* private fields */ }
Expand description
The client side of a security context
Implementations§
source§impl ClientCtx
impl ClientCtx
sourcepub fn new(
cred: Cred,
target: Name,
flags: CtxFlags,
mech: Option<&'static Oid>
) -> ClientCtx
pub fn new( cred: Cred, target: Name, flags: CtxFlags, mech: Option<&'static Oid> ) -> ClientCtx
Create a new uninitialized client security context using the
specified credentials, targeting the service named by target,
and optionally using a specific mechanism (otherwise gssapi
will pick a default for you). To finish initializing the
context you must call step
.
Examples found in repository?
102 103 104 105 106 107 108 109 110 111 112 113
fn setup_client_ctx(
service_name: Name,
desired_mechs: &OidSet
) -> Result<ClientCtx, Error> {
let client_cred = Cred::acquire(
None, None, CredUsage::Initiate, Some(&desired_mechs)
)?;
println!("acquired default client credentials: {:#?}", client_cred.info()?);
Ok(ClientCtx::new(
client_cred, service_name, CtxFlags::GSS_C_MUTUAL_FLAG, Some(&GSS_MECH_KRB5)
))
}
More examples
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn setup_client_ctx(
service_name: Name,
desired_mechs: &OidSet,
) -> Result<ClientCtx, Error> {
let client_cred =
Cred::acquire(None, None, CredUsage::Initiate, Some(&desired_mechs))?;
println!(
"acquired default client credentials: {:#?}",
client_cred.info()?
);
Ok(ClientCtx::new(
client_cred,
service_name,
CtxFlags::GSS_C_MUTUAL_FLAG,
Some(&GSS_MECH_KRB5),
))
}
sourcepub fn step(
&mut self,
tok: Option<&[u8]>,
channel_bindings: Option<&[u8]>
) -> Result<Option<Buf>, Error>
pub fn step( &mut self, tok: Option<&[u8]>, channel_bindings: Option<&[u8]> ) -> Result<Option<Buf>, Error>
Perform 1 step in the initialization of the specfied security context. Since the client initiates context creation, the token will initially be None. If the connection uses channel bindings, they are passed as the second argument.
As a result this step, GSSAPI will give you a token
to send to the server. The server may send back a token, which
you must feed to this function, and possibly get another token
to send to the server. This will go on a mechanism specifiec
number of times until step returns Ok(None)
. At that point
the context is fully initialized.
Examples found in repository?
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
fn run(service_name: &[u8]) -> Result<(), Error> {
let desired_mechs = {
let mut s = OidSet::new()?;
s.add(&GSS_MECH_KRB5)?;
s
};
let (mut server_ctx, cname) = setup_server_ctx(service_name, &desired_mechs)?;
let mut client_ctx = setup_client_ctx(cname, &desired_mechs)?;
let mut server_tok: Option<Buf> = None;
loop {
match client_ctx.step(server_tok.as_ref().map(|b| &**b), None)? {
None => break,
Some(client_tok) => match server_ctx.step(&*client_tok)? {
None => break,
Some(tok) => { server_tok = Some(tok); }
}
}
}
println!("security context initialized successfully");
println!("client ctx info: {:#?}", client_ctx.info()?);
println!("server ctx info: {:#?}", server_ctx.info()?);
let secret_msg = client_ctx.wrap(true, b"super secret message")?;
let decoded_msg = server_ctx.unwrap(&*secret_msg)?;
println!("the decrypted message is: '{}'", String::from_utf8_lossy(&*decoded_msg));
Ok(())
}
More examples
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
fn run(service_name: &[u8]) -> Result<(), Error> {
let desired_mechs = {
let mut s = OidSet::new()?;
s.add(&GSS_MECH_KRB5)?;
s
};
let (mut server_ctx, cname) = setup_server_ctx(service_name, &desired_mechs)?;
let mut client_ctx = setup_client_ctx(cname, &desired_mechs)?;
let mut server_tok: Option<Buf> = None;
loop {
match client_ctx.step(server_tok.as_ref().map(|b| &**b), None)? {
None => break,
Some(client_tok) => match server_ctx.step(&*client_tok)? {
None => break,
Some(tok) => {
server_tok = Some(tok);
}
},
}
}
println!("security context initialized successfully");
println!("client ctx info: {:#?}", client_ctx.info()?);
println!("server ctx info: {:#?}", server_ctx.info()?);
println!("wrapping secret message using no alloc method");
let encrypted = wrap_secret_msg_noalloc(&mut client_ctx)?;
let decrypted = unwrap_secret_msg(&mut server_ctx, encrypted)?;
println!(
"The secret message is \"{}\"",
String::from_utf8_lossy(&*decrypted)
);
println!("wrapping secret message using alloc method");
let encrypted = wrap_secret_msg_alloc(&mut client_ctx)?;
let decrypted = unwrap_secret_msg(&mut server_ctx, encrypted)?;
println!(
"The secret message is \"{}\"",
String::from_utf8_lossy(&*decrypted)
);
Ok(())
}
Trait Implementations§
source§impl SecurityContext for ClientCtx
impl SecurityContext for ClientCtx
source§fn wrap(&mut self, encrypt: bool, msg: &[u8]) -> Result<Buf, Error>
fn wrap(&mut self, encrypt: bool, msg: &[u8]) -> Result<Buf, Error>
encrypt
is true
then only the other side of the context can read the
message. In any case the other side can always verify message
integrity.source§fn wrap_iov(
&mut self,
encrypt: bool,
msg: &mut [GssIov<'_>]
) -> Result<(), Error>
fn wrap_iov( &mut self, encrypt: bool, msg: &mut [GssIov<'_>] ) -> Result<(), Error>
source§fn wrap_iov_length(
&mut self,
encrypt: bool,
msg: &mut [GssIovFake]
) -> Result<(), Error>
fn wrap_iov_length( &mut self, encrypt: bool, msg: &mut [GssIovFake] ) -> Result<(), Error>
wrap_iov
.