Ockam 是一个 Rust 和 Elixir 库,用于端到端加密、相互认证、安全通信。现代分布式应用程序中的数据很少通过单个点对点传输连接进行交换。应用程序消息在到达最终目的地之前,通常会通过复杂的、多跳、多协议的路由——跨数据中心、通过队列和缓存、通过网关和代理。
Ockam 是一套编程库和基础设施,它使我们的应用程序可以轻松地保证数据的端到端完整性、真实性和机密性。
特征
- 端到端加密、相互认证的安全通道。
- 密钥的建立、轮换和撤销。
- 由隐私上下文隔离的身份配置文件。
- 基于属性的访问控制
- 适用于各种操作环境、传输协议和加密硬件的附加组件。
- 多种语言的库 - Rust、Elixir。
Ockam
-
安装 Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
设置一个新的 cargo 项目以开始。
cargo new --lib hello_ockam && cd hello_ockam && mkdir examples &&
echo 'ockam = "*"' >> Cargo.toml && cargo build
-
在examples/hello.rs创建一个文件并将以下代码片段复制到其中。
// examples/hello.rs
use ockam::{route, Context, Entity, Result, TrustEveryonePolicy, Vault};
#[ockam::node]
async fn main(mut ctx: Context) -> Result<()> {
// Create a Vault to safely store secret keys for Alice and Bob.
let vault = Vault::create(&ctx).await?;
// Create an Entity to represent Bob.
let mut bob = Entity::create(&ctx, &vault).await?;
// Create a secure channel listener for Bob that will wait for requests to
// initiate an Authenticated Key Exchange.
bob.create_secure_channel_listener("bob", TrustEveryonePolicy).await?;
// Create an entity to represent Alice.
let mut alice = Entity::create(&ctx, &vault).await?;
// As Alice, connect to Bob's secure channel listener and perform an
// Authenticated Key Exchange to establish an encrypted secure channel with Bob.
let channel = alice.create_secure_channel("bob", TrustEveryonePolicy).await?;
// Send a message, ** THROUGH ** the secure channel,
// to the "app" worker on the other side.
//
// This message will automatically get encrypted when it enters the channel
// and decrypted just before it exits the channel.
ctx.send(route![channel, "app"], "Hello Ockam!".to_string()).await?;
// Wait to receive a message for the "app" worker and print it.
let message = ctx.receive::<String>().await?;
println!("App Received: {}", message); // should print "Hello Ockam!"
// Stop all workers, stop the node, cleanup and return.
ctx.stop().await
}
-
运行示例
cargo run --example hello