Skip to content

Commit

Permalink
changed public-key to slice
Browse files Browse the repository at this point in the history
Signed-off-by: pxp928 <[email protected]>
  • Loading branch information
pxp928 committed Aug 19, 2022
1 parent a0309bc commit c2cc210
Show file tree
Hide file tree
Showing 23 changed files with 286 additions and 159 deletions.
2 changes: 1 addition & 1 deletion Makefile.swagger
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is generated after swagger runs as part of the build; do not edit!
SWAGGER_GEN=pkg/generated/client/entries/create_log_entry_parameters.go pkg/generated/client/entries/create_log_entry_responses.go pkg/generated/client/entries/entries_client.go pkg/generated/client/entries/get_log_entry_by_index_parameters.go pkg/generated/client/entries/get_log_entry_by_index_responses.go pkg/generated/client/entries/get_log_entry_by_uuid_parameters.go pkg/generated/client/entries/get_log_entry_by_uuid_responses.go pkg/generated/client/entries/search_log_query_parameters.go pkg/generated/client/entries/search_log_query_responses.go pkg/generated/client/index/index_client.go pkg/generated/client/index/search_index_parameters.go pkg/generated/client/index/search_index_responses.go pkg/generated/client/pubkey/get_public_key_parameters.go pkg/generated/client/pubkey/get_public_key_responses.go pkg/generated/client/pubkey/pubkey_client.go pkg/generated/client/rekor_client.go pkg/generated/client/server/get_rekor_version_parameters.go pkg/generated/client/server/get_rekor_version_responses.go pkg/generated/client/server/server_client.go pkg/generated/client/tlog/get_log_info_parameters.go pkg/generated/client/tlog/get_log_info_responses.go pkg/generated/client/tlog/get_log_proof_parameters.go pkg/generated/client/tlog/get_log_proof_responses.go pkg/generated/client/tlog/tlog_client.go pkg/generated/models//alpine.go pkg/generated/models//alpine_schema.go pkg/generated/models//alpine_v001_schema.go pkg/generated/models//consistency_proof.go pkg/generated/models//cose.go pkg/generated/models//cose_schema.go pkg/generated/models//cose_v001_schema.go pkg/generated/models//error.go pkg/generated/models//hashedrekord.go pkg/generated/models//hashedrekord_schema.go pkg/generated/models//hashedrekord_v001_schema.go pkg/generated/models//helm.go pkg/generated/models//helm_schema.go pkg/generated/models//helm_v001_schema.go pkg/generated/models//inactive_shard_log_info.go pkg/generated/models//inclusion_proof.go pkg/generated/models//intoto.go pkg/generated/models//intoto_schema.go pkg/generated/models//intoto_v001_schema.go pkg/generated/models//intoto_v002_schema.go pkg/generated/models//jar.go pkg/generated/models//jar_schema.go pkg/generated/models//jar_v001_schema.go pkg/generated/models//log_entry.go pkg/generated/models//log_info.go pkg/generated/models//proposed_entry.go pkg/generated/models//rekord.go pkg/generated/models//rekord_schema.go pkg/generated/models//rekord_v001_schema.go pkg/generated/models//rekor_version.go pkg/generated/models//rfc3161.go pkg/generated/models//rfc3161_schema.go pkg/generated/models//rfc3161_v001_schema.go pkg/generated/models//rpm.go pkg/generated/models//rpm_schema.go pkg/generated/models//rpm_v001_schema.go pkg/generated/models//search_index.go pkg/generated/models//search_log_query.go pkg/generated/models//tuf.go pkg/generated/models//tuf_schema.go pkg/generated/models//tuf_v001_schema.go pkg/generated/restapi//doc.go pkg/generated/restapi//embedded_spec.go pkg/generated/restapi//operations/entries/create_log_entry.go pkg/generated/restapi//operations/entries/create_log_entry_parameters.go pkg/generated/restapi//operations/entries/create_log_entry_responses.go pkg/generated/restapi//operations/entries/create_log_entry_urlbuilder.go pkg/generated/restapi//operations/entries/get_log_entry_by_index.go pkg/generated/restapi//operations/entries/get_log_entry_by_index_parameters.go pkg/generated/restapi//operations/entries/get_log_entry_by_index_responses.go pkg/generated/restapi//operations/entries/get_log_entry_by_index_urlbuilder.go pkg/generated/restapi//operations/entries/get_log_entry_by_uuid.go pkg/generated/restapi//operations/entries/get_log_entry_by_uuid_parameters.go pkg/generated/restapi//operations/entries/get_log_entry_by_uuid_responses.go pkg/generated/restapi//operations/entries/get_log_entry_by_uuid_urlbuilder.go pkg/generated/restapi//operations/entries/search_log_query.go pkg/generated/restapi//operations/entries/search_log_query_parameters.go pkg/generated/restapi//operations/entries/search_log_query_responses.go pkg/generated/restapi//operations/entries/search_log_query_urlbuilder.go pkg/generated/restapi//operations/index/search_index.go pkg/generated/restapi//operations/index/search_index_parameters.go pkg/generated/restapi//operations/index/search_index_responses.go pkg/generated/restapi//operations/index/search_index_urlbuilder.go pkg/generated/restapi//operations/pubkey/get_public_key.go pkg/generated/restapi//operations/pubkey/get_public_key_parameters.go pkg/generated/restapi//operations/pubkey/get_public_key_responses.go pkg/generated/restapi//operations/pubkey/get_public_key_urlbuilder.go pkg/generated/restapi//operations/rekor_server_api.go pkg/generated/restapi//operations/server/get_rekor_version.go pkg/generated/restapi//operations/server/get_rekor_version_parameters.go pkg/generated/restapi//operations/server/get_rekor_version_responses.go pkg/generated/restapi//operations/server/get_rekor_version_urlbuilder.go pkg/generated/restapi//operations/tlog/get_log_info.go pkg/generated/restapi//operations/tlog/get_log_info_parameters.go pkg/generated/restapi//operations/tlog/get_log_info_responses.go pkg/generated/restapi//operations/tlog/get_log_info_urlbuilder.go pkg/generated/restapi//operations/tlog/get_log_proof.go pkg/generated/restapi//operations/tlog/get_log_proof_parameters.go pkg/generated/restapi//operations/tlog/get_log_proof_responses.go pkg/generated/restapi//operations/tlog/get_log_proof_urlbuilder.go pkg/generated/restapi//server.go
SWAGGER_GEN=pkg/generated/client/entries/create_log_entry_parameters.go pkg/generated/client/entries/create_log_entry_responses.go pkg/generated/client/entries/entries_client.go pkg/generated/client/entries/get_log_entry_by_index_parameters.go pkg/generated/client/entries/get_log_entry_by_index_responses.go pkg/generated/client/entries/get_log_entry_by_uuid_parameters.go pkg/generated/client/entries/get_log_entry_by_uuid_responses.go pkg/generated/client/entries/search_log_query_parameters.go pkg/generated/client/entries/search_log_query_responses.go pkg/generated/client/index/index_client.go pkg/generated/client/index/search_index_parameters.go pkg/generated/client/index/search_index_responses.go pkg/generated/client/pubkey/get_public_key_parameters.go pkg/generated/client/pubkey/get_public_key_responses.go pkg/generated/client/pubkey/pubkey_client.go pkg/generated/client/rekor_client.go pkg/generated/client/server/get_rekor_version_parameters.go pkg/generated/client/server/get_rekor_version_responses.go pkg/generated/client/server/server_client.go pkg/generated/client/tlog/get_log_info_parameters.go pkg/generated/client/tlog/get_log_info_responses.go pkg/generated/client/tlog/get_log_proof_parameters.go pkg/generated/client/tlog/get_log_proof_responses.go pkg/generated/client/tlog/tlog_client.go pkg/generated/models/alpine.go pkg/generated/models/alpine_schema.go pkg/generated/models/alpine_v001_schema.go pkg/generated/models/consistency_proof.go pkg/generated/models/cose.go pkg/generated/models/cose_schema.go pkg/generated/models/cose_v001_schema.go pkg/generated/models/error.go pkg/generated/models/hashedrekord.go pkg/generated/models/hashedrekord_schema.go pkg/generated/models/hashedrekord_v001_schema.go pkg/generated/models/helm.go pkg/generated/models/helm_schema.go pkg/generated/models/helm_v001_schema.go pkg/generated/models/inactive_shard_log_info.go pkg/generated/models/inclusion_proof.go pkg/generated/models/intoto.go pkg/generated/models/intoto_schema.go pkg/generated/models/intoto_v001_schema.go pkg/generated/models/intoto_v002_schema.go pkg/generated/models/jar.go pkg/generated/models/jar_schema.go pkg/generated/models/jar_v001_schema.go pkg/generated/models/log_entry.go pkg/generated/models/log_info.go pkg/generated/models/proposed_entry.go pkg/generated/models/rekord.go pkg/generated/models/rekord_schema.go pkg/generated/models/rekord_v001_schema.go pkg/generated/models/rekor_version.go pkg/generated/models/rfc3161.go pkg/generated/models/rfc3161_schema.go pkg/generated/models/rfc3161_v001_schema.go pkg/generated/models/rpm.go pkg/generated/models/rpm_schema.go pkg/generated/models/rpm_v001_schema.go pkg/generated/models/search_index.go pkg/generated/models/search_log_query.go pkg/generated/models/tuf.go pkg/generated/models/tuf_schema.go pkg/generated/models/tuf_v001_schema.go pkg/generated/restapi/doc.go pkg/generated/restapi/embedded_spec.go pkg/generated/restapi/operations/entries/create_log_entry.go pkg/generated/restapi/operations/entries/create_log_entry_parameters.go pkg/generated/restapi/operations/entries/create_log_entry_responses.go pkg/generated/restapi/operations/entries/create_log_entry_urlbuilder.go pkg/generated/restapi/operations/entries/get_log_entry_by_index.go pkg/generated/restapi/operations/entries/get_log_entry_by_index_parameters.go pkg/generated/restapi/operations/entries/get_log_entry_by_index_responses.go pkg/generated/restapi/operations/entries/get_log_entry_by_index_urlbuilder.go pkg/generated/restapi/operations/entries/get_log_entry_by_uuid.go pkg/generated/restapi/operations/entries/get_log_entry_by_uuid_parameters.go pkg/generated/restapi/operations/entries/get_log_entry_by_uuid_responses.go pkg/generated/restapi/operations/entries/get_log_entry_by_uuid_urlbuilder.go pkg/generated/restapi/operations/entries/search_log_query.go pkg/generated/restapi/operations/entries/search_log_query_parameters.go pkg/generated/restapi/operations/entries/search_log_query_responses.go pkg/generated/restapi/operations/entries/search_log_query_urlbuilder.go pkg/generated/restapi/operations/index/search_index.go pkg/generated/restapi/operations/index/search_index_parameters.go pkg/generated/restapi/operations/index/search_index_responses.go pkg/generated/restapi/operations/index/search_index_urlbuilder.go pkg/generated/restapi/operations/pubkey/get_public_key.go pkg/generated/restapi/operations/pubkey/get_public_key_parameters.go pkg/generated/restapi/operations/pubkey/get_public_key_responses.go pkg/generated/restapi/operations/pubkey/get_public_key_urlbuilder.go pkg/generated/restapi/operations/rekor_server_api.go pkg/generated/restapi/operations/server/get_rekor_version.go pkg/generated/restapi/operations/server/get_rekor_version_parameters.go pkg/generated/restapi/operations/server/get_rekor_version_responses.go pkg/generated/restapi/operations/server/get_rekor_version_urlbuilder.go pkg/generated/restapi/operations/tlog/get_log_info.go pkg/generated/restapi/operations/tlog/get_log_info_parameters.go pkg/generated/restapi/operations/tlog/get_log_info_responses.go pkg/generated/restapi/operations/tlog/get_log_info_urlbuilder.go pkg/generated/restapi/operations/tlog/get_log_proof.go pkg/generated/restapi/operations/tlog/get_log_proof_parameters.go pkg/generated/restapi/operations/tlog/get_log_proof_responses.go pkg/generated/restapi/operations/tlog/get_log_proof_urlbuilder.go pkg/generated/restapi/server.go
20 changes: 3 additions & 17 deletions cmd/rekor-cli/app/pflag_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ func addArtifactPFlags(cmd *cobra.Command) error {
false,
},
"public-key": {
fileOrURLFlag,
"path or URL to public key file",
false,
},
"multi-public-key": {
multiFileOrURLFlag,
"path or URL to public key files",
"path or URL to public key file",
false,
},
"artifact": {
Expand Down Expand Up @@ -154,16 +149,7 @@ func CreatePropsFromPflags() *types.ArtifactProperties {
}

publicKeyString := viper.GetString("public-key")
if publicKeyString != "" {
if isURL(publicKeyString) {
props.PublicKeyPath, _ = url.Parse(publicKeyString)
} else {
props.PublicKeyPath = &url.URL{Path: publicKeyString}
}
}

multiPublicKeyString := viper.GetString("multi-public-key")
splitPubKeyString := strings.Split(multiPublicKeyString, ",")
splitPubKeyString := strings.Split(publicKeyString, ",")
if len(splitPubKeyString) > 0 {
collectedKeys := []*url.URL{}
for _, key := range splitPubKeyString {
Expand All @@ -174,7 +160,7 @@ func CreatePropsFromPflags() *types.ArtifactProperties {
collectedKeys = append(collectedKeys, &url.URL{Path: key})
}
}
props.MultiPublicKeyPaths = collectedKeys
props.PublicKeyPath = collectedKeys
}

props.PKIFormat = viper.GetString("pki-format")
Expand Down
12 changes: 10 additions & 2 deletions cmd/rekor-cli/app/pflags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,19 @@ func TestArtifactPFlags(t *testing.T) {
expectParseSuccess: true,
expectValidateSuccess: false,
},
{
caseDesc: "valid intoto - one keys",
typeStr: "intoto",
artifact: "../../../tests/intoto_dsse.json",
publicKey: "../../../tests/intoto_dsse.pem",
expectParseSuccess: true,
expectValidateSuccess: true,
},
{
caseDesc: "valid intoto - multi keys",
typeStr: "intoto",
artifact: "../../../tests/intoto_multi_dsse.json",
multiPublicKey: []string{"../../../tests/intoto_dsse.pem", "../../../tests/intoto_dsse.pem"},
multiPublicKey: []string{"../../../tests/intoto_dsse.pem", "../../../tests/intoto_multi_pub2.pem"},
expectParseSuccess: true,
expectValidateSuccess: true,
},
Expand Down Expand Up @@ -416,7 +424,7 @@ func TestArtifactPFlags(t *testing.T) {
}
if len(tc.multiPublicKey) > 0 {
for _, key := range tc.multiPublicKey {
args = append(args, "--multi-public-key", key)
args = append(args, "--public-key", key)
}
}
if tc.uuid != "" {
Expand Down
19 changes: 11 additions & 8 deletions cmd/rekor-cli/app/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,18 @@ var searchCmd = &cobra.Command{
default:
return nil, fmt.Errorf("unknown pki-format %v", pkiFormat)
}
publicKeyStr := viper.GetString("public-key")
if isURL(publicKeyStr) {
params.Query.PublicKey.URL = strfmt.URI(publicKeyStr)
} else {
keyBytes, err := ioutil.ReadFile(filepath.Clean(publicKeyStr))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)

splitPubKeyString := strings.Split(publicKeyStr, ",")
if len(splitPubKeyString) == 1 {
if isURL(splitPubKeyString[0]) {
params.Query.PublicKey.URL = strfmt.URI(splitPubKeyString[0])
} else {
keyBytes, err := ioutil.ReadFile(filepath.Clean(splitPubKeyString[0]))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
}
params.Query.PublicKey.Content = strfmt.Base64(keyBytes)
}
params.Query.PublicKey.Content = strfmt.Base64(keyBytes)
}
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/generated/models/intoto_v002_schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions pkg/generated/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions pkg/types/alpine/v0.0.1/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,21 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types

re.AlpineModel.PublicKey = &models.AlpineV001SchemaPublicKey{}
publicKeyBytes := props.PublicKeyBytes
if publicKeyBytes == nil {
publicKeyBytes, err = ioutil.ReadFile(filepath.Clean(props.PublicKeyPath.Path))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
if len(publicKeyBytes) == 0 {
if len(props.PublicKeyPath) > 1 {
return nil, errors.New("only one public key must be provided")
}
re.AlpineModel.PublicKey.Content = (*strfmt.Base64)(&publicKeyBytes)
if len(props.PublicKeyPath) == 1 {
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPath[0].Path))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
}
publicKeyBytes = append(publicKeyBytes, keyBytes)
re.AlpineModel.PublicKey.Content = (*strfmt.Base64)(&publicKeyBytes[0])
}

} else {
re.AlpineModel.PublicKey.Content = (*strfmt.Base64)(&publicKeyBytes)
re.AlpineModel.PublicKey.Content = (*strfmt.Base64)(&publicKeyBytes[0])
}

if err := re.validate(); err != nil {
Expand Down
18 changes: 12 additions & 6 deletions pkg/types/cose/v0.0.1/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,25 @@ func (v V001Entry) CreateFromArtifactProperties(_ context.Context, props types.A
}
}
publicKeyBytes := props.PublicKeyBytes
if publicKeyBytes == nil {
if props.PublicKeyPath == nil {
if len(publicKeyBytes) == 0 {
if len(props.PublicKeyPath) == 0 {
return nil, errors.New("public key must be provided to verify signature")
}
publicKeyBytes, err = ioutil.ReadFile(filepath.Clean(props.PublicKeyPath.Path))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
if len(props.PublicKeyPath) > 1 {
return nil, errors.New("only one public key must be provided")
}
if len(props.PublicKeyPath) == 1 {
keyBytes, err := ioutil.ReadFile(filepath.Clean(props.PublicKeyPath[0].Path))
if err != nil {
return nil, fmt.Errorf("error reading public key file: %w", err)
}
publicKeyBytes = append(publicKeyBytes, keyBytes)
}
}
if err != nil {
return nil, err
}
kb := strfmt.Base64(publicKeyBytes)
kb := strfmt.Base64(publicKeyBytes[0])
mb := strfmt.Base64(messageBytes)

re := V001Entry{
Expand Down
6 changes: 2 additions & 4 deletions pkg/types/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ type ArtifactProperties struct {
ArtifactBytes []byte
SignaturePath *url.URL
SignatureBytes []byte
PublicKeyPath *url.URL
PublicKeyBytes []byte
MultiPublicKeyBytes [][]byte
MultiPublicKeyPaths []*url.URL
PublicKeyPath []*url.URL
PublicKeyBytes [][]byte
PKIFormat string
}
Loading

0 comments on commit c2cc210

Please sign in to comment.