Bläddra i källkod

readd vendored module changes

tags/v2.2.0-rc1
Shivaram Lingamneni 4 år sedan
förälder
incheckning
31b6bfa84e

+ 4
- 0
vendor/github.com/dgrijalva/jwt-go/.gitignore Visa fil

@@ -0,0 +1,4 @@
1
+.DS_Store
2
+bin
3
+
4
+

+ 13
- 0
vendor/github.com/dgrijalva/jwt-go/.travis.yml Visa fil

@@ -0,0 +1,13 @@
1
+language: go
2
+
3
+script:
4
+    - go vet ./...
5
+    - go test -v ./...
6
+
7
+go:
8
+  - 1.3
9
+  - 1.4
10
+  - 1.5
11
+  - 1.6
12
+  - 1.7
13
+  - tip

+ 8
- 0
vendor/github.com/dgrijalva/jwt-go/LICENSE Visa fil

@@ -0,0 +1,8 @@
1
+Copyright (c) 2012 Dave Grijalva
2
+
3
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+

+ 97
- 0
vendor/github.com/dgrijalva/jwt-go/MIGRATION_GUIDE.md Visa fil

@@ -0,0 +1,97 @@
1
+## Migration Guide from v2 -> v3
2
+
3
+Version 3 adds several new, frequently requested features.  To do so, it introduces a few breaking changes.  We've worked to keep these as minimal as possible.  This guide explains the breaking changes and how you can quickly update your code.
4
+
5
+### `Token.Claims` is now an interface type
6
+
7
+The most requested feature from the 2.0 verison of this library was the ability to provide a custom type to the JSON parser for claims. This was implemented by introducing a new interface, `Claims`, to replace `map[string]interface{}`.  We also included two concrete implementations of `Claims`: `MapClaims` and `StandardClaims`.
8
+
9
+`MapClaims` is an alias for `map[string]interface{}` with built in validation behavior.  It is the default claims type when using `Parse`.  The usage is unchanged except you must type cast the claims property.
10
+
11
+The old example for parsing a token looked like this..
12
+
13
+```go
14
+	if token, err := jwt.Parse(tokenString, keyLookupFunc); err == nil {
15
+		fmt.Printf("Token for user %v expires %v", token.Claims["user"], token.Claims["exp"])
16
+	}
17
+```
18
+
19
+is now directly mapped to...
20
+
21
+```go
22
+	if token, err := jwt.Parse(tokenString, keyLookupFunc); err == nil {
23
+		claims := token.Claims.(jwt.MapClaims)
24
+		fmt.Printf("Token for user %v expires %v", claims["user"], claims["exp"])
25
+	}
26
+```
27
+
28
+`StandardClaims` is designed to be embedded in your custom type.  You can supply a custom claims type with the new `ParseWithClaims` function.  Here's an example of using a custom claims type.
29
+
30
+```go
31
+	type MyCustomClaims struct {
32
+		User string
33
+		*StandardClaims
34
+	}
35
+	
36
+	if token, err := jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, keyLookupFunc); err == nil {
37
+		claims := token.Claims.(*MyCustomClaims)
38
+		fmt.Printf("Token for user %v expires %v", claims.User, claims.StandardClaims.ExpiresAt)
39
+	}
40
+```
41
+
42
+### `ParseFromRequest` has been moved
43
+
44
+To keep this library focused on the tokens without becoming overburdened with complex request processing logic, `ParseFromRequest` and its new companion `ParseFromRequestWithClaims` have been moved to a subpackage, `request`.  The method signatues have also been augmented to receive a new argument: `Extractor`.
45
+
46
+`Extractors` do the work of picking the token string out of a request.  The interface is simple and composable.
47
+
48
+This simple parsing example:
49
+
50
+```go
51
+	if token, err := jwt.ParseFromRequest(tokenString, req, keyLookupFunc); err == nil {
52
+		fmt.Printf("Token for user %v expires %v", token.Claims["user"], token.Claims["exp"])
53
+	}
54
+```
55
+
56
+is directly mapped to:
57
+
58
+```go
59
+	if token, err := request.ParseFromRequest(req, request.OAuth2Extractor, keyLookupFunc); err == nil {
60
+		claims := token.Claims.(jwt.MapClaims)
61
+		fmt.Printf("Token for user %v expires %v", claims["user"], claims["exp"])
62
+	}
63
+```
64
+
65
+There are several concrete `Extractor` types provided for your convenience:
66
+
67
+* `HeaderExtractor` will search a list of headers until one contains content.
68
+* `ArgumentExtractor` will search a list of keys in request query and form arguments until one contains content.
69
+* `MultiExtractor` will try a list of `Extractors` in order until one returns content.
70
+* `AuthorizationHeaderExtractor` will look in the `Authorization` header for a `Bearer` token.
71
+* `OAuth2Extractor` searches the places an OAuth2 token would be specified (per the spec): `Authorization` header and `access_token` argument
72
+* `PostExtractionFilter` wraps an `Extractor`, allowing you to process the content before it's parsed.  A simple example is stripping the `Bearer ` text from a header
73
+
74
+
75
+### RSA signing methods no longer accept `[]byte` keys
76
+
77
+Due to a [critical vulnerability](https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/), we've decided the convenience of accepting `[]byte` instead of `rsa.PublicKey` or `rsa.PrivateKey` isn't worth the risk of misuse.
78
+
79
+To replace this behavior, we've added two helper methods: `ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)` and `ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)`.  These are just simple helpers for unpacking PEM encoded PKCS1 and PKCS8 keys. If your keys are encoded any other way, all you need to do is convert them to the `crypto/rsa` package's types.
80
+
81
+```go 
82
+	func keyLookupFunc(*Token) (interface{}, error) {
83
+		// Don't forget to validate the alg is what you expect:
84
+		if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
85
+			return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
86
+		}
87
+		
88
+		// Look up key 
89
+		key, err := lookupPublicKey(token.Header["kid"])
90
+		if err != nil {
91
+			return nil, err
92
+		}
93
+		
94
+		// Unpack key from PEM encoded PKCS8
95
+		return jwt.ParseRSAPublicKeyFromPEM(key)
96
+	}
97
+```

+ 100
- 0
vendor/github.com/dgrijalva/jwt-go/README.md Visa fil

@@ -0,0 +1,100 @@
1
+# jwt-go
2
+
3
+[![Build Status](https://travis-ci.org/dgrijalva/jwt-go.svg?branch=master)](https://travis-ci.org/dgrijalva/jwt-go)
4
+[![GoDoc](https://godoc.org/github.com/dgrijalva/jwt-go?status.svg)](https://godoc.org/github.com/dgrijalva/jwt-go)
5
+
6
+A [go](http://www.golang.org) (or 'golang' for search engine friendliness) implementation of [JSON Web Tokens](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html)
7
+
8
+**NEW VERSION COMING:** There have been a lot of improvements suggested since the version 3.0.0 released in 2016. I'm working now on cutting two different releases: 3.2.0 will contain any non-breaking changes or enhancements. 4.0.0 will follow shortly which will include breaking changes. See the 4.0.0 milestone to get an idea of what's coming. If you have other ideas, or would like to participate in 4.0.0, now's the time. If you depend on this library and don't want to be interrupted, I recommend you use your dependency mangement tool to pin to version 3. 
9
+
10
+**SECURITY NOTICE:** Some older versions of Go have a security issue in the cryotp/elliptic. Recommendation is to upgrade to at least 1.8.3. See issue #216 for more detail.
11
+
12
+**SECURITY NOTICE:** It's important that you [validate the `alg` presented is what you expect](https://auth0.com/blog/2015/03/31/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.
13
+
14
+## What the heck is a JWT?
15
+
16
+JWT.io has [a great introduction](https://jwt.io/introduction) to JSON Web Tokens.
17
+
18
+In short, it's a signed JSON object that does something useful (for example, authentication).  It's commonly used for `Bearer` tokens in Oauth 2.  A token is made of three parts, separated by `.`'s.  The first two parts are JSON objects, that have been [base64url](http://tools.ietf.org/html/rfc4648) encoded.  The last part is the signature, encoded the same way.
19
+
20
+The first part is called the header.  It contains the necessary information for verifying the last part, the signature.  For example, which encryption method was used for signing and what key was used.
21
+
22
+The part in the middle is the interesting bit.  It's called the Claims and contains the actual stuff you care about.  Refer to [the RFC](http://self-issued.info/docs/draft-jones-json-web-token.html) for information about reserved keys and the proper way to add your own.
23
+
24
+## What's in the box?
25
+
26
+This library supports the parsing and verification as well as the generation and signing of JWTs.  Current supported signing algorithms are HMAC SHA, RSA, RSA-PSS, and ECDSA, though hooks are present for adding your own.
27
+
28
+## Examples
29
+
30
+See [the project documentation](https://godoc.org/github.com/dgrijalva/jwt-go) for examples of usage:
31
+
32
+* [Simple example of parsing and validating a token](https://godoc.org/github.com/dgrijalva/jwt-go#example-Parse--Hmac)
33
+* [Simple example of building and signing a token](https://godoc.org/github.com/dgrijalva/jwt-go#example-New--Hmac)
34
+* [Directory of Examples](https://godoc.org/github.com/dgrijalva/jwt-go#pkg-examples)
35
+
36
+## Extensions
37
+
38
+This library publishes all the necessary components for adding your own signing methods.  Simply implement the `SigningMethod` interface and register a factory method using `RegisterSigningMethod`.  
39
+
40
+Here's an example of an extension that integrates with the Google App Engine signing tools: https://github.com/someone1/gcp-jwt-go
41
+
42
+## Compliance
43
+
44
+This library was last reviewed to comply with [RTF 7519](http://www.rfc-editor.org/info/rfc7519) dated May 2015 with a few notable differences:
45
+
46
+* In order to protect against accidental use of [Unsecured JWTs](http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#UnsecuredJWT), tokens using `alg=none` will only be accepted if the constant `jwt.UnsafeAllowNoneSignatureType` is provided as the key.
47
+
48
+## Project Status & Versioning
49
+
50
+This library is considered production ready.  Feedback and feature requests are appreciated.  The API should be considered stable.  There should be very few backwards-incompatible changes outside of major version updates (and only with good reason).
51
+
52
+This project uses [Semantic Versioning 2.0.0](http://semver.org).  Accepted pull requests will land on `master`.  Periodically, versions will be tagged from `master`.  You can find all the releases on [the project releases page](https://github.com/dgrijalva/jwt-go/releases).
53
+
54
+While we try to make it obvious when we make breaking changes, there isn't a great mechanism for pushing announcements out to users.  You may want to use this alternative package include: `gopkg.in/dgrijalva/jwt-go.v3`.  It will do the right thing WRT semantic versioning.
55
+
56
+**BREAKING CHANGES:*** 
57
+* Version 3.0.0 includes _a lot_ of changes from the 2.x line, including a few that break the API.  We've tried to break as few things as possible, so there should just be a few type signature changes.  A full list of breaking changes is available in `VERSION_HISTORY.md`.  See `MIGRATION_GUIDE.md` for more information on updating your code.
58
+
59
+## Usage Tips
60
+
61
+### Signing vs Encryption
62
+
63
+A token is simply a JSON object that is signed by its author. this tells you exactly two things about the data:
64
+
65
+* The author of the token was in the possession of the signing secret
66
+* The data has not been modified since it was signed
67
+
68
+It's important to know that JWT does not provide encryption, which means anyone who has access to the token can read its contents. If you need to protect (encrypt) the data, there is a companion spec, `JWE`, that provides this functionality. JWE is currently outside the scope of this library.
69
+
70
+### Choosing a Signing Method
71
+
72
+There are several signing methods available, and you should probably take the time to learn about the various options before choosing one.  The principal design decision is most likely going to be symmetric vs asymmetric.
73
+
74
+Symmetric signing methods, such as HSA, use only a single secret. This is probably the simplest signing method to use since any `[]byte` can be used as a valid secret. They are also slightly computationally faster to use, though this rarely is enough to matter. Symmetric signing methods work the best when both producers and consumers of tokens are trusted, or even the same system. Since the same secret is used to both sign and validate tokens, you can't easily distribute the key for validation.
75
+
76
+Asymmetric signing methods, such as RSA, use different keys for signing and verifying tokens. This makes it possible to produce tokens with a private key, and allow any consumer to access the public key for verification.
77
+
78
+### Signing Methods and Key Types
79
+
80
+Each signing method expects a different object type for its signing keys. See the package documentation for details. Here are the most common ones:
81
+
82
+* The [HMAC signing method](https://godoc.org/github.com/dgrijalva/jwt-go#SigningMethodHMAC) (`HS256`,`HS384`,`HS512`) expect `[]byte` values for signing and validation
83
+* The [RSA signing method](https://godoc.org/github.com/dgrijalva/jwt-go#SigningMethodRSA) (`RS256`,`RS384`,`RS512`) expect `*rsa.PrivateKey` for signing and `*rsa.PublicKey` for validation
84
+* The [ECDSA signing method](https://godoc.org/github.com/dgrijalva/jwt-go#SigningMethodECDSA) (`ES256`,`ES384`,`ES512`) expect `*ecdsa.PrivateKey` for signing and `*ecdsa.PublicKey` for validation
85
+
86
+### JWT and OAuth
87
+
88
+It's worth mentioning that OAuth and JWT are not the same thing. A JWT token is simply a signed JSON object. It can be used anywhere such a thing is useful. There is some confusion, though, as JWT is the most common type of bearer token used in OAuth2 authentication.
89
+
90
+Without going too far down the rabbit hole, here's a description of the interaction of these technologies:
91
+
92
+* OAuth is a protocol for allowing an identity provider to be separate from the service a user is logging in to. For example, whenever you use Facebook to log into a different service (Yelp, Spotify, etc), you are using OAuth.
93
+* OAuth defines several options for passing around authentication data. One popular method is called a "bearer token". A bearer token is simply a string that _should_ only be held by an authenticated user. Thus, simply presenting this token proves your identity. You can probably derive from here why a JWT might make a good bearer token.
94
+* Because bearer tokens are used for authentication, it's important they're kept secret. This is why transactions that use bearer tokens typically happen over SSL.
95
+
96
+## More
97
+
98
+Documentation can be found [on godoc.org](http://godoc.org/github.com/dgrijalva/jwt-go).
99
+
100
+The command line utility included in this project (cmd/jwt) provides a straightforward example of token creation and parsing as well as a useful tool for debugging your own integration. You'll also find several implementation examples in the documentation.

+ 118
- 0
vendor/github.com/dgrijalva/jwt-go/VERSION_HISTORY.md Visa fil

@@ -0,0 +1,118 @@
1
+## `jwt-go` Version History
2
+
3
+#### 3.2.0
4
+
5
+* Added method `ParseUnverified` to allow users to split up the tasks of parsing and validation
6
+* HMAC signing method returns `ErrInvalidKeyType` instead of `ErrInvalidKey` where appropriate
7
+* Added options to `request.ParseFromRequest`, which allows for an arbitrary list of modifiers to parsing behavior. Initial set include `WithClaims` and `WithParser`. Existing usage of this function will continue to work as before.
8
+* Deprecated `ParseFromRequestWithClaims` to simplify API in the future.
9
+
10
+#### 3.1.0
11
+
12
+* Improvements to `jwt` command line tool
13
+* Added `SkipClaimsValidation` option to `Parser`
14
+* Documentation updates
15
+
16
+#### 3.0.0
17
+
18
+* **Compatibility Breaking Changes**: See MIGRATION_GUIDE.md for tips on updating your code
19
+	* Dropped support for `[]byte` keys when using RSA signing methods.  This convenience feature could contribute to security vulnerabilities involving mismatched key types with signing methods.
20
+	* `ParseFromRequest` has been moved to `request` subpackage and usage has changed
21
+	* The `Claims` property on `Token` is now type `Claims` instead of `map[string]interface{}`.  The default value is type `MapClaims`, which is an alias to `map[string]interface{}`.  This makes it possible to use a custom type when decoding claims.
22
+* Other Additions and Changes
23
+	* Added `Claims` interface type to allow users to decode the claims into a custom type
24
+	* Added `ParseWithClaims`, which takes a third argument of type `Claims`.  Use this function instead of `Parse` if you have a custom type you'd like to decode into.
25
+	* Dramatically improved the functionality and flexibility of `ParseFromRequest`, which is now in the `request` subpackage
26
+	* Added `ParseFromRequestWithClaims` which is the `FromRequest` equivalent of `ParseWithClaims`
27
+	* Added new interface type `Extractor`, which is used for extracting JWT strings from http requests.  Used with `ParseFromRequest` and `ParseFromRequestWithClaims`.
28
+	* Added several new, more specific, validation errors to error type bitmask
29
+	* Moved examples from README to executable example files
30
+	* Signing method registry is now thread safe
31
+	* Added new property to `ValidationError`, which contains the raw error returned by calls made by parse/verify (such as those returned by keyfunc or json parser)
32
+
33
+#### 2.7.0
34
+
35
+This will likely be the last backwards compatible release before 3.0.0, excluding essential bug fixes.
36
+
37
+* Added new option `-show` to the `jwt` command that will just output the decoded token without verifying
38
+* Error text for expired tokens includes how long it's been expired
39
+* Fixed incorrect error returned from `ParseRSAPublicKeyFromPEM`
40
+* Documentation updates
41
+
42
+#### 2.6.0
43
+
44
+* Exposed inner error within ValidationError
45
+* Fixed validation errors when using UseJSONNumber flag
46
+* Added several unit tests
47
+
48
+#### 2.5.0
49
+
50
+* Added support for signing method none.  You shouldn't use this.  The API tries to make this clear.
51
+* Updated/fixed some documentation
52
+* Added more helpful error message when trying to parse tokens that begin with `BEARER `
53
+
54
+#### 2.4.0
55
+
56
+* Added new type, Parser, to allow for configuration of various parsing parameters
57
+	* You can now specify a list of valid signing methods.  Anything outside this set will be rejected.
58
+	* You can now opt to use the `json.Number` type instead of `float64` when parsing token JSON
59
+* Added support for [Travis CI](https://travis-ci.org/dgrijalva/jwt-go)
60
+* Fixed some bugs with ECDSA parsing
61
+
62
+#### 2.3.0
63
+
64
+* Added support for ECDSA signing methods
65
+* Added support for RSA PSS signing methods (requires go v1.4)
66
+
67
+#### 2.2.0
68
+
69
+* Gracefully handle a `nil` `Keyfunc` being passed to `Parse`.  Result will now be the parsed token and an error, instead of a panic.
70
+
71
+#### 2.1.0
72
+
73
+Backwards compatible API change that was missed in 2.0.0.
74
+
75
+* The `SignedString` method on `Token` now takes `interface{}` instead of `[]byte`
76
+
77
+#### 2.0.0
78
+
79
+There were two major reasons for breaking backwards compatibility with this update.  The first was a refactor required to expand the width of the RSA and HMAC-SHA signing implementations.  There will likely be no required code changes to support this change.
80
+
81
+The second update, while unfortunately requiring a small change in integration, is required to open up this library to other signing methods.  Not all keys used for all signing methods have a single standard on-disk representation.  Requiring `[]byte` as the type for all keys proved too limiting.  Additionally, this implementation allows for pre-parsed tokens to be reused, which might matter in an application that parses a high volume of tokens with a small set of keys.  Backwards compatibilty has been maintained for passing `[]byte` to the RSA signing methods, but they will also accept `*rsa.PublicKey` and `*rsa.PrivateKey`.
82
+
83
+It is likely the only integration change required here will be to change `func(t *jwt.Token) ([]byte, error)` to `func(t *jwt.Token) (interface{}, error)` when calling `Parse`.
84
+
85
+* **Compatibility Breaking Changes**
86
+	* `SigningMethodHS256` is now `*SigningMethodHMAC` instead of `type struct`
87
+	* `SigningMethodRS256` is now `*SigningMethodRSA` instead of `type struct`
88
+	* `KeyFunc` now returns `interface{}` instead of `[]byte`
89
+	* `SigningMethod.Sign` now takes `interface{}` instead of `[]byte` for the key
90
+	* `SigningMethod.Verify` now takes `interface{}` instead of `[]byte` for the key
91
+* Renamed type `SigningMethodHS256` to `SigningMethodHMAC`.  Specific sizes are now just instances of this type.
92
+    * Added public package global `SigningMethodHS256`
93
+    * Added public package global `SigningMethodHS384`
94
+    * Added public package global `SigningMethodHS512`
95
+* Renamed type `SigningMethodRS256` to `SigningMethodRSA`.  Specific sizes are now just instances of this type.
96
+    * Added public package global `SigningMethodRS256`
97
+    * Added public package global `SigningMethodRS384`
98
+    * Added public package global `SigningMethodRS512`
99
+* Moved sample private key for HMAC tests from an inline value to a file on disk.  Value is unchanged.
100
+* Refactored the RSA implementation to be easier to read
101
+* Exposed helper methods `ParseRSAPrivateKeyFromPEM` and `ParseRSAPublicKeyFromPEM`
102
+
103
+#### 1.0.2
104
+
105
+* Fixed bug in parsing public keys from certificates
106
+* Added more tests around the parsing of keys for RS256
107
+* Code refactoring in RS256 implementation.  No functional changes
108
+
109
+#### 1.0.1
110
+
111
+* Fixed panic if RS256 signing method was passed an invalid key
112
+
113
+#### 1.0.0
114
+
115
+* First versioned release
116
+* API stabilized
117
+* Supports creating, signing, parsing, and validating JWT tokens
118
+* Supports RS256 and HS256 signing methods

+ 134
- 0
vendor/github.com/dgrijalva/jwt-go/claims.go Visa fil

@@ -0,0 +1,134 @@
1
+package jwt
2
+
3
+import (
4
+	"crypto/subtle"
5
+	"fmt"
6
+	"time"
7
+)
8
+
9
+// For a type to be a Claims object, it must just have a Valid method that determines
10
+// if the token is invalid for any supported reason
11
+type Claims interface {
12
+	Valid() error
13
+}
14
+
15
+// Structured version of Claims Section, as referenced at
16
+// https://tools.ietf.org/html/rfc7519#section-4.1
17
+// See examples for how to use this with your own claim types
18
+type StandardClaims struct {
19
+	Audience  string `json:"aud,omitempty"`
20
+	ExpiresAt int64  `json:"exp,omitempty"`
21
+	Id        string `json:"jti,omitempty"`
22
+	IssuedAt  int64  `json:"iat,omitempty"`
23
+	Issuer    string `json:"iss,omitempty"`
24
+	NotBefore int64  `json:"nbf,omitempty"`
25
+	Subject   string `json:"sub,omitempty"`
26
+}
27
+
28
+// Validates time based claims "exp, iat, nbf".
29
+// There is no accounting for clock skew.
30
+// As well, if any of the above claims are not in the token, it will still
31
+// be considered a valid claim.
32
+func (c StandardClaims) Valid() error {
33
+	vErr := new(ValidationError)
34
+	now := TimeFunc().Unix()
35
+
36
+	// The claims below are optional, by default, so if they are set to the
37
+	// default value in Go, let's not fail the verification for them.
38
+	if c.VerifyExpiresAt(now, false) == false {
39
+		delta := time.Unix(now, 0).Sub(time.Unix(c.ExpiresAt, 0))
40
+		vErr.Inner = fmt.Errorf("token is expired by %v", delta)
41
+		vErr.Errors |= ValidationErrorExpired
42
+	}
43
+
44
+	if c.VerifyIssuedAt(now, false) == false {
45
+		vErr.Inner = fmt.Errorf("Token used before issued")
46
+		vErr.Errors |= ValidationErrorIssuedAt
47
+	}
48
+
49
+	if c.VerifyNotBefore(now, false) == false {
50
+		vErr.Inner = fmt.Errorf("token is not valid yet")
51
+		vErr.Errors |= ValidationErrorNotValidYet
52
+	}
53
+
54
+	if vErr.valid() {
55
+		return nil
56
+	}
57
+
58
+	return vErr
59
+}
60
+
61
+// Compares the aud claim against cmp.
62
+// If required is false, this method will return true if the value matches or is unset
63
+func (c *StandardClaims) VerifyAudience(cmp string, req bool) bool {
64
+	return verifyAud(c.Audience, cmp, req)
65
+}
66
+
67
+// Compares the exp claim against cmp.
68
+// If required is false, this method will return true if the value matches or is unset
69
+func (c *StandardClaims) VerifyExpiresAt(cmp int64, req bool) bool {
70
+	return verifyExp(c.ExpiresAt, cmp, req)
71
+}
72
+
73
+// Compares the iat claim against cmp.
74
+// If required is false, this method will return true if the value matches or is unset
75
+func (c *StandardClaims) VerifyIssuedAt(cmp int64, req bool) bool {
76
+	return verifyIat(c.IssuedAt, cmp, req)
77
+}
78
+
79
+// Compares the iss claim against cmp.
80
+// If required is false, this method will return true if the value matches or is unset
81
+func (c *StandardClaims) VerifyIssuer(cmp string, req bool) bool {
82
+	return verifyIss(c.Issuer, cmp, req)
83
+}
84
+
85
+// Compares the nbf claim against cmp.
86
+// If required is false, this method will return true if the value matches or is unset
87
+func (c *StandardClaims) VerifyNotBefore(cmp int64, req bool) bool {
88
+	return verifyNbf(c.NotBefore, cmp, req)
89
+}
90
+
91
+// ----- helpers
92
+
93
+func verifyAud(aud string, cmp string, required bool) bool {
94
+	if aud == "" {
95
+		return !required
96
+	}
97
+	if subtle.ConstantTimeCompare([]byte(aud), []byte(cmp)) != 0 {
98
+		return true
99
+	} else {
100
+		return false
101
+	}
102
+}
103
+
104
+func verifyExp(exp int64, now int64, required bool) bool {
105
+	if exp == 0 {
106
+		return !required
107
+	}
108
+	return now <= exp
109
+}
110
+
111
+func verifyIat(iat int64, now int64, required bool) bool {
112
+	if iat == 0 {
113
+		return !required
114
+	}
115
+	return now >= iat
116
+}
117
+
118
+func verifyIss(iss string, cmp string, required bool) bool {
119
+	if iss == "" {
120
+		return !required
121
+	}
122
+	if subtle.ConstantTimeCompare([]byte(iss), []byte(cmp)) != 0 {
123
+		return true
124
+	} else {
125
+		return false
126
+	}
127
+}
128
+
129
+func verifyNbf(nbf int64, now int64, required bool) bool {
130
+	if nbf == 0 {
131
+		return !required
132
+	}
133
+	return now >= nbf
134
+}

+ 4
- 0
vendor/github.com/dgrijalva/jwt-go/doc.go Visa fil

@@ -0,0 +1,4 @@
1
+// Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html
2
+//
3
+// See README.md for more info.
4
+package jwt

+ 148
- 0
vendor/github.com/dgrijalva/jwt-go/ecdsa.go Visa fil

@@ -0,0 +1,148 @@
1
+package jwt
2
+
3
+import (
4
+	"crypto"
5
+	"crypto/ecdsa"
6
+	"crypto/rand"
7
+	"errors"
8
+	"math/big"
9
+)
10
+
11
+var (
12
+	// Sadly this is missing from crypto/ecdsa compared to crypto/rsa
13
+	ErrECDSAVerification = errors.New("crypto/ecdsa: verification error")
14
+)
15
+
16
+// Implements the ECDSA family of signing methods signing methods
17
+// Expects *ecdsa.PrivateKey for signing and *ecdsa.PublicKey for verification
18
+type SigningMethodECDSA struct {
19
+	Name      string
20
+	Hash      crypto.Hash
21
+	KeySize   int
22
+	CurveBits int
23
+}
24
+
25
+// Specific instances for EC256 and company
26
+var (
27
+	SigningMethodES256 *SigningMethodECDSA
28
+	SigningMethodES384 *SigningMethodECDSA
29
+	SigningMethodES512 *SigningMethodECDSA
30
+)
31
+
32
+func init() {
33
+	// ES256
34
+	SigningMethodES256 = &SigningMethodECDSA{"ES256", crypto.SHA256, 32, 256}
35
+	RegisterSigningMethod(SigningMethodES256.Alg(), func() SigningMethod {
36
+		return SigningMethodES256
37
+	})
38
+
39
+	// ES384
40
+	SigningMethodES384 = &SigningMethodECDSA{"ES384", crypto.SHA384, 48, 384}
41
+	RegisterSigningMethod(SigningMethodES384.Alg(), func() SigningMethod {
42
+		return SigningMethodES384
43
+	})
44
+
45
+	// ES512
46
+	SigningMethodES512 = &SigningMethodECDSA{"ES512", crypto.SHA512, 66, 521}
47
+	RegisterSigningMethod(SigningMethodES512.Alg(), func() SigningMethod {
48
+		return SigningMethodES512
49
+	})
50
+}
51
+
52
+func (m *SigningMethodECDSA) Alg() string {
53
+	return m.Name
54
+}
55
+
56
+// Implements the Verify method from SigningMethod
57
+// For this verify method, key must be an ecdsa.PublicKey struct
58
+func (m *SigningMethodECDSA) Verify(signingString, signature string, key interface{}) error {
59
+	var err error
60
+
61
+	// Decode the signature
62
+	var sig []byte
63
+	if sig, err = DecodeSegment(signature); err != nil {
64
+		return err
65
+	}
66
+
67
+	// Get the key
68
+	var ecdsaKey *ecdsa.PublicKey
69
+	switch k := key.(type) {
70
+	case *ecdsa.PublicKey:
71
+		ecdsaKey = k
72
+	default:
73
+		return ErrInvalidKeyType
74
+	}
75
+
76
+	if len(sig) != 2*m.KeySize {
77
+		return ErrECDSAVerification
78
+	}
79
+
80
+	r := big.NewInt(0).SetBytes(sig[:m.KeySize])
81
+	s := big.NewInt(0).SetBytes(sig[m.KeySize:])
82
+
83
+	// Create hasher
84
+	if !m.Hash.Available() {
85
+		return ErrHashUnavailable
86
+	}
87
+	hasher := m.Hash.New()
88
+	hasher.Write([]byte(signingString))
89
+
90
+	// Verify the signature
91
+	if verifystatus := ecdsa.Verify(ecdsaKey, hasher.Sum(nil), r, s); verifystatus == true {
92
+		return nil
93
+	} else {
94
+		return ErrECDSAVerification
95
+	}
96
+}
97
+
98
+// Implements the Sign method from SigningMethod
99
+// For this signing method, key must be an ecdsa.PrivateKey struct
100
+func (m *SigningMethodECDSA) Sign(signingString string, key interface{}) (string, error) {
101
+	// Get the key
102
+	var ecdsaKey *ecdsa.PrivateKey
103
+	switch k := key.(type) {
104
+	case *ecdsa.PrivateKey:
105
+		ecdsaKey = k
106
+	default:
107
+		return "", ErrInvalidKeyType
108
+	}
109
+
110
+	// Create the hasher
111
+	if !m.Hash.Available() {
112
+		return "", ErrHashUnavailable
113
+	}
114
+
115
+	hasher := m.Hash.New()
116
+	hasher.Write([]byte(signingString))
117
+
118
+	// Sign the string and return r, s
119
+	if r, s, err := ecdsa.Sign(rand.Reader, ecdsaKey, hasher.Sum(nil)); err == nil {
120
+		curveBits := ecdsaKey.Curve.Params().BitSize
121
+
122
+		if m.CurveBits != curveBits {
123
+			return "", ErrInvalidKey
124
+		}
125
+
126
+		keyBytes := curveBits / 8
127
+		if curveBits%8 > 0 {
128
+			keyBytes += 1
129
+		}
130
+
131
+		// We serialize the outpus (r and s) into big-endian byte arrays and pad
132
+		// them with zeros on the left to make sure the sizes work out. Both arrays
133
+		// must be keyBytes long, and the output must be 2*keyBytes long.
134
+		rBytes := r.Bytes()
135
+		rBytesPadded := make([]byte, keyBytes)
136
+		copy(rBytesPadded[keyBytes-len(rBytes):], rBytes)
137
+
138
+		sBytes := s.Bytes()
139
+		sBytesPadded := make([]byte, keyBytes)
140
+		copy(sBytesPadded[keyBytes-len(sBytes):], sBytes)
141
+
142
+		out := append(rBytesPadded, sBytesPadded...)
143
+
144
+		return EncodeSegment(out), nil
145
+	} else {
146
+		return "", err
147
+	}
148
+}

+ 67
- 0
vendor/github.com/dgrijalva/jwt-go/ecdsa_utils.go Visa fil

@@ -0,0 +1,67 @@
1
+package jwt
2
+
3
+import (
4
+	"crypto/ecdsa"
5
+	"crypto/x509"
6
+	"encoding/pem"
7
+	"errors"
8
+)
9
+
10
+var (
11
+	ErrNotECPublicKey  = errors.New("Key is not a valid ECDSA public key")
12
+	ErrNotECPrivateKey = errors.New("Key is not a valid ECDSA private key")
13
+)
14
+
15
+// Parse PEM encoded Elliptic Curve Private Key Structure
16
+func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error) {
17
+	var err error
18
+
19
+	// Parse PEM block
20
+	var block *pem.Block
21
+	if block, _ = pem.Decode(key); block == nil {
22
+		return nil, ErrKeyMustBePEMEncoded
23
+	}
24
+
25
+	// Parse the key
26
+	var parsedKey interface{}
27
+	if parsedKey, err = x509.ParseECPrivateKey(block.Bytes); err != nil {
28
+		return nil, err
29
+	}
30
+
31
+	var pkey *ecdsa.PrivateKey
32
+	var ok bool
33
+	if pkey, ok = parsedKey.(*ecdsa.PrivateKey); !ok {
34
+		return nil, ErrNotECPrivateKey
35
+	}
36
+
37
+	return pkey, nil
38
+}
39
+
40
+// Parse PEM encoded PKCS1 or PKCS8 public key
41
+func ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error) {
42
+	var err error
43
+
44
+	// Parse PEM block
45
+	var block *pem.Block
46
+	if block, _ = pem.Decode(key); block == nil {
47
+		return nil, ErrKeyMustBePEMEncoded
48
+	}
49
+
50
+	// Parse the key
51
+	var parsedKey interface{}
52
+	if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil {
53
+		if cert, err := x509.ParseCertificate(block.Bytes); err == nil {
54
+			parsedKey = cert.PublicKey
55
+		} else {
56
+			return nil, err
57
+		}
58
+	}
59
+
60
+	var pkey *ecdsa.PublicKey
61
+	var ok bool
62
+	if pkey, ok = parsedKey.(*ecdsa.PublicKey); !ok {
63
+		return nil, ErrNotECPublicKey
64
+	}
65
+
66
+	return pkey, nil
67
+}

+ 59
- 0
vendor/github.com/dgrijalva/jwt-go/errors.go Visa fil

@@ -0,0 +1,59 @@
1
+package jwt
2
+
3
+import (
4
+	"errors"
5
+)
6
+
7
+// Error constants
8
+var (
9
+	ErrInvalidKey      = errors.New("key is invalid")
10
+	ErrInvalidKeyType  = errors.New("key is of invalid type")
11
+	ErrHashUnavailable = errors.New("the requested hash function is unavailable")
12
+)
13
+
14
+// The errors that might occur when parsing and validating a token
15
+const (
16
+	ValidationErrorMalformed        uint32 = 1 << iota // Token is malformed
17
+	ValidationErrorUnverifiable                        // Token could not be verified because of signing problems
18
+	ValidationErrorSignatureInvalid                    // Signature validation failed
19
+
20
+	// Standard Claim validation errors
21
+	ValidationErrorAudience      // AUD validation failed
22
+	ValidationErrorExpired       // EXP validation failed
23
+	ValidationErrorIssuedAt      // IAT validation failed
24
+	ValidationErrorIssuer        // ISS validation failed
25
+	ValidationErrorNotValidYet   // NBF validation failed
26
+	ValidationErrorId            // JTI validation failed
27
+	ValidationErrorClaimsInvalid // Generic claims validation error
28
+)
29
+
30
+// Helper for constructing a ValidationError with a string error message
31
+func NewValidationError(errorText string, errorFlags uint32) *ValidationError {
32
+	return &ValidationError{
33
+		text:   errorText,
34
+		Errors: errorFlags,
35
+	}
36
+}
37
+
38
+// The error from Parse if token is not valid
39
+type ValidationError struct {
40
+	Inner  error  // stores the error returned by external dependencies, i.e.: KeyFunc
41
+	Errors uint32 // bitfield.  see ValidationError... constants
42
+	text   string // errors that do not have a valid error just have text
43
+}
44
+
45
+// Validation error is an error type
46
+func (e ValidationError) Error() string {
47
+	if e.Inner != nil {
48
+		return e.Inner.Error()
49
+	} else if e.text != "" {
50
+		return e.text
51
+	} else {
52
+		return "token is invalid"
53
+	}
54
+}
55
+
56
+// No errors
57
+func (e *ValidationError) valid() bool {
58
+	return e.Errors == 0
59
+}

+ 95
- 0
vendor/github.com/dgrijalva/jwt-go/hmac.go Visa fil

@@ -0,0 +1,95 @@
1
+package jwt
2
+
3
+import (
4
+	"crypto"
5
+	"crypto/hmac"
6
+	"errors"
7
+)
8
+
9
+// Implements the HMAC-SHA family of signing methods signing methods
10
+// Expects key type of []byte for both signing and validation
11
+type SigningMethodHMAC struct {
12
+	Name string
13
+	Hash crypto.Hash
14
+}
15
+
16
+// Specific instances for HS256 and company
17
+var (
18
+	SigningMethodHS256  *SigningMethodHMAC
19
+	SigningMethodHS384  *SigningMethodHMAC
20
+	SigningMethodHS512  *SigningMethodHMAC
21
+	ErrSignatureInvalid = errors.New("signature is invalid")
22
+)
23
+
24
+func init() {
25
+	// HS256
26
+	SigningMethodHS256 = &SigningMethodHMAC{"HS256", crypto.SHA256}
27
+	RegisterSigningMethod(SigningMethodHS256.Alg(), func() SigningMethod {
28
+		return SigningMethodHS256
29
+	})
30
+
31
+	// HS384
32
+	SigningMethodHS384 = &SigningMethodHMAC{"HS384", crypto.SHA384}
33
+	RegisterSigningMethod(SigningMethodHS384.Alg(), func() SigningMethod {
34
+		return SigningMethodHS384
35
+	})
36
+
37
+	// HS512
38
+	SigningMethodHS512 = &SigningMethodHMAC{"HS512", crypto.SHA512}
39
+	RegisterSigningMethod(SigningMethodHS512.Alg(), func() SigningMethod {
40
+		return SigningMethodHS512
41
+	})
42
+}
43
+
44
+func (m *SigningMethodHMAC) Alg() string {
45
+	return m.Name
46
+}
47
+
48
+// Verify the signature of HSXXX tokens.  Returns nil if the signature is valid.
49
+func (m *SigningMethodHMAC) Verify(signingString, signature string, key interface{}) error {
50
+	// Verify the key is the right type
51
+	keyBytes, ok := key.([]byte)
52
+	if !ok {
53
+		return ErrInvalidKeyType
54
+	}
55
+
56
+	// Decode signature, for comparison
57
+	sig, err := DecodeSegment(signature)
58
+	if err != nil {
59
+		return err
60
+	}
61
+
62
+	// Can we use the specified hashing method?
63
+	if !m.Hash.Available() {
64
+		return ErrHashUnavailable
65
+	}
66
+
67
+	// This signing method is symmetric, so we validate the signature
68
+	// by reproducing the signature from the signing string and key, then
69
+	// comparing that against the provided signature.
70
+	hasher := hmac.New(m.Hash.New, keyBytes)
71
+	hasher.Write([]byte(signingString))
72
+	if !hmac.Equal(sig, hasher.Sum(nil)) {
73
+		return ErrSignatureInvalid
74
+	}
75
+
76
+	// No validation errors.  Signature is good.
77
+	return nil
78
+}
79
+
80
+// Implements the Sign method from SigningMethod for this signing method.
81
+// Key must be []byte
82
+func (m *SigningMethodHMAC) Sign(signingString string, key interface{}) (string, error) {
83
+	if keyBytes, ok := key.([]byte); ok {
84
+		if !m.Hash.Available() {
85
+			return "", ErrHashUnavailable
86
+		}
87
+
88
+		hasher := hmac.New(m.Hash.New, keyBytes)
89
+		hasher.Write([]byte(signingString))
90
+
91
+		return EncodeSegment(hasher.Sum(nil)), nil
92
+	}
93
+
94
+	return "", ErrInvalidKeyType
95
+}

+ 94
- 0
vendor/github.com/dgrijalva/jwt-go/map_claims.go Visa fil

@@ -0,0 +1,94 @@
1
+package jwt
2
+
3
+import (
4
+	"encoding/json"
5
+	"errors"
6
+	// "fmt"
7
+)
8
+
9
+// Claims type that uses the map[string]interface{} for JSON decoding
10
+// This is the default claims type if you don't supply one
11
+type MapClaims map[string]interface{}
12
+
13
+// Compares the aud claim against cmp.
14
+// If required is false, this method will return true if the value matches or is unset
15
+func (m MapClaims) VerifyAudience(cmp string, req bool) bool {
16
+	aud, _ := m["aud"].(string)
17
+	return verifyAud(aud, cmp, req)
18
+}
19
+
20
+// Compares the exp claim against cmp.
21
+// If required is false, this method will return true if the value matches or is unset
22
+func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool {
23
+	switch exp := m["exp"].(type) {
24
+	case float64:
25
+		return verifyExp(int64(exp), cmp, req)
26
+	case json.Number:
27
+		v, _ := exp.Int64()
28
+		return verifyExp(v, cmp, req)
29
+	}
30
+	return req == false
31
+}
32
+
33
+// Compares the iat claim against cmp.
34
+// If required is false, this method will return true if the value matches or is unset
35
+func (m MapClaims) VerifyIssuedAt(cmp int64, req bool) bool {
36
+	switch iat := m["iat"].(type) {
37
+	case float64:
38
+		return verifyIat(int64(iat), cmp, req)
39
+	case json.Number:
40
+		v, _ := iat.Int64()
41
+		return verifyIat(v, cmp, req)
42
+	}
43
+	return req == false
44
+}
45
+
46
+// Compares the iss claim against cmp.
47
+// If required is false, this method will return true if the value matches or is unset
48
+func (m MapClaims) VerifyIssuer(cmp string, req bool) bool {
49
+	iss, _ := m["iss"].(string)
50
+	return verifyIss(iss, cmp, req)
51
+}
52
+
53
+// Compares the nbf claim against cmp.
54
+// If required is false, this method will return true if the value matches or is unset
55
+func (m MapClaims) VerifyNotBefore(cmp int64, req bool) bool {
56
+	switch nbf := m["nbf"].(type) {
57
+	case float64:
58
+		return verifyNbf(int64(nbf), cmp, req)
59
+	case json.Number:
60
+		v, _ := nbf.Int64()
61
+		return verifyNbf(v, cmp, req)
62
+	}
63
+	return req == false
64
+}
65
+
66
+// Validates time based claims "exp, iat, nbf".
67
+// There is no accounting for clock skew.
68
+// As well, if any of the above claims are not in the token, it will still
69
+// be considered a valid claim.
70
+func (m MapClaims) Valid() error {
71
+	vErr := new(ValidationError)
72
+	now := TimeFunc().Unix()
73
+
74
+	if m.VerifyExpiresAt(now, false) == false {
75
+		vErr.Inner = errors.New("Token is expired")
76
+		vErr.Errors |= ValidationErrorExpired
77
+	}
78
+
79
+	if m.VerifyIssuedAt(now, false) == false {
80
+		vErr.Inner = errors.New("Token used before issued")
81
+		vErr.Errors |= ValidationErrorIssuedAt
82
+	}
83
+
84
+	if m.VerifyNotBefore(now, false) == false {
85
+		vErr.Inner = errors.New("Token is not valid yet")
86
+		vErr.Errors |= ValidationErrorNotValidYet
87
+	}
88
+
89
+	if vErr.valid() {
90
+		return nil
91
+	}
92
+
93
+	return vErr
94
+}

+ 52
- 0
vendor/github.com/dgrijalva/jwt-go/none.go Visa fil

@@ -0,0 +1,52 @@
1
+package jwt
2
+
3
+// Implements the none signing method.  This is required by the spec
4
+// but you probably should never use it.
5
+var SigningMethodNone *signingMethodNone
6
+
7
+const UnsafeAllowNoneSignatureType unsafeNoneMagicConstant = "none signing method allowed"
8
+
9
+var NoneSignatureTypeDisallowedError error
10
+
11
+type signingMethodNone struct{}
12
+type unsafeNoneMagicConstant string
13
+
14
+func init() {
15
+	SigningMethodNone = &signingMethodNone{}
16
+	NoneSignatureTypeDisallowedError = NewValidationError("'none' signature type is not allowed", ValidationErrorSignatureInvalid)
17
+
18
+	RegisterSigningMethod(SigningMethodNone.Alg(), func() SigningMethod {
19
+		return SigningMethodNone
20
+	})
21
+}
22
+
23
+func (m *signingMethodNone) Alg() string {
24
+	return "none"
25
+}
26
+
27
+// Only allow 'none' alg type if UnsafeAllowNoneSignatureType is specified as the key
28
+func (m *signingMethodNone) Verify(signingString, signature string, key interface{}) (err error) {
29
+	// Key must be UnsafeAllowNoneSignatureType to prevent accidentally
30
+	// accepting 'none' signing method
31
+	if _, ok := key.(unsafeNoneMagicConstant); !ok {
32
+		return NoneSignatureTypeDisallowedError
33
+	}
34
+	// If signing method is none, signature must be an empty string
35
+	if signature != "" {
36
+		return NewValidationError(
37
+			"'none' signing method with non-empty signature",
38
+			ValidationErrorSignatureInvalid,
39
+		)
40
+	}
41
+
42
+	// Accept 'none' signing method.
43
+	return nil
44
+}
45
+
46
+// Only allow 'none' signing if UnsafeAllowNoneSignatureType is specified as the key
47
+func (m *signingMethodNone) Sign(signingString string, key interface{}) (string, error) {
48
+	if _, ok := key.(unsafeNoneMagicConstant); ok {
49
+		return "", nil
50
+	}
51
+	return "", NoneSignatureTypeDisallowedError
52
+}

+ 148
- 0
vendor/github.com/dgrijalva/jwt-go/parser.go Visa fil

@@ -0,0 +1,148 @@
1
+package jwt
2
+
3
+import (
4
+	"bytes"
5
+	"encoding/json"
6
+	"fmt"
7
+	"strings"
8
+)
9
+
10
+type Parser struct {
11
+	ValidMethods         []string // If populated, only these methods will be considered valid
12
+	UseJSONNumber        bool     // Use JSON Number format in JSON decoder
13
+	SkipClaimsValidation bool     // Skip claims validation during token parsing
14
+}
15
+
16
+// Parse, validate, and return a token.
17
+// keyFunc will receive the parsed token and should return the key for validating.
18
+// If everything is kosher, err will be nil
19
+func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) {
20
+	return p.ParseWithClaims(tokenString, MapClaims{}, keyFunc)
21
+}
22
+
23
+func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) {
24
+	token, parts, err := p.ParseUnverified(tokenString, claims)
25
+	if err != nil {
26
+		return token, err
27
+	}
28
+
29
+	// Verify signing method is in the required set
30
+	if p.ValidMethods != nil {
31
+		var signingMethodValid = false
32
+		var alg = token.Method.Alg()
33
+		for _, m := range p.ValidMethods {
34
+			if m == alg {
35
+				signingMethodValid = true
36
+				break
37
+			}
38
+		}
39
+		if !signingMethodValid {
40
+			// signing method is not in the listed set
41
+			return token, NewValidationError(fmt.Sprintf("signing method %v is invalid", alg), ValidationErrorSignatureInvalid)
42
+		}
43
+	}
44
+
45
+	// Lookup key
46
+	var key interface{}
47
+	if keyFunc == nil {
48
+		// keyFunc was not provided.  short circuiting validation
49
+		return token, NewValidationError("no Keyfunc was provided.", ValidationErrorUnverifiable)
50
+	}
51
+	if key, err = keyFunc(token); err != nil {
52
+		// keyFunc returned an error
53
+		if ve, ok := err.(*ValidationError); ok {
54
+			return token, ve
55
+		}
56
+		return token, &ValidationError{Inner: err, Errors: ValidationErrorUnverifiable}
57
+	}
58
+
59
+	vErr := &ValidationError{}
60
+
61
+	// Validate Claims
62
+	if !p.SkipClaimsValidation {
63
+		if err := token.Claims.Valid(); err != nil {
64
+
65
+			// If the Claims Valid returned an error, check if it is a validation error,
66
+			// If it was another error type, create a ValidationError with a generic ClaimsInvalid flag set
67
+			if e, ok := err.(*ValidationError); !ok {
68
+				vErr = &ValidationError{Inner: err, Errors: ValidationErrorClaimsInvalid}
69
+			} else {
70
+				vErr = e
71
+			}
72
+		}
73
+	}
74
+
75
+	// Perform validation
76
+	token.Signature = parts[2]
77
+	if err = token.Method.Verify(strings.Join(parts[0:2], "."), token.Signature, key); err != nil {
78
+		vErr.Inner = err
79
+		vErr.Errors |= ValidationErrorSignatureInvalid
80
+	}
81
+
82
+	if vErr.valid() {
83
+		token.Valid = true
84
+		return token, nil
85
+	}
86
+
87
+	return token, vErr
88
+}
89
+
90
+// WARNING: Don't use this method unless you know what you're doing
91
+//
92
+// This method parses the token but doesn't validate the signature. It's only
93
+// ever useful in cases where you know the signature is valid (because it has
94
+// been checked previously in the stack) and you want to extract values from
95
+// it.
96
+func (p *Parser) ParseUnverified(tokenString string, claims Claims) (token *Token, parts []string, err error) {
97
+	parts = strings.Split(tokenString, ".")
98
+	if len(parts) != 3 {
99
+		return nil, parts, NewValidationError("token contains an invalid number of segments", ValidationErrorMalformed)
100
+	}
101
+
102
+	token = &Token{Raw: tokenString}
103
+
104
+	// parse Header
105
+	var headerBytes []byte
106
+	if headerBytes, err = DecodeSegment(parts[0]); err != nil {
107
+		if strings.HasPrefix(strings.ToLower(tokenString), "bearer ") {
108
+			return token, parts, NewValidationError("tokenstring should not contain 'bearer '", ValidationErrorMalformed)
109
+		}
110
+		return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed}
111
+	}
112
+	if err = json.Unmarshal(headerBytes, &token.Header); err != nil {
113
+		return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed}
114
+	}
115
+
116
+	// parse Claims
117
+	var claimBytes []byte
118
+	token.Claims = claims
119
+
120
+	if claimBytes, err = DecodeSegment(parts[1]); err != nil {
121
+		return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed}
122
+	}
123
+	dec := json.NewDecoder(bytes.NewBuffer(claimBytes))
124
+	if p.UseJSONNumber {
125
+		dec.UseNumber()
126
+	}
127
+	// JSON Decode.  Special case for map type to avoid weird pointer behavior
128
+	if c, ok := token.Claims.(MapClaims); ok {
129
+		err = dec.Decode(&c)
130
+	} else {
131
+		err = dec.Decode(&claims)
132
+	}
133
+	// Handle decode error
134
+	if err != nil {
135
+		return token, parts, &ValidationError{Inner: err, Errors: ValidationErrorMalformed}
136
+	}
137
+
138
+	// Lookup signature method
139
+	if method, ok := token.Header["alg"].(string); ok {
140
+		if token.Method = GetSigningMethod(method); token.Method == nil {
141
+			return token, parts, NewValidationError("signing method (alg) is unavailable.", ValidationErrorUnverifiable)
142
+		}
143
+	} else {
144
+		return token, parts, NewValidationError("signing method (alg) is unspecified.", ValidationErrorUnverifiable)
145
+	}
146
+
147
+	return token, parts, nil
148
+}

+ 101
- 0
vendor/github.com/dgrijalva/jwt-go/rsa.go Visa fil

@@ -0,0 +1,101 @@
1
+package jwt
2
+
3
+import (
4
+	"crypto"
5
+	"crypto/rand"
6
+	"crypto/rsa"
7
+)
8
+
9
+// Implements the RSA family of signing methods signing methods
10
+// Expects *rsa.PrivateKey for signing and *rsa.PublicKey for validation
11
+type SigningMethodRSA struct {
12
+	Name string
13
+	Hash crypto.Hash
14
+}
15
+
16
+// Specific instances for RS256 and company
17
+var (
18
+	SigningMethodRS256 *SigningMethodRSA
19
+	SigningMethodRS384 *SigningMethodRSA
20
+	SigningMethodRS512 *SigningMethodRSA
21
+)
22
+
23
+func init() {
24
+	// RS256
25
+	SigningMethodRS256 = &SigningMethodRSA{"RS256", crypto.SHA256}
26
+	RegisterSigningMethod(SigningMethodRS256.Alg(), func() SigningMethod {
27
+		return SigningMethodRS256
28
+	})
29
+
30
+	// RS384
31
+	SigningMethodRS384 = &SigningMethodRSA{"RS384", crypto.SHA384}
32
+	RegisterSigningMethod(SigningMethodRS384.Alg(), func() SigningMethod {
33
+		return SigningMethodRS384
34
+	})
35
+
36
+	// RS512
37
+	SigningMethodRS512 = &SigningMethodRSA{"RS512", crypto.SHA512}
38
+	RegisterSigningMethod(SigningMethodRS512.Alg(), func() SigningMethod {
39
+		return SigningMethodRS512
40
+	})
41
+}
42
+
43
+func (m *SigningMethodRSA) Alg() string {
44
+	return m.Name
45
+}
46
+
47
+// Implements the Verify method from SigningMethod
48
+// For this signing method, must be an *rsa.PublicKey structure.
49
+func (m *SigningMethodRSA) Verify(signingString, signature string, key interface{}) error {
50
+	var err error
51
+
52
+	// Decode the signature
53
+	var sig []byte
54
+	if sig, err = DecodeSegment(signature); err != nil {
55
+		return err
56
+	}
57
+
58
+	var rsaKey *rsa.PublicKey
59
+	var ok bool
60
+
61
+	if rsaKey, ok = key.(*rsa.PublicKey); !ok {
62
+		return ErrInvalidKeyType
63
+	}
64
+
65
+	// Create hasher
66
+	if !m.Hash.Available() {
67
+		return ErrHashUnavailable
68
+	}
69
+	hasher := m.Hash.New()
70
+	hasher.Write([]byte(signingString))
71
+
72
+	// Verify the signature
73
+	return rsa.VerifyPKCS1v15(rsaKey, m.Hash, hasher.Sum(nil), sig)
74
+}
75
+
76
+// Implements the Sign method from SigningMethod
77
+// For this signing method, must be an *rsa.PrivateKey structure.
78
+func (m *SigningMethodRSA) Sign(signingString string, key interface{}) (string, error) {
79
+	var rsaKey *rsa.PrivateKey
80
+	var ok bool
81
+
82
+	// Validate type of key
83
+	if rsaKey, ok = key.(*rsa.PrivateKey); !ok {
84
+		return "", ErrInvalidKey
85
+	}
86
+
87
+	// Create the hasher
88
+	if !m.Hash.Available() {
89
+		return "", ErrHashUnavailable
90
+	}
91
+
92
+	hasher := m.Hash.New()
93
+	hasher.Write([]byte(signingString))
94
+
95
+	// Sign the string and return the encoded bytes
96
+	if sigBytes, err := rsa.SignPKCS1v15(rand.Reader, rsaKey, m.Hash, hasher.Sum(nil)); err == nil {
97
+		return EncodeSegment(sigBytes), nil
98
+	} else {
99
+		return "", err
100
+	}
101
+}

+ 126
- 0
vendor/github.com/dgrijalva/jwt-go/rsa_pss.go Visa fil

@@ -0,0 +1,126 @@
1
+// +build go1.4
2
+
3
+package jwt
4
+
5
+import (
6
+	"crypto"
7
+	"crypto/rand"
8
+	"crypto/rsa"
9
+)
10
+
11
+// Implements the RSAPSS family of signing methods signing methods
12
+type SigningMethodRSAPSS struct {
13
+	*SigningMethodRSA
14
+	Options *rsa.PSSOptions
15
+}
16
+
17
+// Specific instances for RS/PS and company
18
+var (
19
+	SigningMethodPS256 *SigningMethodRSAPSS
20
+	SigningMethodPS384 *SigningMethodRSAPSS
21
+	SigningMethodPS512 *SigningMethodRSAPSS
22
+)
23
+
24
+func init() {
25
+	// PS256
26
+	SigningMethodPS256 = &SigningMethodRSAPSS{
27
+		&SigningMethodRSA{
28
+			Name: "PS256",
29
+			Hash: crypto.SHA256,
30
+		},
31
+		&rsa.PSSOptions{
32
+			SaltLength: rsa.PSSSaltLengthAuto,
33
+			Hash:       crypto.SHA256,
34
+		},
35
+	}
36
+	RegisterSigningMethod(SigningMethodPS256.Alg(), func() SigningMethod {
37
+		return SigningMethodPS256
38
+	})
39
+
40
+	// PS384
41
+	SigningMethodPS384 = &SigningMethodRSAPSS{
42
+		&SigningMethodRSA{
43
+			Name: "PS384",
44
+			Hash: crypto.SHA384,
45
+		},
46
+		&rsa.PSSOptions{
47
+			SaltLength: rsa.PSSSaltLengthAuto,
48
+			Hash:       crypto.SHA384,
49
+		},
50
+	}
51
+	RegisterSigningMethod(SigningMethodPS384.Alg(), func() SigningMethod {
52
+		return SigningMethodPS384
53
+	})
54
+
55
+	// PS512
56
+	SigningMethodPS512 = &SigningMethodRSAPSS{
57
+		&SigningMethodRSA{
58
+			Name: "PS512",
59
+			Hash: crypto.SHA512,
60
+		},
61
+		&rsa.PSSOptions{
62
+			SaltLength: rsa.PSSSaltLengthAuto,
63
+			Hash:       crypto.SHA512,
64
+		},
65
+	}
66
+	RegisterSigningMethod(SigningMethodPS512.Alg(), func() SigningMethod {
67
+		return SigningMethodPS512
68
+	})
69
+}
70
+
71
+// Implements the Verify method from SigningMethod
72
+// For this verify method, key must be an rsa.PublicKey struct
73
+func (m *SigningMethodRSAPSS) Verify(signingString, signature string, key interface{}) error {
74
+	var err error
75
+
76
+	// Decode the signature
77
+	var sig []byte
78
+	if sig, err = DecodeSegment(signature); err != nil {
79
+		return err
80
+	}
81
+
82
+	var rsaKey *rsa.PublicKey
83
+	switch k := key.(type) {
84
+	case *rsa.PublicKey:
85
+		rsaKey = k
86
+	default:
87
+		return ErrInvalidKey
88
+	}
89
+
90
+	// Create hasher
91
+	if !m.Hash.Available() {
92
+		return ErrHashUnavailable
93
+	}
94
+	hasher := m.Hash.New()
95
+	hasher.Write([]byte(signingString))
96
+
97
+	return rsa.VerifyPSS(rsaKey, m.Hash, hasher.Sum(nil), sig, m.Options)
98
+}
99
+
100
+// Implements the Sign method from SigningMethod
101
+// For this signing method, key must be an rsa.PrivateKey struct
102
+func (m *SigningMethodRSAPSS) Sign(signingString string, key interface{}) (string, error) {
103
+	var rsaKey *rsa.PrivateKey
104
+
105
+	switch k := key.(type) {
106
+	case *rsa.PrivateKey:
107
+		rsaKey = k
108
+	default:
109
+		return "", ErrInvalidKeyType
110
+	}
111
+
112
+	// Create the hasher
113
+	if !m.Hash.Available() {
114
+		return "", ErrHashUnavailable
115
+	}
116
+
117
+	hasher := m.Hash.New()
118
+	hasher.Write([]byte(signingString))
119
+
120
+	// Sign the string and return the encoded bytes
121
+	if sigBytes, err := rsa.SignPSS(rand.Reader, rsaKey, m.Hash, hasher.Sum(nil), m.Options); err == nil {
122
+		return EncodeSegment(sigBytes), nil
123
+	} else {
124
+		return "", err
125
+	}
126
+}

+ 101
- 0
vendor/github.com/dgrijalva/jwt-go/rsa_utils.go Visa fil

@@ -0,0 +1,101 @@
1
+package jwt
2
+
3
+import (
4
+	"crypto/rsa"
5
+	"crypto/x509"
6
+	"encoding/pem"
7
+	"errors"
8
+)
9
+
10
+var (
11
+	ErrKeyMustBePEMEncoded = errors.New("Invalid Key: Key must be PEM encoded PKCS1 or PKCS8 private key")
12
+	ErrNotRSAPrivateKey    = errors.New("Key is not a valid RSA private key")
13
+	ErrNotRSAPublicKey     = errors.New("Key is not a valid RSA public key")
14
+)
15
+
16
+// Parse PEM encoded PKCS1 or PKCS8 private key
17
+func ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error) {
18
+	var err error
19
+
20
+	// Parse PEM block
21
+	var block *pem.Block
22
+	if block, _ = pem.Decode(key); block == nil {
23
+		return nil, ErrKeyMustBePEMEncoded
24
+	}
25
+
26
+	var parsedKey interface{}
27
+	if parsedKey, err = x509.ParsePKCS1PrivateKey(block.Bytes); err != nil {
28
+		if parsedKey, err = x509.ParsePKCS8PrivateKey(block.Bytes); err != nil {
29
+			return nil, err
30
+		}
31
+	}
32
+
33
+	var pkey *rsa.PrivateKey
34
+	var ok bool
35
+	if pkey, ok = parsedKey.(*rsa.PrivateKey); !ok {
36
+		return nil, ErrNotRSAPrivateKey
37
+	}
38
+
39
+	return pkey, nil
40
+}
41
+
42
+// Parse PEM encoded PKCS1 or PKCS8 private key protected with password
43
+func ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error) {
44
+	var err error
45
+
46
+	// Parse PEM block
47
+	var block *pem.Block
48
+	if block, _ = pem.Decode(key); block == nil {
49
+		return nil, ErrKeyMustBePEMEncoded
50
+	}
51
+
52
+	var parsedKey interface{}
53
+
54
+	var blockDecrypted []byte
55
+	if blockDecrypted, err = x509.DecryptPEMBlock(block, []byte(password)); err != nil {
56
+		return nil, err
57
+	}
58
+
59
+	if parsedKey, err = x509.ParsePKCS1PrivateKey(blockDecrypted); err != nil {
60
+		if parsedKey, err = x509.ParsePKCS8PrivateKey(blockDecrypted); err != nil {
61
+			return nil, err
62
+		}
63
+	}
64
+
65
+	var pkey *rsa.PrivateKey
66
+	var ok bool
67
+	if pkey, ok = parsedKey.(*rsa.PrivateKey); !ok {
68
+		return nil, ErrNotRSAPrivateKey
69
+	}
70
+
71
+	return pkey, nil
72
+}
73
+
74
+// Parse PEM encoded PKCS1 or PKCS8 public key
75
+func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error) {
76
+	var err error
77
+
78
+	// Parse PEM block
79
+	var block *pem.Block
80
+	if block, _ = pem.Decode(key); block == nil {
81
+		return nil, ErrKeyMustBePEMEncoded
82
+	}
83
+
84
+	// Parse the key
85
+	var parsedKey interface{}
86
+	if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err != nil {
87
+		if cert, err := x509.ParseCertificate(block.Bytes); err == nil {
88
+			parsedKey = cert.PublicKey
89
+		} else {
90
+			return nil, err
91
+		}
92
+	}
93
+
94
+	var pkey *rsa.PublicKey
95
+	var ok bool
96
+	if pkey, ok = parsedKey.(*rsa.PublicKey); !ok {
97
+		return nil, ErrNotRSAPublicKey
98
+	}
99
+
100
+	return pkey, nil
101
+}

+ 35
- 0
vendor/github.com/dgrijalva/jwt-go/signing_method.go Visa fil

@@ -0,0 +1,35 @@
1
+package jwt
2
+
3
+import (
4
+	"sync"
5
+)
6
+
7
+var signingMethods = map[string]func() SigningMethod{}
8
+var signingMethodLock = new(sync.RWMutex)
9
+
10
+// Implement SigningMethod to add new methods for signing or verifying tokens.
11
+type SigningMethod interface {
12
+	Verify(signingString, signature string, key interface{}) error // Returns nil if signature is valid
13
+	Sign(signingString string, key interface{}) (string, error)    // Returns encoded signature or error
14
+	Alg() string                                                   // returns the alg identifier for this method (example: 'HS256')
15
+}
16
+
17
+// Register the "alg" name and a factory function for signing method.
18
+// This is typically done during init() in the method's implementation
19
+func RegisterSigningMethod(alg string, f func() SigningMethod) {
20
+	signingMethodLock.Lock()
21
+	defer signingMethodLock.Unlock()
22
+
23
+	signingMethods[alg] = f
24
+}
25
+
26
+// Get a signing method from an "alg" string
27
+func GetSigningMethod(alg string) (method SigningMethod) {
28
+	signingMethodLock.RLock()
29
+	defer signingMethodLock.RUnlock()
30
+
31
+	if methodF, ok := signingMethods[alg]; ok {
32
+		method = methodF()
33
+	}
34
+	return
35
+}

+ 108
- 0
vendor/github.com/dgrijalva/jwt-go/token.go Visa fil

@@ -0,0 +1,108 @@
1
+package jwt
2
+
3
+import (
4
+	"encoding/base64"
5
+	"encoding/json"
6
+	"strings"
7
+	"time"
8
+)
9
+
10
+// TimeFunc provides the current time when parsing token to validate "exp" claim (expiration time).
11
+// You can override it to use another time value.  This is useful for testing or if your
12
+// server uses a different time zone than your tokens.
13
+var TimeFunc = time.Now
14
+
15
+// Parse methods use this callback function to supply
16
+// the key for verification.  The function receives the parsed,
17
+// but unverified Token.  This allows you to use properties in the
18
+// Header of the token (such as `kid`) to identify which key to use.
19
+type Keyfunc func(*Token) (interface{}, error)
20
+
21
+// A JWT Token.  Different fields will be used depending on whether you're
22
+// creating or parsing/verifying a token.
23
+type Token struct {
24
+	Raw       string                 // The raw token.  Populated when you Parse a token
25
+	Method    SigningMethod          // The signing method used or to be used
26
+	Header    map[string]interface{} // The first segment of the token
27
+	Claims    Claims                 // The second segment of the token
28
+	Signature string                 // The third segment of the token.  Populated when you Parse a token
29
+	Valid     bool                   // Is the token valid?  Populated when you Parse/Verify a token
30
+}
31
+
32
+// Create a new Token.  Takes a signing method
33
+func New(method SigningMethod) *Token {
34
+	return NewWithClaims(method, MapClaims{})
35
+}
36
+
37
+func NewWithClaims(method SigningMethod, claims Claims) *Token {
38
+	return &Token{
39
+		Header: map[string]interface{}{
40
+			"typ": "JWT",
41
+			"alg": method.Alg(),
42
+		},
43
+		Claims: claims,
44
+		Method: method,
45
+	}
46
+}
47
+
48
+// Get the complete, signed token
49
+func (t *Token) SignedString(key interface{}) (string, error) {
50
+	var sig, sstr string
51
+	var err error
52
+	if sstr, err = t.SigningString(); err != nil {
53
+		return "", err
54
+	}
55
+	if sig, err = t.Method.Sign(sstr, key); err != nil {
56
+		return "", err
57
+	}
58
+	return strings.Join([]string{sstr, sig}, "."), nil
59
+}
60
+
61
+// Generate the signing string.  This is the
62
+// most expensive part of the whole deal.  Unless you
63
+// need this for something special, just go straight for
64
+// the SignedString.
65
+func (t *Token) SigningString() (string, error) {
66
+	var err error
67
+	parts := make([]string, 2)
68
+	for i, _ := range parts {
69
+		var jsonValue []byte
70
+		if i == 0 {
71
+			if jsonValue, err = json.Marshal(t.Header); err != nil {
72
+				return "", err
73
+			}
74
+		} else {
75
+			if jsonValue, err = json.Marshal(t.Claims); err != nil {
76
+				return "", err
77
+			}
78
+		}
79
+
80
+		parts[i] = EncodeSegment(jsonValue)
81
+	}
82
+	return strings.Join(parts, "."), nil
83
+}
84
+
85
+// Parse, validate, and return a token.
86
+// keyFunc will receive the parsed token and should return the key for validating.
87
+// If everything is kosher, err will be nil
88
+func Parse(tokenString string, keyFunc Keyfunc) (*Token, error) {
89
+	return new(Parser).Parse(tokenString, keyFunc)
90
+}
91
+
92
+func ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) {
93
+	return new(Parser).ParseWithClaims(tokenString, claims, keyFunc)
94
+}
95
+
96
+// Encode JWT specific base64url encoding with padding stripped
97
+func EncodeSegment(seg []byte) string {
98
+	return strings.TrimRight(base64.URLEncoding.EncodeToString(seg), "=")
99
+}
100
+
101
+// Decode JWT specific base64url encoding with padding stripped
102
+func DecodeSegment(seg string) ([]byte, error) {
103
+	if l := len(seg) % 4; l > 0 {
104
+		seg += strings.Repeat("=", 4-l)
105
+	}
106
+
107
+	return base64.URLEncoding.DecodeString(seg)
108
+}

+ 3
- 2
vendor/modules.txt Visa fil

@@ -1,6 +1,9 @@
1 1
 # code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48
2 2
 ## explicit
3 3
 code.cloudfoundry.org/bytefmt
4
+# github.com/dgrijalva/jwt-go v3.2.0+incompatible
5
+## explicit
6
+github.com/dgrijalva/jwt-go
4 7
 # github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
5 8
 ## explicit
6 9
 github.com/docopt/docopt-go
@@ -15,8 +18,6 @@ github.com/go-sql-driver/mysql
15 18
 # github.com/gorilla/websocket v1.4.2
16 19
 ## explicit
17 20
 github.com/gorilla/websocket
18
-# github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940
19
-## explicit
20 21
 # github.com/goshuirc/irc-go v0.0.0-20200311142257-57fd157327ac
21 22
 ## explicit
22 23
 github.com/goshuirc/irc-go/ircfmt

Laddar…
Avbryt
Spara