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

refactor OIDMatcher into separate utils package #454

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/verifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"time"

"github.com/sigstore/rekor-monitor/pkg/rekor"
file "github.com/sigstore/rekor-monitor/pkg/util"
"github.com/sigstore/rekor-monitor/pkg/util/file"
"github.com/sigstore/rekor/pkg/client"
gclient "github.com/sigstore/rekor/pkg/generated/client"
"github.com/sigstore/rekor/pkg/util"
Expand Down
23 changes: 23 additions & 0 deletions pkg/identity/identity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 The Sigstore 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 identity

import "encoding/asn1"

// OIDMatcher holds an OID field and a list of values to match on
type OIDMatcher struct {
ObjectIdentifier asn1.ObjectIdentifier `yaml:"objectIdentifier"`
ExtensionValues []string `yaml:"extensionValues"`
}
9 changes: 2 additions & 7 deletions pkg/rekor/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strings"

"github.com/go-openapi/runtime"
"github.com/sigstore/rekor-monitor/pkg/identity"
"github.com/sigstore/rekor/pkg/generated/models"
"github.com/sigstore/rekor/pkg/pki"
"github.com/sigstore/rekor/pkg/types"
Expand Down Expand Up @@ -57,12 +58,6 @@ type CertificateIdentity struct {
Issuers []string `yaml:"issuers"`
}

// OIDMatcher holds an OID field and a list of values to match on
type OIDMatcher struct {
ObjectIdentifier asn1.ObjectIdentifier `yaml:"objectIdentifier"`
ExtensionValues []string `yaml:"extensionValues"`
}

// MonitoredValues holds a set of values to compare against a given entry
type MonitoredValues struct {
// CertificateIdentities contains a list of subjects and issuers
Expand All @@ -80,7 +75,7 @@ type MonitoredValues struct {
Subjects []string `yaml:"subjects"`
// OIDMatchers contains a list of OID extension fields and associated values
// ex. Build Signer URI, associated with specific workflow URIs
OIDMatchers []OIDMatcher `yaml:"oidMatchers"`
OIDMatchers []identity.OIDMatcher `yaml:"oidMatchers"`
}

// IdentityEntry holds a certificate subject, issuer, and log entry metadata
Expand Down
13 changes: 7 additions & 6 deletions pkg/rekor/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"time"

"github.com/go-openapi/swag"
"github.com/sigstore/rekor-monitor/pkg/identity"
"github.com/sigstore/rekor-monitor/pkg/test"
"github.com/sigstore/rekor/pkg/generated/models"
"github.com/sigstore/rekor/pkg/types"
Expand Down Expand Up @@ -526,7 +527,7 @@ func TestMatchedIndicesForOIDMatchers(t *testing.T) {

// match to oid with matching extension value
matches, err := MatchedIndices([]models.LogEntry{logEntry}, MonitoredValues{
OIDMatchers: []OIDMatcher{
OIDMatchers: []identity.OIDMatcher{
{
ObjectIdentifier: oid,
ExtensionValues: []string{extValueString},
Expand All @@ -547,7 +548,7 @@ func TestMatchedIndicesForOIDMatchers(t *testing.T) {

// no match to oid with different extension value
matches, err = MatchedIndices([]models.LogEntry{logEntry}, MonitoredValues{
OIDMatchers: []OIDMatcher{
OIDMatchers: []identity.OIDMatcher{
{
ObjectIdentifier: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 9},
ExtensionValues: []string{"wrong"},
Expand All @@ -562,7 +563,7 @@ func TestMatchedIndicesForOIDMatchers(t *testing.T) {

// no match to oid with different oid extension field
matches, err = MatchedIndices([]models.LogEntry{logEntry}, MonitoredValues{
OIDMatchers: []OIDMatcher{
OIDMatchers: []identity.OIDMatcher{
{
ObjectIdentifier: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57264, 1, 14},
ExtensionValues: []string{"test cert value"},
Expand Down Expand Up @@ -620,7 +621,7 @@ func TestMatchedIndicesFailures(t *testing.T) {

func TestMatchedIndicesFailuresOIDExtensionEmpty(t *testing.T) {
// failure: oid extension empty
_, err := MatchedIndices(nil, MonitoredValues{OIDMatchers: []OIDMatcher{{
_, err := MatchedIndices(nil, MonitoredValues{OIDMatchers: []identity.OIDMatcher{{
ObjectIdentifier: asn1.ObjectIdentifier{},
ExtensionValues: []string{""},
}}})
Expand All @@ -631,7 +632,7 @@ func TestMatchedIndicesFailuresOIDExtensionEmpty(t *testing.T) {

func TestMatchedIndicesFailuresOIDExtensionValuesEmpty(t *testing.T) {
// failure: oid extension values list empty
_, err := MatchedIndices(nil, MonitoredValues{OIDMatchers: []OIDMatcher{{
_, err := MatchedIndices(nil, MonitoredValues{OIDMatchers: []identity.OIDMatcher{{
ObjectIdentifier: asn1.ObjectIdentifier{2, 5, 29, 17},
ExtensionValues: []string{},
}}})
Expand All @@ -642,7 +643,7 @@ func TestMatchedIndicesFailuresOIDExtensionValuesEmpty(t *testing.T) {

func TestMatchedIndicesFailuresOIDExtensionValueEmpty(t *testing.T) {
// failure: oid extension value string empty
_, err := MatchedIndices(nil, MonitoredValues{OIDMatchers: []OIDMatcher{{
_, err := MatchedIndices(nil, MonitoredValues{OIDMatchers: []identity.OIDMatcher{{
ObjectIdentifier: asn1.ObjectIdentifier{2, 5, 29, 17},
ExtensionValues: []string{""},
}}})
Expand Down
File renamed without changes.
File renamed without changes.
Loading