Proyecto audio control. inicado con panel y control.
This commit is contained in:
21
node_modules/jsonwebtoken/LICENSE
generated
vendored
Normal file
21
node_modules/jsonwebtoken/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Auth0, Inc. <support@auth0.com> (http://auth0.com)
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
396
node_modules/jsonwebtoken/README.md
generated
vendored
Normal file
396
node_modules/jsonwebtoken/README.md
generated
vendored
Normal file
@@ -0,0 +1,396 @@
|
||||
# jsonwebtoken
|
||||
|
||||
| **Build** | **Dependency** |
|
||||
|-----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
|
||||
| [](http://travis-ci.org/auth0/node-jsonwebtoken) | [](https://david-dm.org/auth0/node-jsonwebtoken) |
|
||||
|
||||
|
||||
An implementation of [JSON Web Tokens](https://tools.ietf.org/html/rfc7519).
|
||||
|
||||
This was developed against `draft-ietf-oauth-json-web-token-08`. It makes use of [node-jws](https://github.com/brianloveswords/node-jws)
|
||||
|
||||
# Install
|
||||
|
||||
```bash
|
||||
$ npm install jsonwebtoken
|
||||
```
|
||||
|
||||
# Migration notes
|
||||
|
||||
* [From v8 to v9](https://github.com/auth0/node-jsonwebtoken/wiki/Migration-Notes:-v8-to-v9)
|
||||
* [From v7 to v8](https://github.com/auth0/node-jsonwebtoken/wiki/Migration-Notes:-v7-to-v8)
|
||||
|
||||
# Usage
|
||||
|
||||
### jwt.sign(payload, secretOrPrivateKey, [options, callback])
|
||||
|
||||
(Asynchronous) If a callback is supplied, the callback is called with the `err` or the JWT.
|
||||
|
||||
(Synchronous) Returns the JsonWebToken as string
|
||||
|
||||
`payload` could be an object literal, buffer or string representing valid JSON.
|
||||
> **Please _note_ that** `exp` or any other claim is only set if the payload is an object literal. Buffer or string payloads are not checked for JSON validity.
|
||||
|
||||
> If `payload` is not a buffer or a string, it will be coerced into a string using `JSON.stringify`.
|
||||
|
||||
`secretOrPrivateKey` is a string (utf-8 encoded), buffer, object, or KeyObject containing either the secret for HMAC algorithms or the PEM
|
||||
encoded private key for RSA and ECDSA. In case of a private key with passphrase an object `{ key, passphrase }` can be used (based on [crypto documentation](https://nodejs.org/api/crypto.html#crypto_sign_sign_private_key_output_format)), in this case be sure you pass the `algorithm` option.
|
||||
When signing with RSA algorithms the minimum modulus length is 2048 except when the allowInsecureKeySizes option is set to true. Private keys below this size will be rejected with an error.
|
||||
|
||||
`options`:
|
||||
|
||||
* `algorithm` (default: `HS256`)
|
||||
* `expiresIn`: expressed in seconds or a string describing a time span [vercel/ms](https://github.com/vercel/ms).
|
||||
> Eg: `60`, `"2 days"`, `"10h"`, `"7d"`. A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc), otherwise milliseconds unit is used by default (`"120"` is equal to `"120ms"`).
|
||||
* `notBefore`: expressed in seconds or a string describing a time span [vercel/ms](https://github.com/vercel/ms).
|
||||
> Eg: `60`, `"2 days"`, `"10h"`, `"7d"`. A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc), otherwise milliseconds unit is used by default (`"120"` is equal to `"120ms"`).
|
||||
* `audience`
|
||||
* `issuer`
|
||||
* `jwtid`
|
||||
* `subject`
|
||||
* `noTimestamp`
|
||||
* `header`
|
||||
* `keyid`
|
||||
* `mutatePayload`: if true, the sign function will modify the payload object directly. This is useful if you need a raw reference to the payload after claims have been applied to it but before it has been encoded into a token.
|
||||
* `allowInsecureKeySizes`: if true allows private keys with a modulus below 2048 to be used for RSA
|
||||
* `allowInvalidAsymmetricKeyTypes`: if true, allows asymmetric keys which do not match the specified algorithm. This option is intended only for backwards compatability and should be avoided.
|
||||
|
||||
|
||||
|
||||
> There are no default values for `expiresIn`, `notBefore`, `audience`, `subject`, `issuer`. These claims can also be provided in the payload directly with `exp`, `nbf`, `aud`, `sub` and `iss` respectively, but you **_can't_** include in both places.
|
||||
|
||||
Remember that `exp`, `nbf` and `iat` are **NumericDate**, see related [Token Expiration (exp claim)](#token-expiration-exp-claim)
|
||||
|
||||
|
||||
The header can be customized via the `options.header` object.
|
||||
|
||||
Generated jwts will include an `iat` (issued at) claim by default unless `noTimestamp` is specified. If `iat` is inserted in the payload, it will be used instead of the real timestamp for calculating other things like `exp` given a timespan in `options.expiresIn`.
|
||||
|
||||
Synchronous Sign with default (HMAC SHA256)
|
||||
|
||||
```js
|
||||
var jwt = require('jsonwebtoken');
|
||||
var token = jwt.sign({ foo: 'bar' }, 'shhhhh');
|
||||
```
|
||||
|
||||
Synchronous Sign with RSA SHA256
|
||||
```js
|
||||
// sign with RSA SHA256
|
||||
var privateKey = fs.readFileSync('private.key');
|
||||
var token = jwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256' });
|
||||
```
|
||||
|
||||
Sign asynchronously
|
||||
```js
|
||||
jwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256' }, function(err, token) {
|
||||
console.log(token);
|
||||
});
|
||||
```
|
||||
|
||||
Backdate a jwt 30 seconds
|
||||
```js
|
||||
var older_token = jwt.sign({ foo: 'bar', iat: Math.floor(Date.now() / 1000) - 30 }, 'shhhhh');
|
||||
```
|
||||
|
||||
#### Token Expiration (exp claim)
|
||||
|
||||
The standard for JWT defines an `exp` claim for expiration. The expiration is represented as a **NumericDate**:
|
||||
|
||||
> A JSON numeric value representing the number of seconds from 1970-01-01T00:00:00Z UTC until the specified UTC date/time, ignoring leap seconds. This is equivalent to the IEEE Std 1003.1, 2013 Edition [POSIX.1] definition "Seconds Since the Epoch", in which each day is accounted for by exactly 86400 seconds, other than that non-integer values can be represented. See RFC 3339 [RFC3339] for details regarding date/times in general and UTC in particular.
|
||||
|
||||
This means that the `exp` field should contain the number of seconds since the epoch.
|
||||
|
||||
Signing a token with 1 hour of expiration:
|
||||
|
||||
```javascript
|
||||
jwt.sign({
|
||||
exp: Math.floor(Date.now() / 1000) + (60 * 60),
|
||||
data: 'foobar'
|
||||
}, 'secret');
|
||||
```
|
||||
|
||||
Another way to generate a token like this with this library is:
|
||||
|
||||
```javascript
|
||||
jwt.sign({
|
||||
data: 'foobar'
|
||||
}, 'secret', { expiresIn: 60 * 60 });
|
||||
|
||||
//or even better:
|
||||
|
||||
jwt.sign({
|
||||
data: 'foobar'
|
||||
}, 'secret', { expiresIn: '1h' });
|
||||
```
|
||||
|
||||
### jwt.verify(token, secretOrPublicKey, [options, callback])
|
||||
|
||||
(Asynchronous) If a callback is supplied, function acts asynchronously. The callback is called with the decoded payload if the signature is valid and optional expiration, audience, or issuer are valid. If not, it will be called with the error.
|
||||
|
||||
(Synchronous) If a callback is not supplied, function acts synchronously. Returns the payload decoded if the signature is valid and optional expiration, audience, or issuer are valid. If not, it will throw the error.
|
||||
|
||||
> __Warning:__ When the token comes from an untrusted source (e.g. user input or external requests), the returned decoded payload should be treated like any other user input; please make sure to sanitize and only work with properties that are expected
|
||||
|
||||
`token` is the JsonWebToken string
|
||||
|
||||
`secretOrPublicKey` is a string (utf-8 encoded), buffer, or KeyObject containing either the secret for HMAC algorithms, or the PEM
|
||||
encoded public key for RSA and ECDSA.
|
||||
If `jwt.verify` is called asynchronous, `secretOrPublicKey` can be a function that should fetch the secret or public key. See below for a detailed example
|
||||
|
||||
As mentioned in [this comment](https://github.com/auth0/node-jsonwebtoken/issues/208#issuecomment-231861138), there are other libraries that expect base64 encoded secrets (random bytes encoded using base64), if that is your case you can pass `Buffer.from(secret, 'base64')`, by doing this the secret will be decoded using base64 and the token verification will use the original random bytes.
|
||||
|
||||
`options`
|
||||
|
||||
* `algorithms`: List of strings with the names of the allowed algorithms. For instance, `["HS256", "HS384"]`.
|
||||
> If not specified a defaults will be used based on the type of key provided
|
||||
> * secret - ['HS256', 'HS384', 'HS512']
|
||||
> * rsa - ['RS256', 'RS384', 'RS512']
|
||||
> * ec - ['ES256', 'ES384', 'ES512']
|
||||
> * default - ['RS256', 'RS384', 'RS512']
|
||||
* `audience`: if you want to check audience (`aud`), provide a value here. The audience can be checked against a string, a regular expression or a list of strings and/or regular expressions.
|
||||
> Eg: `"urn:foo"`, `/urn:f[o]{2}/`, `[/urn:f[o]{2}/, "urn:bar"]`
|
||||
* `complete`: return an object with the decoded `{ payload, header, signature }` instead of only the usual content of the payload.
|
||||
* `issuer` (optional): string or array of strings of valid values for the `iss` field.
|
||||
* `jwtid` (optional): if you want to check JWT ID (`jti`), provide a string value here.
|
||||
* `ignoreExpiration`: if `true` do not validate the expiration of the token.
|
||||
* `ignoreNotBefore`...
|
||||
* `subject`: if you want to check subject (`sub`), provide a value here
|
||||
* `clockTolerance`: number of seconds to tolerate when checking the `nbf` and `exp` claims, to deal with small clock differences among different servers
|
||||
* `maxAge`: the maximum allowed age for tokens to still be valid. It is expressed in seconds or a string describing a time span [vercel/ms](https://github.com/vercel/ms).
|
||||
> Eg: `1000`, `"2 days"`, `"10h"`, `"7d"`. A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc), otherwise milliseconds unit is used by default (`"120"` is equal to `"120ms"`).
|
||||
* `clockTimestamp`: the time in seconds that should be used as the current time for all necessary comparisons.
|
||||
* `nonce`: if you want to check `nonce` claim, provide a string value here. It is used on Open ID for the ID Tokens. ([Open ID implementation notes](https://openid.net/specs/openid-connect-core-1_0.html#NonceNotes))
|
||||
* `allowInvalidAsymmetricKeyTypes`: if true, allows asymmetric keys which do not match the specified algorithm. This option is intended only for backwards compatability and should be avoided.
|
||||
|
||||
```js
|
||||
// verify a token symmetric - synchronous
|
||||
var decoded = jwt.verify(token, 'shhhhh');
|
||||
console.log(decoded.foo) // bar
|
||||
|
||||
// verify a token symmetric
|
||||
jwt.verify(token, 'shhhhh', function(err, decoded) {
|
||||
console.log(decoded.foo) // bar
|
||||
});
|
||||
|
||||
// invalid token - synchronous
|
||||
try {
|
||||
var decoded = jwt.verify(token, 'wrong-secret');
|
||||
} catch(err) {
|
||||
// err
|
||||
}
|
||||
|
||||
// invalid token
|
||||
jwt.verify(token, 'wrong-secret', function(err, decoded) {
|
||||
// err
|
||||
// decoded undefined
|
||||
});
|
||||
|
||||
// verify a token asymmetric
|
||||
var cert = fs.readFileSync('public.pem'); // get public key
|
||||
jwt.verify(token, cert, function(err, decoded) {
|
||||
console.log(decoded.foo) // bar
|
||||
});
|
||||
|
||||
// verify audience
|
||||
var cert = fs.readFileSync('public.pem'); // get public key
|
||||
jwt.verify(token, cert, { audience: 'urn:foo' }, function(err, decoded) {
|
||||
// if audience mismatch, err == invalid audience
|
||||
});
|
||||
|
||||
// verify issuer
|
||||
var cert = fs.readFileSync('public.pem'); // get public key
|
||||
jwt.verify(token, cert, { audience: 'urn:foo', issuer: 'urn:issuer' }, function(err, decoded) {
|
||||
// if issuer mismatch, err == invalid issuer
|
||||
});
|
||||
|
||||
// verify jwt id
|
||||
var cert = fs.readFileSync('public.pem'); // get public key
|
||||
jwt.verify(token, cert, { audience: 'urn:foo', issuer: 'urn:issuer', jwtid: 'jwtid' }, function(err, decoded) {
|
||||
// if jwt id mismatch, err == invalid jwt id
|
||||
});
|
||||
|
||||
// verify subject
|
||||
var cert = fs.readFileSync('public.pem'); // get public key
|
||||
jwt.verify(token, cert, { audience: 'urn:foo', issuer: 'urn:issuer', jwtid: 'jwtid', subject: 'subject' }, function(err, decoded) {
|
||||
// if subject mismatch, err == invalid subject
|
||||
});
|
||||
|
||||
// alg mismatch
|
||||
var cert = fs.readFileSync('public.pem'); // get public key
|
||||
jwt.verify(token, cert, { algorithms: ['RS256'] }, function (err, payload) {
|
||||
// if token alg != RS256, err == invalid signature
|
||||
});
|
||||
|
||||
// Verify using getKey callback
|
||||
// Example uses https://github.com/auth0/node-jwks-rsa as a way to fetch the keys.
|
||||
var jwksClient = require('jwks-rsa');
|
||||
var client = jwksClient({
|
||||
jwksUri: 'https://sandrino.auth0.com/.well-known/jwks.json'
|
||||
});
|
||||
function getKey(header, callback){
|
||||
client.getSigningKey(header.kid, function(err, key) {
|
||||
var signingKey = key.publicKey || key.rsaPublicKey;
|
||||
callback(null, signingKey);
|
||||
});
|
||||
}
|
||||
|
||||
jwt.verify(token, getKey, options, function(err, decoded) {
|
||||
console.log(decoded.foo) // bar
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary><em></em>Need to peek into a JWT without verifying it? (Click to expand)</summary>
|
||||
|
||||
### jwt.decode(token [, options])
|
||||
|
||||
(Synchronous) Returns the decoded payload without verifying if the signature is valid.
|
||||
|
||||
> __Warning:__ This will __not__ verify whether the signature is valid. You should __not__ use this for untrusted messages. You most likely want to use `jwt.verify` instead.
|
||||
|
||||
> __Warning:__ When the token comes from an untrusted source (e.g. user input or external request), the returned decoded payload should be treated like any other user input; please make sure to sanitize and only work with properties that are expected
|
||||
|
||||
|
||||
`token` is the JsonWebToken string
|
||||
|
||||
`options`:
|
||||
|
||||
* `json`: force JSON.parse on the payload even if the header doesn't contain `"typ":"JWT"`.
|
||||
* `complete`: return an object with the decoded payload and header.
|
||||
|
||||
Example
|
||||
|
||||
```js
|
||||
// get the decoded payload ignoring signature, no secretOrPrivateKey needed
|
||||
var decoded = jwt.decode(token);
|
||||
|
||||
// get the decoded payload and header
|
||||
var decoded = jwt.decode(token, {complete: true});
|
||||
console.log(decoded.header);
|
||||
console.log(decoded.payload)
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## Errors & Codes
|
||||
Possible thrown errors during verification.
|
||||
Error is the first argument of the verification callback.
|
||||
|
||||
### TokenExpiredError
|
||||
|
||||
Thrown error if the token is expired.
|
||||
|
||||
Error object:
|
||||
|
||||
* name: 'TokenExpiredError'
|
||||
* message: 'jwt expired'
|
||||
* expiredAt: [ExpDate]
|
||||
|
||||
```js
|
||||
jwt.verify(token, 'shhhhh', function(err, decoded) {
|
||||
if (err) {
|
||||
/*
|
||||
err = {
|
||||
name: 'TokenExpiredError',
|
||||
message: 'jwt expired',
|
||||
expiredAt: 1408621000
|
||||
}
|
||||
*/
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### JsonWebTokenError
|
||||
Error object:
|
||||
|
||||
* name: 'JsonWebTokenError'
|
||||
* message:
|
||||
* 'invalid token' - the header or payload could not be parsed
|
||||
* 'jwt malformed' - the token does not have three components (delimited by a `.`)
|
||||
* 'jwt signature is required'
|
||||
* 'invalid signature'
|
||||
* 'jwt audience invalid. expected: [OPTIONS AUDIENCE]'
|
||||
* 'jwt issuer invalid. expected: [OPTIONS ISSUER]'
|
||||
* 'jwt id invalid. expected: [OPTIONS JWT ID]'
|
||||
* 'jwt subject invalid. expected: [OPTIONS SUBJECT]'
|
||||
|
||||
```js
|
||||
jwt.verify(token, 'shhhhh', function(err, decoded) {
|
||||
if (err) {
|
||||
/*
|
||||
err = {
|
||||
name: 'JsonWebTokenError',
|
||||
message: 'jwt malformed'
|
||||
}
|
||||
*/
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### NotBeforeError
|
||||
Thrown if current time is before the nbf claim.
|
||||
|
||||
Error object:
|
||||
|
||||
* name: 'NotBeforeError'
|
||||
* message: 'jwt not active'
|
||||
* date: 2018-10-04T16:10:44.000Z
|
||||
|
||||
```js
|
||||
jwt.verify(token, 'shhhhh', function(err, decoded) {
|
||||
if (err) {
|
||||
/*
|
||||
err = {
|
||||
name: 'NotBeforeError',
|
||||
message: 'jwt not active',
|
||||
date: 2018-10-04T16:10:44.000Z
|
||||
}
|
||||
*/
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Algorithms supported
|
||||
|
||||
Array of supported algorithms. The following algorithms are currently supported.
|
||||
|
||||
| alg Parameter Value | Digital Signature or MAC Algorithm |
|
||||
|---------------------|------------------------------------------------------------------------|
|
||||
| HS256 | HMAC using SHA-256 hash algorithm |
|
||||
| HS384 | HMAC using SHA-384 hash algorithm |
|
||||
| HS512 | HMAC using SHA-512 hash algorithm |
|
||||
| RS256 | RSASSA-PKCS1-v1_5 using SHA-256 hash algorithm |
|
||||
| RS384 | RSASSA-PKCS1-v1_5 using SHA-384 hash algorithm |
|
||||
| RS512 | RSASSA-PKCS1-v1_5 using SHA-512 hash algorithm |
|
||||
| PS256 | RSASSA-PSS using SHA-256 hash algorithm (only node ^6.12.0 OR >=8.0.0) |
|
||||
| PS384 | RSASSA-PSS using SHA-384 hash algorithm (only node ^6.12.0 OR >=8.0.0) |
|
||||
| PS512 | RSASSA-PSS using SHA-512 hash algorithm (only node ^6.12.0 OR >=8.0.0) |
|
||||
| ES256 | ECDSA using P-256 curve and SHA-256 hash algorithm |
|
||||
| ES384 | ECDSA using P-384 curve and SHA-384 hash algorithm |
|
||||
| ES512 | ECDSA using P-521 curve and SHA-512 hash algorithm |
|
||||
| none | No digital signature or MAC value included |
|
||||
|
||||
## Refreshing JWTs
|
||||
|
||||
First of all, we recommend you to think carefully if auto-refreshing a JWT will not introduce any vulnerability in your system.
|
||||
|
||||
We are not comfortable including this as part of the library, however, you can take a look at [this example](https://gist.github.com/ziluvatar/a3feb505c4c0ec37059054537b38fc48) to show how this could be accomplished.
|
||||
Apart from that example there are [an issue](https://github.com/auth0/node-jsonwebtoken/issues/122) and [a pull request](https://github.com/auth0/node-jsonwebtoken/pull/172) to get more knowledge about this topic.
|
||||
|
||||
# TODO
|
||||
|
||||
* X.509 certificate chain is not checked
|
||||
|
||||
## Issue Reporting
|
||||
|
||||
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.
|
||||
|
||||
## Author
|
||||
|
||||
[Auth0](https://auth0.com)
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.
|
||||
30
node_modules/jsonwebtoken/decode.js
generated
vendored
Normal file
30
node_modules/jsonwebtoken/decode.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var jws = require('jws');
|
||||
|
||||
module.exports = function (jwt, options) {
|
||||
options = options || {};
|
||||
var decoded = jws.decode(jwt, options);
|
||||
if (!decoded) { return null; }
|
||||
var payload = decoded.payload;
|
||||
|
||||
//try parse the payload
|
||||
if(typeof payload === 'string') {
|
||||
try {
|
||||
var obj = JSON.parse(payload);
|
||||
if(obj !== null && typeof obj === 'object') {
|
||||
payload = obj;
|
||||
}
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
//return header if `complete` option is enabled. header includes claims
|
||||
//such as `kid` and `alg` used to select the key within a JWKS needed to
|
||||
//verify the signature
|
||||
if (options.complete === true) {
|
||||
return {
|
||||
header: decoded.header,
|
||||
payload: payload,
|
||||
signature: decoded.signature
|
||||
};
|
||||
}
|
||||
return payload;
|
||||
};
|
||||
8
node_modules/jsonwebtoken/index.js
generated
vendored
Normal file
8
node_modules/jsonwebtoken/index.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
decode: require('./decode'),
|
||||
verify: require('./verify'),
|
||||
sign: require('./sign'),
|
||||
JsonWebTokenError: require('./lib/JsonWebTokenError'),
|
||||
NotBeforeError: require('./lib/NotBeforeError'),
|
||||
TokenExpiredError: require('./lib/TokenExpiredError'),
|
||||
};
|
||||
14
node_modules/jsonwebtoken/lib/JsonWebTokenError.js
generated
vendored
Normal file
14
node_modules/jsonwebtoken/lib/JsonWebTokenError.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
var JsonWebTokenError = function (message, error) {
|
||||
Error.call(this, message);
|
||||
if(Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
this.name = 'JsonWebTokenError';
|
||||
this.message = message;
|
||||
if (error) this.inner = error;
|
||||
};
|
||||
|
||||
JsonWebTokenError.prototype = Object.create(Error.prototype);
|
||||
JsonWebTokenError.prototype.constructor = JsonWebTokenError;
|
||||
|
||||
module.exports = JsonWebTokenError;
|
||||
13
node_modules/jsonwebtoken/lib/NotBeforeError.js
generated
vendored
Normal file
13
node_modules/jsonwebtoken/lib/NotBeforeError.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
var JsonWebTokenError = require('./JsonWebTokenError');
|
||||
|
||||
var NotBeforeError = function (message, date) {
|
||||
JsonWebTokenError.call(this, message);
|
||||
this.name = 'NotBeforeError';
|
||||
this.date = date;
|
||||
};
|
||||
|
||||
NotBeforeError.prototype = Object.create(JsonWebTokenError.prototype);
|
||||
|
||||
NotBeforeError.prototype.constructor = NotBeforeError;
|
||||
|
||||
module.exports = NotBeforeError;
|
||||
13
node_modules/jsonwebtoken/lib/TokenExpiredError.js
generated
vendored
Normal file
13
node_modules/jsonwebtoken/lib/TokenExpiredError.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
var JsonWebTokenError = require('./JsonWebTokenError');
|
||||
|
||||
var TokenExpiredError = function (message, expiredAt) {
|
||||
JsonWebTokenError.call(this, message);
|
||||
this.name = 'TokenExpiredError';
|
||||
this.expiredAt = expiredAt;
|
||||
};
|
||||
|
||||
TokenExpiredError.prototype = Object.create(JsonWebTokenError.prototype);
|
||||
|
||||
TokenExpiredError.prototype.constructor = TokenExpiredError;
|
||||
|
||||
module.exports = TokenExpiredError;
|
||||
3
node_modules/jsonwebtoken/lib/asymmetricKeyDetailsSupported.js
generated
vendored
Normal file
3
node_modules/jsonwebtoken/lib/asymmetricKeyDetailsSupported.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
const semver = require('semver');
|
||||
|
||||
module.exports = semver.satisfies(process.version, '>=15.7.0');
|
||||
3
node_modules/jsonwebtoken/lib/psSupported.js
generated
vendored
Normal file
3
node_modules/jsonwebtoken/lib/psSupported.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var semver = require('semver');
|
||||
|
||||
module.exports = semver.satisfies(process.version, '^6.12.0 || >=8.0.0');
|
||||
3
node_modules/jsonwebtoken/lib/rsaPssKeyDetailsSupported.js
generated
vendored
Normal file
3
node_modules/jsonwebtoken/lib/rsaPssKeyDetailsSupported.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
const semver = require('semver');
|
||||
|
||||
module.exports = semver.satisfies(process.version, '>=16.9.0');
|
||||
18
node_modules/jsonwebtoken/lib/timespan.js
generated
vendored
Normal file
18
node_modules/jsonwebtoken/lib/timespan.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
var ms = require('ms');
|
||||
|
||||
module.exports = function (time, iat) {
|
||||
var timestamp = iat || Math.floor(Date.now() / 1000);
|
||||
|
||||
if (typeof time === 'string') {
|
||||
var milliseconds = ms(time);
|
||||
if (typeof milliseconds === 'undefined') {
|
||||
return;
|
||||
}
|
||||
return Math.floor(timestamp + milliseconds / 1000);
|
||||
} else if (typeof time === 'number') {
|
||||
return timestamp + time;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
66
node_modules/jsonwebtoken/lib/validateAsymmetricKey.js
generated
vendored
Normal file
66
node_modules/jsonwebtoken/lib/validateAsymmetricKey.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
const ASYMMETRIC_KEY_DETAILS_SUPPORTED = require('./asymmetricKeyDetailsSupported');
|
||||
const RSA_PSS_KEY_DETAILS_SUPPORTED = require('./rsaPssKeyDetailsSupported');
|
||||
|
||||
const allowedAlgorithmsForKeys = {
|
||||
'ec': ['ES256', 'ES384', 'ES512'],
|
||||
'rsa': ['RS256', 'PS256', 'RS384', 'PS384', 'RS512', 'PS512'],
|
||||
'rsa-pss': ['PS256', 'PS384', 'PS512']
|
||||
};
|
||||
|
||||
const allowedCurves = {
|
||||
ES256: 'prime256v1',
|
||||
ES384: 'secp384r1',
|
||||
ES512: 'secp521r1',
|
||||
};
|
||||
|
||||
module.exports = function(algorithm, key) {
|
||||
if (!algorithm || !key) return;
|
||||
|
||||
const keyType = key.asymmetricKeyType;
|
||||
if (!keyType) return;
|
||||
|
||||
const allowedAlgorithms = allowedAlgorithmsForKeys[keyType];
|
||||
|
||||
if (!allowedAlgorithms) {
|
||||
throw new Error(`Unknown key type "${keyType}".`);
|
||||
}
|
||||
|
||||
if (!allowedAlgorithms.includes(algorithm)) {
|
||||
throw new Error(`"alg" parameter for "${keyType}" key type must be one of: ${allowedAlgorithms.join(', ')}.`)
|
||||
}
|
||||
|
||||
/*
|
||||
* Ignore the next block from test coverage because it gets executed
|
||||
* conditionally depending on the Node version. Not ignoring it would
|
||||
* prevent us from reaching the target % of coverage for versions of
|
||||
* Node under 15.7.0.
|
||||
*/
|
||||
/* istanbul ignore next */
|
||||
if (ASYMMETRIC_KEY_DETAILS_SUPPORTED) {
|
||||
switch (keyType) {
|
||||
case 'ec':
|
||||
const keyCurve = key.asymmetricKeyDetails.namedCurve;
|
||||
const allowedCurve = allowedCurves[algorithm];
|
||||
|
||||
if (keyCurve !== allowedCurve) {
|
||||
throw new Error(`"alg" parameter "${algorithm}" requires curve "${allowedCurve}".`);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'rsa-pss':
|
||||
if (RSA_PSS_KEY_DETAILS_SUPPORTED) {
|
||||
const length = parseInt(algorithm.slice(-3), 10);
|
||||
const { hashAlgorithm, mgf1HashAlgorithm, saltLength } = key.asymmetricKeyDetails;
|
||||
|
||||
if (hashAlgorithm !== `sha${length}` || mgf1HashAlgorithm !== hashAlgorithm) {
|
||||
throw new Error(`Invalid key for this operation, its RSA-PSS parameters do not meet the requirements of "alg" ${algorithm}.`);
|
||||
}
|
||||
|
||||
if (saltLength !== undefined && saltLength > length >> 3) {
|
||||
throw new Error(`Invalid key for this operation, its RSA-PSS parameter saltLength does not meet the requirements of "alg" ${algorithm}.`)
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
node_modules/jsonwebtoken/node_modules/jwa/LICENSE
generated
vendored
Normal file
17
node_modules/jsonwebtoken/node_modules/jwa/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
Copyright (c) 2013 Brian J. Brennan
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
150
node_modules/jsonwebtoken/node_modules/jwa/README.md
generated
vendored
Normal file
150
node_modules/jsonwebtoken/node_modules/jwa/README.md
generated
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
# node-jwa [](https://travis-ci.org/brianloveswords/node-jwa)
|
||||
|
||||
A
|
||||
[JSON Web Algorithms](http://tools.ietf.org/id/draft-ietf-jose-json-web-algorithms-08.html)
|
||||
implementation focusing (exclusively, at this point) on the algorithms necessary for
|
||||
[JSON Web Signatures](http://self-issued.info/docs/draft-ietf-jose-json-web-signature.html).
|
||||
|
||||
This library supports all of the required, recommended and optional cryptographic algorithms for JWS:
|
||||
|
||||
alg Parameter Value | Digital Signature or MAC Algorithm
|
||||
----------------|----------------------------
|
||||
HS256 | HMAC using SHA-256 hash algorithm
|
||||
HS384 | HMAC using SHA-384 hash algorithm
|
||||
HS512 | HMAC using SHA-512 hash algorithm
|
||||
RS256 | RSASSA using SHA-256 hash algorithm
|
||||
RS384 | RSASSA using SHA-384 hash algorithm
|
||||
RS512 | RSASSA using SHA-512 hash algorithm
|
||||
PS256 | RSASSA-PSS using SHA-256 hash algorithm
|
||||
PS384 | RSASSA-PSS using SHA-384 hash algorithm
|
||||
PS512 | RSASSA-PSS using SHA-512 hash algorithm
|
||||
ES256 | ECDSA using P-256 curve and SHA-256 hash algorithm
|
||||
ES384 | ECDSA using P-384 curve and SHA-384 hash algorithm
|
||||
ES512 | ECDSA using P-521 curve and SHA-512 hash algorithm
|
||||
none | No digital signature or MAC value included
|
||||
|
||||
Please note that PS* only works on Node 6.12+ (excluding 7.x).
|
||||
|
||||
# Requirements
|
||||
|
||||
In order to run the tests, a recent version of OpenSSL is
|
||||
required. **The version that comes with OS X (OpenSSL 0.9.8r 8 Feb
|
||||
2011) is not recent enough**, as it does not fully support ECDSA
|
||||
keys. You'll need to use a version > 1.0.0; I tested with OpenSSL 1.0.1c 10 May 2012.
|
||||
|
||||
# Testing
|
||||
|
||||
To run the tests, do
|
||||
|
||||
```bash
|
||||
$ npm test
|
||||
```
|
||||
|
||||
This will generate a bunch of keypairs to use in testing. If you want to
|
||||
generate new keypairs, do `make clean` before running `npm test` again.
|
||||
|
||||
## Methodology
|
||||
|
||||
I spawn `openssl dgst -sign` to test OpenSSL sign → JS verify and
|
||||
`openssl dgst -verify` to test JS sign → OpenSSL verify for each of the
|
||||
RSA and ECDSA algorithms.
|
||||
|
||||
# Usage
|
||||
|
||||
## jwa(algorithm)
|
||||
|
||||
Creates a new `jwa` object with `sign` and `verify` methods for the
|
||||
algorithm. Valid values for algorithm can be found in the table above
|
||||
(`'HS256'`, `'HS384'`, etc) and are case-insensitive. Passing an invalid
|
||||
algorithm value will throw a `TypeError`.
|
||||
|
||||
|
||||
## jwa#sign(input, secretOrPrivateKey)
|
||||
|
||||
Sign some input with either a secret for HMAC algorithms, or a private
|
||||
key for RSA and ECDSA algorithms.
|
||||
|
||||
If input is not already a string or buffer, `JSON.stringify` will be
|
||||
called on it to attempt to coerce it.
|
||||
|
||||
For the HMAC algorithm, `secretOrPrivateKey` should be a string or a
|
||||
buffer. For ECDSA and RSA, the value should be a string representing a
|
||||
PEM encoded **private** key.
|
||||
|
||||
Output [base64url](http://en.wikipedia.org/wiki/Base64#URL_applications)
|
||||
formatted. This is for convenience as JWS expects the signature in this
|
||||
format. If your application needs the output in a different format,
|
||||
[please open an issue](https://github.com/brianloveswords/node-jwa/issues). In
|
||||
the meantime, you can use
|
||||
[brianloveswords/base64url](https://github.com/brianloveswords/base64url)
|
||||
to decode the signature.
|
||||
|
||||
As of nodejs *v0.11.8*, SPKAC support was introduce. If your nodeJs
|
||||
version satisfies, then you can pass an object `{ key: '..', passphrase: '...' }`
|
||||
|
||||
|
||||
## jwa#verify(input, signature, secretOrPublicKey)
|
||||
|
||||
Verify a signature. Returns `true` or `false`.
|
||||
|
||||
`signature` should be a base64url encoded string.
|
||||
|
||||
For the HMAC algorithm, `secretOrPublicKey` should be a string or a
|
||||
buffer. For ECDSA and RSA, the value should be a string represented a
|
||||
PEM encoded **public** key.
|
||||
|
||||
|
||||
# Example
|
||||
|
||||
HMAC
|
||||
```js
|
||||
const jwa = require('jwa');
|
||||
|
||||
const hmac = jwa('HS256');
|
||||
const input = 'super important stuff';
|
||||
const secret = 'shhhhhh';
|
||||
|
||||
const signature = hmac.sign(input, secret);
|
||||
hmac.verify(input, signature, secret) // === true
|
||||
hmac.verify(input, signature, 'trickery!') // === false
|
||||
```
|
||||
|
||||
With keys
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const jwa = require('jwa');
|
||||
const privateKey = fs.readFileSync(__dirname + '/ecdsa-p521-private.pem');
|
||||
const publicKey = fs.readFileSync(__dirname + '/ecdsa-p521-public.pem');
|
||||
|
||||
const ecdsa = jwa('ES512');
|
||||
const input = 'very important stuff';
|
||||
|
||||
const signature = ecdsa.sign(input, privateKey);
|
||||
ecdsa.verify(input, signature, publicKey) // === true
|
||||
```
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
```
|
||||
Copyright (c) 2013 Brian J. Brennan
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
```
|
||||
266
node_modules/jsonwebtoken/node_modules/jwa/index.js
generated
vendored
Normal file
266
node_modules/jsonwebtoken/node_modules/jwa/index.js
generated
vendored
Normal file
@@ -0,0 +1,266 @@
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
var crypto = require('crypto');
|
||||
var formatEcdsa = require('ecdsa-sig-formatter');
|
||||
var util = require('util');
|
||||
|
||||
var MSG_INVALID_ALGORITHM = '"%s" is not a valid algorithm.\n Supported algorithms are:\n "HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "ES256", "ES384", "ES512" and "none".'
|
||||
var MSG_INVALID_SECRET = 'secret must be a string or buffer';
|
||||
var MSG_INVALID_VERIFIER_KEY = 'key must be a string or a buffer';
|
||||
var MSG_INVALID_SIGNER_KEY = 'key must be a string, a buffer or an object';
|
||||
|
||||
var supportsKeyObjects = typeof crypto.createPublicKey === 'function';
|
||||
if (supportsKeyObjects) {
|
||||
MSG_INVALID_VERIFIER_KEY += ' or a KeyObject';
|
||||
MSG_INVALID_SECRET += 'or a KeyObject';
|
||||
}
|
||||
|
||||
function checkIsPublicKey(key) {
|
||||
if (Buffer.isBuffer(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof key === 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!supportsKeyObjects) {
|
||||
throw typeError(MSG_INVALID_VERIFIER_KEY);
|
||||
}
|
||||
|
||||
if (typeof key !== 'object') {
|
||||
throw typeError(MSG_INVALID_VERIFIER_KEY);
|
||||
}
|
||||
|
||||
if (typeof key.type !== 'string') {
|
||||
throw typeError(MSG_INVALID_VERIFIER_KEY);
|
||||
}
|
||||
|
||||
if (typeof key.asymmetricKeyType !== 'string') {
|
||||
throw typeError(MSG_INVALID_VERIFIER_KEY);
|
||||
}
|
||||
|
||||
if (typeof key.export !== 'function') {
|
||||
throw typeError(MSG_INVALID_VERIFIER_KEY);
|
||||
}
|
||||
};
|
||||
|
||||
function checkIsPrivateKey(key) {
|
||||
if (Buffer.isBuffer(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof key === 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof key === 'object') {
|
||||
return;
|
||||
}
|
||||
|
||||
throw typeError(MSG_INVALID_SIGNER_KEY);
|
||||
};
|
||||
|
||||
function checkIsSecretKey(key) {
|
||||
if (Buffer.isBuffer(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof key === 'string') {
|
||||
return key;
|
||||
}
|
||||
|
||||
if (!supportsKeyObjects) {
|
||||
throw typeError(MSG_INVALID_SECRET);
|
||||
}
|
||||
|
||||
if (typeof key !== 'object') {
|
||||
throw typeError(MSG_INVALID_SECRET);
|
||||
}
|
||||
|
||||
if (key.type !== 'secret') {
|
||||
throw typeError(MSG_INVALID_SECRET);
|
||||
}
|
||||
|
||||
if (typeof key.export !== 'function') {
|
||||
throw typeError(MSG_INVALID_SECRET);
|
||||
}
|
||||
}
|
||||
|
||||
function fromBase64(base64) {
|
||||
return base64
|
||||
.replace(/=/g, '')
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_');
|
||||
}
|
||||
|
||||
function toBase64(base64url) {
|
||||
base64url = base64url.toString();
|
||||
|
||||
var padding = 4 - base64url.length % 4;
|
||||
if (padding !== 4) {
|
||||
for (var i = 0; i < padding; ++i) {
|
||||
base64url += '=';
|
||||
}
|
||||
}
|
||||
|
||||
return base64url
|
||||
.replace(/\-/g, '+')
|
||||
.replace(/_/g, '/');
|
||||
}
|
||||
|
||||
function typeError(template) {
|
||||
var args = [].slice.call(arguments, 1);
|
||||
var errMsg = util.format.bind(util, template).apply(null, args);
|
||||
return new TypeError(errMsg);
|
||||
}
|
||||
|
||||
function bufferOrString(obj) {
|
||||
return Buffer.isBuffer(obj) || typeof obj === 'string';
|
||||
}
|
||||
|
||||
function normalizeInput(thing) {
|
||||
if (!bufferOrString(thing))
|
||||
thing = JSON.stringify(thing);
|
||||
return thing;
|
||||
}
|
||||
|
||||
function createHmacSigner(bits) {
|
||||
return function sign(thing, secret) {
|
||||
checkIsSecretKey(secret);
|
||||
thing = normalizeInput(thing);
|
||||
var hmac = crypto.createHmac('sha' + bits, secret);
|
||||
var sig = (hmac.update(thing), hmac.digest('base64'))
|
||||
return fromBase64(sig);
|
||||
}
|
||||
}
|
||||
|
||||
var bufferEqual;
|
||||
var timingSafeEqual = 'timingSafeEqual' in crypto ? function timingSafeEqual(a, b) {
|
||||
if (a.byteLength !== b.byteLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return crypto.timingSafeEqual(a, b)
|
||||
} : function timingSafeEqual(a, b) {
|
||||
if (!bufferEqual) {
|
||||
bufferEqual = require('buffer-equal-constant-time');
|
||||
}
|
||||
|
||||
return bufferEqual(a, b)
|
||||
}
|
||||
|
||||
function createHmacVerifier(bits) {
|
||||
return function verify(thing, signature, secret) {
|
||||
var computedSig = createHmacSigner(bits)(thing, secret);
|
||||
return timingSafeEqual(Buffer.from(signature), Buffer.from(computedSig));
|
||||
}
|
||||
}
|
||||
|
||||
function createKeySigner(bits) {
|
||||
return function sign(thing, privateKey) {
|
||||
checkIsPrivateKey(privateKey);
|
||||
thing = normalizeInput(thing);
|
||||
// Even though we are specifying "RSA" here, this works with ECDSA
|
||||
// keys as well.
|
||||
var signer = crypto.createSign('RSA-SHA' + bits);
|
||||
var sig = (signer.update(thing), signer.sign(privateKey, 'base64'));
|
||||
return fromBase64(sig);
|
||||
}
|
||||
}
|
||||
|
||||
function createKeyVerifier(bits) {
|
||||
return function verify(thing, signature, publicKey) {
|
||||
checkIsPublicKey(publicKey);
|
||||
thing = normalizeInput(thing);
|
||||
signature = toBase64(signature);
|
||||
var verifier = crypto.createVerify('RSA-SHA' + bits);
|
||||
verifier.update(thing);
|
||||
return verifier.verify(publicKey, signature, 'base64');
|
||||
}
|
||||
}
|
||||
|
||||
function createPSSKeySigner(bits) {
|
||||
return function sign(thing, privateKey) {
|
||||
checkIsPrivateKey(privateKey);
|
||||
thing = normalizeInput(thing);
|
||||
var signer = crypto.createSign('RSA-SHA' + bits);
|
||||
var sig = (signer.update(thing), signer.sign({
|
||||
key: privateKey,
|
||||
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
||||
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST
|
||||
}, 'base64'));
|
||||
return fromBase64(sig);
|
||||
}
|
||||
}
|
||||
|
||||
function createPSSKeyVerifier(bits) {
|
||||
return function verify(thing, signature, publicKey) {
|
||||
checkIsPublicKey(publicKey);
|
||||
thing = normalizeInput(thing);
|
||||
signature = toBase64(signature);
|
||||
var verifier = crypto.createVerify('RSA-SHA' + bits);
|
||||
verifier.update(thing);
|
||||
return verifier.verify({
|
||||
key: publicKey,
|
||||
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
|
||||
saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST
|
||||
}, signature, 'base64');
|
||||
}
|
||||
}
|
||||
|
||||
function createECDSASigner(bits) {
|
||||
var inner = createKeySigner(bits);
|
||||
return function sign() {
|
||||
var signature = inner.apply(null, arguments);
|
||||
signature = formatEcdsa.derToJose(signature, 'ES' + bits);
|
||||
return signature;
|
||||
};
|
||||
}
|
||||
|
||||
function createECDSAVerifer(bits) {
|
||||
var inner = createKeyVerifier(bits);
|
||||
return function verify(thing, signature, publicKey) {
|
||||
signature = formatEcdsa.joseToDer(signature, 'ES' + bits).toString('base64');
|
||||
var result = inner(thing, signature, publicKey);
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
function createNoneSigner() {
|
||||
return function sign() {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function createNoneVerifier() {
|
||||
return function verify(thing, signature) {
|
||||
return signature === '';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function jwa(algorithm) {
|
||||
var signerFactories = {
|
||||
hs: createHmacSigner,
|
||||
rs: createKeySigner,
|
||||
ps: createPSSKeySigner,
|
||||
es: createECDSASigner,
|
||||
none: createNoneSigner,
|
||||
}
|
||||
var verifierFactories = {
|
||||
hs: createHmacVerifier,
|
||||
rs: createKeyVerifier,
|
||||
ps: createPSSKeyVerifier,
|
||||
es: createECDSAVerifer,
|
||||
none: createNoneVerifier,
|
||||
}
|
||||
var match = algorithm.match(/^(RS|PS|ES|HS)(256|384|512)$|^(none)$/i);
|
||||
if (!match)
|
||||
throw typeError(MSG_INVALID_ALGORITHM, algorithm);
|
||||
var algo = (match[1] || match[3]).toLowerCase();
|
||||
var bits = match[2];
|
||||
|
||||
return {
|
||||
sign: signerFactories[algo](bits),
|
||||
verify: verifierFactories[algo](bits),
|
||||
}
|
||||
};
|
||||
37
node_modules/jsonwebtoken/node_modules/jwa/package.json
generated
vendored
Normal file
37
node_modules/jsonwebtoken/node_modules/jwa/package.json
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "jwa",
|
||||
"version": "1.4.2",
|
||||
"description": "JWA implementation (supports all JWS algorithms)",
|
||||
"main": "index.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"dependencies": {
|
||||
"buffer-equal-constant-time": "^1.0.1",
|
||||
"ecdsa-sig-formatter": "1.0.11",
|
||||
"safe-buffer": "^5.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"base64url": "^2.0.0",
|
||||
"jwk-to-pem": "^2.0.1",
|
||||
"semver": "4.3.6",
|
||||
"tap": "6.2.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/brianloveswords/node-jwa.git"
|
||||
},
|
||||
"keywords": [
|
||||
"jwa",
|
||||
"jws",
|
||||
"jwt",
|
||||
"rsa",
|
||||
"ecdsa",
|
||||
"hmac"
|
||||
],
|
||||
"author": "Brian J. Brennan <brianloveswords@gmail.com>",
|
||||
"license": "MIT"
|
||||
}
|
||||
34
node_modules/jsonwebtoken/node_modules/jws/CHANGELOG.md
generated
vendored
Normal file
34
node_modules/jsonwebtoken/node_modules/jws/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [3.0.0]
|
||||
### Changed
|
||||
- **BREAKING**: `jwt.verify` now requires an `algorithm` parameter, and
|
||||
`jws.createVerify` requires an `algorithm` option. The `"alg"` field
|
||||
signature headers is ignored. This mitigates a critical security flaw
|
||||
in the library which would allow an attacker to generate signatures with
|
||||
arbitrary contents that would be accepted by `jwt.verify`. See
|
||||
https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/
|
||||
for details.
|
||||
|
||||
## [2.0.0] - 2015-01-30
|
||||
### Changed
|
||||
- **BREAKING**: Default payload encoding changed from `binary` to
|
||||
`utf8`. `utf8` is a is a more sensible default than `binary` because
|
||||
many payloads, as far as I can tell, will contain user-facing
|
||||
strings that could be in any language. (<code>[6b6de48]</code>)
|
||||
|
||||
- Code reorganization, thanks [@fearphage]! (<code>[7880050]</code>)
|
||||
|
||||
### Added
|
||||
- Option in all relevant methods for `encoding`. For those few users
|
||||
that might be depending on a `binary` encoding of the messages, this
|
||||
is for them. (<code>[6b6de48]</code>)
|
||||
|
||||
[unreleased]: https://github.com/brianloveswords/node-jws/compare/v2.0.0...HEAD
|
||||
[2.0.0]: https://github.com/brianloveswords/node-jws/compare/v1.0.1...v2.0.0
|
||||
|
||||
[7880050]: https://github.com/brianloveswords/node-jws/commit/7880050
|
||||
[6b6de48]: https://github.com/brianloveswords/node-jws/commit/6b6de48
|
||||
|
||||
[@fearphage]: https://github.com/fearphage
|
||||
17
node_modules/jsonwebtoken/node_modules/jws/LICENSE
generated
vendored
Normal file
17
node_modules/jsonwebtoken/node_modules/jws/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
Copyright (c) 2013 Brian J. Brennan
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
22
node_modules/jsonwebtoken/node_modules/jws/index.js
generated
vendored
Normal file
22
node_modules/jsonwebtoken/node_modules/jws/index.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/*global exports*/
|
||||
var SignStream = require('./lib/sign-stream');
|
||||
var VerifyStream = require('./lib/verify-stream');
|
||||
|
||||
var ALGORITHMS = [
|
||||
'HS256', 'HS384', 'HS512',
|
||||
'RS256', 'RS384', 'RS512',
|
||||
'PS256', 'PS384', 'PS512',
|
||||
'ES256', 'ES384', 'ES512'
|
||||
];
|
||||
|
||||
exports.ALGORITHMS = ALGORITHMS;
|
||||
exports.sign = SignStream.sign;
|
||||
exports.verify = VerifyStream.verify;
|
||||
exports.decode = VerifyStream.decode;
|
||||
exports.isValid = VerifyStream.isValid;
|
||||
exports.createSign = function createSign(opts) {
|
||||
return new SignStream(opts);
|
||||
};
|
||||
exports.createVerify = function createVerify(opts) {
|
||||
return new VerifyStream(opts);
|
||||
};
|
||||
55
node_modules/jsonwebtoken/node_modules/jws/lib/data-stream.js
generated
vendored
Normal file
55
node_modules/jsonwebtoken/node_modules/jws/lib/data-stream.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*global module, process*/
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
var Stream = require('stream');
|
||||
var util = require('util');
|
||||
|
||||
function DataStream(data) {
|
||||
this.buffer = null;
|
||||
this.writable = true;
|
||||
this.readable = true;
|
||||
|
||||
// No input
|
||||
if (!data) {
|
||||
this.buffer = Buffer.alloc(0);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Stream
|
||||
if (typeof data.pipe === 'function') {
|
||||
this.buffer = Buffer.alloc(0);
|
||||
data.pipe(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Buffer or String
|
||||
// or Object (assumedly a passworded key)
|
||||
if (data.length || typeof data === 'object') {
|
||||
this.buffer = data;
|
||||
this.writable = false;
|
||||
process.nextTick(function () {
|
||||
this.emit('end', data);
|
||||
this.readable = false;
|
||||
this.emit('close');
|
||||
}.bind(this));
|
||||
return this;
|
||||
}
|
||||
|
||||
throw new TypeError('Unexpected data type ('+ typeof data + ')');
|
||||
}
|
||||
util.inherits(DataStream, Stream);
|
||||
|
||||
DataStream.prototype.write = function write(data) {
|
||||
this.buffer = Buffer.concat([this.buffer, Buffer.from(data)]);
|
||||
this.emit('data', data);
|
||||
};
|
||||
|
||||
DataStream.prototype.end = function end(data) {
|
||||
if (data)
|
||||
this.write(data);
|
||||
this.emit('end', data);
|
||||
this.emit('close');
|
||||
this.writable = false;
|
||||
this.readable = false;
|
||||
};
|
||||
|
||||
module.exports = DataStream;
|
||||
78
node_modules/jsonwebtoken/node_modules/jws/lib/sign-stream.js
generated
vendored
Normal file
78
node_modules/jsonwebtoken/node_modules/jws/lib/sign-stream.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/*global module*/
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
var DataStream = require('./data-stream');
|
||||
var jwa = require('jwa');
|
||||
var Stream = require('stream');
|
||||
var toString = require('./tostring');
|
||||
var util = require('util');
|
||||
|
||||
function base64url(string, encoding) {
|
||||
return Buffer
|
||||
.from(string, encoding)
|
||||
.toString('base64')
|
||||
.replace(/=/g, '')
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_');
|
||||
}
|
||||
|
||||
function jwsSecuredInput(header, payload, encoding) {
|
||||
encoding = encoding || 'utf8';
|
||||
var encodedHeader = base64url(toString(header), 'binary');
|
||||
var encodedPayload = base64url(toString(payload), encoding);
|
||||
return util.format('%s.%s', encodedHeader, encodedPayload);
|
||||
}
|
||||
|
||||
function jwsSign(opts) {
|
||||
var header = opts.header;
|
||||
var payload = opts.payload;
|
||||
var secretOrKey = opts.secret || opts.privateKey;
|
||||
var encoding = opts.encoding;
|
||||
var algo = jwa(header.alg);
|
||||
var securedInput = jwsSecuredInput(header, payload, encoding);
|
||||
var signature = algo.sign(securedInput, secretOrKey);
|
||||
return util.format('%s.%s', securedInput, signature);
|
||||
}
|
||||
|
||||
function SignStream(opts) {
|
||||
var secret = opts.secret||opts.privateKey||opts.key;
|
||||
var secretStream = new DataStream(secret);
|
||||
this.readable = true;
|
||||
this.header = opts.header;
|
||||
this.encoding = opts.encoding;
|
||||
this.secret = this.privateKey = this.key = secretStream;
|
||||
this.payload = new DataStream(opts.payload);
|
||||
this.secret.once('close', function () {
|
||||
if (!this.payload.writable && this.readable)
|
||||
this.sign();
|
||||
}.bind(this));
|
||||
|
||||
this.payload.once('close', function () {
|
||||
if (!this.secret.writable && this.readable)
|
||||
this.sign();
|
||||
}.bind(this));
|
||||
}
|
||||
util.inherits(SignStream, Stream);
|
||||
|
||||
SignStream.prototype.sign = function sign() {
|
||||
try {
|
||||
var signature = jwsSign({
|
||||
header: this.header,
|
||||
payload: this.payload.buffer,
|
||||
secret: this.secret.buffer,
|
||||
encoding: this.encoding
|
||||
});
|
||||
this.emit('done', signature);
|
||||
this.emit('data', signature);
|
||||
this.emit('end');
|
||||
this.readable = false;
|
||||
return signature;
|
||||
} catch (e) {
|
||||
this.readable = false;
|
||||
this.emit('error', e);
|
||||
this.emit('close');
|
||||
}
|
||||
};
|
||||
|
||||
SignStream.sign = jwsSign;
|
||||
|
||||
module.exports = SignStream;
|
||||
10
node_modules/jsonwebtoken/node_modules/jws/lib/tostring.js
generated
vendored
Normal file
10
node_modules/jsonwebtoken/node_modules/jws/lib/tostring.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/*global module*/
|
||||
var Buffer = require('buffer').Buffer;
|
||||
|
||||
module.exports = function toString(obj) {
|
||||
if (typeof obj === 'string')
|
||||
return obj;
|
||||
if (typeof obj === 'number' || Buffer.isBuffer(obj))
|
||||
return obj.toString();
|
||||
return JSON.stringify(obj);
|
||||
};
|
||||
120
node_modules/jsonwebtoken/node_modules/jws/lib/verify-stream.js
generated
vendored
Normal file
120
node_modules/jsonwebtoken/node_modules/jws/lib/verify-stream.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
/*global module*/
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
var DataStream = require('./data-stream');
|
||||
var jwa = require('jwa');
|
||||
var Stream = require('stream');
|
||||
var toString = require('./tostring');
|
||||
var util = require('util');
|
||||
var JWS_REGEX = /^[a-zA-Z0-9\-_]+?\.[a-zA-Z0-9\-_]+?\.([a-zA-Z0-9\-_]+)?$/;
|
||||
|
||||
function isObject(thing) {
|
||||
return Object.prototype.toString.call(thing) === '[object Object]';
|
||||
}
|
||||
|
||||
function safeJsonParse(thing) {
|
||||
if (isObject(thing))
|
||||
return thing;
|
||||
try { return JSON.parse(thing); }
|
||||
catch (e) { return undefined; }
|
||||
}
|
||||
|
||||
function headerFromJWS(jwsSig) {
|
||||
var encodedHeader = jwsSig.split('.', 1)[0];
|
||||
return safeJsonParse(Buffer.from(encodedHeader, 'base64').toString('binary'));
|
||||
}
|
||||
|
||||
function securedInputFromJWS(jwsSig) {
|
||||
return jwsSig.split('.', 2).join('.');
|
||||
}
|
||||
|
||||
function signatureFromJWS(jwsSig) {
|
||||
return jwsSig.split('.')[2];
|
||||
}
|
||||
|
||||
function payloadFromJWS(jwsSig, encoding) {
|
||||
encoding = encoding || 'utf8';
|
||||
var payload = jwsSig.split('.')[1];
|
||||
return Buffer.from(payload, 'base64').toString(encoding);
|
||||
}
|
||||
|
||||
function isValidJws(string) {
|
||||
return JWS_REGEX.test(string) && !!headerFromJWS(string);
|
||||
}
|
||||
|
||||
function jwsVerify(jwsSig, algorithm, secretOrKey) {
|
||||
if (!algorithm) {
|
||||
var err = new Error("Missing algorithm parameter for jws.verify");
|
||||
err.code = "MISSING_ALGORITHM";
|
||||
throw err;
|
||||
}
|
||||
jwsSig = toString(jwsSig);
|
||||
var signature = signatureFromJWS(jwsSig);
|
||||
var securedInput = securedInputFromJWS(jwsSig);
|
||||
var algo = jwa(algorithm);
|
||||
return algo.verify(securedInput, signature, secretOrKey);
|
||||
}
|
||||
|
||||
function jwsDecode(jwsSig, opts) {
|
||||
opts = opts || {};
|
||||
jwsSig = toString(jwsSig);
|
||||
|
||||
if (!isValidJws(jwsSig))
|
||||
return null;
|
||||
|
||||
var header = headerFromJWS(jwsSig);
|
||||
|
||||
if (!header)
|
||||
return null;
|
||||
|
||||
var payload = payloadFromJWS(jwsSig);
|
||||
if (header.typ === 'JWT' || opts.json)
|
||||
payload = JSON.parse(payload, opts.encoding);
|
||||
|
||||
return {
|
||||
header: header,
|
||||
payload: payload,
|
||||
signature: signatureFromJWS(jwsSig)
|
||||
};
|
||||
}
|
||||
|
||||
function VerifyStream(opts) {
|
||||
opts = opts || {};
|
||||
var secretOrKey = opts.secret||opts.publicKey||opts.key;
|
||||
var secretStream = new DataStream(secretOrKey);
|
||||
this.readable = true;
|
||||
this.algorithm = opts.algorithm;
|
||||
this.encoding = opts.encoding;
|
||||
this.secret = this.publicKey = this.key = secretStream;
|
||||
this.signature = new DataStream(opts.signature);
|
||||
this.secret.once('close', function () {
|
||||
if (!this.signature.writable && this.readable)
|
||||
this.verify();
|
||||
}.bind(this));
|
||||
|
||||
this.signature.once('close', function () {
|
||||
if (!this.secret.writable && this.readable)
|
||||
this.verify();
|
||||
}.bind(this));
|
||||
}
|
||||
util.inherits(VerifyStream, Stream);
|
||||
VerifyStream.prototype.verify = function verify() {
|
||||
try {
|
||||
var valid = jwsVerify(this.signature.buffer, this.algorithm, this.key.buffer);
|
||||
var obj = jwsDecode(this.signature.buffer, this.encoding);
|
||||
this.emit('done', valid, obj);
|
||||
this.emit('data', valid);
|
||||
this.emit('end');
|
||||
this.readable = false;
|
||||
return valid;
|
||||
} catch (e) {
|
||||
this.readable = false;
|
||||
this.emit('error', e);
|
||||
this.emit('close');
|
||||
}
|
||||
};
|
||||
|
||||
VerifyStream.decode = jwsDecode;
|
||||
VerifyStream.isValid = isValidJws;
|
||||
VerifyStream.verify = jwsVerify;
|
||||
|
||||
module.exports = VerifyStream;
|
||||
34
node_modules/jsonwebtoken/node_modules/jws/package.json
generated
vendored
Normal file
34
node_modules/jsonwebtoken/node_modules/jws/package.json
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "jws",
|
||||
"version": "3.2.2",
|
||||
"description": "Implementation of JSON Web Signatures",
|
||||
"main": "index.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/brianloveswords/node-jws.git"
|
||||
},
|
||||
"keywords": [
|
||||
"jws",
|
||||
"json",
|
||||
"web",
|
||||
"signatures"
|
||||
],
|
||||
"author": "Brian J Brennan",
|
||||
"license": "MIT",
|
||||
"readmeFilename": "readme.md",
|
||||
"gitHead": "c0f6b27bcea5a2ad2e304d91c2e842e4076a6b03",
|
||||
"dependencies": {
|
||||
"jwa": "^1.4.1",
|
||||
"safe-buffer": "^5.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"semver": "^5.1.0",
|
||||
"tape": "~2.14.0"
|
||||
}
|
||||
}
|
||||
255
node_modules/jsonwebtoken/node_modules/jws/readme.md
generated
vendored
Normal file
255
node_modules/jsonwebtoken/node_modules/jws/readme.md
generated
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
# node-jws [](http://travis-ci.org/brianloveswords/node-jws)
|
||||
|
||||
An implementation of [JSON Web Signatures](http://self-issued.info/docs/draft-ietf-jose-json-web-signature.html).
|
||||
|
||||
This was developed against `draft-ietf-jose-json-web-signature-08` and
|
||||
implements the entire spec **except** X.509 Certificate Chain
|
||||
signing/verifying (patches welcome).
|
||||
|
||||
There are both synchronous (`jws.sign`, `jws.verify`) and streaming
|
||||
(`jws.createSign`, `jws.createVerify`) APIs.
|
||||
|
||||
# Install
|
||||
|
||||
```bash
|
||||
$ npm install jws
|
||||
```
|
||||
|
||||
# Usage
|
||||
|
||||
## jws.ALGORITHMS
|
||||
|
||||
Array of supported algorithms. The following algorithms are currently supported.
|
||||
|
||||
alg Parameter Value | Digital Signature or MAC Algorithm
|
||||
----------------|----------------------------
|
||||
HS256 | HMAC using SHA-256 hash algorithm
|
||||
HS384 | HMAC using SHA-384 hash algorithm
|
||||
HS512 | HMAC using SHA-512 hash algorithm
|
||||
RS256 | RSASSA using SHA-256 hash algorithm
|
||||
RS384 | RSASSA using SHA-384 hash algorithm
|
||||
RS512 | RSASSA using SHA-512 hash algorithm
|
||||
PS256 | RSASSA-PSS using SHA-256 hash algorithm
|
||||
PS384 | RSASSA-PSS using SHA-384 hash algorithm
|
||||
PS512 | RSASSA-PSS using SHA-512 hash algorithm
|
||||
ES256 | ECDSA using P-256 curve and SHA-256 hash algorithm
|
||||
ES384 | ECDSA using P-384 curve and SHA-384 hash algorithm
|
||||
ES512 | ECDSA using P-521 curve and SHA-512 hash algorithm
|
||||
none | No digital signature or MAC value included
|
||||
|
||||
## jws.sign(options)
|
||||
|
||||
(Synchronous) Return a JSON Web Signature for a header and a payload.
|
||||
|
||||
Options:
|
||||
|
||||
* `header`
|
||||
* `payload`
|
||||
* `secret` or `privateKey`
|
||||
* `encoding` (Optional, defaults to 'utf8')
|
||||
|
||||
`header` must be an object with an `alg` property. `header.alg` must be
|
||||
one a value found in `jws.ALGORITHMS`. See above for a table of
|
||||
supported algorithms.
|
||||
|
||||
If `payload` is not a buffer or a string, it will be coerced into a string
|
||||
using `JSON.stringify`.
|
||||
|
||||
Example
|
||||
|
||||
```js
|
||||
const signature = jws.sign({
|
||||
header: { alg: 'HS256' },
|
||||
payload: 'h. jon benjamin',
|
||||
secret: 'has a van',
|
||||
});
|
||||
```
|
||||
|
||||
## jws.verify(signature, algorithm, secretOrKey)
|
||||
|
||||
(Synchronous) Returns `true` or `false` for whether a signature matches a
|
||||
secret or key.
|
||||
|
||||
`signature` is a JWS Signature. `header.alg` must be a value found in `jws.ALGORITHMS`.
|
||||
See above for a table of supported algorithms. `secretOrKey` is a string or
|
||||
buffer containing either the secret for HMAC algorithms, or the PEM
|
||||
encoded public key for RSA and ECDSA.
|
||||
|
||||
Note that the `"alg"` value from the signature header is ignored.
|
||||
|
||||
|
||||
## jws.decode(signature)
|
||||
|
||||
(Synchronous) Returns the decoded header, decoded payload, and signature
|
||||
parts of the JWS Signature.
|
||||
|
||||
Returns an object with three properties, e.g.
|
||||
```js
|
||||
{ header: { alg: 'HS256' },
|
||||
payload: 'h. jon benjamin',
|
||||
signature: 'YOWPewyGHKu4Y_0M_vtlEnNlqmFOclqp4Hy6hVHfFT4'
|
||||
}
|
||||
```
|
||||
|
||||
## jws.createSign(options)
|
||||
|
||||
Returns a new SignStream object.
|
||||
|
||||
Options:
|
||||
|
||||
* `header` (required)
|
||||
* `payload`
|
||||
* `key` || `privateKey` || `secret`
|
||||
* `encoding` (Optional, defaults to 'utf8')
|
||||
|
||||
Other than `header`, all options expect a string or a buffer when the
|
||||
value is known ahead of time, or a stream for convenience.
|
||||
`key`/`privateKey`/`secret` may also be an object when using an encrypted
|
||||
private key, see the [crypto documentation][encrypted-key-docs].
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
|
||||
// This...
|
||||
jws.createSign({
|
||||
header: { alg: 'RS256' },
|
||||
privateKey: privateKeyStream,
|
||||
payload: payloadStream,
|
||||
}).on('done', function(signature) {
|
||||
// ...
|
||||
});
|
||||
|
||||
// is equivalent to this:
|
||||
const signer = jws.createSign({
|
||||
header: { alg: 'RS256' },
|
||||
});
|
||||
privateKeyStream.pipe(signer.privateKey);
|
||||
payloadStream.pipe(signer.payload);
|
||||
signer.on('done', function(signature) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
## jws.createVerify(options)
|
||||
|
||||
Returns a new VerifyStream object.
|
||||
|
||||
Options:
|
||||
|
||||
* `signature`
|
||||
* `algorithm`
|
||||
* `key` || `publicKey` || `secret`
|
||||
* `encoding` (Optional, defaults to 'utf8')
|
||||
|
||||
All options expect a string or a buffer when the value is known ahead of
|
||||
time, or a stream for convenience.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
|
||||
// This...
|
||||
jws.createVerify({
|
||||
publicKey: pubKeyStream,
|
||||
signature: sigStream,
|
||||
}).on('done', function(verified, obj) {
|
||||
// ...
|
||||
});
|
||||
|
||||
// is equivilant to this:
|
||||
const verifier = jws.createVerify();
|
||||
pubKeyStream.pipe(verifier.publicKey);
|
||||
sigStream.pipe(verifier.signature);
|
||||
verifier.on('done', function(verified, obj) {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
## Class: SignStream
|
||||
|
||||
A `Readable Stream` that emits a single data event (the calculated
|
||||
signature) when done.
|
||||
|
||||
### Event: 'done'
|
||||
`function (signature) { }`
|
||||
|
||||
### signer.payload
|
||||
|
||||
A `Writable Stream` that expects the JWS payload. Do *not* use if you
|
||||
passed a `payload` option to the constructor.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
payloadStream.pipe(signer.payload);
|
||||
```
|
||||
|
||||
### signer.secret<br>signer.key<br>signer.privateKey
|
||||
|
||||
A `Writable Stream`. Expects the JWS secret for HMAC, or the privateKey
|
||||
for ECDSA and RSA. Do *not* use if you passed a `secret` or `key` option
|
||||
to the constructor.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
privateKeyStream.pipe(signer.privateKey);
|
||||
```
|
||||
|
||||
## Class: VerifyStream
|
||||
|
||||
This is a `Readable Stream` that emits a single data event, the result
|
||||
of whether or not that signature was valid.
|
||||
|
||||
### Event: 'done'
|
||||
`function (valid, obj) { }`
|
||||
|
||||
`valid` is a boolean for whether or not the signature is valid.
|
||||
|
||||
### verifier.signature
|
||||
|
||||
A `Writable Stream` that expects a JWS Signature. Do *not* use if you
|
||||
passed a `signature` option to the constructor.
|
||||
|
||||
### verifier.secret<br>verifier.key<br>verifier.publicKey
|
||||
|
||||
A `Writable Stream` that expects a public key or secret. Do *not* use if you
|
||||
passed a `key` or `secret` option to the constructor.
|
||||
|
||||
# TODO
|
||||
|
||||
* It feels like there should be some convenience options/APIs for
|
||||
defining the algorithm rather than having to define a header object
|
||||
with `{ alg: 'ES512' }` or whatever every time.
|
||||
|
||||
* X.509 support, ugh
|
||||
|
||||
# License
|
||||
|
||||
MIT
|
||||
|
||||
```
|
||||
Copyright (c) 2013-2015 Brian J. Brennan
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
```
|
||||
|
||||
[encrypted-key-docs]: https://nodejs.org/api/crypto.html#crypto_sign_sign_private_key_output_format
|
||||
162
node_modules/jsonwebtoken/node_modules/ms/index.js
generated
vendored
Normal file
162
node_modules/jsonwebtoken/node_modules/ms/index.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Helpers.
|
||||
*/
|
||||
|
||||
var s = 1000;
|
||||
var m = s * 60;
|
||||
var h = m * 60;
|
||||
var d = h * 24;
|
||||
var w = d * 7;
|
||||
var y = d * 365.25;
|
||||
|
||||
/**
|
||||
* Parse or format the given `val`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `long` verbose formatting [false]
|
||||
*
|
||||
* @param {String|Number} val
|
||||
* @param {Object} [options]
|
||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
||||
* @return {String|Number}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function (val, options) {
|
||||
options = options || {};
|
||||
var type = typeof val;
|
||||
if (type === 'string' && val.length > 0) {
|
||||
return parse(val);
|
||||
} else if (type === 'number' && isFinite(val)) {
|
||||
return options.long ? fmtLong(val) : fmtShort(val);
|
||||
}
|
||||
throw new Error(
|
||||
'val is not a non-empty string or a valid number. val=' +
|
||||
JSON.stringify(val)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `str` and return milliseconds.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parse(str) {
|
||||
str = String(str);
|
||||
if (str.length > 100) {
|
||||
return;
|
||||
}
|
||||
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
||||
str
|
||||
);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
var n = parseFloat(match[1]);
|
||||
var type = (match[2] || 'ms').toLowerCase();
|
||||
switch (type) {
|
||||
case 'years':
|
||||
case 'year':
|
||||
case 'yrs':
|
||||
case 'yr':
|
||||
case 'y':
|
||||
return n * y;
|
||||
case 'weeks':
|
||||
case 'week':
|
||||
case 'w':
|
||||
return n * w;
|
||||
case 'days':
|
||||
case 'day':
|
||||
case 'd':
|
||||
return n * d;
|
||||
case 'hours':
|
||||
case 'hour':
|
||||
case 'hrs':
|
||||
case 'hr':
|
||||
case 'h':
|
||||
return n * h;
|
||||
case 'minutes':
|
||||
case 'minute':
|
||||
case 'mins':
|
||||
case 'min':
|
||||
case 'm':
|
||||
return n * m;
|
||||
case 'seconds':
|
||||
case 'second':
|
||||
case 'secs':
|
||||
case 'sec':
|
||||
case 's':
|
||||
return n * s;
|
||||
case 'milliseconds':
|
||||
case 'millisecond':
|
||||
case 'msecs':
|
||||
case 'msec':
|
||||
case 'ms':
|
||||
return n;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Short format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtShort(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return Math.round(ms / d) + 'd';
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return Math.round(ms / h) + 'h';
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return Math.round(ms / m) + 'm';
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return Math.round(ms / s) + 's';
|
||||
}
|
||||
return ms + 'ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Long format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtLong(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return plural(ms, msAbs, d, 'day');
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return plural(ms, msAbs, h, 'hour');
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return plural(ms, msAbs, m, 'minute');
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return plural(ms, msAbs, s, 'second');
|
||||
}
|
||||
return ms + ' ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluralization helper.
|
||||
*/
|
||||
|
||||
function plural(ms, msAbs, n, name) {
|
||||
var isPlural = msAbs >= n * 1.5;
|
||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
||||
}
|
||||
21
node_modules/jsonwebtoken/node_modules/ms/license.md
generated
vendored
Normal file
21
node_modules/jsonwebtoken/node_modules/ms/license.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Vercel, Inc.
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
38
node_modules/jsonwebtoken/node_modules/ms/package.json
generated
vendored
Normal file
38
node_modules/jsonwebtoken/node_modules/ms/package.json
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "ms",
|
||||
"version": "2.1.3",
|
||||
"description": "Tiny millisecond conversion utility",
|
||||
"repository": "vercel/ms",
|
||||
"main": "./index",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"scripts": {
|
||||
"precommit": "lint-staged",
|
||||
"lint": "eslint lib/* bin/*",
|
||||
"test": "mocha tests.js"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"npm run lint",
|
||||
"prettier --single-quote --write",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"eslint": "4.18.2",
|
||||
"expect.js": "0.3.1",
|
||||
"husky": "0.14.3",
|
||||
"lint-staged": "5.0.0",
|
||||
"mocha": "4.0.1",
|
||||
"prettier": "2.0.5"
|
||||
}
|
||||
}
|
||||
59
node_modules/jsonwebtoken/node_modules/ms/readme.md
generated
vendored
Normal file
59
node_modules/jsonwebtoken/node_modules/ms/readme.md
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
# ms
|
||||
|
||||

|
||||
|
||||
Use this package to easily convert various time formats to milliseconds.
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
ms('2 days') // 172800000
|
||||
ms('1d') // 86400000
|
||||
ms('10h') // 36000000
|
||||
ms('2.5 hrs') // 9000000
|
||||
ms('2h') // 7200000
|
||||
ms('1m') // 60000
|
||||
ms('5s') // 5000
|
||||
ms('1y') // 31557600000
|
||||
ms('100') // 100
|
||||
ms('-3 days') // -259200000
|
||||
ms('-1h') // -3600000
|
||||
ms('-200') // -200
|
||||
```
|
||||
|
||||
### Convert from Milliseconds
|
||||
|
||||
```js
|
||||
ms(60000) // "1m"
|
||||
ms(2 * 60000) // "2m"
|
||||
ms(-3 * 60000) // "-3m"
|
||||
ms(ms('10 hours')) // "10h"
|
||||
```
|
||||
|
||||
### Time Format Written-Out
|
||||
|
||||
```js
|
||||
ms(60000, { long: true }) // "1 minute"
|
||||
ms(2 * 60000, { long: true }) // "2 minutes"
|
||||
ms(-3 * 60000, { long: true }) // "-3 minutes"
|
||||
ms(ms('10 hours'), { long: true }) // "10 hours"
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Works both in [Node.js](https://nodejs.org) and in the browser
|
||||
- If a number is supplied to `ms`, a string with a unit is returned
|
||||
- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns `100` for `'100'`)
|
||||
- If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned
|
||||
|
||||
## Related Packages
|
||||
|
||||
- [ms.macro](https://github.com/knpwrs/ms.macro) - Run `ms` as a macro at build-time.
|
||||
|
||||
## Caught a Bug?
|
||||
|
||||
1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device
|
||||
2. Link the package to the global module directory: `npm link`
|
||||
3. Within the module you want to test your local development instance of ms, just link it to the dependencies: `npm link ms`. Instead of the default one from npm, Node.js will now use your clone of ms!
|
||||
|
||||
As always, you can run the tests using: `npm test`
|
||||
71
node_modules/jsonwebtoken/package.json
generated
vendored
Normal file
71
node_modules/jsonwebtoken/package.json
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"name": "jsonwebtoken",
|
||||
"version": "9.0.2",
|
||||
"description": "JSON Web Token implementation (symmetric and asymmetric)",
|
||||
"main": "index.js",
|
||||
"nyc": {
|
||||
"check-coverage": true,
|
||||
"lines": 95,
|
||||
"statements": 95,
|
||||
"functions": 100,
|
||||
"branches": 95,
|
||||
"exclude": [
|
||||
"./test/**"
|
||||
],
|
||||
"reporter": [
|
||||
"json",
|
||||
"lcov",
|
||||
"text-summary"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"coverage": "nyc mocha --use_strict",
|
||||
"test": "npm run lint && npm run coverage && cost-of-modules"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/auth0/node-jsonwebtoken"
|
||||
},
|
||||
"keywords": [
|
||||
"jwt"
|
||||
],
|
||||
"author": "auth0",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/auth0/node-jsonwebtoken/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"jws": "^3.2.2",
|
||||
"lodash.includes": "^4.3.0",
|
||||
"lodash.isboolean": "^3.0.3",
|
||||
"lodash.isinteger": "^4.0.4",
|
||||
"lodash.isnumber": "^3.0.3",
|
||||
"lodash.isplainobject": "^4.0.6",
|
||||
"lodash.isstring": "^4.0.1",
|
||||
"lodash.once": "^4.0.0",
|
||||
"ms": "^2.1.1",
|
||||
"semver": "^7.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"atob": "^2.1.2",
|
||||
"chai": "^4.1.2",
|
||||
"conventional-changelog": "~1.1.0",
|
||||
"cost-of-modules": "^1.0.1",
|
||||
"eslint": "^4.19.1",
|
||||
"mocha": "^5.2.0",
|
||||
"nsp": "^2.6.2",
|
||||
"nyc": "^11.9.0",
|
||||
"sinon": "^6.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"npm": ">=6",
|
||||
"node": ">=12"
|
||||
},
|
||||
"files": [
|
||||
"lib",
|
||||
"decode.js",
|
||||
"sign.js",
|
||||
"verify.js"
|
||||
]
|
||||
}
|
||||
253
node_modules/jsonwebtoken/sign.js
generated
vendored
Normal file
253
node_modules/jsonwebtoken/sign.js
generated
vendored
Normal file
@@ -0,0 +1,253 @@
|
||||
const timespan = require('./lib/timespan');
|
||||
const PS_SUPPORTED = require('./lib/psSupported');
|
||||
const validateAsymmetricKey = require('./lib/validateAsymmetricKey');
|
||||
const jws = require('jws');
|
||||
const includes = require('lodash.includes');
|
||||
const isBoolean = require('lodash.isboolean');
|
||||
const isInteger = require('lodash.isinteger');
|
||||
const isNumber = require('lodash.isnumber');
|
||||
const isPlainObject = require('lodash.isplainobject');
|
||||
const isString = require('lodash.isstring');
|
||||
const once = require('lodash.once');
|
||||
const { KeyObject, createSecretKey, createPrivateKey } = require('crypto')
|
||||
|
||||
const SUPPORTED_ALGS = ['RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES512', 'HS256', 'HS384', 'HS512', 'none'];
|
||||
if (PS_SUPPORTED) {
|
||||
SUPPORTED_ALGS.splice(3, 0, 'PS256', 'PS384', 'PS512');
|
||||
}
|
||||
|
||||
const sign_options_schema = {
|
||||
expiresIn: { isValid: function(value) { return isInteger(value) || (isString(value) && value); }, message: '"expiresIn" should be a number of seconds or string representing a timespan' },
|
||||
notBefore: { isValid: function(value) { return isInteger(value) || (isString(value) && value); }, message: '"notBefore" should be a number of seconds or string representing a timespan' },
|
||||
audience: { isValid: function(value) { return isString(value) || Array.isArray(value); }, message: '"audience" must be a string or array' },
|
||||
algorithm: { isValid: includes.bind(null, SUPPORTED_ALGS), message: '"algorithm" must be a valid string enum value' },
|
||||
header: { isValid: isPlainObject, message: '"header" must be an object' },
|
||||
encoding: { isValid: isString, message: '"encoding" must be a string' },
|
||||
issuer: { isValid: isString, message: '"issuer" must be a string' },
|
||||
subject: { isValid: isString, message: '"subject" must be a string' },
|
||||
jwtid: { isValid: isString, message: '"jwtid" must be a string' },
|
||||
noTimestamp: { isValid: isBoolean, message: '"noTimestamp" must be a boolean' },
|
||||
keyid: { isValid: isString, message: '"keyid" must be a string' },
|
||||
mutatePayload: { isValid: isBoolean, message: '"mutatePayload" must be a boolean' },
|
||||
allowInsecureKeySizes: { isValid: isBoolean, message: '"allowInsecureKeySizes" must be a boolean'},
|
||||
allowInvalidAsymmetricKeyTypes: { isValid: isBoolean, message: '"allowInvalidAsymmetricKeyTypes" must be a boolean'}
|
||||
};
|
||||
|
||||
const registered_claims_schema = {
|
||||
iat: { isValid: isNumber, message: '"iat" should be a number of seconds' },
|
||||
exp: { isValid: isNumber, message: '"exp" should be a number of seconds' },
|
||||
nbf: { isValid: isNumber, message: '"nbf" should be a number of seconds' }
|
||||
};
|
||||
|
||||
function validate(schema, allowUnknown, object, parameterName) {
|
||||
if (!isPlainObject(object)) {
|
||||
throw new Error('Expected "' + parameterName + '" to be a plain object.');
|
||||
}
|
||||
Object.keys(object)
|
||||
.forEach(function(key) {
|
||||
const validator = schema[key];
|
||||
if (!validator) {
|
||||
if (!allowUnknown) {
|
||||
throw new Error('"' + key + '" is not allowed in "' + parameterName + '"');
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!validator.isValid(object[key])) {
|
||||
throw new Error(validator.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function validateOptions(options) {
|
||||
return validate(sign_options_schema, false, options, 'options');
|
||||
}
|
||||
|
||||
function validatePayload(payload) {
|
||||
return validate(registered_claims_schema, true, payload, 'payload');
|
||||
}
|
||||
|
||||
const options_to_payload = {
|
||||
'audience': 'aud',
|
||||
'issuer': 'iss',
|
||||
'subject': 'sub',
|
||||
'jwtid': 'jti'
|
||||
};
|
||||
|
||||
const options_for_objects = [
|
||||
'expiresIn',
|
||||
'notBefore',
|
||||
'noTimestamp',
|
||||
'audience',
|
||||
'issuer',
|
||||
'subject',
|
||||
'jwtid',
|
||||
];
|
||||
|
||||
module.exports = function (payload, secretOrPrivateKey, options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
} else {
|
||||
options = options || {};
|
||||
}
|
||||
|
||||
const isObjectPayload = typeof payload === 'object' &&
|
||||
!Buffer.isBuffer(payload);
|
||||
|
||||
const header = Object.assign({
|
||||
alg: options.algorithm || 'HS256',
|
||||
typ: isObjectPayload ? 'JWT' : undefined,
|
||||
kid: options.keyid
|
||||
}, options.header);
|
||||
|
||||
function failure(err) {
|
||||
if (callback) {
|
||||
return callback(err);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (!secretOrPrivateKey && options.algorithm !== 'none') {
|
||||
return failure(new Error('secretOrPrivateKey must have a value'));
|
||||
}
|
||||
|
||||
if (secretOrPrivateKey != null && !(secretOrPrivateKey instanceof KeyObject)) {
|
||||
try {
|
||||
secretOrPrivateKey = createPrivateKey(secretOrPrivateKey)
|
||||
} catch (_) {
|
||||
try {
|
||||
secretOrPrivateKey = createSecretKey(typeof secretOrPrivateKey === 'string' ? Buffer.from(secretOrPrivateKey) : secretOrPrivateKey)
|
||||
} catch (_) {
|
||||
return failure(new Error('secretOrPrivateKey is not valid key material'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (header.alg.startsWith('HS') && secretOrPrivateKey.type !== 'secret') {
|
||||
return failure(new Error((`secretOrPrivateKey must be a symmetric key when using ${header.alg}`)))
|
||||
} else if (/^(?:RS|PS|ES)/.test(header.alg)) {
|
||||
if (secretOrPrivateKey.type !== 'private') {
|
||||
return failure(new Error((`secretOrPrivateKey must be an asymmetric key when using ${header.alg}`)))
|
||||
}
|
||||
if (!options.allowInsecureKeySizes &&
|
||||
!header.alg.startsWith('ES') &&
|
||||
secretOrPrivateKey.asymmetricKeyDetails !== undefined && //KeyObject.asymmetricKeyDetails is supported in Node 15+
|
||||
secretOrPrivateKey.asymmetricKeyDetails.modulusLength < 2048) {
|
||||
return failure(new Error(`secretOrPrivateKey has a minimum key size of 2048 bits for ${header.alg}`));
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof payload === 'undefined') {
|
||||
return failure(new Error('payload is required'));
|
||||
} else if (isObjectPayload) {
|
||||
try {
|
||||
validatePayload(payload);
|
||||
}
|
||||
catch (error) {
|
||||
return failure(error);
|
||||
}
|
||||
if (!options.mutatePayload) {
|
||||
payload = Object.assign({},payload);
|
||||
}
|
||||
} else {
|
||||
const invalid_options = options_for_objects.filter(function (opt) {
|
||||
return typeof options[opt] !== 'undefined';
|
||||
});
|
||||
|
||||
if (invalid_options.length > 0) {
|
||||
return failure(new Error('invalid ' + invalid_options.join(',') + ' option for ' + (typeof payload ) + ' payload'));
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof payload.exp !== 'undefined' && typeof options.expiresIn !== 'undefined') {
|
||||
return failure(new Error('Bad "options.expiresIn" option the payload already has an "exp" property.'));
|
||||
}
|
||||
|
||||
if (typeof payload.nbf !== 'undefined' && typeof options.notBefore !== 'undefined') {
|
||||
return failure(new Error('Bad "options.notBefore" option the payload already has an "nbf" property.'));
|
||||
}
|
||||
|
||||
try {
|
||||
validateOptions(options);
|
||||
}
|
||||
catch (error) {
|
||||
return failure(error);
|
||||
}
|
||||
|
||||
if (!options.allowInvalidAsymmetricKeyTypes) {
|
||||
try {
|
||||
validateAsymmetricKey(header.alg, secretOrPrivateKey);
|
||||
} catch (error) {
|
||||
return failure(error);
|
||||
}
|
||||
}
|
||||
|
||||
const timestamp = payload.iat || Math.floor(Date.now() / 1000);
|
||||
|
||||
if (options.noTimestamp) {
|
||||
delete payload.iat;
|
||||
} else if (isObjectPayload) {
|
||||
payload.iat = timestamp;
|
||||
}
|
||||
|
||||
if (typeof options.notBefore !== 'undefined') {
|
||||
try {
|
||||
payload.nbf = timespan(options.notBefore, timestamp);
|
||||
}
|
||||
catch (err) {
|
||||
return failure(err);
|
||||
}
|
||||
if (typeof payload.nbf === 'undefined') {
|
||||
return failure(new Error('"notBefore" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'));
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof options.expiresIn !== 'undefined' && typeof payload === 'object') {
|
||||
try {
|
||||
payload.exp = timespan(options.expiresIn, timestamp);
|
||||
}
|
||||
catch (err) {
|
||||
return failure(err);
|
||||
}
|
||||
if (typeof payload.exp === 'undefined') {
|
||||
return failure(new Error('"expiresIn" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'));
|
||||
}
|
||||
}
|
||||
|
||||
Object.keys(options_to_payload).forEach(function (key) {
|
||||
const claim = options_to_payload[key];
|
||||
if (typeof options[key] !== 'undefined') {
|
||||
if (typeof payload[claim] !== 'undefined') {
|
||||
return failure(new Error('Bad "options.' + key + '" option. The payload already has an "' + claim + '" property.'));
|
||||
}
|
||||
payload[claim] = options[key];
|
||||
}
|
||||
});
|
||||
|
||||
const encoding = options.encoding || 'utf8';
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback = callback && once(callback);
|
||||
|
||||
jws.createSign({
|
||||
header: header,
|
||||
privateKey: secretOrPrivateKey,
|
||||
payload: payload,
|
||||
encoding: encoding
|
||||
}).once('error', callback)
|
||||
.once('done', function (signature) {
|
||||
// TODO: Remove in favor of the modulus length check before signing once node 15+ is the minimum supported version
|
||||
if(!options.allowInsecureKeySizes && /^(?:RS|PS)/.test(header.alg) && signature.length < 256) {
|
||||
return callback(new Error(`secretOrPrivateKey has a minimum key size of 2048 bits for ${header.alg}`))
|
||||
}
|
||||
callback(null, signature);
|
||||
});
|
||||
} else {
|
||||
let signature = jws.sign({header: header, payload: payload, secret: secretOrPrivateKey, encoding: encoding});
|
||||
// TODO: Remove in favor of the modulus length check before signing once node 15+ is the minimum supported version
|
||||
if(!options.allowInsecureKeySizes && /^(?:RS|PS)/.test(header.alg) && signature.length < 256) {
|
||||
throw new Error(`secretOrPrivateKey has a minimum key size of 2048 bits for ${header.alg}`)
|
||||
}
|
||||
return signature
|
||||
}
|
||||
};
|
||||
263
node_modules/jsonwebtoken/verify.js
generated
vendored
Normal file
263
node_modules/jsonwebtoken/verify.js
generated
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
const JsonWebTokenError = require('./lib/JsonWebTokenError');
|
||||
const NotBeforeError = require('./lib/NotBeforeError');
|
||||
const TokenExpiredError = require('./lib/TokenExpiredError');
|
||||
const decode = require('./decode');
|
||||
const timespan = require('./lib/timespan');
|
||||
const validateAsymmetricKey = require('./lib/validateAsymmetricKey');
|
||||
const PS_SUPPORTED = require('./lib/psSupported');
|
||||
const jws = require('jws');
|
||||
const {KeyObject, createSecretKey, createPublicKey} = require("crypto");
|
||||
|
||||
const PUB_KEY_ALGS = ['RS256', 'RS384', 'RS512'];
|
||||
const EC_KEY_ALGS = ['ES256', 'ES384', 'ES512'];
|
||||
const RSA_KEY_ALGS = ['RS256', 'RS384', 'RS512'];
|
||||
const HS_ALGS = ['HS256', 'HS384', 'HS512'];
|
||||
|
||||
if (PS_SUPPORTED) {
|
||||
PUB_KEY_ALGS.splice(PUB_KEY_ALGS.length, 0, 'PS256', 'PS384', 'PS512');
|
||||
RSA_KEY_ALGS.splice(RSA_KEY_ALGS.length, 0, 'PS256', 'PS384', 'PS512');
|
||||
}
|
||||
|
||||
module.exports = function (jwtString, secretOrPublicKey, options, callback) {
|
||||
if ((typeof options === 'function') && !callback) {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
//clone this object since we are going to mutate it.
|
||||
options = Object.assign({}, options);
|
||||
|
||||
let done;
|
||||
|
||||
if (callback) {
|
||||
done = callback;
|
||||
} else {
|
||||
done = function(err, data) {
|
||||
if (err) throw err;
|
||||
return data;
|
||||
};
|
||||
}
|
||||
|
||||
if (options.clockTimestamp && typeof options.clockTimestamp !== 'number') {
|
||||
return done(new JsonWebTokenError('clockTimestamp must be a number'));
|
||||
}
|
||||
|
||||
if (options.nonce !== undefined && (typeof options.nonce !== 'string' || options.nonce.trim() === '')) {
|
||||
return done(new JsonWebTokenError('nonce must be a non-empty string'));
|
||||
}
|
||||
|
||||
if (options.allowInvalidAsymmetricKeyTypes !== undefined && typeof options.allowInvalidAsymmetricKeyTypes !== 'boolean') {
|
||||
return done(new JsonWebTokenError('allowInvalidAsymmetricKeyTypes must be a boolean'));
|
||||
}
|
||||
|
||||
const clockTimestamp = options.clockTimestamp || Math.floor(Date.now() / 1000);
|
||||
|
||||
if (!jwtString){
|
||||
return done(new JsonWebTokenError('jwt must be provided'));
|
||||
}
|
||||
|
||||
if (typeof jwtString !== 'string') {
|
||||
return done(new JsonWebTokenError('jwt must be a string'));
|
||||
}
|
||||
|
||||
const parts = jwtString.split('.');
|
||||
|
||||
if (parts.length !== 3){
|
||||
return done(new JsonWebTokenError('jwt malformed'));
|
||||
}
|
||||
|
||||
let decodedToken;
|
||||
|
||||
try {
|
||||
decodedToken = decode(jwtString, { complete: true });
|
||||
} catch(err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
if (!decodedToken) {
|
||||
return done(new JsonWebTokenError('invalid token'));
|
||||
}
|
||||
|
||||
const header = decodedToken.header;
|
||||
let getSecret;
|
||||
|
||||
if(typeof secretOrPublicKey === 'function') {
|
||||
if(!callback) {
|
||||
return done(new JsonWebTokenError('verify must be called asynchronous if secret or public key is provided as a callback'));
|
||||
}
|
||||
|
||||
getSecret = secretOrPublicKey;
|
||||
}
|
||||
else {
|
||||
getSecret = function(header, secretCallback) {
|
||||
return secretCallback(null, secretOrPublicKey);
|
||||
};
|
||||
}
|
||||
|
||||
return getSecret(header, function(err, secretOrPublicKey) {
|
||||
if(err) {
|
||||
return done(new JsonWebTokenError('error in secret or public key callback: ' + err.message));
|
||||
}
|
||||
|
||||
const hasSignature = parts[2].trim() !== '';
|
||||
|
||||
if (!hasSignature && secretOrPublicKey){
|
||||
return done(new JsonWebTokenError('jwt signature is required'));
|
||||
}
|
||||
|
||||
if (hasSignature && !secretOrPublicKey) {
|
||||
return done(new JsonWebTokenError('secret or public key must be provided'));
|
||||
}
|
||||
|
||||
if (!hasSignature && !options.algorithms) {
|
||||
return done(new JsonWebTokenError('please specify "none" in "algorithms" to verify unsigned tokens'));
|
||||
}
|
||||
|
||||
if (secretOrPublicKey != null && !(secretOrPublicKey instanceof KeyObject)) {
|
||||
try {
|
||||
secretOrPublicKey = createPublicKey(secretOrPublicKey);
|
||||
} catch (_) {
|
||||
try {
|
||||
secretOrPublicKey = createSecretKey(typeof secretOrPublicKey === 'string' ? Buffer.from(secretOrPublicKey) : secretOrPublicKey);
|
||||
} catch (_) {
|
||||
return done(new JsonWebTokenError('secretOrPublicKey is not valid key material'))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.algorithms) {
|
||||
if (secretOrPublicKey.type === 'secret') {
|
||||
options.algorithms = HS_ALGS;
|
||||
} else if (['rsa', 'rsa-pss'].includes(secretOrPublicKey.asymmetricKeyType)) {
|
||||
options.algorithms = RSA_KEY_ALGS
|
||||
} else if (secretOrPublicKey.asymmetricKeyType === 'ec') {
|
||||
options.algorithms = EC_KEY_ALGS
|
||||
} else {
|
||||
options.algorithms = PUB_KEY_ALGS
|
||||
}
|
||||
}
|
||||
|
||||
if (options.algorithms.indexOf(decodedToken.header.alg) === -1) {
|
||||
return done(new JsonWebTokenError('invalid algorithm'));
|
||||
}
|
||||
|
||||
if (header.alg.startsWith('HS') && secretOrPublicKey.type !== 'secret') {
|
||||
return done(new JsonWebTokenError((`secretOrPublicKey must be a symmetric key when using ${header.alg}`)))
|
||||
} else if (/^(?:RS|PS|ES)/.test(header.alg) && secretOrPublicKey.type !== 'public') {
|
||||
return done(new JsonWebTokenError((`secretOrPublicKey must be an asymmetric key when using ${header.alg}`)))
|
||||
}
|
||||
|
||||
if (!options.allowInvalidAsymmetricKeyTypes) {
|
||||
try {
|
||||
validateAsymmetricKey(header.alg, secretOrPublicKey);
|
||||
} catch (e) {
|
||||
return done(e);
|
||||
}
|
||||
}
|
||||
|
||||
let valid;
|
||||
|
||||
try {
|
||||
valid = jws.verify(jwtString, decodedToken.header.alg, secretOrPublicKey);
|
||||
} catch (e) {
|
||||
return done(e);
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
return done(new JsonWebTokenError('invalid signature'));
|
||||
}
|
||||
|
||||
const payload = decodedToken.payload;
|
||||
|
||||
if (typeof payload.nbf !== 'undefined' && !options.ignoreNotBefore) {
|
||||
if (typeof payload.nbf !== 'number') {
|
||||
return done(new JsonWebTokenError('invalid nbf value'));
|
||||
}
|
||||
if (payload.nbf > clockTimestamp + (options.clockTolerance || 0)) {
|
||||
return done(new NotBeforeError('jwt not active', new Date(payload.nbf * 1000)));
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof payload.exp !== 'undefined' && !options.ignoreExpiration) {
|
||||
if (typeof payload.exp !== 'number') {
|
||||
return done(new JsonWebTokenError('invalid exp value'));
|
||||
}
|
||||
if (clockTimestamp >= payload.exp + (options.clockTolerance || 0)) {
|
||||
return done(new TokenExpiredError('jwt expired', new Date(payload.exp * 1000)));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.audience) {
|
||||
const audiences = Array.isArray(options.audience) ? options.audience : [options.audience];
|
||||
const target = Array.isArray(payload.aud) ? payload.aud : [payload.aud];
|
||||
|
||||
const match = target.some(function (targetAudience) {
|
||||
return audiences.some(function (audience) {
|
||||
return audience instanceof RegExp ? audience.test(targetAudience) : audience === targetAudience;
|
||||
});
|
||||
});
|
||||
|
||||
if (!match) {
|
||||
return done(new JsonWebTokenError('jwt audience invalid. expected: ' + audiences.join(' or ')));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.issuer) {
|
||||
const invalid_issuer =
|
||||
(typeof options.issuer === 'string' && payload.iss !== options.issuer) ||
|
||||
(Array.isArray(options.issuer) && options.issuer.indexOf(payload.iss) === -1);
|
||||
|
||||
if (invalid_issuer) {
|
||||
return done(new JsonWebTokenError('jwt issuer invalid. expected: ' + options.issuer));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.subject) {
|
||||
if (payload.sub !== options.subject) {
|
||||
return done(new JsonWebTokenError('jwt subject invalid. expected: ' + options.subject));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.jwtid) {
|
||||
if (payload.jti !== options.jwtid) {
|
||||
return done(new JsonWebTokenError('jwt jwtid invalid. expected: ' + options.jwtid));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.nonce) {
|
||||
if (payload.nonce !== options.nonce) {
|
||||
return done(new JsonWebTokenError('jwt nonce invalid. expected: ' + options.nonce));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.maxAge) {
|
||||
if (typeof payload.iat !== 'number') {
|
||||
return done(new JsonWebTokenError('iat required when maxAge is specified'));
|
||||
}
|
||||
|
||||
const maxAgeTimestamp = timespan(options.maxAge, payload.iat);
|
||||
if (typeof maxAgeTimestamp === 'undefined') {
|
||||
return done(new JsonWebTokenError('"maxAge" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60'));
|
||||
}
|
||||
if (clockTimestamp >= maxAgeTimestamp + (options.clockTolerance || 0)) {
|
||||
return done(new TokenExpiredError('maxAge exceeded', new Date(maxAgeTimestamp * 1000)));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.complete === true) {
|
||||
const signature = decodedToken.signature;
|
||||
|
||||
return done(null, {
|
||||
header: header,
|
||||
payload: payload,
|
||||
signature: signature
|
||||
});
|
||||
}
|
||||
|
||||
return done(null, payload);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user