Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sign: switch to SHA2-256 signature by default #1706

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ lint: checkfmt setup-golangci-lint ## Run linters and checks like golangci-lint
.PHONY: unit
unit:
go test ./... -race
SIGNING_DIGEST=SHA1 go test ./... -race

.PHONY: integration
integration:
go test ./... -race -tags=integration
SIGNING_DIGEST=SHA1 go test ./... -race -tags=integration

.PHONY: test
test: integration
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/numpy-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ test:
# TODO(pnasrat): fix to use multiple python
contents:
packages:
- python-3.12
- python-3.13
pipeline:
# Test import with command (python -c "import numpy")
- uses: python/test
with:
command: python3.12 -c "import numpy"
command: python3.13 -c "import numpy"
# Test import directly (python -c "import numpy")
- uses: python/import
with:
Expand Down
20 changes: 15 additions & 5 deletions pkg/build/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ type ApkSigner interface {
SignatureName() string
}

var melangeApkDigest crypto.Hash

func init() {
melangeApkDigest = crypto.SHA256
if digest, ok := os.LookupEnv("SIGNING_DIGEST"); ok {
switch digest {
case "SHA256":
case "SHA1":
melangeApkDigest = crypto.SHA1
default:
panic(fmt.Errorf("unsupported SIGNING_DIGEST"))
}
}
}

func EmitSignature(ctx context.Context, signer ApkSigner, controlData []byte, sde time.Time) ([]byte, error) {
_, span := otel.Tracer("melange").Start(ctx, "EmitSignature")
defer span.End()
Expand Down Expand Up @@ -73,12 +88,7 @@ type KeyApkSigner struct {
KeyPassphrase string
}

const melangeApkDigest = crypto.SHA1

// const melangeApkDigest = crypto.SHA256

func (s KeyApkSigner) Sign(control []byte) ([]byte, error) {

controlDigest, err := sign.HashData(control, melangeApkDigest)
if err != nil {
return nil, err
Expand Down
16 changes: 12 additions & 4 deletions pkg/sign/apk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ func TestAPK(t *testing.T) {
if err != nil {
t.Fatal(err)
}
melangeApkDigest := crypto.SHA1
prefix := ".SIGN.RSA."
// melangeApkDigest := crypto.SHA256
// prefix := ".SIGN.RSA256."
melangeApkDigest := crypto.SHA256
prefix := ".SIGN.RSA256."
if digest, ok := os.LookupEnv("SIGNING_DIGEST"); ok {
switch digest {
case "SHA256":
case "SHA1":
melangeApkDigest = crypto.SHA1
prefix = ".SIGN.RSA."
default:
t.Fatalf("unsupported SIGNING_DIGEST")
}
}
if sigName != prefix+testPubkey {
t.Fatalf("unexpected signature name %s", sigName)
}
Expand Down
Loading