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

Unexpected behavior checking Public PEM key with github.com/golang-jwt/jwt package #1514

Closed
felixgomez opened this issue Feb 15, 2023 · 0 comments · Fixed by #1524
Closed
Labels
area/core bug Something isn't working
Milestone

Comments

@felixgomez
Copy link

The following program sample.go triggers an unexpected result

package main

import (
	"github.com/golang-jwt/jwt/v4"
	"log"
)

func main() {
	publicKeyPem := `
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC03uKR6amRLogLQMS7OqT+x08g
Am8X5ScmfuYD+JktiqN9TQLRB8qQaclnaj+OjNEBnmt6Ttf1xBIwSPn+lmjjxhoZ
8gS5rbks30bqasHBFSJYaMlkWunIvhef89uswbjyyYB1Qyazf+jpmfZh9KWOJp8S
pGIMWgMqdk7MMA03IwIDAQAB
-----END PUBLIC KEY-----`

	_, err := jwt.ParseRSAPublicKeyFromPEM([]byte(publicKeyPem))

	if err != nil {
		log.Printf("%v", err)
	}
}

Expected result

Empty output (public key is correct)

Got

2023/02/15 15:04:52 key is not a valid RSA public key

Yaegi Version

v0.15.0

Additional Notes

it seems that the error comes from https://github.com/golang-jwt/jwt/blob/9358574a7a1a2c8d644f22b6e8de627ba85c58d0/rsa_utils.go#L100

@mvertes mvertes added bug Something isn't working area/core labels Feb 16, 2023
traefiker pushed a commit that referenced this issue Mar 14, 2023
closes #1514

hi!
I had the same problem as #1514 and I wanted to fix it, I found
When asserting *crypto/rsa.PublicKey, using the typ attribute of node to get an nil rtype, resulting in the assertion result being nok

This code contains the same problem
```go
package main

import (
	"log"
	"crypto/rsa"
)

func main() {

    var pKey interface{} = &rsa.PublicKey{}

    if _, ok := pKey.(*rsa.PublicKey); ok {
        log.Println("ok")
    } else {
        log.Println("nok")
    }
}

```

So I submitted this Pull Request, hope it will be merged
@traefiker traefiker added this to the v0.15.x milestone Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants