Skip to content

Commit

Permalink
Merge pull request #178 from edytuk/v2.11.1
Browse files Browse the repository at this point in the history
Merge sylabs/sif through v2.11.1
  • Loading branch information
DrDaveD authored Mar 20, 2023
2 parents 5e91f3b + 724f1e6 commit dac6e95
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Install Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.51
version: v1.52
skip-pkg-cache: true
skip-build-cache: true

Expand Down
6 changes: 5 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ linters:
- typecheck
- unconvert
- unparam
# - unused
- unused
- whitespace

linters-settings:
errorlint:
# Go 1.19 compatibility (https://github.com/sylabs/sif/issues/265).
errorf-multi: false

misspell:
locale: US
4 changes: 2 additions & 2 deletions pkg/integrity/clearsign.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newClearsignEncoder(e *openpgp.Entity, timeFunc func() time.Time) *clearsig

// signMessage signs the message from r in clear-sign format, and writes the result to w. On
// success, the hash function is returned.
func (en *clearsignEncoder) signMessage(ctx context.Context, w io.Writer, r io.Reader) (crypto.Hash, error) {
func (en *clearsignEncoder) signMessage(_ context.Context, w io.Writer, r io.Reader) (crypto.Hash, error) {
plaintext, err := clearsign.Encode(w, en.e.PrivateKey, en.config)
if err != nil {
return 0, err
Expand All @@ -67,7 +67,7 @@ func newClearsignDecoder(kr openpgp.KeyRing) *clearsignDecoder {

// verifyMessage reads a message from r, verifies its signature, and returns the message contents.
// On success, the signing entity is set in vr.
func (de *clearsignDecoder) verifyMessage(ctx context.Context, r io.Reader, h crypto.Hash, vr *VerifyResult) ([]byte, error) { //nolint:lll
func (de *clearsignDecoder) verifyMessage(_ context.Context, r io.Reader, _ crypto.Hash, vr *VerifyResult) ([]byte, error) { //nolint:lll
data, err := io.ReadAll(r)
if err != nil {
return nil, err
Expand Down
4 changes: 1 addition & 3 deletions pkg/integrity/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Apptainer a Series of LF Projects LLC.
// For website terms of use, trademark policy, privacy policy and other
// project policies see https://lfprojects.org/policies
// Copyright (c) 2020-2022, Sylabs Inc. All rights reserved.
// Copyright (c) 2020-2023, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file
// distributed with the sources of this project regarding your rights to use or distribute this
// software.
Expand Down Expand Up @@ -121,7 +121,6 @@ func (d digest) MarshalJSON() ([]byte, error) {
func (d *digest) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
//nolint:errorlint // Go 1.19 compatibility
return fmt.Errorf("%w: %v", errDigestMalformed, err)
}

Expand All @@ -134,7 +133,6 @@ func (d *digest) UnmarshalJSON(data []byte) error {

v, err := hex.DecodeString(value)
if err != nil {
//nolint:errorlint // Go 1.19 compatibility
return fmt.Errorf("%w: %v", errDigestMalformed, err)
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/integrity/dsse.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func (de *dsseDecoder) verifyMessage(ctx context.Context, r io.Reader, h crypto.

vr.aks, err = v.Verify(ctx, &e)
if err != nil {
//nolint:errorlint // Go 1.19 compatibility
return nil, fmt.Errorf("%w: %v", errDSSEVerifyEnvelopeFailed, err)
}

Expand Down Expand Up @@ -172,7 +171,7 @@ func (s *dsseSigner) Sign(ctx context.Context, data []byte) ([]byte, error) {
var errSignNotImplemented = errors.New("sign not implemented")

// Verify is not implemented, but required for the dsse.SignVerifier interface.
func (s *dsseSigner) Verify(ctx context.Context, data, sig []byte) error {
func (s *dsseSigner) Verify(_ context.Context, _, _ []byte) error {
return errSignNotImplemented
}

Expand Down
19 changes: 13 additions & 6 deletions pkg/integrity/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,19 @@ type Signer struct {
// By default, one digital signature is added per object group in f. To override this behavior,
// consider using OptSignGroup and/or OptSignObjects.
//
// By default, signature, header and descriptor timestamps are set to the current time. To override
// this behavior, consider using OptSignWithTime or OptSignDeterministic.
// By default, signature timestamps are set to the current time. To override this behavior,
// consider using OptSignWithTime.
//
// By default, header and descriptor timestamps are set to the current time for non-deterministic
// images, and unset otherwise. To override this behavior, consider using OptSignWithTime or
// OptSignDeterministic.
func NewSigner(f *sif.FileImage, opts ...SignerOpt) (*Signer, error) {
if f == nil {
return nil, fmt.Errorf("integrity: %w", errNilFileImage)
}

so := signOpts{
timeFunc: time.Now,
ctx: context.Background(),
ctx: context.Background(),
}

// Apply options.
Expand All @@ -350,7 +353,11 @@ func NewSigner(f *sif.FileImage, opts ...SignerOpt) (*Signer, error) {
return nil, fmt.Errorf("integrity: %w", err)
}
case so.e != nil:
en = newClearsignEncoder(so.e, so.timeFunc)
timeFunc := time.Now
if so.timeFunc != nil {
timeFunc = so.timeFunc
}
en = newClearsignEncoder(so.e, timeFunc)
commonOpts = append(commonOpts, optSignGroupFingerprint(so.e.PrimaryKey.Fingerprint))
default:
return nil, fmt.Errorf("integrity: %w", ErrNoKeyMaterial)
Expand Down Expand Up @@ -414,7 +421,7 @@ func (s *Signer) Sign() error {
var opts []sif.AddOpt
if s.opts.deterministic {
opts = append(opts, sif.OptAddDeterministic())
} else {
} else if s.opts.timeFunc != nil {
opts = append(opts, sif.OptAddWithTime(s.opts.timeFunc()))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/integrity/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func (v mockVerifier) signatures() ([]sif.Descriptor, error) {
return v.sigs, v.sigsErr
}

func (v mockVerifier) verifySignature(ctx context.Context, sig sif.Descriptor, de decoder, vr *VerifyResult) error {
func (v mockVerifier) verifySignature(_ context.Context, _ sif.Descriptor, _ decoder, vr *VerifyResult) error {
vr.verified = v.verified
vr.e = v.e
return v.verifyErr
Expand Down
42 changes: 23 additions & 19 deletions pkg/sif/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func createContainer(rw ReadWriter, co createOpts) (*FileImage, error) {
// By default, the image ID is set to a randomly generated value. To override this, consider using
// OptCreateDeterministic or OptCreateWithID.
//
// By default, the image creation time is set to time.Now(). To override this, consider using
// By default, the image creation time is set to the current time. To override this, consider using
// OptCreateDeterministic or OptCreateWithTime.
//
// By default, the image will support a maximum of 48 descriptors. To change this, consider using
Expand Down Expand Up @@ -300,7 +300,7 @@ func CreateContainer(rw ReadWriter, opts ...CreateOpt) (*FileImage, error) {
// By default, the image ID is set to a randomly generated value. To override this, consider using
// OptCreateDeterministic or OptCreateWithID.
//
// By default, the image creation time is set to time.Now(). To override this, consider using
// By default, the image creation time is set to the current time. To override this, consider using
// OptCreateDeterministic or OptCreateWithTime.
//
// By default, the image will support a maximum of 48 descriptors. To change this, consider using
Expand Down Expand Up @@ -397,11 +397,13 @@ func OptAddWithTime(t time.Time) AddOpt {

// AddObject adds a new data object and its descriptor into the specified SIF file.
//
// By default, the image modification time is set to the current time. To override this, consider
// using OptAddDeterministic or OptAddWithTime.
// By default, the image modification time is set to the current time for non-deterministic images,
// and unset otherwise. To override this, consider using OptAddDeterministic or OptAddWithTime.
func (f *FileImage) AddObject(di DescriptorInput, opts ...AddOpt) error {
ao := addOpts{
t: time.Now(),
ao := addOpts{}

if !f.isDeterministic() {
ao.t = time.Now()
}

for _, opt := range opts {
Expand Down Expand Up @@ -453,11 +455,7 @@ func (f *FileImage) isLast(d *rawDescriptor) bool {
func (f *FileImage) truncateAt(d *rawDescriptor) error {
start := d.Offset + d.Size - d.SizeWithPadding

if err := f.rw.Truncate(start); err != nil {
return err
}

return nil
return f.rw.Truncate(start)
}

// deleteOpts accumulates object deletion options.
Expand Down Expand Up @@ -510,11 +508,14 @@ var errCompactNotImplemented = errors.New("compact not implemented for non-last
// To zero the data region of the deleted object, use OptDeleteZero. To compact the file following
// object deletion, use OptDeleteCompact.
//
// By default, the image modification time is set to time.Now(). To override this, consider using
// OptDeleteDeterministic or OptDeleteWithTime.
// By default, the image modification time is set to the current time for non-deterministic images,
// and unset otherwise. To override this, consider using OptDeleteDeterministic or
// OptDeleteWithTime.
func (f *FileImage) DeleteObject(id uint32, opts ...DeleteOpt) error {
do := deleteOpts{
t: time.Now(),
do := deleteOpts{}

if !f.isDeterministic() {
do.t = time.Now()
}

for _, opt := range opts {
Expand Down Expand Up @@ -600,11 +601,14 @@ var (

// SetPrimPart sets the specified system partition to be the primary one.
//
// By default, the image/object modification times are set to time.Now(). To override this,
// consider using OptSetDeterministic or OptSetWithTime.
// By default, the image/object modification times are set to the current time for
// non-deterministic images, and unset otherwise. To override this, consider using
// OptSetDeterministic or OptSetWithTime.
func (f *FileImage) SetPrimPart(id uint32, opts ...SetOpt) error {
so := setOpts{
t: time.Now(),
so := setOpts{}

if !f.isDeterministic() {
so.t = time.Now()
}

for _, opt := range opts {
Expand Down
71 changes: 41 additions & 30 deletions pkg/sif/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@ func TestAddObject(t *testing.T) {
),
wantErr: errPrimaryPartition,
},
{
name: "Deterministic",
createOpts: []CreateOpt{
OptCreateWithID("de170c43-36ab-44a8-bca9-1ea1a070a274"),
OptCreateWithTime(time.Unix(946702800, 0)),
},
di: getDescriptorInput(t, DataGeneric, []byte{0xfa, 0xce}),
opts: []AddOpt{
OptAddDeterministic(),
},
},
{
name: "WithTime",
createOpts: []CreateOpt{
Expand All @@ -339,9 +350,6 @@ func TestAddObject(t *testing.T) {
OptCreateDeterministic(),
},
di: getDescriptorInput(t, DataGeneric, []byte{0xfa, 0xce}),
opts: []AddOpt{
OptAddDeterministic(),
},
},
{
name: "EmptyNotAligned",
Expand All @@ -351,9 +359,6 @@ func TestAddObject(t *testing.T) {
di: getDescriptorInput(t, DataGeneric, []byte{0xfa, 0xce},
OptObjectAlignment(0),
),
opts: []AddOpt{
OptAddDeterministic(),
},
},
{
name: "EmptyAligned",
Expand All @@ -363,9 +368,6 @@ func TestAddObject(t *testing.T) {
di: getDescriptorInput(t, DataGeneric, []byte{0xfa, 0xce},
OptObjectAlignment(128),
),
opts: []AddOpt{
OptAddDeterministic(),
},
},
{
name: "NotEmpty",
Expand All @@ -378,9 +380,6 @@ func TestAddObject(t *testing.T) {
di: getDescriptorInput(t, DataPartition, []byte{0xfe, 0xed},
OptPartitionMetadata(FsSquash, PartPrimSys, "386"),
),
opts: []AddOpt{
OptAddDeterministic(),
},
},
{
name: "NotEmptyNotAligned",
Expand All @@ -394,9 +393,6 @@ func TestAddObject(t *testing.T) {
OptPartitionMetadata(FsSquash, PartPrimSys, "386"),
OptObjectAlignment(0),
),
opts: []AddOpt{
OptAddDeterministic(),
},
},
{
name: "NotEmptyAligned",
Expand All @@ -410,9 +406,6 @@ func TestAddObject(t *testing.T) {
OptPartitionMetadata(FsSquash, PartPrimSys, "386"),
OptObjectAlignment(128),
),
opts: []AddOpt{
OptAddDeterministic(),
},
},
}

Expand Down Expand Up @@ -465,7 +458,6 @@ func TestDeleteObject(t *testing.T) {
},
id: 1,
opts: []DeleteOpt{
OptDeleteDeterministic(),
OptDeleteZero(true),
},
},
Expand All @@ -479,7 +471,6 @@ func TestDeleteObject(t *testing.T) {
},
id: 1,
opts: []DeleteOpt{
OptDeleteDeterministic(),
OptDeleteCompact(true),
},
},
Expand All @@ -493,11 +484,24 @@ func TestDeleteObject(t *testing.T) {
},
id: 1,
opts: []DeleteOpt{
OptDeleteDeterministic(),
OptDeleteZero(true),
OptDeleteCompact(true),
},
},
{
name: "Deterministic",
createOpts: []CreateOpt{
OptCreateWithID("de170c43-36ab-44a8-bca9-1ea1a070a274"),
OptCreateWithDescriptors(
getDescriptorInput(t, DataGeneric, []byte{0xfa, 0xce}),
),
OptCreateWithTime(time.Unix(946702800, 0)),
},
id: 1,
opts: []DeleteOpt{
OptDeleteDeterministic(),
},
},
{
name: "WithTime",
createOpts: []CreateOpt{
Expand All @@ -522,9 +526,6 @@ func TestDeleteObject(t *testing.T) {
),
},
id: 1,
opts: []DeleteOpt{
OptDeleteDeterministic(),
},
},
}

Expand Down Expand Up @@ -567,6 +568,22 @@ func TestSetPrimPart(t *testing.T) {
id: 1,
wantErr: ErrObjectNotFound,
},
{
name: "Deterministic",
createOpts: []CreateOpt{
OptCreateWithID("de170c43-36ab-44a8-bca9-1ea1a070a274"),
OptCreateWithDescriptors(
getDescriptorInput(t, DataPartition, []byte{0xfa, 0xce},
OptPartitionMetadata(FsRaw, PartSystem, "386"),
),
),
OptCreateWithTime(time.Unix(946702800, 0)),
},
id: 1,
opts: []SetOpt{
OptSetDeterministic(),
},
},
{
name: "WithTime",
createOpts: []CreateOpt{
Expand Down Expand Up @@ -596,9 +613,6 @@ func TestSetPrimPart(t *testing.T) {
),
},
id: 1,
opts: []SetOpt{
OptSetDeterministic(),
},
},
{
name: "Two",
Expand All @@ -614,9 +628,6 @@ func TestSetPrimPart(t *testing.T) {
),
},
id: 2,
opts: []SetOpt{
OptSetDeterministic(),
},
},
}

Expand Down
Loading

0 comments on commit dac6e95

Please sign in to comment.