ECDSA registry signatures aren't reproducible
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- go
调研方向
先从 registry signatures guide 以及链接的 registry version 和 key endpoints 开始,然后将它们与提供的 Go verification example 进行比较。记录可复现 ECDSA verification 所需的 hashing 和 encoding 细节,并向文档中添加一个可运行的示例。
由索引模型根据 Issue 内容生成。
描述
I'm following the guide at https://docs.npmjs.com/about-registry-signatures, and I'm struggling to verify the ECDSA signatures that get published to the NPM registry.
Some example code, that shows things like which hashing algorithm is used for the contents of bundles (I'm just assuming that it's sha256 currently), and whether the keys are base64 encoded using the standard algorithm or the alternate under RFC 4648, would be immensely helpful.
I've written what I have so far below, and would appreciate some help getting it to work. Feel free to add it to your documentation once it does!
package main
import (
"bytes"
"crypto/ecdsa"
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"fmt"
"io"
"net/http"
)
func downloadPackage(compressedPackage *bytes.Buffer) error {
resp, err := http.Get("https://registry.npmjs.org/light-cycle/-/light-cycle-1.4.3.tgz")
if err != nil {
return fmt.Errorf("package download failed: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("pacakge download bad status code: %s", resp.Status)
}
_, err = io.Copy(compressedPackage, resp.Body)
if err != nil {
return fmt.Errorf("failed to read package to buffer: %v", err)
}
return nil
}
func verifyPackage(compressedPackage *bytes.Buffer) error {
// From https://registry.npmjs.org/light-cycle/1.4.3.
versionSignature := "MEUCIQCX/49atNeSDYZP8betYWEqB0G8zZnIyB7ibC7nRNyMiQIgHosOKHhVTVNBI/6iUNSpDokOc44zsZ7TfybMKj8YdfY="
// From https://registry.npmjs.org/-/npm/v1/keys.
publicKey := "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE1Olb3zMAFFxXKHiIkQO5cJ3Yhl5i6UPp+IhuteBJbuHcA5UogKo0EWtlWwW6KSaKoTNEYL7JlCQiVnkhBktUgg=="
// Decode and parse the public key.
publicKeyBytes, err := base64.StdEncoding.DecodeString(publicKey)
fmt.Printf("PUBLIC KEY BASE 64 BYTES: %x\n", publicKeyBytes)
if err != nil {
return fmt.Errorf("error decoding public key bytes: %v", err)
}
parsedPublicKeyUntyped, err := x509.ParsePKIXPublicKey(publicKeyBytes)
parsedPublicKey := parsedPublicKeyUntyped.(*ecdsa.PublicKey)
fmt.Printf("PARSED PUBLIC KEY X: %v, Y: %v\n", parsedPublicKey.X, parsedPublicKey.Y)
if err != nil {
return fmt.Errorf("error parsing public key: %v", err)
}
// Decode the signature.
versionSignatureBytes, err := base64.StdEncoding.DecodeString(versionSignature)
fmt.Printf("SIGNATURE BYTES: %x\n", versionSignatureBytes)
if err != nil {
return fmt.Errorf("error decoding signature bytes: %v", err)
}
// Verify the signature against the package's SHA256 sum.
// presentSHA256Bytes := md5.Sum(compressedPackage.Bytes())
presentSHA256Bytes := sha256.Sum256(compressedPackage.Bytes())
fmt.Printf("PRESENT SHA256: %x\n", presentSHA256Bytes)
if !ecdsa.VerifyASN1(parsedPublicKey, presentSHA256Bytes[:], versionSignatureBytes) {
return fmt.Errorf("signature verification failed")
}
return nil
}
func main() {
var compressedPackage bytes.Buffer
if err := downloadPackage(&compressedPackage); err != nil {
fmt.Printf("failed to download package: %v", err)
}
if err := verifyPackage(&compressedPackage); err != nil {
fmt.Printf("failed to verify package: %v", err)
}
}
Currently this outputs:
PUBLIC KEY BASE 64 BYTES: 3059301306072a8648ce3d020106082a8648ce3d03010703420004d4e95bdf3300145c572878889103b9709dd8865e62e943e9f8886eb5e0496ee1dc03952880aa34116b655b05ba29268aa1334460bec9942422567921064b5482
PARSED PUBLIC KEY X: 96302633342102462193322732537154456057293035750541189099858346903022946840289, Y: 99515156681666470022533827122417036293197994443229625834881400620927226172546
SIGNATURE BYTES: 304502210097ff8f5ab4d7920d864ff1b7ad61612a0741bccd99c8c81ee26c2ee744dc8c8902201e8b0e2878554d534123fea250d4a90e890e738e33b19ed37f26cc2a3f1875f6
PRESENT SHA256: a1b59bcdca7b8a6844c48fee7031842fcecec26fb028e4b5cbcb8c055ca0eeaa
failed to verify package: signature verification failed
Thank you for any help!
- 主要语言
- MDX
- 星标
- 715
- 派生
- 4.2k
- 平均合并
- 6 天 10 小时
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
npm/documentation 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
npm/documentation#1998 ·
-
难度 1/5 1 小时以内 新手友好度 85/100
npm/documentation#1997 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
npm/documentation#1960 · 1 个 reaction ·
-
Mobile header icons are hard to see可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
npm/documentation#1948 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
npm/documentation#1929 ·
查看 npm/documentation 的全部 Issue
相似的 Issue
-
Update dusk-bls12_381 to 0.16可能已有人在做 @HDauven 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
-
status:untriaged
难度 2/5 1-3 小时 新手友好度 72/100
midnightntwrk/midnight-zk#558 ·
维护者通常 2 天内回复
-
FixPending
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
indygreg/cryptography-rs#99 ·
-
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 2 天内回复