Skip to content

Commit da65a5f

Browse files
committed
fix: use encryption instead of zip wrapper
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
1 parent dd7ff9a commit da65a5f

6 files changed

Lines changed: 62 additions & 69 deletions

File tree

test/e2e/internal/utils/crypto.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright The Notary Project Authors.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package utils
15+
16+
import (
17+
"crypto/aes"
18+
"crypto/cipher"
19+
"fmt"
20+
"os"
21+
)
22+
23+
// DecryptFile decrypts the AES encrypted file using an AES key and outputs the
24+
// decrypted file.
25+
func DecryptFile(inputFilename string, aesKey []byte, outputFilename string) error {
26+
ciphertext, err := os.ReadFile(inputFilename)
27+
if err != nil {
28+
return err
29+
}
30+
31+
block, err := aes.NewCipher(aesKey)
32+
if err != nil {
33+
return err
34+
}
35+
36+
aesGCM, err := cipher.NewGCM(block)
37+
if err != nil {
38+
return err
39+
}
40+
41+
nonceSize := aesGCM.NonceSize()
42+
if len(ciphertext) < nonceSize {
43+
return fmt.Errorf("ciphertext too short")
44+
}
45+
46+
nonce, ciphertext := ciphertext[:nonceSize], ciphertext[nonceSize:]
47+
48+
plaintext, err := aesGCM.Open(nil, nonce, ciphertext, nil)
49+
if err != nil {
50+
return err
51+
}
52+
53+
return os.WriteFile(outputFilename, plaintext, 0600)
54+
}

test/e2e/internal/utils/zip.go

Lines changed: 0 additions & 62 deletions
This file was deleted.

test/e2e/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ export NOTATION_E2E_BLOB_TRUST_POLICY_PATH=$CWD/testdata/blob/trustpolicies
126126
export NOTATION_E2E_TEST_DATA_PATH=$CWD/testdata
127127

128128
# run tests
129-
ginkgo -r -p -v
129+
ginkgo -r -p -v --focus "with zip bomb total file size exceeds 256 MiB size li"

test/e2e/suite/plugin/install.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ var _ = Describe("notation plugin install", func() {
7979

8080
It("with zip bomb total file size exceeds 256 MiB size limit", func() {
8181
Host(nil, func(notation *utils.ExecOpts, _ *Artifact, vhost *utils.VirtualHost) {
82-
// extract the test file from the wrapped file to avoid the issue of the zip bomb being
83-
// identified as a malicious file by the antivirus software
84-
wrappedFilePath := filepath.Join(NotationE2EMaliciousPluginArchivePath, "wrapped_zip_bomb.zip")
85-
fileName := "zip_bomb.zip"
86-
targetPath := vhost.AbsolutePath(NotationDirName, fileName)
87-
if err := utils.ExtractSingleFileFromZip(wrappedFilePath, fileName, targetPath); err != nil {
82+
// The original test file was encrypted to avoid being identified as
83+
// a malicious file by antivirus software. Decrypt on the fly to
84+
// avoid the issue.
85+
aesKey := []byte("9951d6610db9e6327b4af77f057fb494")
86+
encryptedFilePath := filepath.Join(NotationE2EMaliciousPluginArchivePath, "zip_bomb.zip.enc")
87+
targetPath := vhost.AbsolutePath(NotationDirName, "zip_bomb.zip")
88+
if err := utils.DecryptFile(encryptedFilePath, aesKey, targetPath); err != nil {
8889
Fail(fmt.Sprintf("failed to extract file from zip: %v", err))
8990
}
9091

-5.6 KB
Binary file not shown.
41.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)