nucypher的umbral代理重加密实现
umbral的Python项目详细描述
pyumbral是Umbral阈值代理重新加密方案的参考实现。 它是开源的,用python构建,使用OpenSSL和Cryptography.io。
使用umbral,alice(数据所有者)可以将解密权限委托给bob 通过由 半可信代理集或^ {EM1}$urSulaseEEM >。当这些代理的阈值 通过执行重新加密,bob能够将这些独立的 使用他的私钥重新加密和解密原始邮件。
pyumbral是nucypher背后的加密引擎, 一种代理重加密网络,用于在分散系统中增强隐私权。
用法
密钥生成
与任何公钥密码体制一样,用户需要一对公钥和私钥。 此外,委托访问其数据的用户(如本例中的alice)需要一个签名密钥对。
fromumbralimportpre,keys,signing# Generate Umbral keys for Alice.alices_private_key=keys.UmbralPrivateKey.gen_key()alices_public_key=alices_private_key.get_pubkey()alices_signing_key=keys.UmbralPrivateKey.gen_key()alices_verifying_key=alices_signing_key.get_pubkey()alices_signer=signing.Signer(private_key=alices_signing_key)# Generate Umbral keys for Bob.bobs_private_key=keys.UmbralPrivateKey.gen_key()bobs_public_key=bobs_private_key.get_pubkey()
加密
现在让我们用alice的公钥加密数据。 调用pre.encrypt将同时返回ciphertext和capsule。 请注意,任何具有alice公钥的人都可以执行此操作。
因为数据是用爱丽丝的公钥加密的, 爱丽丝可以打开胶囊,用她的私钥解密密文。
# Encrypt data with Alice's public key.plaintext=b'Proxy Re-Encryption is cool!'ciphertext,capsule=pre.encrypt(alices_public_key,plaintext)# Decrypt data with Alice's private key.cleartext=pre.decrypt(ciphertext=ciphertext,capsule=capsule,decrypting_key=alices_private_key)
重新加密密钥片段
当爱丽丝想让鲍勃打开她的加密信息时, 她创建re encryption key fragments,或“kfrags”, 下一个被发送到N代理或^ {EM1}$urSulaseEEM >。
# Alice generates "M of N" re-encryption key fragments (or "KFrags") for Bob.# In this example, 10 out of 20.kfrags=pre.generate_kfrags(delegating_privkey=alices_private_key,signer=alices_signer,receiving_pubkey=bobs_public_key,threshold=10,N=20)
重新加密
鲍勃让几个乌苏拉重新加密太空舱,以便他能打开它。 每个ursula使用^{tt4}对胶囊执行重新加密。$ 由alice提供,通过这种方式获得“胶囊片段”,或cfrag。
bob从几个ursula收集得到的cfrag。 bob必须收集至少thresholdcfrag才能激活胶囊。
# Several Ursulas perform re-encryption, and Bob collects the resulting `cfrags`.# He must gather at least `threshold` `cfrags` in order to activate the capsule.capsule.set_correctness_keys(delegating=alices_public_key,receiving=bobs_public_key,verifying=alices_verifying_key)cfrags=list()# Bob's cfrag collectionforkfraginkfrags[:10]:cfrag=pre.reencrypt(kfrag=kfrag,capsule=capsule)cfrags.append(cfrag)# Bob collects a cfrag
由bob解密
最后,bob通过附加至少thresholdcfrags来激活胶囊, 然后解密重新加密的密文。
# Bob activates and opens the capsuleforcfragincfrags:capsule.attach_cfrag(cfrag)bob_cleartext=pre.decrypt(ciphertext=ciphertext,capsule=capsule,decrypting_key=bobs_private_key)assertbob_cleartext==plaintext
请参阅docs目录中更详细的用法示例。
快速安装
要安装pyumbral,只需使用pip:
$ pip3 install umbral
或者,您可以签出repo并从那里安装它。 nucypher团队使用pipenv来管理pyumbral的依赖项。 建议的安装步骤如下:
$ sudo pip3 install pipenv $ pipenv install
安装后,可以激活项目虚拟环境 在当前终端会话中运行pipenv shell。
有关pipenv的更多信息,请在此处找到官方文档:https://docs.pipenv.org/。
学术白皮书
umbral方案学术白皮书和密码规范 在GitHub上可用。
“Umbral: A Threshold Proxy Re-Encryption Scheme” by David Nuñez. https://github.com/nucypher/umbral-doc/blob/master/umbral-doc.pdf
安全性
如果您使用任何密码识别漏洞, 请通过电子邮件security@nucypher.com将相关信息发送给您的调查结果。 我们将与研究人员合作,协调合作伙伴之间的漏洞披露 并确保用户成功缓解漏洞。
在整个报告过程中, 我们希望研究人员遵守一个禁运期,根据披露的严重程度可能有所不同。 这确保我们有机会解决任何问题,确定进一步的问题(如果有的话),并通知我们的用户。
有时漏洞更敏感,需要额外的预防措施。 我们很乐意合作使用一种更安全的媒介,比如信号。 通过电子邮件security@nucypher.com我们将协调一个通信通道我们都很满意的内尔。