Skip to content

Commit bda7223

Browse files
authored
Migrate Digest Upload Algorithm from MD5 to SHA-256 (FIPS 140-3)
LMCROSSITXSADEPLOY-3224
1 parent ecb9333 commit bda7223

4 files changed

Lines changed: 86 additions & 24 deletions

File tree

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ require (
1414
github.com/onsi/ginkgo v1.16.4
1515
github.com/onsi/gomega v1.38.2
1616
github.com/pborman/uuid v1.2.0
17-
golang.org/x/net v0.56.0
17+
golang.org/x/crypto v0.55.0
18+
golang.org/x/net v0.57.0
1819
gopkg.in/cheggaaa/pb.v1 v1.0.28
1920
gopkg.in/yaml.v3 v3.0.1
2021
)
@@ -59,10 +60,9 @@ require (
5960
github.com/stretchr/testify v1.11.1 // indirect
6061
github.com/vito/go-interact v1.0.0 // indirect
6162
go.yaml.in/yaml/v3 v3.0.4 // indirect
62-
golang.org/x/crypto v0.53.0 // indirect
63-
golang.org/x/sys v0.46.0 // indirect
64-
golang.org/x/term v0.44.0 // indirect
65-
golang.org/x/text v0.38.0 // indirect
63+
golang.org/x/sys v0.47.0 // indirect
64+
golang.org/x/term v0.45.0 // indirect
65+
golang.org/x/text v0.41.0 // indirect
6666
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
6767
gopkg.in/yaml.v2 v2.4.0 // indirect
6868
)

go.sum

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,13 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U
409409
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
410410
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
411411
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
412-
golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
413-
golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio=
412+
golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M=
413+
golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis=
414414
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
415415
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
416416
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
417-
golang.org/x/mod v0.36.0 h1:JJjpVx6myfUsUdAzZuOSTTmRE0PfZeNWzzvKrP7amb4=
418-
golang.org/x/mod v0.36.0/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ=
417+
golang.org/x/mod v0.38.0 h1:MECBjubtXD7yj4HrhIUcywNaGeNVUdfVnxmPajOk4yk=
418+
golang.org/x/mod v0.38.0/go.mod h1:V6Xz0pq8TQ3dGqVQ1FVHuelZpAL0uNhSkk9ogYP3c40=
419419
golang.org/x/net v0.0.0-20180418062111-d41e8174641f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
420420
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
421421
golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -439,8 +439,8 @@ golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT
439439
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
440440
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
441441
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
442-
golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o=
443-
golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
442+
golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE=
443+
golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU=
444444
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
445445
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
446446
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -450,8 +450,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
450450
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
451451
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
452452
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
453-
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
454-
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
453+
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
454+
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
455455
golang.org/x/sys v0.0.0-20180419222023-a2a45943ae67/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
456456
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
457457
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -480,21 +480,21 @@ golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBc
480480
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
481481
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
482482
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
483-
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
484-
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
483+
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
484+
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
485485
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
486486
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
487-
golang.org/x/term v0.44.0 h1:0rLvDRCtNj0gZkyIXhCyOb2OAzEhLVqc4B+hrsBhrmc=
488-
golang.org/x/term v0.44.0/go.mod h1:7ze4MdzUzLXpSAoFP1H0bOI9aXDqveSvatT5vKcFh2Y=
487+
golang.org/x/term v0.45.0 h1:NwWyBmoJCbfTHpxrWoZ9C6/VxOf7ic219I8xZZFdrf0=
488+
golang.org/x/term v0.45.0/go.mod h1:9aqxs0blBcrm/n0L9QW0aRVD+ktan8ssZromtqJC43w=
489489
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
490490
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
491491
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
492492
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
493493
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
494494
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
495495
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
496-
golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE=
497-
golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4=
496+
golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8=
497+
golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M=
498498
golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
499499
golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
500500
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -510,8 +510,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
510510
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
511511
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
512512
golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
513-
golang.org/x/tools v0.45.0 h1:18qN3FAooORvApf5XjCXgsuayZOEtXf6JK18I3+ONa8=
514-
golang.org/x/tools v0.45.0/go.mod h1:LuUGqqaXcXMEFEruIVJVm5mgDD8vww/z/SR1gQ4uE/0=
513+
golang.org/x/tools v0.48.0 h1:3+hClM1aLL5mjMKm5ovokw9epgRXPuu2tILgismM6RE=
514+
golang.org/x/tools v0.48.0/go.mod h1:08xX0orndb/F7jJxGDicx061tyd5pcMto75YMAXr6lk=
515515
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
516516
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
517517
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

util/digest.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"io"
1212
"os"
1313
"strings"
14+
15+
"golang.org/x/crypto/sha3"
1416
)
1517

1618
// ComputeFileChecksum computes the checksum of the specified file based on the specified algorithm
@@ -19,12 +21,18 @@ func ComputeFileChecksum(filePath, algorithm string) (string, error) {
1921
switch strings.ToUpper(algorithm) {
2022
case "MD5":
2123
hasher = md5.New()
22-
case "SHA1":
24+
case "SHA1", "SHA-1":
2325
hasher = sha1.New()
24-
case "SHA256":
26+
case "SHA256", "SHA-256":
2527
hasher = sha256.New()
26-
case "SHA512":
28+
case "SHA384", "SHA-384":
29+
hasher = sha512.New384()
30+
case "SHA512", "SHA-512":
2731
hasher = sha512.New()
32+
case "SHA3-256":
33+
hasher = sha3.New256()
34+
case "SHA3-512":
35+
hasher = sha3.New512()
2836
default:
2937
return "", fmt.Errorf("Unsupported digest algorithm %q", algorithm)
3038
}

util/digest_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,60 @@ var _ = Describe("Digest", func() {
4646
})
4747
})
4848

49+
Context("with SHA-384 algorithm name (as returned by deploy service for FIPS+NCS)", func() {
50+
It("should compute the SHA-384 digest of the file", func() {
51+
const testFileContent = "test file content"
52+
os.WriteFile(testFile.Name(), []byte(testFileContent), 0644)
53+
digest, err := util.ComputeFileChecksum(testFilePath, "SHA-384")
54+
testutil.ExpectNoErrorAndResult(err, digest, "4b87814537ab46771af4f37f259d6321f8c36b9e0d9ed1eda10005031cf7de752b9937a9cfe02744a3fc9785c3106317")
55+
})
56+
})
57+
58+
Context("with legacy hyphenated SHA-256 algorithm name", func() {
59+
It("should compute the SHA-256 digest of the file", func() {
60+
const testFileContent = "test file content"
61+
os.WriteFile(testFile.Name(), []byte(testFileContent), 0644)
62+
digest, err := util.ComputeFileChecksum(testFilePath, "SHA-256")
63+
testutil.ExpectNoErrorAndResult(err, digest, "60f5237ed4049f0382661ef009d2bc42e48c3ceb3edb6600f7024e7ab3b838f3")
64+
})
65+
})
66+
67+
Context("with legacy hyphenated SHA-1 algorithm name", func() {
68+
It("should compute the SHA-1 digest of the file", func() {
69+
const testFileContent = "test file content"
70+
os.WriteFile(testFile.Name(), []byte(testFileContent), 0644)
71+
digest, err := util.ComputeFileChecksum(testFilePath, "SHA-1")
72+
testutil.ExpectNoErrorAndResult(err, digest, "9032bbc224ed8b39183cb93b9a7447727ce67f9d")
73+
})
74+
})
75+
76+
Context("with legacy hyphenated SHA-512 algorithm name", func() {
77+
It("should compute the SHA-512 digest of the file", func() {
78+
const testFileContent = "test file content"
79+
os.WriteFile(testFile.Name(), []byte(testFileContent), 0644)
80+
digest, err := util.ComputeFileChecksum(testFilePath, "SHA-512")
81+
testutil.ExpectNoErrorAndResult(err, digest, "6543084c6981d2d3e44d295d20adee4e5fa3fc1bb2b7d3ac80ca456b0141dfd75657ba40ea5ae398824b3a871c8b7762c8bdbcbc252fa7f358d33d90ee455d86")
82+
})
83+
})
84+
85+
Context("with SHA3-256 algorithm", func() {
86+
It("should compute the SHA3-256 digest of the file", func() {
87+
const testFileContent = "test file content"
88+
os.WriteFile(testFile.Name(), []byte(testFileContent), 0644)
89+
digest, err := util.ComputeFileChecksum(testFilePath, "SHA3-256")
90+
testutil.ExpectNoErrorAndResult(err, digest, "0de0da51c6d2c645c7822739d886b15894c0baa51e668415b683b3d028a12758")
91+
})
92+
})
93+
94+
Context("with SHA3-512 algorithm", func() {
95+
It("should compute the SHA3-512 digest of the file", func() {
96+
const testFileContent = "test file content"
97+
os.WriteFile(testFile.Name(), []byte(testFileContent), 0644)
98+
digest, err := util.ComputeFileChecksum(testFilePath, "SHA3-512")
99+
testutil.ExpectNoErrorAndResult(err, digest, "fa9fc2b12fcb7ca5e1758dfb907d139d9f803676a8659de0b0527e77adf4b332631a22306bad174e46ce47a4e5b6e4fd2ccdc58cefa51b233c0e5ce6651330f8")
100+
})
101+
})
102+
49103
AfterEach(func() {
50104
testFile.Close()
51105
os.Remove(testFileName)

0 commit comments

Comments
 (0)