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

SHA-256 hash support for unverified upstream sources #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

manishk-arista
Copy link
Contributor

Unverified upstream sources (those with skip-check: true) are inherently risky as they lack a verification method. Any changes to these sources could go undetected. To address this, we now calculate and store the SHA-256 hash of unverified sources. This hash is added to the eext.yaml file under the src-sha256-hash field. During the create-srpm command, the hash in eext.yaml will be compared with the hash of the downloaded sources.

impl/create_srpm.go Outdated Show resolved Hide resolved
impl/create_srpm.go Outdated Show resolved Hide resolved
impl/create_srpm.go Outdated Show resolved Hide resolved
manifest/manifest.go Outdated Show resolved Hide resolved
@manishk-arista manishk-arista force-pushed the manishk-upstreamSrc-sha branch 2 times, most recently from 1a76c05 to 3ec6eb1 Compare December 16, 2024 15:16
impl/create_srpm.go Outdated Show resolved Hide resolved
impl/create_srpm.go Outdated Show resolved Hide resolved
impl/create_srpm.go Outdated Show resolved Hide resolved
impl/create_srpm.go Outdated Show resolved Hide resolved
manifest/manifest.go Outdated Show resolved Hide resolved
impl/create_srpm_for_others.go Outdated Show resolved Hide resolved
manifest/manifest.go Outdated Show resolved Hide resolved
util/util.go Outdated Show resolved Hide resolved
impl/create_srpm_for_others.go Show resolved Hide resolved
impl/create_srpm_for_others.go Outdated Show resolved Hide resolved
@@ -42,3 +42,12 @@ func TestMatchTarballSignature(t *testing.T) {
t.Log("Test tarball Signatue Match")
testTarballSig(t, "matchTarball")
}

func TestUpstreamSourcesSHA256Hash(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a test case where sha256 check fails.

util/util.go Outdated
func GenerateSha256Hash(filePath string) (string, error) {
file, err := os.Open(filePath)
if err != nil {
return "", fmt.Errorf("errored with %s while creating file",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fnt.Errorf( "%sGenerateSha256Hash: errored out with '%s',
errPrefix, err )

@@ -0,0 +1,16 @@
---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename dir as upstream-hash-check-good
Also add a bad eext.yaml case under upstream-hash-check-bad

Copy link
Contributor Author

@manishk-arista manishk-arista Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

present test case is checking for bad SHA256 hash

impl/create_srpm_from_others_test.go Outdated Show resolved Hide resolved
Unverified upstream sources (those with `skip-check: true`)
are inherently risky as they lack a verification method. Any
changes to these sources could go undetected. To address
this, we now calculate and store the SHA-256 hash of
unverified sources. This hash is added to the `eext.yaml`
file under the `src-sha256-hash` field. During the
`create-srpm` command, the hash in `eext.yaml` will be
compared with the hash of the downloaded sources.
@manishk-arista manishk-arista force-pushed the manishk-upstreamSrc-sha branch from 65476af to 7ca1e86 Compare December 23, 2024 07:24
@@ -131,6 +131,7 @@ type UpstreamSrc struct {
FullURL string `yaml:"full-url"`
GitBundle GitBundle `yaml:"git"`
Signature Signature `yaml:"signature"`
Sha256 string `yaml:"Sha256"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we go with sha256 in the yaml file? All other fields follow lowercase convention.

@@ -50,6 +50,19 @@ func (bldr *srpmBuilder) getUpstreamSourceForOthers(upstreamSrcFromManifest mani
}
bldr.log("downloaded")

if upstreamSrcFromManifest.Sha256 != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic can be moved to a separate function. This will help you write test cases specifically for success/fail of signature check, instead of running create-srpm command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants