#ed25519 #security #random-key #crypto

edcert

一个用于基于Ed25519进行内容签名和验证的crate

21个稳定版本 (7个主要版本)

使用旧Rust 2015

9.0.1 2016年10月22日
8.2.0 2016年10月14日
8.1.0 2016年4月5日
7.0.0 2016年4月2日
2.1.2 2016年3月14日

#1506 in 密码学


3 crates 使用

MIT 许可证

60KB
786

Build Status

大家好,欢迎来到我的crate "edcert"的git页面。

Edcert是一个用于数据认证和验证的简单库。

工作原理

  1. 您创建一个主密钥对。这将用于签名最高级别的证书。
  2. 您创建一个根证书。使用主密钥签名此证书。
  3. 现在您可以创建其他证书并使用证书互相签名。
  4. 以json编码格式在网络中传输您的证书。
  5. 使用".sign"和".verify"方法使用证书签名和验证数据。

该设计使用"超级安全、超级快"的椭圆曲线Ed25519,您可以在这里了解更多信息

对于加密,它使用基于NaClsodiumoxide库,这是Dan Bernstein等人所知的著名加密库

示例

use chrono::Timelike;
use chrono::UTC;
use chrono::duration::Duration;
use meta::Meta;
use certificate::Certificate;
use validator::Validatable;
use validator::Validator;
use root_validator::RootValidator;
use trust_validator::TrustValidator;
use revoker::NoRevoker;

// create random master key
let (mpk, msk) = ed25519::generate_keypair();

// create random certificate
let meta = Meta::new_empty();
let expires = UTC::now()
                  .checked_add(Duration::days(90))
                  .expect("Failed to add 90 days to expiration date.")
                  .with_nanosecond(0)
                  .unwrap();
let mut cert = Certificate::generate_random(meta, expires);

// sign certificate with master key
cert.sign_with_master(&msk);

// we can use a RootValidator, which analyzes the trust chain.
// in this case, the top-most certificate must be signed with the right private key for mpk.
let cv = RootValidator::new(&mpk, NoRevoker);

// now we use the CV to validate certificates
assert_eq!(true, cv.is_valid(&cert).is_ok());

// we could also use a TrustValidator. It's like RootValidator, but you can also give trusted
// certificates. If the chain contains one of these, the upper certificates aren't checked
// with the master public key. We can give any 32 byte key here, it doesn't matter.
let mut tcv = TrustValidator::new(&[0; 32], NoRevoker);
tcv.add_trusted_certificates(vec![cert.get_id()]);

// even though we gave a wrong master key, this certificate is valid, because it is trusted.
assert_eq!(true, tcv.is_valid(&cert).is_ok());

// now we sign data with it
let data = [1; 42];

// and sign the data with the certificate
let signature = cert.sign(&data)
                    .expect("This fails, if no private key is known to the certificate.");

// the signature must be valid
assert_eq!(true, cert.verify(&data, &signature));

待办事项

加密项目中总是有要处理的事情。这里只是其中一些

  • 添加安全内存零化(使用secrets crate)
  • 添加自签名证书*

*:如果您通过一个指纹来识别证书,比如他的公钥,任何人都可以发送一个带有任何到期日期的证书版本给您。如果您在您的信任存储中有该证书,您将不会注意到,因为您只检查指纹是否已知。

为了防止这种情况,我们将在信任存储中只允许自签名证书,并检查签名是否有效,因为攻击者无法重新创建签名。

许可证

MIT

这意味着您可以在开源项目和/或商业项目中使用此代码而没有任何问题。请阅读许可证文件"LICENSE"以获取详细信息

依赖关系

~20MB
~123K SLoC