Skip to content

Commit

Permalink
Merge pull request #61 from ThalesIgnite/fix-min-sessions
Browse files Browse the repository at this point in the history
Return error if MaxSessions=1
  • Loading branch information
Duncan Jones authored Oct 24, 2019
2 parents 3d83a0a + 698cdbd commit c6ebc96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crypto11.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ type Config struct {
Pin string

// Maximum number of concurrent sessions to open. If zero, DefaultMaxSessions is used.
// Otherwise, the value specified must be at least 2.
MaxSessions int

// Maximum time to wait for a session from the sessions pool. Zero means wait indefinitely.
Expand Down Expand Up @@ -277,6 +278,9 @@ func Configure(config *Config) (*Context, error) {
if config.MaxSessions == 0 {
config.MaxSessions = DefaultMaxSessions
}
if config.MaxSessions == 1 {
return nil, errors.New("MaxSessions must be larger than 1")
}

instance := &Context{
cfg: config,
Expand Down
9 changes: 9 additions & 0 deletions crypto11_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ func TestNoLogin(t *testing.T) {
assert.Equal(t, pkcs11.Error(pkcs11.CKR_USER_NOT_LOGGED_IN), p11Err)
}

func TestInvalidMaxSessions(t *testing.T) {
cfg, err := getConfig("config")
require.NoError(t, err)

cfg.MaxSessions = 1
_, err = Configure(cfg)
require.Error(t, err)
}

// randomBytes returns 32 random bytes.
func randomBytes() []byte {
result := make([]byte, 32)
Expand Down

0 comments on commit c6ebc96

Please sign in to comment.