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

Resolves #2685 #2853

Merged
merged 4 commits into from
Mar 31, 2023
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
6 changes: 4 additions & 2 deletions cmd/cosign/cli/options/pkcs11_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package options

import (
"github.com/sigstore/cosign/v2/pkg/cosign/env"
"github.com/spf13/cobra"
)

Expand All @@ -28,8 +29,9 @@ var _ Interface = (*PKCS11ToolListTokensOptions)(nil)

// AddFlags implements Interface
func (o *PKCS11ToolListTokensOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.ModulePath, "module-path", "",
cmd.Flags().StringVar(&o.ModulePath, "module-path", env.Getenv(env.VariablePKCS11ModulePath),
"absolute path to the PKCS11 module")
_ = cmd.Flags().SetAnnotation("module-path", cobra.BashCompFilenameExt, []string{})
}

// PKCS11ToolListKeysUrisOptions is the wrapper for `pkcs11-tool list-keys-uris` related options.
Expand All @@ -43,7 +45,7 @@ var _ Interface = (*PKCS11ToolListKeysUrisOptions)(nil)

// AddFlags implements Interface
func (o *PKCS11ToolListKeysUrisOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.ModulePath, "module-path", "",
cmd.Flags().StringVar(&o.ModulePath, "module-path", env.Getenv(env.VariablePKCS11ModulePath),
"absolute path to the PKCS11 module")
_ = cmd.Flags().SetAnnotation("module-path", cobra.BashCompFilenameExt, []string{})

Expand Down
8 changes: 7 additions & 1 deletion cmd/cosign/cli/pkcs11cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func GetKeysInfo(_ context.Context, modulePath string, slotID uint, pin string)
}

// Open a new session to the token.
session, err := ctx.OpenSession(slotID, pkcs11.CKF_SERIAL_SESSION|pkcs11.CKF_RW_SESSION)
session, err := ctx.OpenSession(slotID, pkcs11.CKF_SERIAL_SESSION)
if err != nil {
return nil, fmt.Errorf("open session: %w", err)
}
Expand Down Expand Up @@ -205,6 +205,9 @@ func GetKeysInfo(_ context.Context, modulePath string, slotID uint, pin string)
}

func ListTokensCmd(ctx context.Context, modulePath string) error {
if modulePath == "" {
return fmt.Errorf("please specify --module-path or set COSIGN_PKCS11_MODULE_PATH")
}
tokens, err := GetTokens(ctx, modulePath)
if err != nil {
return err
Expand All @@ -223,6 +226,9 @@ func ListTokensCmd(ctx context.Context, modulePath string) error {
}

func ListKeysUrisCmd(ctx context.Context, modulePath string, slotID uint, pin string) error {
if modulePath == "" {
return fmt.Errorf("please specify --module-path or set COSIGN_PKCS11_MODULE_PATH")
}
keysInfo, err := GetKeysInfo(ctx, modulePath, slotID, pin)
if err != nil {
return err
Expand Down