misskey-dev / node-http-message-signatures

An JavaScript (Node.js and browsers) implementation for HTTP Message Signatures (RFC 9421)
MIT License
9 stars 4 forks source link

Web Crypto APIを使う #3

Closed tamaina closed 6 months ago

tamaina commented 6 months ago

汎用性が増す

(Nodeでのパフォーマンス面での違いがなければ実装したい)

mei23 commented 6 months ago

普通に出来そうだけどEd25519がExperimentalなのが気になるわね https://nodejs.org/api/webcrypto.html#ed25519ed448x25519x448-key-pairs

tamaina commented 6 months ago

crypto.subtle.importKey、なんかalgorithmを提供する必要があるらしく面倒

https://developer.mozilla.org/ja/docs/Web/API/SubtleCrypto/importKey#algorithm

spkiにアルゴリズム情報があるんだからパースしてくれ

(しかもRSA鍵はハッシュアルゴリズムを事前指定させるのどういうことなんだ)

tamaina commented 6 months ago

image

https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/sign#browser_compatibility

えぇぇ

tamaina commented 6 months ago

image

なんかWeb Crypto APIの方が署名検証早いんすけど

tamaina commented 6 months ago

@lapo/asn1jsがesbuildでうまくバンドルできない

tamaina commented 6 months ago

https://github.com/misskey-dev/node-http-message-signatures/blob/0b2ef2318aca1b405f92d1ae2da10e0a8ecd2b24/src/keypair.ts#L79-L87 (PKCS1→SPKI)とか https://github.com/misskey-dev/node-http-message-signatures/blob/0b2ef2318aca1b405f92d1ae2da10e0a8ecd2b24/src/utils.ts#L10 (PKCS8のパース)とかも自前で実装する必要があるのか

tamaina commented 6 months ago

ところで: toSpkiPublicKeyをどっかに突っ込み忘れてるわね?

(多分MisskeyのPersonのKeyレンダリングで補正しているのがそのままやってきたっぽい?)

tamaina commented 6 months ago

メモ https://github.com/nodejs/node/blob/7e05126fcab705babefae81bb83c3d310646e5a2/src/crypto/crypto_keys.cc#L1209

tamaina commented 6 months ago

メモ https://github.com/nodejs/node/blob/9930f114a00d17a0b2d6c7f6086aa77c0b971e28/src/crypto/crypto_keys.cc#L104

tamaina commented 6 months ago

メモ https://github.com/nodejs/node/blob/9930f114a00d17a0b2d6c7f6086aa77c0b971e28/src/crypto/crypto_keys.cc#L104

nodeもやっぱり「SPKIっぽくなかったらPKCS#1にする」という方法をとっていることがわかった

tamaina commented 6 months ago

なんかWeb Crypto APIの方が署名検証早いんすけど

awaitしてなかったんだからそりゃ速いよ…

最新版(Signを実装

image

tamaina commented 6 months ago

Web Verifyは改善の余地がありそう

tamaina commented 6 months ago

image

Promise.allで処理させたら爆速になった

tamaina commented 6 months ago

(node用の実装も残しておきたさはあるけど、Web環境に取り込んでも大丈夫なようにするには工夫が必要そう

tamaina commented 6 months ago

うんいらんな

tamaina commented 6 months ago

https://github.com/misskey-dev/node-http-message-signatures/commit/8286028414a5f801dea2d515f2d0f3735f2e378a

DraftはWeb Crypto APIで動くようになった

tamaina commented 6 months ago

Complete