Include JS WebCrypto raw format for openssl_get_publicKey
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
With the inclusion of JS WebCrypto API, I believe it is necessary to support the exported raw format when client sends their own public EC keys to the server.
const { publicKey } = await crypto.subtle.generateKey({
name : 'ECDH',
namedCurve : 'P-256'
}, true, ['deriveBits'])
const exported_key = new Uint8Array(await crypto.subtle.exportKey('raw', publicKey))
fetch('key.php', {
method : 'post',
body : btoa(String.fromCharCode(...exported_key))
}).then(e=>e.text())
However, openssl_pkey_get_public only accepts PEM formatted string. This would mean a whole lot of concatenating to do before we are able to get the public OpenSSLAsymmetricKey
$raw_format = base64_decode(file_get_content("php://input"));
// This header is only for P-256
$asn_1_header = pack('C*', ...[48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0]);
var_dump(openssl_get_publicKey("-----BEGIN PUBLIC KEY-----\n".base64_encode($asn_1_header.$raw_format)."\n-----END PUBLIC KEY-----"));
It would be pretty cool to simplify it so that it becomes the following.
openssl_get_publicKey($raw_format);
I think alternatively we can make a new function for openssl to load what JS Web Crypto generated as "raw" type.
Note
I know that WebCrypto API does allow exporting SPKI key but that is besides the point. To add to this, when you subscribe to pushmanager, a p256dh is given in "raw" format as defined by WebCrypto API.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 openssl_get_publicKey 和 openssl_pkey_get_public 入口开始,检查当前如何接受 OpenSSL 公钥。确定应如何识别和支持原始 WebCrypto EC 公钥输入,包括所述的 P-256 示例;完成的标准是原始输入无需手动进行 ASN.1 或 PEM 封装即可生成 OpenSSLAsymmetricKey。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, php
- 领域
- cryptography
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100