@verdaccio/signature 7.0.0-next.1 → 7.0.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/index.d.ts +1 -1
- package/build/index.js +8 -2
- package/build/index.js.map +1 -1
- package/build/jwt-token.js +1 -1
- package/build/jwt-token.js.map +1 -1
- package/build/legacy-signature/index.js +3 -6
- package/build/legacy-signature/index.js.map +1 -1
- package/build/signature.js +2 -3
- package/build/signature.js.map +1 -1
- package/build/utils.js +2 -4
- package/build/utils.js.map +1 -1
- package/package.json +4 -5
- package/src/index.ts +1 -1
- package/src/jwt-token.ts +1 -1
- package/src/signature.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @verdaccio/signature
|
|
2
2
|
|
|
3
|
+
## 7.0.0-next.3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f047cc8: refactor: auth with legacy sign support
|
|
8
|
+
|
|
9
|
+
## 7.0.0-next.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 312bc100f: chore: export signature options type
|
|
14
|
+
|
|
3
15
|
## 7.0.0-next.1
|
|
4
16
|
|
|
5
17
|
### Major Changes
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { aesDecryptDeprecated, aesEncryptDeprecated, generateRandomSecretKeyDeprecated, } from './legacy-signature';
|
|
2
2
|
export { aesDecrypt, aesEncrypt } from './signature';
|
|
3
|
-
export { signPayload, verifyPayload } from './jwt-token';
|
|
3
|
+
export { signPayload, verifyPayload, SignOptionsSignature } from './jwt-token';
|
|
4
4
|
export * as utils from './utils';
|
|
5
5
|
export * as types from './types';
|
|
6
6
|
export { parseBasicPayload } from './token';
|
package/build/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "SignOptionsSignature", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _jwtToken.SignOptionsSignature;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "aesDecrypt", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
@@ -60,6 +66,6 @@ exports.utils = _utils;
|
|
|
60
66
|
var _types = _interopRequireWildcard(require("./types"));
|
|
61
67
|
exports.types = _types;
|
|
62
68
|
var _token = require("./token");
|
|
63
|
-
function _getRequireWildcardCache(
|
|
64
|
-
function _interopRequireWildcard(
|
|
69
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
70
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
65
71
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_legacySignature","require","_signature","_jwtToken","_utils","_interopRequireWildcard","exports","utils","_types","types","_token","_getRequireWildcardCache","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_legacySignature","require","_signature","_jwtToken","_utils","_interopRequireWildcard","exports","utils","_types","types","_token","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set"],"sources":["../src/index.ts"],"sourcesContent":["export {\n aesDecryptDeprecated,\n aesEncryptDeprecated,\n generateRandomSecretKeyDeprecated,\n} from './legacy-signature';\nexport { aesDecrypt, aesEncrypt } from './signature';\nexport { signPayload, verifyPayload, SignOptionsSignature } from './jwt-token';\nexport * as utils from './utils';\nexport * as types from './types';\nexport { parseBasicPayload } from './token';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAA+E,IAAAG,MAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAAAK,OAAA,CAAAC,KAAA,GAAAH,MAAA;AAAA,IAAAI,MAAA,GAAAH,uBAAA,CAAAJ,OAAA;AAAAK,OAAA,CAAAG,KAAA,GAAAD,MAAA;AAG/E,IAAAE,MAAA,GAAAT,OAAA;AAA4C,SAAAU,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,CAAA,CAAAC,GAAA,IAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAI,CAAA,IAAAV,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAQ,CAAA,GAAAA,CAAA"}
|
package/build/jwt-token.js
CHANGED
|
@@ -37,7 +37,7 @@ async function signPayload(payload, secretOrPrivateKey, options = {}) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
function verifyPayload(token, secretOrPrivateKey) {
|
|
40
|
-
debug('
|
|
40
|
+
debug('verifying jwt token');
|
|
41
41
|
return _jsonwebtoken.default.verify(token, secretOrPrivateKey);
|
|
42
42
|
}
|
|
43
43
|
//# sourceMappingURL=jwt-token.js.map
|
package/build/jwt-token.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-token.js","names":["_debug","_interopRequireDefault","require","_jsonwebtoken","obj","__esModule","default","debug","buildDebug","signPayload","payload","secretOrPrivateKey","options","Promise","resolve","reject","jwt","sign","notBefore","error","token","message","verifyPayload","verify"],"sources":["../src/jwt-token.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport jwt, { SignOptions } from 'jsonwebtoken';\n\nimport { RemoteUser } from '@verdaccio/types';\n\nexport type SignOptionsSignature = Pick<SignOptions, 'algorithm' | 'expiresIn' | 'notBefore'>;\n\nconst debug = buildDebug('verdaccio:auth:token:jwt');\n/**\n * Sign the payload and return JWT\n * https://github.com/auth0/node-jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback\n * @param payload\n * @param secretOrPrivateKey\n * @param options\n */\nexport async function signPayload(\n payload: RemoteUser,\n secretOrPrivateKey: string,\n options: SignOptionsSignature = {}\n): Promise<string> {\n return new Promise(function (resolve, reject) {\n debug('sign jwt token');\n jwt.sign(\n payload,\n secretOrPrivateKey, // FIXME: upgrade to the latest library and types\n {\n // 1 === 1ms (one millisecond)\n notBefore: '1', // Make sure the time will not rollback :)\n ...options,\n },\n (error, token) => {\n if (error) {\n debug('error on sign jwt token %s', error.message);\n return reject(error);\n }\n debug('signed jwt token successfully');\n return resolve(token as string);\n }\n );\n });\n}\n\nexport function verifyPayload(token: string, secretOrPrivateKey: string): RemoteUser {\n debug('
|
|
1
|
+
{"version":3,"file":"jwt-token.js","names":["_debug","_interopRequireDefault","require","_jsonwebtoken","obj","__esModule","default","debug","buildDebug","signPayload","payload","secretOrPrivateKey","options","Promise","resolve","reject","jwt","sign","notBefore","error","token","message","verifyPayload","verify"],"sources":["../src/jwt-token.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport jwt, { SignOptions } from 'jsonwebtoken';\n\nimport { RemoteUser } from '@verdaccio/types';\n\nexport type SignOptionsSignature = Pick<SignOptions, 'algorithm' | 'expiresIn' | 'notBefore'>;\n\nconst debug = buildDebug('verdaccio:auth:token:jwt');\n/**\n * Sign the payload and return JWT\n * https://github.com/auth0/node-jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback\n * @param payload\n * @param secretOrPrivateKey\n * @param options\n */\nexport async function signPayload(\n payload: RemoteUser,\n secretOrPrivateKey: string,\n options: SignOptionsSignature = {}\n): Promise<string> {\n return new Promise(function (resolve, reject) {\n debug('sign jwt token');\n jwt.sign(\n payload,\n secretOrPrivateKey, // FIXME: upgrade to the latest library and types\n {\n // 1 === 1ms (one millisecond)\n notBefore: '1', // Make sure the time will not rollback :)\n ...options,\n },\n (error, token) => {\n if (error) {\n debug('error on sign jwt token %s', error.message);\n return reject(error);\n }\n debug('signed jwt token successfully');\n return resolve(token as string);\n }\n );\n });\n}\n\nexport function verifyPayload(token: string, secretOrPrivateKey: string): RemoteUser {\n debug('verifying jwt token');\n return jwt.verify(token, secretOrPrivateKey) as RemoteUser;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAgD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAMhD,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,0BAA0B,CAAC;AACpD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeC,WAAWA,CAC/BC,OAAmB,EACnBC,kBAA0B,EAC1BC,OAA6B,GAAG,CAAC,CAAC,EACjB;EACjB,OAAO,IAAIC,OAAO,CAAC,UAAUC,OAAO,EAAEC,MAAM,EAAE;IAC5CR,KAAK,CAAC,gBAAgB,CAAC;IACvBS,qBAAG,CAACC,IAAI,CACNP,OAAO,EACPC,kBAAkB;IAAE;IACpB;MACE;MACAO,SAAS,EAAE,GAAG;MAAE;MAChB,GAAGN;IACL,CAAC,EACD,CAACO,KAAK,EAAEC,KAAK,KAAK;MAChB,IAAID,KAAK,EAAE;QACTZ,KAAK,CAAC,4BAA4B,EAAEY,KAAK,CAACE,OAAO,CAAC;QAClD,OAAON,MAAM,CAACI,KAAK,CAAC;MACtB;MACAZ,KAAK,CAAC,+BAA+B,CAAC;MACtC,OAAOO,OAAO,CAACM,KAAe,CAAC;IACjC,CACF,CAAC;EACH,CAAC,CAAC;AACJ;AAEO,SAASE,aAAaA,CAACF,KAAa,EAAET,kBAA0B,EAAc;EACnFJ,KAAK,CAAC,qBAAqB,CAAC;EAC5B,OAAOS,qBAAG,CAACO,MAAM,CAACH,KAAK,EAAET,kBAAkB,CAAC;AAC9C"}
|
|
@@ -10,9 +10,8 @@ exports.defaultTarballHashAlgorithm = exports.defaultAlgorithm = void 0;
|
|
|
10
10
|
exports.generateRandomSecretKeyDeprecated = generateRandomSecretKeyDeprecated;
|
|
11
11
|
var _crypto = require("crypto");
|
|
12
12
|
var _utils = require("../utils");
|
|
13
|
-
const defaultAlgorithm = 'aes192';
|
|
14
|
-
exports.
|
|
15
|
-
const defaultTarballHashAlgorithm = 'sha1';
|
|
13
|
+
const defaultAlgorithm = exports.defaultAlgorithm = 'aes192';
|
|
14
|
+
const defaultTarballHashAlgorithm = exports.defaultTarballHashAlgorithm = 'sha1';
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
*
|
|
@@ -20,7 +19,6 @@ const defaultTarballHashAlgorithm = 'sha1';
|
|
|
20
19
|
* @param secret
|
|
21
20
|
* @returns
|
|
22
21
|
*/
|
|
23
|
-
exports.defaultTarballHashAlgorithm = defaultTarballHashAlgorithm;
|
|
24
22
|
function aesEncryptDeprecated(buf, secret) {
|
|
25
23
|
// deprecated (it will be removed in Verdaccio 6), it is a breaking change
|
|
26
24
|
// https://nodejs.org/api/crypto.html#crypto_crypto_createcipher_algorithm_password_options
|
|
@@ -49,12 +47,11 @@ function aesDecryptDeprecated(buf, secret) {
|
|
|
49
47
|
return Buffer.alloc(0);
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
|
-
const TOKEN_VALID_LENGTH_DEPRECATED = 64;
|
|
50
|
+
const TOKEN_VALID_LENGTH_DEPRECATED = exports.TOKEN_VALID_LENGTH_DEPRECATED = 64;
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* Generate a secret key of 64 characters.
|
|
56
54
|
*/
|
|
57
|
-
exports.TOKEN_VALID_LENGTH_DEPRECATED = TOKEN_VALID_LENGTH_DEPRECATED;
|
|
58
55
|
function generateRandomSecretKeyDeprecated() {
|
|
59
56
|
return (0, _utils.generateRandomHexString)(6);
|
|
60
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_crypto","require","_utils","defaultAlgorithm","exports","defaultTarballHashAlgorithm","aesEncryptDeprecated","buf","secret","c","createCipher","b1","update","b2","final","Buffer","concat","aesDecryptDeprecated","createDecipher","_","alloc","TOKEN_VALID_LENGTH_DEPRECATED","generateRandomSecretKeyDeprecated","generateRandomHexString"],"sources":["../../src/legacy-signature/index.ts"],"sourcesContent":["import { createCipher, createDecipher } from 'crypto';\n\nimport { generateRandomHexString } from '../utils';\n\nexport const defaultAlgorithm = 'aes192';\nexport const defaultTarballHashAlgorithm = 'sha1';\n\n/**\n *\n * @param buf\n * @param secret\n * @returns\n */\nexport function aesEncryptDeprecated(buf: Buffer, secret: string): Buffer {\n // deprecated (it will be removed in Verdaccio 6), it is a breaking change\n // https://nodejs.org/api/crypto.html#crypto_crypto_createcipher_algorithm_password_options\n // https://www.grainger.xyz/changing-from-cipher-to-cipheriv/\n const c = createCipher(defaultAlgorithm, secret);\n const b1 = c.update(buf);\n const b2 = c.final();\n return Buffer.concat([b1, b2]);\n}\n\n/**\n *\n * @param buf\n * @param secret\n * @returns\n */\nexport function aesDecryptDeprecated(buf: Buffer, secret: string): Buffer {\n try {\n // https://nodejs.org/api/crypto.html#crypto_crypto_createdecipher_algorithm_password_options\n // https://www.grainger.xyz/changing-from-cipher-to-cipheriv/\n const c = createDecipher(defaultAlgorithm, secret);\n const b1 = c.update(buf);\n const b2 = c.final();\n return Buffer.concat([b1, b2]);\n } catch (_) {\n return Buffer.alloc(0);\n }\n}\n\nexport const TOKEN_VALID_LENGTH_DEPRECATED = 64;\n\n/**\n * Generate a secret key of 64 characters.\n */\nexport function generateRandomSecretKeyDeprecated(): string {\n return generateRandomHexString(6);\n}\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEO,MAAME,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","names":["_crypto","require","_utils","defaultAlgorithm","exports","defaultTarballHashAlgorithm","aesEncryptDeprecated","buf","secret","c","createCipher","b1","update","b2","final","Buffer","concat","aesDecryptDeprecated","createDecipher","_","alloc","TOKEN_VALID_LENGTH_DEPRECATED","generateRandomSecretKeyDeprecated","generateRandomHexString"],"sources":["../../src/legacy-signature/index.ts"],"sourcesContent":["import { createCipher, createDecipher } from 'crypto';\n\nimport { generateRandomHexString } from '../utils';\n\nexport const defaultAlgorithm = 'aes192';\nexport const defaultTarballHashAlgorithm = 'sha1';\n\n/**\n *\n * @param buf\n * @param secret\n * @returns\n */\nexport function aesEncryptDeprecated(buf: Buffer, secret: string): Buffer {\n // deprecated (it will be removed in Verdaccio 6), it is a breaking change\n // https://nodejs.org/api/crypto.html#crypto_crypto_createcipher_algorithm_password_options\n // https://www.grainger.xyz/changing-from-cipher-to-cipheriv/\n const c = createCipher(defaultAlgorithm, secret);\n const b1 = c.update(buf);\n const b2 = c.final();\n return Buffer.concat([b1, b2]);\n}\n\n/**\n *\n * @param buf\n * @param secret\n * @returns\n */\nexport function aesDecryptDeprecated(buf: Buffer, secret: string): Buffer {\n try {\n // https://nodejs.org/api/crypto.html#crypto_crypto_createdecipher_algorithm_password_options\n // https://www.grainger.xyz/changing-from-cipher-to-cipheriv/\n const c = createDecipher(defaultAlgorithm, secret);\n const b1 = c.update(buf);\n const b2 = c.final();\n return Buffer.concat([b1, b2]);\n } catch (_) {\n return Buffer.alloc(0);\n }\n}\n\nexport const TOKEN_VALID_LENGTH_DEPRECATED = 64;\n\n/**\n * Generate a secret key of 64 characters.\n */\nexport function generateRandomSecretKeyDeprecated(): string {\n return generateRandomHexString(6);\n}\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEO,MAAME,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAG,QAAQ;AACjC,MAAME,2BAA2B,GAAAD,OAAA,CAAAC,2BAAA,GAAG,MAAM;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,oBAAoBA,CAACC,GAAW,EAAEC,MAAc,EAAU;EACxE;EACA;EACA;EACA,MAAMC,CAAC,GAAG,IAAAC,oBAAY,EAACP,gBAAgB,EAAEK,MAAM,CAAC;EAChD,MAAMG,EAAE,GAAGF,CAAC,CAACG,MAAM,CAACL,GAAG,CAAC;EACxB,MAAMM,EAAE,GAAGJ,CAAC,CAACK,KAAK,CAAC,CAAC;EACpB,OAAOC,MAAM,CAACC,MAAM,CAAC,CAACL,EAAE,EAAEE,EAAE,CAAC,CAAC;AAChC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,oBAAoBA,CAACV,GAAW,EAAEC,MAAc,EAAU;EACxE,IAAI;IACF;IACA;IACA,MAAMC,CAAC,GAAG,IAAAS,sBAAc,EAACf,gBAAgB,EAAEK,MAAM,CAAC;IAClD,MAAMG,EAAE,GAAGF,CAAC,CAACG,MAAM,CAACL,GAAG,CAAC;IACxB,MAAMM,EAAE,GAAGJ,CAAC,CAACK,KAAK,CAAC,CAAC;IACpB,OAAOC,MAAM,CAACC,MAAM,CAAC,CAACL,EAAE,EAAEE,EAAE,CAAC,CAAC;EAChC,CAAC,CAAC,OAAOM,CAAC,EAAE;IACV,OAAOJ,MAAM,CAACK,KAAK,CAAC,CAAC,CAAC;EACxB;AACF;AAEO,MAAMC,6BAA6B,GAAAjB,OAAA,CAAAiB,6BAAA,GAAG,EAAE;;AAE/C;AACA;AACA;AACO,SAASC,iCAAiCA,CAAA,EAAW;EAC1D,OAAO,IAAAC,8BAAuB,EAAC,CAAC,CAAC;AACnC"}
|
package/build/signature.js
CHANGED
|
@@ -11,8 +11,7 @@ var _debug = _interopRequireDefault(require("debug"));
|
|
|
11
11
|
var _config = require("@verdaccio/config");
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
const debug = (0, _debug.default)('verdaccio:auth:token:legacy');
|
|
14
|
-
const defaultAlgorithm = process.env.VERDACCIO_LEGACY_ALGORITHM || 'aes-256-ctr';
|
|
15
|
-
exports.defaultAlgorithm = defaultAlgorithm;
|
|
14
|
+
const defaultAlgorithm = exports.defaultAlgorithm = process.env.VERDACCIO_LEGACY_ALGORITHM || 'aes-256-ctr';
|
|
16
15
|
const inputEncoding = 'utf8';
|
|
17
16
|
const outputEncoding = 'hex';
|
|
18
17
|
// Must be 256 bits (32 characters)
|
|
@@ -24,7 +23,7 @@ function aesEncrypt(value, key) {
|
|
|
24
23
|
debug('encrypt %o', value);
|
|
25
24
|
debug('algorithm %o', defaultAlgorithm);
|
|
26
25
|
// IV must be a buffer of length 16
|
|
27
|
-
const iv =
|
|
26
|
+
const iv = (0, _crypto.randomBytes)(16);
|
|
28
27
|
const secretKey = VERDACCIO_LEGACY_ENCRYPTION_KEY || key;
|
|
29
28
|
const isKeyValid = (secretKey === null || secretKey === void 0 ? void 0 : secretKey.length) === _config.TOKEN_VALID_LENGTH;
|
|
30
29
|
debug('length secret key %o', secretKey === null || secretKey === void 0 ? void 0 : secretKey.length);
|
package/build/signature.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.js","names":["_crypto","require","_debug","_interopRequireDefault","_config","obj","__esModule","default","debug","buildDebug","defaultAlgorithm","process","env","VERDACCIO_LEGACY_ALGORITHM","
|
|
1
|
+
{"version":3,"file":"signature.js","names":["_crypto","require","_debug","_interopRequireDefault","_config","obj","__esModule","default","debug","buildDebug","defaultAlgorithm","exports","process","env","VERDACCIO_LEGACY_ALGORITHM","inputEncoding","outputEncoding","VERDACCIO_LEGACY_ENCRYPTION_KEY","aesEncrypt","value","key","iv","randomBytes","secretKey","isKeyValid","length","TOKEN_VALID_LENGTH","cipher","createCipheriv","encrypted","update","final","token","toString","Buffer","from","aesDecrypt","buff","textParts","split","IV","shift","encryptedText","join","decipher","createDecipheriv","decrypted","_"],"sources":["../src/signature.ts"],"sourcesContent":["import {\n BinaryToTextEncoding,\n CharacterEncoding,\n createCipheriv,\n createDecipheriv,\n randomBytes,\n} from 'crypto';\nimport buildDebug from 'debug';\n\nimport { TOKEN_VALID_LENGTH } from '@verdaccio/config';\n\nconst debug = buildDebug('verdaccio:auth:token:legacy');\n\nexport const defaultAlgorithm = process.env.VERDACCIO_LEGACY_ALGORITHM || 'aes-256-ctr';\nconst inputEncoding: CharacterEncoding = 'utf8';\nconst outputEncoding: BinaryToTextEncoding = 'hex';\n// Must be 256 bits (32 characters)\n// https://stackoverflow.com/questions/50963160/invalid-key-length-in-crypto-createcipheriv#50963356\nconst VERDACCIO_LEGACY_ENCRYPTION_KEY = process.env.VERDACCIO_LEGACY_ENCRYPTION_KEY;\n\nexport function aesEncrypt(value: string, key: string): string | void {\n // https://nodejs.org/api/crypto.html#crypto_crypto_createcipher_algorithm_password_options\n // https://www.grainger.xyz/posts/changing-from-cipher-to-cipheriv\n debug('encrypt %o', value);\n debug('algorithm %o', defaultAlgorithm);\n // IV must be a buffer of length 16\n const iv = randomBytes(16);\n const secretKey = VERDACCIO_LEGACY_ENCRYPTION_KEY || key;\n const isKeyValid = secretKey?.length === TOKEN_VALID_LENGTH;\n debug('length secret key %o', secretKey?.length);\n debug('is valid secret %o', isKeyValid);\n if (!value || !secretKey || !isKeyValid) {\n return;\n }\n\n const cipher = createCipheriv(defaultAlgorithm, secretKey, iv);\n let encrypted = cipher.update(value, inputEncoding, outputEncoding);\n // @ts-ignore\n encrypted += cipher.final(outputEncoding);\n const token = `${iv.toString('hex')}:${encrypted.toString()}`;\n debug('token generated successfully');\n return Buffer.from(token).toString('base64');\n}\n\nexport function aesDecrypt(value: string, key: string): string | void {\n try {\n const buff = Buffer.from(value, 'base64');\n const textParts = buff.toString().split(':');\n\n // extract the IV from the first half of the value\n // @ts-ignore\n const IV = Buffer.from(textParts.shift(), outputEncoding);\n // extract the encrypted text without the IV\n const encryptedText = Buffer.from(textParts.join(':'), outputEncoding);\n const secretKey = VERDACCIO_LEGACY_ENCRYPTION_KEY || key;\n // decipher the string\n const decipher = createDecipheriv(defaultAlgorithm, secretKey, IV);\n // FIXME: fix type here should allow Buffer\n let decrypted = decipher.update(encryptedText as any, outputEncoding, inputEncoding);\n decrypted += decipher.final(inputEncoding);\n debug('token decrypted successfully');\n return decrypted.toString();\n } catch (_: any) {\n return;\n }\n}\n"],"mappings":"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"}
|
package/build/utils.js
CHANGED
|
@@ -10,13 +10,12 @@ exports.generateRandomHexString = generateRandomHexString;
|
|
|
10
10
|
exports.generateRandomSecretKey = generateRandomSecretKey;
|
|
11
11
|
exports.stringToMD5 = stringToMD5;
|
|
12
12
|
var _crypto = require("crypto");
|
|
13
|
-
const defaultTarballHashAlgorithm = 'sha1';
|
|
13
|
+
const defaultTarballHashAlgorithm = exports.defaultTarballHashAlgorithm = 'sha1';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
*
|
|
17
17
|
* @returns
|
|
18
18
|
*/
|
|
19
|
-
exports.defaultTarballHashAlgorithm = defaultTarballHashAlgorithm;
|
|
20
19
|
function createTarballHash(algorithm = defaultTarballHashAlgorithm) {
|
|
21
20
|
return (0, _crypto.createHash)(algorithm);
|
|
22
21
|
}
|
|
@@ -40,12 +39,11 @@ function stringToMD5(data) {
|
|
|
40
39
|
function generateRandomHexString(length = 8) {
|
|
41
40
|
return (0, _crypto.pseudoRandomBytes)(length).toString('hex');
|
|
42
41
|
}
|
|
43
|
-
const TOKEN_VALID_LENGTH = 32;
|
|
42
|
+
const TOKEN_VALID_LENGTH = exports.TOKEN_VALID_LENGTH = 32;
|
|
44
43
|
|
|
45
44
|
/**
|
|
46
45
|
* Generate a secret of 32 characters.
|
|
47
46
|
*/
|
|
48
|
-
exports.TOKEN_VALID_LENGTH = TOKEN_VALID_LENGTH;
|
|
49
47
|
function generateRandomSecretKey() {
|
|
50
48
|
return (0, _crypto.randomBytes)(TOKEN_VALID_LENGTH).toString('base64').substring(0, TOKEN_VALID_LENGTH);
|
|
51
49
|
}
|
package/build/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["_crypto","require","defaultTarballHashAlgorithm","exports","createTarballHash","algorithm","createHash","stringToMD5","data","update","digest","generateRandomHexString","length","pseudoRandomBytes","toString","TOKEN_VALID_LENGTH","generateRandomSecretKey","randomBytes","substring"],"sources":["../src/utils.ts"],"sourcesContent":["import { Hash, createHash, pseudoRandomBytes, randomBytes } from 'crypto';\n\nexport const defaultTarballHashAlgorithm = 'sha1';\n\n/**\n *\n * @returns\n */\nexport function createTarballHash(algorithm = defaultTarballHashAlgorithm): Hash {\n return createHash(algorithm);\n}\n\n/**\n * Express doesn't do ETAGS with requests <= 1024b\n * we use md5 here, it works well on 1k+ bytes, but with fewer data\n * could improve performance using crc32 after benchmarks.\n * @param {Object} data\n * @return {String}\n */\nexport function stringToMD5(data: Buffer | string): string {\n return createHash('md5').update(data).digest('hex');\n}\n\n/**\n *\n * @param length\n * @returns\n */\nexport function generateRandomHexString(length = 8): string {\n return pseudoRandomBytes(length).toString('hex');\n}\n\nexport const TOKEN_VALID_LENGTH = 32;\n\n/**\n * Generate a secret of 32 characters.\n */\nexport function generateRandomSecretKey(): string {\n return randomBytes(TOKEN_VALID_LENGTH).toString('base64').substring(0, TOKEN_VALID_LENGTH);\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEO,MAAMC,2BAA2B,GAAG,MAAM;;AAEjD;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_crypto","require","defaultTarballHashAlgorithm","exports","createTarballHash","algorithm","createHash","stringToMD5","data","update","digest","generateRandomHexString","length","pseudoRandomBytes","toString","TOKEN_VALID_LENGTH","generateRandomSecretKey","randomBytes","substring"],"sources":["../src/utils.ts"],"sourcesContent":["import { Hash, createHash, pseudoRandomBytes, randomBytes } from 'crypto';\n\nexport const defaultTarballHashAlgorithm = 'sha1';\n\n/**\n *\n * @returns\n */\nexport function createTarballHash(algorithm = defaultTarballHashAlgorithm): Hash {\n return createHash(algorithm);\n}\n\n/**\n * Express doesn't do ETAGS with requests <= 1024b\n * we use md5 here, it works well on 1k+ bytes, but with fewer data\n * could improve performance using crc32 after benchmarks.\n * @param {Object} data\n * @return {String}\n */\nexport function stringToMD5(data: Buffer | string): string {\n return createHash('md5').update(data).digest('hex');\n}\n\n/**\n *\n * @param length\n * @returns\n */\nexport function generateRandomHexString(length = 8): string {\n return pseudoRandomBytes(length).toString('hex');\n}\n\nexport const TOKEN_VALID_LENGTH = 32;\n\n/**\n * Generate a secret of 32 characters.\n */\nexport function generateRandomSecretKey(): string {\n return randomBytes(TOKEN_VALID_LENGTH).toString('base64').substring(0, TOKEN_VALID_LENGTH);\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEO,MAAMC,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAG,MAAM;;AAEjD;AACA;AACA;AACA;AACO,SAASE,iBAAiBA,CAACC,SAAS,GAAGH,2BAA2B,EAAQ;EAC/E,OAAO,IAAAI,kBAAU,EAACD,SAAS,CAAC;AAC9B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,WAAWA,CAACC,IAAqB,EAAU;EACzD,OAAO,IAAAF,kBAAU,EAAC,KAAK,CAAC,CAACG,MAAM,CAACD,IAAI,CAAC,CAACE,MAAM,CAAC,KAAK,CAAC;AACrD;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,uBAAuBA,CAACC,MAAM,GAAG,CAAC,EAAU;EAC1D,OAAO,IAAAC,yBAAiB,EAACD,MAAM,CAAC,CAACE,QAAQ,CAAC,KAAK,CAAC;AAClD;AAEO,MAAMC,kBAAkB,GAAAZ,OAAA,CAAAY,kBAAA,GAAG,EAAE;;AAEpC;AACA;AACA;AACO,SAASC,uBAAuBA,CAAA,EAAW;EAChD,OAAO,IAAAC,mBAAW,EAACF,kBAAkB,CAAC,CAACD,QAAQ,CAAC,QAAQ,CAAC,CAACI,SAAS,CAAC,CAAC,EAAEH,kBAAkB,CAAC;AAC5F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/signature",
|
|
3
|
-
"version": "7.0.0-next.
|
|
3
|
+
"version": "7.0.0-next.3",
|
|
4
4
|
"description": "verdaccio signature utils",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -30,12 +30,11 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"jsonwebtoken": "9.0.2",
|
|
33
|
-
"debug": "4.3.4"
|
|
34
|
-
"lodash": "4.17.21"
|
|
33
|
+
"debug": "4.3.4"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
|
-
"@verdaccio/config": "7.0.0-next.
|
|
38
|
-
"@verdaccio/types": "12.0.0-next.
|
|
36
|
+
"@verdaccio/config": "7.0.0-next.5",
|
|
37
|
+
"@verdaccio/types": "12.0.0-next.2"
|
|
39
38
|
},
|
|
40
39
|
"funding": {
|
|
41
40
|
"type": "opencollective",
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ export {
|
|
|
4
4
|
generateRandomSecretKeyDeprecated,
|
|
5
5
|
} from './legacy-signature';
|
|
6
6
|
export { aesDecrypt, aesEncrypt } from './signature';
|
|
7
|
-
export { signPayload, verifyPayload } from './jwt-token';
|
|
7
|
+
export { signPayload, verifyPayload, SignOptionsSignature } from './jwt-token';
|
|
8
8
|
export * as utils from './utils';
|
|
9
9
|
export * as types from './types';
|
|
10
10
|
export { parseBasicPayload } from './token';
|
package/src/jwt-token.ts
CHANGED
|
@@ -41,6 +41,6 @@ export async function signPayload(
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function verifyPayload(token: string, secretOrPrivateKey: string): RemoteUser {
|
|
44
|
-
debug('
|
|
44
|
+
debug('verifying jwt token');
|
|
45
45
|
return jwt.verify(token, secretOrPrivateKey) as RemoteUser;
|
|
46
46
|
}
|
package/src/signature.ts
CHANGED
|
@@ -24,7 +24,7 @@ export function aesEncrypt(value: string, key: string): string | void {
|
|
|
24
24
|
debug('encrypt %o', value);
|
|
25
25
|
debug('algorithm %o', defaultAlgorithm);
|
|
26
26
|
// IV must be a buffer of length 16
|
|
27
|
-
const iv =
|
|
27
|
+
const iv = randomBytes(16);
|
|
28
28
|
const secretKey = VERDACCIO_LEGACY_ENCRYPTION_KEY || key;
|
|
29
29
|
const isKeyValid = secretKey?.length === TOKEN_VALID_LENGTH;
|
|
30
30
|
debug('length secret key %o', secretKey?.length);
|