Skip to content

Commit

Permalink
Merge pull request #1706 from xnox/main
Browse files Browse the repository at this point in the history
sign: switch to SHA2-256 signature by default
  • Loading branch information
xnox authored Dec 13, 2024
2 parents 004666b + ba60467 commit 13be2e5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
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

0 comments on commit 13be2e5

Please sign in to comment.