Files
docker-compose-updater/internal/auth/keys.go
T
ilovintit cea9b941cf
Build and Push / build (push) Failing after 13m20s
Initial commit: docker-compose-updater
Go 项目,包含:
- 服务端 updater:两阶段协议,ECDSA 签名验证,AES-GCM 加密
- 发送端 dcu-send:Gitea Action CLI
- internal/auth:加解密/签名/会话管理
- internal/docker:Docker CLI 容器查找/拉取/重建
- action/:Gitea Action 定义
- deploy/Dockerfile:多阶段构建
- .gitea/workflows/build.yaml:CI/CD
2026-06-08 15:16:46 +08:00

40 lines
1011 B
Go

package auth
import (
"crypto/ecdsa"
"crypto/x509"
"encoding/pem"
"fmt"
)
// ParseECDSAPrivateKey 解析 PEM 编码的 ECDSA 私钥。
func ParseECDSAPrivateKey(pemData []byte) (*ecdsa.PrivateKey, error) {
block, _ := pem.Decode(pemData)
if block == nil || block.Type != "EC PRIVATE KEY" {
return nil, fmt.Errorf("invalid EC private key PEM")
}
key, err := x509.ParseECPrivateKey(block.Bytes)
if err != nil {
return nil, fmt.Errorf("parse EC private key: %w", err)
}
return key, nil
}
// ParseECDSAPublicKey 解析 PEM 编码的 ECDSA 公钥。
func ParseECDSAPublicKey(pemData []byte) (*ecdsa.PublicKey, error) {
block, _ := pem.Decode(pemData)
if block == nil || block.Type != "PUBLIC KEY" {
return nil, fmt.Errorf("invalid public key PEM")
}
key, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
return nil, fmt.Errorf("parse public key: %w", err)
}
pubKey, ok := key.(*ecdsa.PublicKey)
if !ok {
return nil, fmt.Errorf("key is not ECDSA")
}
return pubKey, nil
}