forked from sigstore/cosign
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fuzzing test for getting password (sigstore#93)
* Add fuzzing test to cosign Signed-off-by: Priya Wadhwa <[email protected]> * Move fuzzing into test directory, add Makefile for building fuzz target Signed-off-by: Priya Wadhwa <[email protected]> * Add build tag for fuzzingg Signed-off-by: Priya Wadhwa <[email protected]> * Fix test Signed-off-by: Priya Wadhwa <[email protected]> * Fix lint Signed-off-by: Priya Wadhwa <[email protected]> * Define Read function immediately Signed-off-by: Priya Wadhwa <[email protected]>
- Loading branch information
priyawadhwa
authored
Mar 16, 2021
1 parent
561f8f2
commit 38e0cae
Showing
8 changed files
with
75 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ cosign.pub | |
/cosign | ||
.vscode | ||
|
||
# fuzzing artifacts | ||
*.libfuzzer | ||
*fuzz.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// +build gofuzz | ||
|
||
/* | ||
Copyright The Rekor Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cli | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/sigstore/cosign/cmd/cosign/cli" | ||
) | ||
|
||
func FuzzGetPassword(data []byte) int { | ||
original := cli.Read | ||
cli.Read = func() func() ([]byte, error) { | ||
return func() ([]byte, error) { | ||
return data, nil | ||
} | ||
} | ||
defer func() { cli.Read = original }() | ||
p, err := cli.GetPass(true) | ||
if err != nil { | ||
panic(fmt.Sprintf("error getting password: %v", err)) | ||
} | ||
// the password we got back is not what was entered | ||
if bytes.Compare(p, data) != 0 { | ||
panic(fmt.Sprintf("input does not match output: %s %s", string(p), string(data))) | ||
} | ||
return 0 | ||
} |