Skip to content

Commit

Permalink
tkn20: prevent panics on key gen errors
Browse files Browse the repository at this point in the history
Both SystemSecretKey.KeyGen and Setup try to dereference the return
values from abe/cpabe/tkn20/internal/tkn without checking for an error.
On error, these values are nil and the functions panic.

This is easy to reproduce by passing an io.Reader that returns an error.
  • Loading branch information
tmthrgd authored and bwesterb committed Mar 6, 2023
1 parent 9aa87e4 commit 547dd87
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions abe/cpabe/tkn20/tkn20.go
Expand Up @@ -62,7 +62,10 @@ func (msk *SystemSecretKey) KeyGen(rand io.Reader, attrs Attributes) (AttributeK
rand = cryptoRand.Reader
}
sk, err := tkn.DeriveAttributeKeysCCA(rand, &msk.sp, &attrs.attrs)
return AttributeKey{*sk}, err
if err != nil {
return AttributeKey{}, err
}
return AttributeKey{*sk}, nil
}

type AttributeKey struct {
Expand Down Expand Up @@ -150,5 +153,8 @@ func Setup(rand io.Reader) (PublicKey, SystemSecretKey, error) {
rand = cryptoRand.Reader
}
pp, sp, err := tkn.GenerateParams(rand)
return PublicKey{*pp}, SystemSecretKey{*sp}, err
if err != nil {
return PublicKey{}, SystemSecretKey{}, err
}
return PublicKey{*pp}, SystemSecretKey{*sp}, nil
}

0 comments on commit 547dd87

Please sign in to comment.