Include JS WebCrypto raw format for openssl_get_publicKey
まだ誰も着手していません。
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.2k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
エントリポイント openssl_get_publicKey と openssl_pkey_get_public から開始し、現在 OpenSSL の公開鍵がどのように受け入れられているかを確認します。指定された P-256 の例を含め、生の WebCrypto EC 公開鍵入力をどのように認識してサポートすべきかを判断します。生の入力から、ASN.1 や PEM に手動でラップすることなく OpenSSLAsymmetricKey を生成できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, php
- 領域
- cryptography
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100