Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
810825e
Parse PKCS1 or PKCS8 public key
twocs Nov 6, 2021
38ebe4b
Add test for parsing PKCS1 Public Key
Nov 6, 2021
6296976
Parsing PKCS1 Public Key
Nov 6, 2021
327371d
Ensure passing unit tests
Nov 6, 2021
a8b39b0
Revert Encoding/Decoding changes for better compatibility (#117)
ajermaky Nov 6, 2021
d2c1236
Allow `none` algorithm in jwt command (#121)
AlexanderYastrebov Nov 10, 2021
7cda0ca
Unwrap for ValidationError (#125)
kdeberk Nov 15, 2021
1680a87
cmd: list supported algorithms (-alg flag) (#123)
AlexanderYastrebov Nov 16, 2021
0d1fcaa
#129: Added VerifyIssuer method to RegisteredClaims (#130)
tfonfara Nov 24, 2021
682e394
use errors.Is for extractor errors (#141)
stefantds Dec 15, 2021
e8aec33
Implementing `Is(err) bool` to support Go 1.13 style error checking (…
oxisto Jan 19, 2022
8f8aa33
remove unnecessary for loop in token signing string for readability (…
hyeonjae Feb 3, 2022
112e1d4
updated README.md to contain more extensions (#155)
Feb 3, 2022
ab7eab6
Add JWT logo image attribution (#161)
mfridman Feb 9, 2022
661e258
fix: fixed typo detect by cSpell (#164)
giautm Feb 9, 2022
0f99f76
Set json encoding precision (#162)
mfridman Feb 10, 2022
92549f2
fix: expired token error message (#165)
ydylla Feb 15, 2022
42eb419
feat: port clockskew support (#139)
ksegun Mar 8, 2022
11636c8
Add go1.18 to ci pipeline (#173)
mfridman Mar 18, 2022
ad1bcff
Revert "feat: port clockskew support (#139)" (#184)
mfridman Mar 26, 2022
d85463c
Added MicahParks/keyfunc to extensions (#194)
oxisto Apr 18, 2022
0c8bc44
docs: update link to pkg.go.dev page (#195)
polRk Apr 19, 2022
3558b63
add installation guidelines to the README file (#204)
luigimorel May 27, 2022
0eef781
chore: replace ioutil with io and os (#198)
oxisto Mar 29, 2023
519e4fe
CI check for Go code formatting (#206)
mfridman May 28, 2022
d2de1da
Create SECURITY.md (#171)
mfridman May 28, 2022
8f40bbd
Update SECURITY.md (#207)
oxisto May 28, 2022
780e930
Fixed integer overflow in NumericDate.MarshalJSON (#200)
qqiao Jun 4, 2022
a73dea4
chore: remove unused claims in RSA table driven test (#212)
gkech Jun 4, 2022
c2a8826
fix: link update for README.md for v4 (#217)
krokite Aug 15, 2022
f677bad
Implement a BearerExtractor (#226)
WhyNotHugo Aug 19, 2022
ece1575
Bump matrix to support latest go version (go1.19) (#231)
mfridman Aug 20, 2022
8a02da3
Include https://github.com/golang-jwt/jwe in README (#229)
oxisto Aug 20, 2022
6abd521
Add doc comment to ParseWithClaims (#232)
jkopczyn Sep 26, 2022
057b27f
Removed unneeded if statement (#241)
Krout0n Oct 15, 2022
e4fcde4
No pointer embedding in the example (#255)
oxisto Nov 8, 2022
28173c8
Using `tparse` for nicer CI test display (#251)
oxisto Nov 29, 2022
bfff091
Allow strict base64 decoding (#259)
AlexanderYastrebov Dec 9, 2022
54ef79d
Added GitHub Actions Markdown (#260)
oxisto Feb 19, 2023
a02d89c
`v5` Pre-Release (#234)
oxisto Feb 21, 2023
03042d1
remove string slice and strings.join (#115)
moneszarrugh Feb 22, 2023
17b0e60
Update MIGRATION_GUIDE.md (#289)
liam-verta Mar 24, 2023
7efc1c8
Moving `DecodeSegement` to `Parser` (#278)
oxisto Mar 24, 2023
b6ef509
Adjusting the error checking example (#270)
oxisto Mar 24, 2023
1dc9063
Moved test
oxisto Mar 29, 2023
ca71027
Merge branch 'main' into patch-1
oxisto Mar 29, 2023
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
19 changes: 19 additions & 0 deletions rsa_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package jwt_test

import (
"bytes"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -115,6 +120,17 @@ func TestRSAKeyParsing(t *testing.T) {
pubKey, _ := os.ReadFile("test/sample_key.pub")
badKey := []byte("All your base are belong to key")

randomKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
t.Errorf("Failed to generate RSA private key: %v", err)
}

publicKeyBytes := x509.MarshalPKCS1PublicKey(&randomKey.PublicKey)
pkcs1Buffer := new(bytes.Buffer)
if err = pem.Encode(pkcs1Buffer, &pem.Block{Type: "RSA PUBLIC KEY", Bytes: publicKeyBytes}); err != nil {
t.Errorf("Failed to encode public pem: %v", err)
}

// Test parsePrivateKey
if _, e := jwt.ParseRSAPrivateKeyFromPEM(key); e != nil {
t.Errorf("Failed to parse valid private key: %v", e)
Expand Down Expand Up @@ -149,6 +165,9 @@ func TestRSAKeyParsing(t *testing.T) {
t.Errorf("Parsed invalid key as valid private key: %v", k)
}

if _, err := jwt.ParseRSAPublicKeyFromPEM(pkcs1Buffer.Bytes()); err != nil {
t.Errorf("failed to parse RSA public key: %v", err)
}
}

func BenchmarkRSAParsing(b *testing.B) {
Expand Down
6 changes: 4 additions & 2 deletions rsa_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.Pr
return pkey, nil
}

// ParseRSAPublicKeyFromPEM parses a PEM encoded PKCS1 or PKCS8 public key
// ParseRSAPublicKeyFromPEM parses a certificate or a PEM encoded PKCS1 or PKIX public key
func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error) {
var err error

Expand All @@ -91,7 +91,9 @@ func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error) {
if cert, err := x509.ParseCertificate(block.Bytes); err == nil {
parsedKey = cert.PublicKey
} else {
return nil, err
if parsedKey, err = x509.ParsePKCS1PublicKey(block.Bytes); err != nil {
return nil, err
}
}
}

Expand Down