5 个版本 (3 个破坏性更新)

0.4.0 2024年1月9日
0.3.0 2022年3月29日
0.2.2 2022年2月16日
0.1.1 2022年1月2日
0.1.0 2021年12月31日

#224加密

Download history 211/week @ 2024-04-22 235/week @ 2024-04-29 376/week @ 2024-05-06 364/week @ 2024-05-13 200/week @ 2024-05-20 195/week @ 2024-05-27 267/week @ 2024-06-03 966/week @ 2024-06-10 248/week @ 2024-06-17 275/week @ 2024-06-24 241/week @ 2024-07-01 377/week @ 2024-07-08 331/week @ 2024-07-15 582/week @ 2024-07-22 328/week @ 2024-07-29 255/week @ 2024-08-05

1,516 每月下载量
23 个 crate 中使用 (5 个直接使用)

MIT 许可证

48KB
1K SLoC

跨平台 Kerberos 5 接口

cross-krb5 是 Windows 和 Unix 上 Kerberos 5 服务的安全接口。它提供了与直接使用 gssapi 和 sspi 相当的灵活性,并具有统一的跨平台 api。

除了提供统一的 API,使用 cross-krb5 的服务应能够跨所有支持的操作系统透明地互操作,并应与其他服务互操作,前提是它们不是特定于平台的。

示例

use bytes::Bytes;
use cross_krb5::{AcceptFlags, ClientCtx, InitiateFlags, K5Ctx, Step, ServerCtx};
use std::{env::args, process::exit, sync::mpsc, thread};

enum Msg {
    Token(Bytes),
    Msg(Bytes),
}

fn server(spn: String, input: mpsc::Receiver<Msg>, output: mpsc::Sender<Msg>) {
    let mut server = ServerCtx::new(AcceptFlags::empty(), Some(&spn)).expect("new");
    let mut server = loop {
        let token = match input.recv().expect("expected data") {
            Msg::Msg(_) => panic!("server not finished initializing"),
            Msg::Token(t) => t,
        };
        match server.step(&*token).expect("step") {
            Step::Finished((ctx, token)) => {
                if let Some(token) = token {
                    output.send(Msg::Token(Bytes::copy_from_slice(&*token))).expect("send");
                }
                break ctx
            },
            Step::Continue((ctx, token)) => {
                output.send(Msg::Token(Bytes::copy_from_slice(&*token))).expect("send");
                server = ctx;
            }
        }
    };
    match input.recv().expect("expected data msg") {
        Msg::Token(_) => panic!("unexpected extra token"),
        Msg::Msg(secret_msg) => println!(
            "{}",
            String::from_utf8_lossy(&server.unwrap(&*secret_msg).expect("unwrap"))
        ),
    }
}

fn client(spn: &str, input: mpsc::Receiver<Msg>, output: mpsc::Sender<Msg>) {
    let (mut client, token) =
        ClientCtx::new(InitiateFlags::empty(), None, spn, None).expect("new");
    output.send(Msg::Token(Bytes::copy_from_slice(&*token))).expect("send");
    let mut client = loop {
        let token = match input.recv().expect("expected data") {
            Msg::Msg(_) => panic!("client not finished initializing"),
            Msg::Token(t) => t,
        };
        match client.step(&*token).expect("step") {
            Step::Finished((ctx, token)) => {
                if let Some(token) = token {
                    output.send(Msg::Token(Bytes::copy_from_slice(&*token))).expect("send");
                }
                break ctx
            },
            Step::Continue((ctx, token)) => {
                output.send(Msg::Token(Bytes::copy_from_slice(&*token))).expect("send");
                client = ctx;
            }
        }
    };
    let msg = client.wrap(true, b"super secret message").expect("wrap");
    output.send(Msg::Msg(Bytes::copy_from_slice(&*msg))).expect("send");
}

fn main() {
    let args = args().collect::<Vec<_>>();
    if args.len() != 2 {
        println!("usage: {}: <service/host@REALM>", args[0]);
        exit(1);
    }
    let spn = String::from(&args[1]);
    let (server_snd, server_recv) = mpsc::channel();
    let (client_snd, client_recv) = mpsc::channel();
    thread::spawn(move || server(spn, server_recv, client_snd));
    client(&args[1], client_recv, server_snd);
}

依赖项

~0.4–37MB
~566K SLoC