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

topdown/tokens: protect against nistec panics #5214

Merged
merged 3 commits into from Oct 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions topdown/tokens.go
Expand Up @@ -254,7 +254,12 @@ func builtinJWTVerifyES512(bctx BuiltinContext, args []*ast.Term, iter func(*ast
return err
}

func verifyES(publicKey interface{}, digest []byte, signature []byte) error {
func verifyES(publicKey interface{}, digest []byte, signature []byte) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("ECDSA signature verification error: %v", r)
}
}()
publicKeyEcdsa, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
return fmt.Errorf("incorrect public key type")
Expand Down Expand Up @@ -783,7 +788,12 @@ func verifyRSAPSS(key interface{}, hash crypto.Hash, digest []byte, signature []
return nil
}

func verifyECDSA(key interface{}, hash crypto.Hash, digest []byte, signature []byte) error {
func verifyECDSA(key interface{}, hash crypto.Hash, digest []byte, signature []byte) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("ECDSA signature verification error: %v", r)
}
}()
publicKeyEcdsa, ok := key.(*ecdsa.PublicKey)
if !ok {
return fmt.Errorf("incorrect public key type")
Expand Down