Skip to content

Commit

Permalink
changed to PublicKeyPaths
Browse files Browse the repository at this point in the history
Signed-off-by: pxp928 <parth.psu@gmail.com>
  • Loading branch information
pxp928 committed Aug 26, 2022
1 parent 68e398a commit 1794b90
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/pflag_groups.go
Expand Up @@ -160,7 +160,7 @@ func CreatePropsFromPflags() *types.ArtifactProperties {
collectedKeys = append(collectedKeys, &url.URL{Path: key})
}
}
props.PublicKeyPath = collectedKeys
props.PublicKeyPaths = collectedKeys
}

props.PKIFormat = viper.GetString("pki-format")
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/alpine/v0.0.1/entry.go
Expand Up @@ -323,10 +323,10 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types
re.AlpineModel.PublicKey = &models.AlpineV001SchemaPublicKey{}
publicKeyBytes := props.PublicKeyBytes
if len(publicKeyBytes) == 0 {
if len(props.PublicKeyPath) != 1 {
if len(props.PublicKeyPaths) != 1 {
return nil, errors.New("only one public key must be provided")
}
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPath[0].Path))
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPaths[0].Path))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/cose/v0.0.1/entry.go
Expand Up @@ -317,10 +317,10 @@ func (v V001Entry) CreateFromArtifactProperties(_ context.Context, props types.A
}
publicKeyBytes := props.PublicKeyBytes
if len(publicKeyBytes) == 0 {
if len(props.PublicKeyPath) != 1 {
if len(props.PublicKeyPaths) != 1 {
return nil, errors.New("only one public key must be provided to verify signature")
}
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPath[0].Path))
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPaths[0].Path))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/entries.go
Expand Up @@ -132,7 +132,7 @@ type ArtifactProperties struct {
ArtifactBytes []byte
SignaturePath *url.URL
SignatureBytes []byte
PublicKeyPath []*url.URL
PublicKeyPaths []*url.URL
PublicKeyBytes [][]byte
PKIFormat string
}
4 changes: 2 additions & 2 deletions pkg/types/hashedrekord/v0.0.1/entry.go
Expand Up @@ -218,10 +218,10 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types
re.HashedRekordObj.Signature.PublicKey = &models.HashedrekordV001SchemaSignaturePublicKey{}
publicKeyBytes := props.PublicKeyBytes
if len(publicKeyBytes) == 0 {
if len(props.PublicKeyPath) != 1 {
if len(props.PublicKeyPaths) != 1 {
return nil, errors.New("only one public key must be provided to verify detached signature")
}
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPath[0].Path))
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPaths[0].Path))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/helm/v0.0.1/entry.go
Expand Up @@ -318,10 +318,10 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types
re.HelmObj.PublicKey = &models.HelmV001SchemaPublicKey{}
publicKeyBytes := props.PublicKeyBytes
if len(publicKeyBytes) == 0 {
if len(props.PublicKeyPath) != 1 {
if len(props.PublicKeyPaths) != 1 {
return nil, errors.New("only one public key must be provided")
}
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPath[0].Path))
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPaths[0].Path))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/intoto/v0.0.1/entry.go
Expand Up @@ -293,10 +293,10 @@ func (v V001Entry) CreateFromArtifactProperties(_ context.Context, props types.A
}
publicKeyBytes := props.PublicKeyBytes
if len(publicKeyBytes) == 0 {
if len(props.PublicKeyPath) != 1 {
if len(props.PublicKeyPaths) != 1 {
return nil, errors.New("only one public key must be provided to verify signature")
}
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPath[0].Path))
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPaths[0].Path))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/intoto/v0.0.2/entry.go
Expand Up @@ -319,8 +319,8 @@ func (v V002Entry) CreateFromArtifactProperties(_ context.Context, props types.A
allPubKeyBytes = append(allPubKeyBytes, props.PublicKeyBytes...)
}

if len(props.PublicKeyPath) > 0 {
for _, path := range props.PublicKeyPath {
if len(props.PublicKeyPaths) > 0 {
for _, path := range props.PublicKeyPaths {
if path.IsAbs() {
return nil, errors.New("dsse public keys cannot be fetched over HTTP(S)")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/rekord/v0.0.1/entry.go
Expand Up @@ -392,10 +392,10 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types
re.RekordObj.Signature.PublicKey = &models.RekordV001SchemaSignaturePublicKey{}
publicKeyBytes := props.PublicKeyBytes
if len(publicKeyBytes) == 0 {
if len(props.PublicKeyPath) != 1 {
if len(props.PublicKeyPaths) != 1 {
return nil, errors.New("only one public key must be provided to verify detached signature")
}
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPath[0].Path))
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPaths[0].Path))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/rpm/v0.0.1/entry.go
Expand Up @@ -343,10 +343,10 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types
re.RPMModel.PublicKey = &models.RpmV001SchemaPublicKey{}
publicKeyBytes := props.PublicKeyBytes
if len(publicKeyBytes) == 0 {
if len(props.PublicKeyPath) != 1 {
if len(props.PublicKeyPaths) != 1 {
return nil, errors.New("only one public key must be provided to verify RPM signature")
}
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPath[0].Path))
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPaths[0].Path))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
}
Expand Down
35 changes: 14 additions & 21 deletions pkg/types/tuf/v0.0.1/entry.go
Expand Up @@ -334,31 +334,24 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types
rootBytes := props.PublicKeyBytes
re.TufObj.Root = &models.TUFV001SchemaRoot{}
if len(rootBytes) == 0 {
if len(props.PublicKeyPath) == 0 {
return nil, errors.New("path to root file must be specified")
}
if len(props.PublicKeyPath) > 1 {
if len(props.PublicKeyPaths) != 1 {
return nil, errors.New("only one path to root file must be specified")
}
if len(props.PublicKeyPath) == 1 {
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPath[0].Path))
if err != nil {
return nil, fmt.Errorf("error reading root file: %w", err)
}
rootBytes = append(rootBytes, keyBytes)
}
s := &data.Signed{}
if err := json.Unmarshal(rootBytes[0], s); err != nil {
return nil, err
}
re.TufObj.Root.Content = s
} else {
s := &data.Signed{}
if err := json.Unmarshal(rootBytes[0], s); err != nil {
return nil, err
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPaths[0].Path))
if err != nil {
return nil, fmt.Errorf("error reading root file: %w", err)
}
re.TufObj.Root.Content = s
rootBytes = append(rootBytes, keyBytes)

} else if len(rootBytes) != 1 {
return nil, errors.New("only one root key byte must be provided")
}

root := &data.Signed{}
if err := json.Unmarshal(rootBytes[0], root); err != nil {
return nil, err
}
re.TufObj.Root.Content = root

if err := re.Validate(); err != nil {
return nil, err
Expand Down

0 comments on commit 1794b90

Please sign in to comment.