-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make unsafe uses of
Verify
function explicit / make Verify
option…
…s safe by default (#3) This change re-organizes the logic of `SignedEntityVerifier.Verify`'s functional options in order to make unsafe uses of the `Verify` function explicit / make `Verify`'s options safe by default. After some discussion, it accomplishes this by: - Introducing `WithoutArtifactUnsafe` and `WithoutIdentitiesUnsafe` policy options - Reversing the logic that determines whether the `Verify` loop checks for the presence of artifacts and certificate identities; before, the default was to assume we would not check for artifacts or identities. Now that behaviour must be explicitly requested. - Adding a params struct to `Verify` for encapsulating the optional funcs while giving us the opportunity to expand policy options in the future. Individual commits squashed by this merge commit: * Renamed Verify to VerifyUnsafe. Introduced VerifyWithArtifact and VerifyWithArtifactDigest to make it explicit what the preferred usage path is; users should not use VerifyUnsafe unless they are very very careful and know what they are doing. * gofmt -s * Reverted VerifyUnsafe, VerifyWith* funcs. * Introduced new WithoutIdentitiesUnsafe, WithoutArtifactUnsafe policy options. * Updated comments. * Encapsulated the construction of PolicyConfig inside PolicyBuilder, added validation checks. * Made receiver variables consistent with other PolicyOptions. * Linting. * Added a length check in case no certificate identities are provided. * renamed variable to identityPolicies. * Removed unnecessary pointer deref. * Renamed VerifierConfigurator type to VerifierOption for consistency with PolicyOption. * Toned down some of the comments around Unsafe PolicyOptions. * On 2nd thought, BuildConfig ought to return a pointer. This way, we can't accidentally use a default PolicyConfig struct. * Added tests for policy options, made existing test use Safe path. --------- Signed-off-by: Phill MV <[email protected]>
- Loading branch information
Showing
5 changed files
with
338 additions
and
109 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
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 |
---|---|---|
|
@@ -26,6 +26,8 @@ import ( | |
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var SkipArtifactAndIdentitiesPolicy = verify.NewPolicy(verify.WithoutArtifactUnsafe(), verify.WithoutIdentitiesUnsafe()) | ||
|
||
func TestSignatureVerifier(t *testing.T) { | ||
virtualSigstore, err := ca.NewVirtualSigstore() | ||
assert.NoError(t, err) | ||
|
@@ -70,21 +72,21 @@ func TestEnvelopeSubject(t *testing.T) { | |
verifier, err := verify.NewSignedEntityVerifier(virtualSigstore, verify.WithTransparencyLog(1)) | ||
assert.NoError(t, err) | ||
|
||
_, err = verifier.Verify(entity) | ||
_, err = verifier.Verify(entity, SkipArtifactAndIdentitiesPolicy) | ||
assert.NoError(t, err) | ||
|
||
_, err = verifier.Verify(entity, verify.WithArtifact(bytes.NewBufferString(subjectBody))) | ||
_, err = verifier.Verify(entity, verify.NewPolicy(verify.WithArtifact(bytes.NewBufferString(subjectBody)), verify.WithoutIdentitiesUnsafe())) | ||
assert.NoError(t, err) | ||
|
||
_, err = verifier.Verify(entity, verify.WithArtifactDigest("sha256", digest)) | ||
_, err = verifier.Verify(entity, verify.NewPolicy(verify.WithArtifactDigest("sha256", digest), verify.WithoutIdentitiesUnsafe())) | ||
assert.NoError(t, err) | ||
|
||
// Error: incorrect artifact | ||
_, err = verifier.Verify(entity, verify.WithArtifact(bytes.NewBufferString("Hi, I am a different subject!"))) | ||
_, err = verifier.Verify(entity, verify.NewPolicy(verify.WithArtifact(bytes.NewBufferString("Hi, I am a different subject!")), verify.WithoutIdentitiesUnsafe())) | ||
assert.Error(t, err) | ||
|
||
// Error: incorrect digest algorithm | ||
_, err = verifier.Verify(entity, verify.WithArtifactDigest("sha512", digest)) | ||
_, err = verifier.Verify(entity, verify.NewPolicy(verify.WithArtifactDigest("sha512", digest), verify.WithoutIdentitiesUnsafe())) | ||
assert.Error(t, err) | ||
} | ||
|
||
|
@@ -99,15 +101,15 @@ func TestSignatureVerifierMessageSignature(t *testing.T) { | |
verifier, err := verify.NewSignedEntityVerifier(virtualSigstore, verify.WithTransparencyLog(1)) | ||
assert.NoError(t, err) | ||
|
||
result, err := verifier.Verify(entity, verify.WithArtifact(bytes.NewBufferString(artifact))) | ||
result, err := verifier.Verify(entity, verify.NewPolicy(verify.WithArtifact(bytes.NewBufferString(artifact)), verify.WithoutIdentitiesUnsafe())) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, result.Signature.Certificate.SubjectAlternativeName.Value, "[email protected]") | ||
assert.Equal(t, result.VerifiedTimestamps[0].Type, "Tlog") | ||
|
||
// should fail to verify with a different artifact | ||
artifact2 := "Hi, I am a different artifact!" | ||
result, err = verifier.Verify(entity, verify.WithArtifact(bytes.NewBufferString(artifact2))) | ||
result, err = verifier.Verify(entity, verify.NewPolicy(verify.WithArtifact(bytes.NewBufferString(artifact2)), verify.WithoutIdentitiesUnsafe())) | ||
assert.Error(t, err) | ||
assert.Nil(t, result) | ||
} |
Oops, something went wrong.