Upgrade to latest version of golang-jwt (as forked for 1.14) (#16607)
* Forcibly update the vendored versions using a replace Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
3107c9dfc3
commit
7760a7f385
13 changed files with 349 additions and 86 deletions
2
go.mod
2
go.mod
|
@ -153,3 +153,5 @@ require (
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/hashicorp/go-version => github.com/6543/go-version v1.2.4
|
replace github.com/hashicorp/go-version => github.com/6543/go-version v1.2.4
|
||||||
|
|
||||||
|
replace github.com/golang-jwt/jwt v3.2.1+incompatible => github.com/zeripath/jwt v3.2.2-go1.14+incompatible
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -495,8 +495,6 @@ github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 h1:yXtpJr/LV6PFu4nTLgfjQ
|
||||||
github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14/go.mod h1:jPoNZLWDAqA5N3G5amEoiNbhVrmM+ZQEcnQvNQ2KaZk=
|
github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14/go.mod h1:jPoNZLWDAqA5N3G5amEoiNbhVrmM+ZQEcnQvNQ2KaZk=
|
||||||
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85 h1:UjoPNDAQ5JPCjlxoJd6K8ALZqSDDhk2ymieAZOVaDg0=
|
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85 h1:UjoPNDAQ5JPCjlxoJd6K8ALZqSDDhk2ymieAZOVaDg0=
|
||||||
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85/go.mod h1:fR6z1Ie6rtF7kl/vBYMfgD5/G5B1blui7z426/sj2DU=
|
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85/go.mod h1:fR6z1Ie6rtF7kl/vBYMfgD5/G5B1blui7z426/sj2DU=
|
||||||
github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c=
|
|
||||||
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
|
||||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
|
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
|
||||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
|
@ -1154,6 +1152,8 @@ github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691/go.mod
|
||||||
github.com/yuin/goldmark-meta v1.0.0 h1:ScsatUIT2gFS6azqzLGUjgOnELsBOxMXerM3ogdJhAM=
|
github.com/yuin/goldmark-meta v1.0.0 h1:ScsatUIT2gFS6azqzLGUjgOnELsBOxMXerM3ogdJhAM=
|
||||||
github.com/yuin/goldmark-meta v1.0.0/go.mod h1:zsNNOrZ4nLuyHAJeLQEZcQat8dm70SmB2kHbls092Gc=
|
github.com/yuin/goldmark-meta v1.0.0/go.mod h1:zsNNOrZ4nLuyHAJeLQEZcQat8dm70SmB2kHbls092Gc=
|
||||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||||
|
github.com/zeripath/jwt v3.2.2-go1.14+incompatible h1:jqxA3KuCQRLn0lHdt1G8t1EUJ92FmRUFnXHghVvJLJs=
|
||||||
|
github.com/zeripath/jwt v3.2.2-go1.14+incompatible/go.mod h1:pYPrRXN84mQC6u5c/08icdKllASIBEOurvsTPbDurLs=
|
||||||
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
|
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
|
||||||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||||
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||||
|
|
11
vendor/github.com/golang-jwt/jwt/.travis.yml
generated
vendored
11
vendor/github.com/golang-jwt/jwt/.travis.yml
generated
vendored
|
@ -1,11 +0,0 @@
|
||||||
language: go
|
|
||||||
|
|
||||||
script:
|
|
||||||
- go vet ./...
|
|
||||||
- go test -v ./...
|
|
||||||
|
|
||||||
go:
|
|
||||||
- 1.7
|
|
||||||
- 1.8
|
|
||||||
- 1.9
|
|
||||||
- 1.10
|
|
9
vendor/github.com/golang-jwt/jwt/README.md
generated
vendored
9
vendor/github.com/golang-jwt/jwt/README.md
generated
vendored
|
@ -9,10 +9,17 @@ A [go](http://www.golang.org) (or 'golang' for search engine friendliness) imple
|
||||||
|
|
||||||
Future releases will be using the `github.com/golang-jwt/jwt` import path and continue the existing versioning scheme of `v3.x.x+incompatible`. Backwards-compatible patches and fixes will be done on the `v3` release branch, where as new build-breaking features will be developed in a `v4` release, possibly including a SIV-style import path.
|
Future releases will be using the `github.com/golang-jwt/jwt` import path and continue the existing versioning scheme of `v3.x.x+incompatible`. Backwards-compatible patches and fixes will be done on the `v3` release branch, where as new build-breaking features will be developed in a `v4` release, possibly including a SIV-style import path.
|
||||||
|
|
||||||
**SECURITY NOTICE:** Some older versions of Go have a security issue in the crypto/elliptic. Recommendation is to upgrade to at least 1.8.3. See issue [dgrijalva/jwt-go#216](https://github.com/dgrijalva/jwt-go/issues/216) for more detail.
|
**SECURITY NOTICE:** Some older versions of Go have a security issue in the crypto/elliptic. Recommendation is to upgrade to at least 1.15 See issue [dgrijalva/jwt-go#216](https://github.com/dgrijalva/jwt-go/issues/216) for more detail.
|
||||||
|
|
||||||
**SECURITY NOTICE:** It's important that you [validate the `alg` presented is what you expect](https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/). This library attempts to make it easy to do the right thing by requiring key types match the expected alg, but you should take the extra step to verify it in your usage. See the examples provided.
|
**SECURITY NOTICE:** It's important that you [validate the `alg` presented is what you expect](https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/). This library attempts to make it easy to do the right thing by requiring key types match the expected alg, but you should take the extra step to verify it in your usage. See the examples provided.
|
||||||
|
|
||||||
|
### Supported Go versions
|
||||||
|
|
||||||
|
Our support of Go versions is aligned with Go's [version release policy](https://golang.org/doc/devel/release#policy).
|
||||||
|
So we will support a major version of Go until there are two newer major releases.
|
||||||
|
We no longer support building jwt-go with unsupported Go versions, as these contain security vulnerabilities
|
||||||
|
which will not be fixed.
|
||||||
|
|
||||||
## What the heck is a JWT?
|
## What the heck is a JWT?
|
||||||
|
|
||||||
JWT.io has [a great introduction](https://jwt.io/introduction) to JSON Web Tokens.
|
JWT.io has [a great introduction](https://jwt.io/introduction) to JSON Web Tokens.
|
||||||
|
|
12
vendor/github.com/golang-jwt/jwt/VERSION_HISTORY.md
generated
vendored
12
vendor/github.com/golang-jwt/jwt/VERSION_HISTORY.md
generated
vendored
|
@ -1,5 +1,17 @@
|
||||||
## `jwt-go` Version History
|
## `jwt-go` Version History
|
||||||
|
|
||||||
|
|
||||||
|
#### 3.2.2-go1.14
|
||||||
|
|
||||||
|
Whilst go1.14 is not officially supported upstream anymore there are a few projects which require go1.14 compilation support. This forked release simply contains a workaround for go1.14.
|
||||||
|
|
||||||
|
#### 3.2.2
|
||||||
|
|
||||||
|
* Starting from this release, we are adopting the policy to support the most 2 recent versions of Go currently available. By the time of this release, this is Go 1.15 and 1.16 ([#28](https://github.com/golang-jwt/jwt/pull/28)).
|
||||||
|
* Fixed a potential issue that could occur when the verification of `exp`, `iat` or `nbf` was not required and contained invalid contents, i.e. non-numeric/date. Thanks for @thaJeztah for making us aware of that and @giorgos-f3 for originally reporting it to the formtech fork ([#40](https://github.com/golang-jwt/jwt/pull/40)).
|
||||||
|
* Added support for EdDSA / ED25519 ([#36](https://github.com/golang-jwt/jwt/pull/36)).
|
||||||
|
* Optimized allocations ([#33](https://github.com/golang-jwt/jwt/pull/33)).
|
||||||
|
|
||||||
#### 3.2.1
|
#### 3.2.1
|
||||||
|
|
||||||
* **Import Path Change**: See MIGRATION_GUIDE.md for tips on updating your code
|
* **Import Path Change**: See MIGRATION_GUIDE.md for tips on updating your code
|
||||||
|
|
53
vendor/github.com/golang-jwt/jwt/ecdsa.go
generated
vendored
53
vendor/github.com/golang-jwt/jwt/ecdsa.go
generated
vendored
|
@ -3,7 +3,6 @@ package jwt
|
||||||
import (
|
import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"crypto/rand"
|
|
||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
)
|
)
|
||||||
|
@ -94,55 +93,3 @@ func (m *SigningMethodECDSA) Verify(signingString, signature string, key interfa
|
||||||
|
|
||||||
return ErrECDSAVerification
|
return ErrECDSAVerification
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements the Sign method from SigningMethod
|
|
||||||
// For this signing method, key must be an ecdsa.PrivateKey struct
|
|
||||||
func (m *SigningMethodECDSA) Sign(signingString string, key interface{}) (string, error) {
|
|
||||||
// Get the key
|
|
||||||
var ecdsaKey *ecdsa.PrivateKey
|
|
||||||
switch k := key.(type) {
|
|
||||||
case *ecdsa.PrivateKey:
|
|
||||||
ecdsaKey = k
|
|
||||||
default:
|
|
||||||
return "", ErrInvalidKeyType
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the hasher
|
|
||||||
if !m.Hash.Available() {
|
|
||||||
return "", ErrHashUnavailable
|
|
||||||
}
|
|
||||||
|
|
||||||
hasher := m.Hash.New()
|
|
||||||
hasher.Write([]byte(signingString))
|
|
||||||
|
|
||||||
// Sign the string and return r, s
|
|
||||||
if r, s, err := ecdsa.Sign(rand.Reader, ecdsaKey, hasher.Sum(nil)); err == nil {
|
|
||||||
curveBits := ecdsaKey.Curve.Params().BitSize
|
|
||||||
|
|
||||||
if m.CurveBits != curveBits {
|
|
||||||
return "", ErrInvalidKey
|
|
||||||
}
|
|
||||||
|
|
||||||
keyBytes := curveBits / 8
|
|
||||||
if curveBits%8 > 0 {
|
|
||||||
keyBytes += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// We serialize the outpus (r and s) into big-endian byte arrays and pad
|
|
||||||
// them with zeros on the left to make sure the sizes work out. Both arrays
|
|
||||||
// must be keyBytes long, and the output must be 2*keyBytes long.
|
|
||||||
rBytes := r.Bytes()
|
|
||||||
rBytesPadded := make([]byte, keyBytes)
|
|
||||||
copy(rBytesPadded[keyBytes-len(rBytes):], rBytes)
|
|
||||||
|
|
||||||
sBytes := s.Bytes()
|
|
||||||
sBytesPadded := make([]byte, keyBytes)
|
|
||||||
copy(sBytesPadded[keyBytes-len(sBytes):], sBytes)
|
|
||||||
|
|
||||||
out := append(rBytesPadded, sBytesPadded...)
|
|
||||||
|
|
||||||
return EncodeSegment(out), nil
|
|
||||||
} else {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
99
vendor/github.com/golang-jwt/jwt/ecdsa_go1.14.go
generated
vendored
Normal file
99
vendor/github.com/golang-jwt/jwt/ecdsa_go1.14.go
generated
vendored
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
//+build !go1.15
|
||||||
|
|
||||||
|
package jwt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/ecdsa"
|
||||||
|
"crypto/rand"
|
||||||
|
"math/big"
|
||||||
|
"math/bits"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Implements the Sign method from SigningMethod
|
||||||
|
// For this signing method, key must be an ecdsa.PrivateKey struct
|
||||||
|
func (m *SigningMethodECDSA) Sign(signingString string, key interface{}) (string, error) {
|
||||||
|
// Get the key
|
||||||
|
var ecdsaKey *ecdsa.PrivateKey
|
||||||
|
switch k := key.(type) {
|
||||||
|
case *ecdsa.PrivateKey:
|
||||||
|
ecdsaKey = k
|
||||||
|
default:
|
||||||
|
return "", ErrInvalidKeyType
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the hasher
|
||||||
|
if !m.Hash.Available() {
|
||||||
|
return "", ErrHashUnavailable
|
||||||
|
}
|
||||||
|
|
||||||
|
hasher := m.Hash.New()
|
||||||
|
hasher.Write([]byte(signingString))
|
||||||
|
|
||||||
|
// Sign the string and return r, s
|
||||||
|
if r, s, err := ecdsa.Sign(rand.Reader, ecdsaKey, hasher.Sum(nil)); err == nil {
|
||||||
|
curveBits := ecdsaKey.Curve.Params().BitSize
|
||||||
|
|
||||||
|
if m.CurveBits != curveBits {
|
||||||
|
return "", ErrInvalidKey
|
||||||
|
}
|
||||||
|
|
||||||
|
keyBytes := curveBits / 8
|
||||||
|
if curveBits%8 > 0 {
|
||||||
|
keyBytes += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// We serialize the outputs (r and s) into big-endian byte arrays
|
||||||
|
// padded with zeros on the left to make sure the sizes work out.
|
||||||
|
// Output must be 2*keyBytes long.
|
||||||
|
out := make([]byte, 2*keyBytes)
|
||||||
|
fillBytesInt(r, out[0:keyBytes]) // r is assigned to the first half of output.
|
||||||
|
fillBytesInt(s, out[keyBytes:]) // s is assigned to the second half of output.
|
||||||
|
|
||||||
|
return EncodeSegment(out), nil
|
||||||
|
} else {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fillBytesInt(x *big.Int, buf []byte) []byte {
|
||||||
|
// Clear whole buffer. (This gets optimized into a memclr.)
|
||||||
|
for i := range buf {
|
||||||
|
buf[i] = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// This code is deeply inspired by go's own implementation but rewritten.
|
||||||
|
|
||||||
|
// Although this function is called bits it returns words
|
||||||
|
words := x.Bits()
|
||||||
|
|
||||||
|
// Words are uints as per the definition of bits.Word and thus there are usually (64) /8 bytes per word
|
||||||
|
bytesPerWord := bits.UintSize / 8
|
||||||
|
|
||||||
|
// If our buffer is longer than the expected number of words start mid-way
|
||||||
|
pos := len(buf) - len(words)*bytesPerWord
|
||||||
|
|
||||||
|
// Now iterate across the words (backwards)
|
||||||
|
for i := range words {
|
||||||
|
// Grab the last word (Which is the biggest number)
|
||||||
|
word := words[len(words)-1-i]
|
||||||
|
|
||||||
|
// Now for each byte in the word
|
||||||
|
// [abcd...] we want buf[0] = a, buf[1] = b ...
|
||||||
|
|
||||||
|
for j := bytesPerWord; j > 0; j-- {
|
||||||
|
d := byte(word)
|
||||||
|
// if our position is less than 0 then panic
|
||||||
|
if pos+j-1 >= 0 {
|
||||||
|
// set the value of the byte to the byte
|
||||||
|
buf[pos+j-1] = d
|
||||||
|
} else if d != 0 {
|
||||||
|
panic("math/big: buffer too small to fit value") // have to use the same panic string for complete compatibility
|
||||||
|
}
|
||||||
|
// shift the word 8 bits and reloop.
|
||||||
|
word >>= 8
|
||||||
|
}
|
||||||
|
pos += bytesPerWord
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf
|
||||||
|
}
|
54
vendor/github.com/golang-jwt/jwt/ecdsa_go1.15.go
generated
vendored
Normal file
54
vendor/github.com/golang-jwt/jwt/ecdsa_go1.15.go
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
//+build go1.15
|
||||||
|
|
||||||
|
package jwt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/ecdsa"
|
||||||
|
"crypto/rand"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Implements the Sign method from SigningMethod
|
||||||
|
// For this signing method, key must be an ecdsa.PrivateKey struct
|
||||||
|
func (m *SigningMethodECDSA) Sign(signingString string, key interface{}) (string, error) {
|
||||||
|
// Get the key
|
||||||
|
var ecdsaKey *ecdsa.PrivateKey
|
||||||
|
switch k := key.(type) {
|
||||||
|
case *ecdsa.PrivateKey:
|
||||||
|
ecdsaKey = k
|
||||||
|
default:
|
||||||
|
return "", ErrInvalidKeyType
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the hasher
|
||||||
|
if !m.Hash.Available() {
|
||||||
|
return "", ErrHashUnavailable
|
||||||
|
}
|
||||||
|
|
||||||
|
hasher := m.Hash.New()
|
||||||
|
hasher.Write([]byte(signingString))
|
||||||
|
|
||||||
|
// Sign the string and return r, s
|
||||||
|
if r, s, err := ecdsa.Sign(rand.Reader, ecdsaKey, hasher.Sum(nil)); err == nil {
|
||||||
|
curveBits := ecdsaKey.Curve.Params().BitSize
|
||||||
|
|
||||||
|
if m.CurveBits != curveBits {
|
||||||
|
return "", ErrInvalidKey
|
||||||
|
}
|
||||||
|
|
||||||
|
keyBytes := curveBits / 8
|
||||||
|
if curveBits%8 > 0 {
|
||||||
|
keyBytes += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// We serialize the outputs (r and s) into big-endian byte arrays
|
||||||
|
// padded with zeros on the left to make sure the sizes work out.
|
||||||
|
// Output must be 2*keyBytes long.
|
||||||
|
out := make([]byte, 2*keyBytes)
|
||||||
|
r.FillBytes(out[0:keyBytes]) // r is assigned to the first half of output.
|
||||||
|
s.FillBytes(out[keyBytes:]) // s is assigned to the second half of output.
|
||||||
|
|
||||||
|
return EncodeSegment(out), nil
|
||||||
|
} else {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
81
vendor/github.com/golang-jwt/jwt/ed25519.go
generated
vendored
Normal file
81
vendor/github.com/golang-jwt/jwt/ed25519.go
generated
vendored
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
package jwt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"crypto/ed25519"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrEd25519Verification = errors.New("ed25519: verification error")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Implements the EdDSA family
|
||||||
|
// Expects ed25519.PrivateKey for signing and ed25519.PublicKey for verification
|
||||||
|
type SigningMethodEd25519 struct{}
|
||||||
|
|
||||||
|
// Specific instance for EdDSA
|
||||||
|
var (
|
||||||
|
SigningMethodEdDSA *SigningMethodEd25519
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
SigningMethodEdDSA = &SigningMethodEd25519{}
|
||||||
|
RegisterSigningMethod(SigningMethodEdDSA.Alg(), func() SigningMethod {
|
||||||
|
return SigningMethodEdDSA
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SigningMethodEd25519) Alg() string {
|
||||||
|
return "EdDSA"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements the Verify method from SigningMethod
|
||||||
|
// For this verify method, key must be an ed25519.PublicKey
|
||||||
|
func (m *SigningMethodEd25519) Verify(signingString, signature string, key interface{}) error {
|
||||||
|
var err error
|
||||||
|
var ed25519Key ed25519.PublicKey
|
||||||
|
var ok bool
|
||||||
|
|
||||||
|
if ed25519Key, ok = key.(ed25519.PublicKey); !ok {
|
||||||
|
return ErrInvalidKeyType
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ed25519Key) != ed25519.PublicKeySize {
|
||||||
|
return ErrInvalidKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode the signature
|
||||||
|
var sig []byte
|
||||||
|
if sig, err = DecodeSegment(signature); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the signature
|
||||||
|
if !ed25519.Verify(ed25519Key, []byte(signingString), sig) {
|
||||||
|
return ErrEd25519Verification
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements the Sign method from SigningMethod
|
||||||
|
// For this signing method, key must be an ed25519.PrivateKey
|
||||||
|
func (m *SigningMethodEd25519) Sign(signingString string, key interface{}) (string, error) {
|
||||||
|
var ed25519Key ed25519.PrivateKey
|
||||||
|
var ok bool
|
||||||
|
|
||||||
|
if ed25519Key, ok = key.(ed25519.PrivateKey); !ok {
|
||||||
|
return "", ErrInvalidKeyType
|
||||||
|
}
|
||||||
|
|
||||||
|
// ed25519.Sign panics if private key not equal to ed25519.PrivateKeySize
|
||||||
|
// this allows to avoid recover usage
|
||||||
|
if len(ed25519Key) != ed25519.PrivateKeySize {
|
||||||
|
return "", ErrInvalidKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sign the string and return the encoded result
|
||||||
|
sig := ed25519.Sign(ed25519Key, []byte(signingString))
|
||||||
|
return EncodeSegment(sig), nil
|
||||||
|
}
|
64
vendor/github.com/golang-jwt/jwt/ed25519_utils.go
generated
vendored
Normal file
64
vendor/github.com/golang-jwt/jwt/ed25519_utils.go
generated
vendored
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
package jwt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto"
|
||||||
|
"crypto/ed25519"
|
||||||
|
"crypto/x509"
|
||||||
|
"encoding/pem"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNotEdPrivateKey = errors.New("Key is not a valid Ed25519 private key")
|
||||||
|
ErrNotEdPublicKey = errors.New("Key is not a valid Ed25519 public key")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Parse PEM-encoded Edwards curve private key
|
||||||
|
func ParseEdPrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// Parse PEM block
|
||||||
|
var block *pem.Block
|
||||||
|
if block, _ = pem.Decode(key); block == nil {
|
||||||
|
return nil, ErrKeyMustBePEMEncoded
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the key
|
||||||
|
var parsedKey interface{}
|
||||||
|
if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var pkey ed25519.PrivateKey
|
||||||
|
var ok bool
|
||||||
|
if pkey, ok = parsedKey.(ed25519.PrivateKey); !ok {
|
||||||
|
return nil, ErrNotEdPrivateKey
|
||||||
|
}
|
||||||
|
|
||||||
|
return pkey, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse PEM-encoded Edwards curve public key
|
||||||
|
func ParseEdPublicKeyFromPEM(key []byte) (crypto.PublicKey, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// Parse PEM block
|
||||||
|
var block *pem.Block
|
||||||
|
if block, _ = pem.Decode(key); block == nil {
|
||||||
|
return nil, ErrKeyMustBePEMEncoded
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the key
|
||||||
|
var parsedKey interface{}
|
||||||
|
if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var pkey ed25519.PublicKey
|
||||||
|
var ok bool
|
||||||
|
if pkey, ok = parsedKey.(ed25519.PublicKey); !ok {
|
||||||
|
return nil, ErrNotEdPublicKey
|
||||||
|
}
|
||||||
|
|
||||||
|
return pkey, nil
|
||||||
|
}
|
36
vendor/github.com/golang-jwt/jwt/map_claims.go
generated
vendored
36
vendor/github.com/golang-jwt/jwt/map_claims.go
generated
vendored
|
@ -34,27 +34,35 @@ func (m MapClaims) VerifyAudience(cmp string, req bool) bool {
|
||||||
// Compares the exp claim against cmp.
|
// Compares the exp claim against cmp.
|
||||||
// If required is false, this method will return true if the value matches or is unset
|
// If required is false, this method will return true if the value matches or is unset
|
||||||
func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool {
|
func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool {
|
||||||
switch exp := m["exp"].(type) {
|
exp, ok := m["exp"]
|
||||||
|
if !ok {
|
||||||
|
return !req
|
||||||
|
}
|
||||||
|
switch expType := exp.(type) {
|
||||||
case float64:
|
case float64:
|
||||||
return verifyExp(int64(exp), cmp, req)
|
return verifyExp(int64(expType), cmp, req)
|
||||||
case json.Number:
|
case json.Number:
|
||||||
v, _ := exp.Int64()
|
v, _ := expType.Int64()
|
||||||
return verifyExp(v, cmp, req)
|
return verifyExp(v, cmp, req)
|
||||||
}
|
}
|
||||||
return !req
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compares the iat claim against cmp.
|
// Compares the iat claim against cmp.
|
||||||
// If required is false, this method will return true if the value matches or is unset
|
// If required is false, this method will return true if the value matches or is unset
|
||||||
func (m MapClaims) VerifyIssuedAt(cmp int64, req bool) bool {
|
func (m MapClaims) VerifyIssuedAt(cmp int64, req bool) bool {
|
||||||
switch iat := m["iat"].(type) {
|
iat, ok := m["iat"]
|
||||||
|
if !ok {
|
||||||
|
return !req
|
||||||
|
}
|
||||||
|
switch iatType := iat.(type) {
|
||||||
case float64:
|
case float64:
|
||||||
return verifyIat(int64(iat), cmp, req)
|
return verifyIat(int64(iatType), cmp, req)
|
||||||
case json.Number:
|
case json.Number:
|
||||||
v, _ := iat.Int64()
|
v, _ := iatType.Int64()
|
||||||
return verifyIat(v, cmp, req)
|
return verifyIat(v, cmp, req)
|
||||||
}
|
}
|
||||||
return !req
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compares the iss claim against cmp.
|
// Compares the iss claim against cmp.
|
||||||
|
@ -67,14 +75,18 @@ func (m MapClaims) VerifyIssuer(cmp string, req bool) bool {
|
||||||
// Compares the nbf claim against cmp.
|
// Compares the nbf claim against cmp.
|
||||||
// If required is false, this method will return true if the value matches or is unset
|
// If required is false, this method will return true if the value matches or is unset
|
||||||
func (m MapClaims) VerifyNotBefore(cmp int64, req bool) bool {
|
func (m MapClaims) VerifyNotBefore(cmp int64, req bool) bool {
|
||||||
switch nbf := m["nbf"].(type) {
|
nbf, ok := m["nbf"]
|
||||||
|
if !ok {
|
||||||
|
return !req
|
||||||
|
}
|
||||||
|
switch nbfType := nbf.(type) {
|
||||||
case float64:
|
case float64:
|
||||||
return verifyNbf(int64(nbf), cmp, req)
|
return verifyNbf(int64(nbfType), cmp, req)
|
||||||
case json.Number:
|
case json.Number:
|
||||||
v, _ := nbf.Int64()
|
v, _ := nbfType.Int64()
|
||||||
return verifyNbf(v, cmp, req)
|
return verifyNbf(v, cmp, req)
|
||||||
}
|
}
|
||||||
return !req
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validates time based claims "exp, iat, nbf".
|
// Validates time based claims "exp, iat, nbf".
|
||||||
|
|
8
vendor/github.com/golang-jwt/jwt/token.go
generated
vendored
8
vendor/github.com/golang-jwt/jwt/token.go
generated
vendored
|
@ -95,14 +95,10 @@ func ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token
|
||||||
|
|
||||||
// Encode JWT specific base64url encoding with padding stripped
|
// Encode JWT specific base64url encoding with padding stripped
|
||||||
func EncodeSegment(seg []byte) string {
|
func EncodeSegment(seg []byte) string {
|
||||||
return strings.TrimRight(base64.URLEncoding.EncodeToString(seg), "=")
|
return base64.RawURLEncoding.EncodeToString(seg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode JWT specific base64url encoding with padding stripped
|
// Decode JWT specific base64url encoding with padding stripped
|
||||||
func DecodeSegment(seg string) ([]byte, error) {
|
func DecodeSegment(seg string) ([]byte, error) {
|
||||||
if l := len(seg) % 4; l > 0 {
|
return base64.RawURLEncoding.DecodeString(seg)
|
||||||
seg += strings.Repeat("=", 4-l)
|
|
||||||
}
|
|
||||||
|
|
||||||
return base64.URLEncoding.DecodeString(seg)
|
|
||||||
}
|
}
|
||||||
|
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
@ -407,7 +407,7 @@ github.com/gogs/cron
|
||||||
# github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
|
# github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
|
||||||
## explicit
|
## explicit
|
||||||
github.com/gogs/go-gogs-client
|
github.com/gogs/go-gogs-client
|
||||||
# github.com/golang-jwt/jwt v3.2.1+incompatible
|
# github.com/golang-jwt/jwt v3.2.1+incompatible => github.com/zeripath/jwt v3.2.2-go1.14+incompatible
|
||||||
## explicit
|
## explicit
|
||||||
github.com/golang-jwt/jwt
|
github.com/golang-jwt/jwt
|
||||||
# github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe
|
# github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe
|
||||||
|
|
Reference in a new issue