@celljs/security 4.0.0 → 4.2.0
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/README.md +113 -1
- package/cell.yml +1 -2
- package/esm/browser/module.d.ts +1 -1
- package/esm/browser/user/behavior-subject.d.ts +16 -0
- package/esm/browser/user/behavior-subject.js +28 -0
- package/esm/browser/user/behavior-subject.js.map +1 -0
- package/esm/browser/user/index.d.ts +1 -0
- package/esm/browser/user/index.js +1 -0
- package/esm/browser/user/index.js.map +1 -1
- package/esm/browser/user/user-manager.d.ts +1 -1
- package/esm/browser/user/user-manager.js +2 -3
- package/esm/browser/user/user-manager.js.map +1 -1
- package/esm/browser/user/user-protocol.d.ts +1 -1
- package/esm/node/access/access-protocol.d.ts +0 -4
- package/esm/node/access/access-protocol.js +0 -1
- package/esm/node/access/access-protocol.js.map +1 -1
- package/esm/node/access/index.d.ts +1 -1
- package/esm/node/access/index.js +1 -1
- package/esm/node/access/index.js.map +1 -1
- package/esm/node/access/method-advice.js +3 -7
- package/esm/node/access/method-advice.js.map +1 -1
- package/esm/node/access/pattern-util.d.ts +8 -0
- package/esm/node/access/pattern-util.js +78 -0
- package/esm/node/access/pattern-util.js.map +1 -0
- package/esm/node/access/policy-provider.js +2 -3
- package/esm/node/access/policy-provider.js.map +1 -1
- package/esm/node/access/policy-resolver.d.ts +3 -2
- package/esm/node/access/policy-resolver.js +8 -11
- package/esm/node/access/policy-resolver.js.map +1 -1
- package/esm/node/access/resource-name-resolver.d.ts +3 -0
- package/esm/node/access/resource-name-resolver.js +10 -7
- package/esm/node/access/resource-name-resolver.js.map +1 -1
- package/esm/node/authentication/authentication-provider.d.ts +8 -0
- package/esm/node/authentication/authentication-provider.js +29 -2
- package/esm/node/authentication/authentication-provider.js.map +1 -1
- package/esm/node/authentication/authentication-success-handler.js +4 -0
- package/esm/node/authentication/authentication-success-handler.js.map +1 -1
- package/esm/node/cache/request-cache.d.ts +2 -0
- package/esm/node/cache/request-cache.js +7 -2
- package/esm/node/cache/request-cache.js.map +1 -1
- package/esm/node/crypto/keygen/base64-string-key-generator.d.ts +4 -0
- package/esm/node/crypto/keygen/base64-string-key-generator.js +6 -4
- package/esm/node/crypto/keygen/base64-string-key-generator.js.map +1 -1
- package/esm/node/crypto/password/password-encoder.d.ts +40 -3
- package/esm/node/crypto/password/password-encoder.js +80 -24
- package/esm/node/crypto/password/password-encoder.js.map +1 -1
- package/esm/node/crypto/password/password-protocol.d.ts +6 -0
- package/esm/node/module.d.ts +1 -2
- package/esm/node/module.js +0 -1
- package/esm/node/module.js.map +1 -1
- package/esm/node/user/user-protocol.d.ts +5 -0
- package/esm/node/user/user-service.d.ts +14 -0
- package/esm/node/user/user-service.js +33 -2
- package/esm/node/user/user-service.js.map +1 -1
- package/lib/browser/module.d.ts +1 -1
- package/lib/browser/user/behavior-subject.d.ts +17 -0
- package/lib/browser/user/behavior-subject.d.ts.map +1 -0
- package/lib/browser/user/behavior-subject.js +32 -0
- package/lib/browser/user/behavior-subject.js.map +1 -0
- package/lib/browser/user/behavior-subject.spec.d.ts +2 -0
- package/lib/browser/user/behavior-subject.spec.d.ts.map +1 -0
- package/lib/browser/user/behavior-subject.spec.js +20 -0
- package/lib/browser/user/behavior-subject.spec.js.map +1 -0
- package/lib/browser/user/index.d.ts +1 -0
- package/lib/browser/user/index.d.ts.map +1 -1
- package/lib/browser/user/index.js +1 -0
- package/lib/browser/user/index.js.map +1 -1
- package/lib/browser/user/user-manager.d.ts +1 -1
- package/lib/browser/user/user-manager.d.ts.map +1 -1
- package/lib/browser/user/user-manager.js +3 -4
- package/lib/browser/user/user-manager.js.map +1 -1
- package/lib/browser/user/user-protocol.d.ts +1 -1
- package/lib/browser/user/user-protocol.d.ts.map +1 -1
- package/lib/node/access/access-protocol.d.ts +0 -4
- package/lib/node/access/access-protocol.d.ts.map +1 -1
- package/lib/node/access/access-protocol.js +1 -2
- package/lib/node/access/access-protocol.js.map +1 -1
- package/lib/node/access/expression-resolvers.spec.d.ts +2 -0
- package/lib/node/access/expression-resolvers.spec.d.ts.map +1 -0
- package/lib/node/access/expression-resolvers.spec.js +57 -0
- package/lib/node/access/expression-resolvers.spec.js.map +1 -0
- package/lib/node/access/index.d.ts +1 -1
- package/lib/node/access/index.d.ts.map +1 -1
- package/lib/node/access/index.js +1 -1
- package/lib/node/access/index.js.map +1 -1
- package/lib/node/access/method-advice.d.ts.map +1 -1
- package/lib/node/access/method-advice.js +2 -5
- package/lib/node/access/method-advice.js.map +1 -1
- package/lib/node/access/pattern-util.d.ts +9 -0
- package/lib/node/access/pattern-util.d.ts.map +1 -0
- package/lib/node/access/pattern-util.js +81 -0
- package/lib/node/access/pattern-util.js.map +1 -0
- package/lib/node/access/pattern-util.spec.d.ts +2 -0
- package/lib/node/access/pattern-util.spec.d.ts.map +1 -0
- package/lib/node/access/pattern-util.spec.js +35 -0
- package/lib/node/access/pattern-util.spec.js.map +1 -0
- package/lib/node/access/policy-provider.js +2 -2
- package/lib/node/access/policy-provider.js.map +1 -1
- package/lib/node/access/policy-resolver.d.ts +3 -2
- package/lib/node/access/policy-resolver.d.ts.map +1 -1
- package/lib/node/access/policy-resolver.js +6 -8
- package/lib/node/access/policy-resolver.js.map +1 -1
- package/lib/node/access/resource-name-resolver.d.ts +3 -0
- package/lib/node/access/resource-name-resolver.d.ts.map +1 -1
- package/lib/node/access/resource-name-resolver.js +9 -5
- package/lib/node/access/resource-name-resolver.js.map +1 -1
- package/lib/node/authentication/authentication-provider.d.ts +8 -0
- package/lib/node/authentication/authentication-provider.d.ts.map +1 -1
- package/lib/node/authentication/authentication-provider.js +29 -1
- package/lib/node/authentication/authentication-provider.js.map +1 -1
- package/lib/node/authentication/authentication-success-handler.d.ts.map +1 -1
- package/lib/node/authentication/authentication-success-handler.js +4 -0
- package/lib/node/authentication/authentication-success-handler.js.map +1 -1
- package/lib/node/authentication/basic-authentication.spec.d.ts +2 -0
- package/lib/node/authentication/basic-authentication.spec.d.ts.map +1 -0
- package/lib/node/authentication/basic-authentication.spec.js +65 -0
- package/lib/node/authentication/basic-authentication.spec.js.map +1 -0
- package/lib/node/cache/request-cache.d.ts +2 -0
- package/lib/node/cache/request-cache.d.ts.map +1 -1
- package/lib/node/cache/request-cache.js +7 -35
- package/lib/node/cache/request-cache.js.map +1 -1
- package/lib/node/cache/request-cache.spec.d.ts +2 -0
- package/lib/node/cache/request-cache.spec.d.ts.map +1 -0
- package/lib/node/cache/request-cache.spec.js +16 -0
- package/lib/node/cache/request-cache.spec.js.map +1 -0
- package/lib/node/crypto/keygen/base64-string-key-generator.d.ts +4 -0
- package/lib/node/crypto/keygen/base64-string-key-generator.d.ts.map +1 -1
- package/lib/node/crypto/keygen/base64-string-key-generator.js +6 -3
- package/lib/node/crypto/keygen/base64-string-key-generator.js.map +1 -1
- package/lib/node/crypto/keygen/base64-string-key-generator.spec.d.ts +2 -0
- package/lib/node/crypto/keygen/base64-string-key-generator.spec.d.ts.map +1 -0
- package/lib/node/crypto/keygen/base64-string-key-generator.spec.js +15 -0
- package/lib/node/crypto/keygen/base64-string-key-generator.spec.js.map +1 -0
- package/lib/node/crypto/password/password-encoder.d.ts +40 -3
- package/lib/node/crypto/password/password-encoder.d.ts.map +1 -1
- package/lib/node/crypto/password/password-encoder.js +80 -23
- package/lib/node/crypto/password/password-encoder.js.map +1 -1
- package/lib/node/crypto/password/password-encoder.spec.d.ts +2 -0
- package/lib/node/crypto/password/password-encoder.spec.d.ts.map +1 -0
- package/lib/node/crypto/password/password-encoder.spec.js +147 -0
- package/lib/node/crypto/password/password-encoder.spec.js.map +1 -0
- package/lib/node/crypto/password/password-protocol.d.ts +6 -0
- package/lib/node/crypto/password/password-protocol.d.ts.map +1 -1
- package/lib/node/module.d.ts +1 -2
- package/lib/node/module.d.ts.map +1 -1
- package/lib/node/module.js +0 -1
- package/lib/node/module.js.map +1 -1
- package/lib/node/user/user-protocol.d.ts +5 -0
- package/lib/node/user/user-protocol.d.ts.map +1 -1
- package/lib/node/user/user-service.d.ts +14 -0
- package/lib/node/user/user-service.d.ts.map +1 -1
- package/lib/node/user/user-service.js +33 -2
- package/lib/node/user/user-service.js.map +1 -1
- package/lib/node/user/user-service.spec.d.ts +2 -0
- package/lib/node/user/user-service.spec.d.ts.map +1 -0
- package/lib/node/user/user-service.spec.js +44 -0
- package/lib/node/user/user-service.spec.js.map +1 -0
- package/package.json +7 -17
- package/src/browser/user/behavior-subject.spec.ts +18 -0
- package/src/browser/user/behavior-subject.ts +36 -0
- package/src/browser/user/index.ts +2 -1
- package/src/browser/user/user-manager.ts +3 -5
- package/src/browser/user/user-protocol.ts +2 -2
- package/src/node/access/access-protocol.ts +0 -5
- package/src/node/access/expression-resolvers.spec.ts +37 -0
- package/src/node/access/index.ts +1 -1
- package/src/node/access/method-advice.ts +1 -2
- package/src/node/access/pattern-util.spec.ts +33 -0
- package/src/node/access/pattern-util.ts +71 -0
- package/src/node/access/policy-provider.ts +3 -3
- package/src/node/access/policy-resolver.ts +8 -10
- package/src/node/access/resource-name-resolver.ts +11 -7
- package/src/node/authentication/authentication-provider.ts +26 -2
- package/src/node/authentication/authentication-success-handler.ts +4 -0
- package/src/node/authentication/basic-authentication.spec.ts +68 -0
- package/src/node/cache/request-cache.spec.ts +14 -0
- package/src/node/cache/request-cache.ts +8 -3
- package/src/node/crypto/keygen/base64-string-key-generator.spec.ts +13 -0
- package/src/node/crypto/keygen/base64-string-key-generator.ts +6 -3
- package/src/node/crypto/password/password-encoder.spec.ts +162 -0
- package/src/node/crypto/password/password-encoder.ts +99 -21
- package/src/node/crypto/password/password-protocol.ts +6 -0
- package/src/node/module.ts +0 -1
- package/src/node/user/user-protocol.ts +5 -0
- package/src/node/user/user-service.spec.ts +46 -0
- package/src/node/user/user-service.ts +32 -2
- package/esm/node/access/jexl-engine-provider.d.ts +0 -5
- package/esm/node/access/jexl-engine-provider.js +0 -22
- package/esm/node/access/jexl-engine-provider.js.map +0 -1
- package/lib/node/access/jexl-engine-provider.d.ts +0 -6
- package/lib/node/access/jexl-engine-provider.d.ts.map +0 -1
- package/lib/node/access/jexl-engine-provider.js +0 -25
- package/lib/node/access/jexl-engine-provider.js.map +0 -1
- package/src/node/access/jexl-engine-provider.ts +0 -18
|
@@ -1,9 +1,46 @@
|
|
|
1
1
|
import { PasswordEncoder } from './password-protocol';
|
|
2
|
+
export interface Pbkdf2PasswordEncoderOptions {
|
|
3
|
+
/** Optional pepper. New hashes mix it into the salt when it is set; legacy hashes were made with `String(secret)`. */
|
|
4
|
+
secret?: string | number;
|
|
5
|
+
/** Legacy hashes only: they are base64 of the hex text. */
|
|
6
|
+
encodeHashAsBase64?: boolean;
|
|
7
|
+
/** Legacy hashes only: PBKDF2 iterations they were made with. Default 250000 (crypto-js 4.2.0). */
|
|
8
|
+
iterations?: number;
|
|
9
|
+
/** Legacy hashes only: derived key length in 32-bit words. Default 4 (16 bytes, crypto-js 4.2.0). */
|
|
10
|
+
keySize?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Password hashes with PBKDF2-HMAC-SHA256 on node:crypto, compared in constant time.
|
|
14
|
+
*
|
|
15
|
+
* New hashes: `pbkdf2-sha256$<iterations>$<salt, base64>$<key, base64>` with 600000 iterations, a 16-byte
|
|
16
|
+
* random salt (followed by the UTF-8 bytes of `secret` when one is set) and a 32-byte key.
|
|
17
|
+
*
|
|
18
|
+
* Legacy hashes (no prefix), as the crypto-js 4.2.0 implementation of 4.x stored them, keep matching:
|
|
19
|
+
* optionally base64 of a text that is a 16-character hex salt followed by the hex key; the key is
|
|
20
|
+
* PBKDF2(password, salt + String(secret)) with SHA-256, `iterations` (default 250000) and `keySize` words
|
|
21
|
+
* (default 4). Without a secret the salt text ends in `undefined`, which is how those hashes were made.
|
|
22
|
+
* Hashes made with crypto-js 4.1 or older (SHA-1, 1 iteration) are not supported.
|
|
23
|
+
* {@link needsUpgrade} is true for legacy hashes, so a login replaces them with a new hash.
|
|
24
|
+
*/
|
|
2
25
|
export declare class Pbkdf2PasswordEncoder implements PasswordEncoder {
|
|
3
|
-
|
|
26
|
+
static readonly PREFIX = "pbkdf2-sha256";
|
|
27
|
+
static readonly ITERATIONS = 600000;
|
|
28
|
+
static readonly SALT_BYTES = 16;
|
|
29
|
+
static readonly KEY_BYTES = 32;
|
|
30
|
+
static readonly LEGACY_ITERATIONS = 250000;
|
|
31
|
+
static readonly LEGACY_KEY_SIZE = 4;
|
|
32
|
+
static readonly LEGACY_SALT_LENGTH = 16;
|
|
33
|
+
protected readonly options: Pbkdf2PasswordEncoderOptions | undefined;
|
|
34
|
+
/** Iterations of new hashes. */
|
|
35
|
+
protected get iterations(): number;
|
|
4
36
|
encode(rawPassword: string): Promise<string>;
|
|
5
|
-
protected doEncode(rawPassword: string, salt: string): string;
|
|
6
37
|
matches(rawPassword: string, encodedPassword: string): Promise<boolean>;
|
|
7
|
-
|
|
38
|
+
needsUpgrade(encodedPassword: string): boolean;
|
|
39
|
+
protected isCurrent(encodedPassword: string): boolean;
|
|
40
|
+
protected pepper(salt: Buffer): Buffer;
|
|
41
|
+
protected matchesCurrent(rawPassword: string, encodedPassword: string): Promise<boolean>;
|
|
42
|
+
protected matchesLegacy(rawPassword: string, encodedPassword: string): Promise<boolean>;
|
|
43
|
+
/** The text the crypto-js implementation stored (before the optional base64): salt + hex key. */
|
|
44
|
+
protected legacyEncode(rawPassword: string, salt: string): Promise<string>;
|
|
8
45
|
}
|
|
9
46
|
//# sourceMappingURL=password-encoder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-encoder.d.ts","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-encoder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"password-encoder.d.ts","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-encoder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAItD,MAAM,WAAW,4BAA4B;IACzC,sHAAsH;IACtH,MAAM,CAAC,EA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,OAAO,CAAC,CAQ5F;IAED,iGAAiG;IACjG,UAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAU/E;CACJ"}
|
|
@@ -8,44 +8,101 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var Pbkdf2PasswordEncoder_1;
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
13
|
exports.Pbkdf2PasswordEncoder = void 0;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
14
|
+
const node_crypto_1 = require("node:crypto");
|
|
15
|
+
const node_util_1 = require("node:util");
|
|
15
16
|
const core_1 = require("@celljs/core");
|
|
16
|
-
|
|
17
|
+
const password_protocol_1 = require("./password-protocol");
|
|
18
|
+
const pbkdf2Async = (0, node_util_1.promisify)(node_crypto_1.pbkdf2);
|
|
19
|
+
/**
|
|
20
|
+
* Password hashes with PBKDF2-HMAC-SHA256 on node:crypto, compared in constant time.
|
|
21
|
+
*
|
|
22
|
+
* New hashes: `pbkdf2-sha256$<iterations>$<salt, base64>$<key, base64>` with 600000 iterations, a 16-byte
|
|
23
|
+
* random salt (followed by the UTF-8 bytes of `secret` when one is set) and a 32-byte key.
|
|
24
|
+
*
|
|
25
|
+
* Legacy hashes (no prefix), as the crypto-js 4.2.0 implementation of 4.x stored them, keep matching:
|
|
26
|
+
* optionally base64 of a text that is a 16-character hex salt followed by the hex key; the key is
|
|
27
|
+
* PBKDF2(password, salt + String(secret)) with SHA-256, `iterations` (default 250000) and `keySize` words
|
|
28
|
+
* (default 4). Without a secret the salt text ends in `undefined`, which is how those hashes were made.
|
|
29
|
+
* Hashes made with crypto-js 4.1 or older (SHA-1, 1 iteration) are not supported.
|
|
30
|
+
* {@link needsUpgrade} is true for legacy hashes, so a login replaces them with a new hash.
|
|
31
|
+
*/
|
|
32
|
+
let Pbkdf2PasswordEncoder = Pbkdf2PasswordEncoder_1 = class Pbkdf2PasswordEncoder {
|
|
33
|
+
/** Iterations of new hashes. */
|
|
34
|
+
get iterations() {
|
|
35
|
+
return Pbkdf2PasswordEncoder_1.ITERATIONS;
|
|
36
|
+
}
|
|
17
37
|
async encode(rawPassword) {
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
38
|
+
const salt = (0, node_crypto_1.randomBytes)(Pbkdf2PasswordEncoder_1.SALT_BYTES);
|
|
39
|
+
const key = await pbkdf2Async(rawPassword, this.pepper(salt), this.iterations, Pbkdf2PasswordEncoder_1.KEY_BYTES, 'sha256');
|
|
40
|
+
return [Pbkdf2PasswordEncoder_1.PREFIX, this.iterations, salt.toString('base64'), key.toString('base64')].join('$');
|
|
41
|
+
}
|
|
42
|
+
async matches(rawPassword, encodedPassword) {
|
|
43
|
+
if (typeof encodedPassword !== 'string' || typeof rawPassword !== 'string') {
|
|
44
|
+
return false;
|
|
23
45
|
}
|
|
24
|
-
return
|
|
46
|
+
return this.isCurrent(encodedPassword) ? this.matchesCurrent(rawPassword, encodedPassword) : this.matchesLegacy(rawPassword, encodedPassword);
|
|
25
47
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
48
|
+
needsUpgrade(encodedPassword) {
|
|
49
|
+
if (!this.isCurrent(encodedPassword)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return Number(encodedPassword.split('$')[1]) < this.iterations;
|
|
29
53
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
54
|
+
isCurrent(encodedPassword) {
|
|
55
|
+
return encodedPassword.startsWith(`${Pbkdf2PasswordEncoder_1.PREFIX}$`);
|
|
56
|
+
}
|
|
57
|
+
pepper(salt) {
|
|
58
|
+
var _a;
|
|
59
|
+
const secret = (_a = this.options) === null || _a === void 0 ? void 0 : _a.secret;
|
|
60
|
+
return secret === undefined || secret === null || secret === '' ? salt : Buffer.concat([salt, Buffer.from(String(secret), 'utf8')]);
|
|
61
|
+
}
|
|
62
|
+
async matchesCurrent(rawPassword, encodedPassword) {
|
|
63
|
+
const [, iterationsText, saltText, keyText, ...rest] = encodedPassword.split('$');
|
|
64
|
+
const iterations = Number(iterationsText);
|
|
65
|
+
if (rest.length > 0 || !Number.isSafeInteger(iterations) || iterations < 1 || !saltText || !keyText) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const expected = Buffer.from(keyText, 'base64');
|
|
69
|
+
if (expected.length !== Pbkdf2PasswordEncoder_1.KEY_BYTES) {
|
|
70
|
+
return false;
|
|
39
71
|
}
|
|
40
|
-
|
|
72
|
+
const actual = await pbkdf2Async(rawPassword, this.pepper(Buffer.from(saltText, 'base64')), iterations, Pbkdf2PasswordEncoder_1.KEY_BYTES, 'sha256');
|
|
73
|
+
return (0, node_crypto_1.timingSafeEqual)(actual, expected);
|
|
74
|
+
}
|
|
75
|
+
async matchesLegacy(rawPassword, encodedPassword) {
|
|
76
|
+
var _a;
|
|
77
|
+
const digested = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.encodeHashAsBase64) ? Buffer.from(encodedPassword, 'base64').toString('utf8') : encodedPassword;
|
|
78
|
+
if (digested.length <= Pbkdf2PasswordEncoder_1.LEGACY_SALT_LENGTH) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const expected = Buffer.from(await this.legacyEncode(rawPassword, digested.substring(0, Pbkdf2PasswordEncoder_1.LEGACY_SALT_LENGTH)), 'utf8');
|
|
82
|
+
const actual = Buffer.from(digested, 'utf8');
|
|
83
|
+
return actual.length === expected.length && (0, node_crypto_1.timingSafeEqual)(actual, expected);
|
|
84
|
+
}
|
|
85
|
+
/** The text the crypto-js implementation stored (before the optional base64): salt + hex key. */
|
|
86
|
+
async legacyEncode(rawPassword, salt) {
|
|
87
|
+
var _a;
|
|
88
|
+
const { secret, iterations, keySize } = (_a = this.options) !== null && _a !== void 0 ? _a : {};
|
|
89
|
+
const key = await pbkdf2Async(rawPassword, `${salt}${secret}`, Number(iterations !== null && iterations !== void 0 ? iterations : Pbkdf2PasswordEncoder_1.LEGACY_ITERATIONS), Number(keySize !== null && keySize !== void 0 ? keySize : Pbkdf2PasswordEncoder_1.LEGACY_KEY_SIZE) * 4, 'sha256');
|
|
90
|
+
return salt + key.toString('hex');
|
|
41
91
|
}
|
|
42
92
|
};
|
|
43
93
|
exports.Pbkdf2PasswordEncoder = Pbkdf2PasswordEncoder;
|
|
94
|
+
Pbkdf2PasswordEncoder.PREFIX = 'pbkdf2-sha256';
|
|
95
|
+
Pbkdf2PasswordEncoder.ITERATIONS = 600000;
|
|
96
|
+
Pbkdf2PasswordEncoder.SALT_BYTES = 16;
|
|
97
|
+
Pbkdf2PasswordEncoder.KEY_BYTES = 32;
|
|
98
|
+
Pbkdf2PasswordEncoder.LEGACY_ITERATIONS = 250000;
|
|
99
|
+
Pbkdf2PasswordEncoder.LEGACY_KEY_SIZE = 4;
|
|
100
|
+
Pbkdf2PasswordEncoder.LEGACY_SALT_LENGTH = 16;
|
|
44
101
|
__decorate([
|
|
45
102
|
(0, core_1.Value)('cell.security.passwordEncoder'),
|
|
46
103
|
__metadata("design:type", Object)
|
|
47
104
|
], Pbkdf2PasswordEncoder.prototype, "options", void 0);
|
|
48
|
-
exports.Pbkdf2PasswordEncoder = Pbkdf2PasswordEncoder = __decorate([
|
|
105
|
+
exports.Pbkdf2PasswordEncoder = Pbkdf2PasswordEncoder = Pbkdf2PasswordEncoder_1 = __decorate([
|
|
49
106
|
(0, core_1.Component)(password_protocol_1.PasswordEncoder)
|
|
50
107
|
], Pbkdf2PasswordEncoder);
|
|
51
108
|
//# sourceMappingURL=password-encoder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-encoder.js","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-encoder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"password-encoder.js","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-encoder.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,6CAAmE;AACnE,yCAAsC;AACtC,uCAAgD;AAChD,2DAAsD;AAEtD,MAAM,WAAW,GAAG,IAAA,qBAAS,EAAC,oBAAM,CAAC,CAAC;AAatC;;;;;;;;;;;;GAYG;AAEI,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAc9B,gCAAgC;IAChC,IAAc,UAAU;QACpB,OAAO,wBAAsB,UAAU,CAAC;IAC5C,CAAC;IAEK,AAAN,KAAK,CAAC,MAAM,CAAC,WAAmB;QAC5B,MAAM,IAAI,GAAG,IAAA,yBAAW,EAAC,wBAAsB,UAAU,CAAC,CAAC;QAC3D,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,wBAAsB,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC1H,OAAO,CAAC,wBAAsB,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,WAAmB,EAAE,eAAuB;QACtD,IAAI,OAAO,eAAe,KAAK,QAAQ,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACzE,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE,eAAe,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,KAAK,CAAC,YAAY,CAAC,WAAmB,EAAE,IAAY;;QAC1D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,SAAG,IAAI,CAAC,OAAO,mCAAI,EAAE,CAAC;QAC3D,MAAM,GAAG,GAAG,MAAM,WAAW,CACzB,WAAW,EACX,GAAG,IAAI,GAAG,MAAM,EAAE,EAClB,MAAM,CAAC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,wBAAsB,iBAAiB,CAAC,EAC7D,MAAM,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,wBAAsB,eAAe,CAAC,GAAG,CAAC,EAC5D,QAAQ,CACX,CAAC;QACF,OAAO,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;CACJ,CAAA;;AAlFmB,4BAAM,GAAG,eAAe,AAAlB,CAAmB;AACzB,gCAAU,GAAG,MAAM,AAAT,CAAU;AACpB,gCAAU,GAAG,EAAE,AAAL,CAAM;AAChB,+BAAS,GAAG,EAAE,AAAL,CAAM;AAEf,uCAAiB,GAAG,MAAM,AAAT,CAAU;AAC3B,qCAAe,GAAG,CAAC,AAAJ,CAAK;AACpB,wCAAkB,GAAG,EAAE,AAAL,CAAM;AAGrB;IADlB,IAAA,YAAK,EAAC,+BAA+B,CAAC;;sDAC8B;gCAZ5D,qBAAqB;IADjC,IAAA,gBAAS,EAAC,mCAAe,CAAC;GACd,qBAAqB,CAoFjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-encoder.spec.d.ts","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-encoder.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const chai_1 = require("chai");
|
|
5
|
+
const password_encoder_1 = require("./password-encoder");
|
|
6
|
+
const authentication_provider_1 = require("../../authentication/authentication-provider");
|
|
7
|
+
/**
|
|
8
|
+
* Golden vectors: legacy hashes made by the crypto-js implementation of this encoder (crypto-js 4.2.0, main 6a87acfc0)
|
|
9
|
+
* for fixed salts, with cell-refactor/stage1/t10-password-vectors/generate.cjs. Stored hashes like these must keep matching.
|
|
10
|
+
*/
|
|
11
|
+
const LEGACY = [
|
|
12
|
+
{ options: { "encodeHashAsBase64": true }, password: "123456", salt: "0123456789abcdef", encoded: "MDEyMzQ1Njc4OWFiY2RlZjA1NjVhMGQzZmI4ZDlhY2U3ZmY5YTY4OTE1YTFiOTll" },
|
|
13
|
+
{ options: { "encodeHashAsBase64": true }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "a1b2c3d4e5f60718", encoded: "YTFiMmMzZDRlNWY2MDcxODE5NWZjMWI0ODk3YjBlMDBjMjU1YTVjNjcxZTUxOGIx" },
|
|
14
|
+
{ options: { "encodeHashAsBase64": true }, password: "中文密码🔐", salt: "ffffffff00000000", encoded: "ZmZmZmZmZmYwMDAwMDAwMDc2MjIyMDk5NzdkMDRjMzdkY2JlYjBhZjNkNjg2NDQ3" },
|
|
15
|
+
{ options: { "encodeHashAsBase64": false }, password: "123456", salt: "a1b2c3d4e5f60718", encoded: "a1b2c3d4e5f60718c1ef95056e13cce639b1b172f002e7ae" },
|
|
16
|
+
{ options: { "encodeHashAsBase64": false }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "ffffffff00000000", encoded: "ffffffff0000000018bbdc72579e0a3093f5f6ea06b82033" },
|
|
17
|
+
{ options: { "encodeHashAsBase64": false }, password: "中文密码🔐", salt: "0123456789abcdef", encoded: "0123456789abcdef066fc4596441dd6bdb884678496ef9fc" },
|
|
18
|
+
{ options: { "encodeHashAsBase64": true, "secret": "s3cr3t" }, password: "123456", salt: "ffffffff00000000", encoded: "ZmZmZmZmZmYwMDAwMDAwMDg4Zjc0NzAyM2E1NjE1NWVjNzU1NzlkZTUxNmQ1Mjhi" },
|
|
19
|
+
{ options: { "encodeHashAsBase64": true, "secret": "s3cr3t" }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "0123456789abcdef", encoded: "MDEyMzQ1Njc4OWFiY2RlZjY4ZGI3ZWU2NGFmMjVhNjdkNWU0MWU0ZTFlZTEyZGY0" },
|
|
20
|
+
{ options: { "encodeHashAsBase64": true, "secret": "s3cr3t" }, password: "中文密码🔐", salt: "a1b2c3d4e5f60718", encoded: "YTFiMmMzZDRlNWY2MDcxODAxYTBjZDMxYTgxZmE0N2UyMDQxNWUzNDJiOTg5ZGMx" },
|
|
21
|
+
{ options: { "encodeHashAsBase64": true, "secret": 123456 }, password: "123456", salt: "0123456789abcdef", encoded: "MDEyMzQ1Njc4OWFiY2RlZjZkNGE0MGRkMDU4MmRmMGI1MjVkM2MxZjE0NjVkNjY5" },
|
|
22
|
+
{ options: { "encodeHashAsBase64": true, "secret": 123456 }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "a1b2c3d4e5f60718", encoded: "YTFiMmMzZDRlNWY2MDcxOGM5ZWY5NjgzNzExMDUwNWUwNWVlYzlkYTRhMjkyYmZj" },
|
|
23
|
+
{ options: { "encodeHashAsBase64": true, "secret": 123456 }, password: "中文密码🔐", salt: "ffffffff00000000", encoded: "ZmZmZmZmZmYwMDAwMDAwMDFkZWZlYjdjYjkxNTNlMzk1YWFiZGUzNWM3NDBjNjg0" },
|
|
24
|
+
{ options: { "encodeHashAsBase64": false, "secret": "密钥🔑", "iterations": 1000 }, password: "123456", salt: "a1b2c3d4e5f60718", encoded: "a1b2c3d4e5f6071822b7276a5d78c8e4111547a26aada7f1" },
|
|
25
|
+
{ options: { "encodeHashAsBase64": false, "secret": "密钥🔑", "iterations": 1000 }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "ffffffff00000000", encoded: "ffffffff0000000068f9b165d52e8bc615b2ebcc6654d149" },
|
|
26
|
+
{ options: { "encodeHashAsBase64": false, "secret": "密钥🔑", "iterations": 1000 }, password: "中文密码🔐", salt: "0123456789abcdef", encoded: "0123456789abcdef27ac13cc586b34fbf24700ef8f5cd54b" },
|
|
27
|
+
{ options: { "encodeHashAsBase64": true, "iterations": 1, "keySize": 8 }, password: "123456", salt: "ffffffff00000000", encoded: "ZmZmZmZmZmYwMDAwMDAwMGYyMjdkNzNkODMwNWU3OWZjOGM2YTc1ZjdmZjZhMGRhNDgwMWFlYTZlZjcxYWM4Mjc0MmIyYzlhNTQyZjJhM2Q=" },
|
|
28
|
+
{ options: { "encodeHashAsBase64": true, "iterations": 1, "keySize": 8 }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "0123456789abcdef", encoded: "MDEyMzQ1Njc4OWFiY2RlZmFmZGEwNTA0YzA5YjJlYjBjNTExOTA3ZWRlZThiNzRmODVhNGU0NWZjODg0ZmZjOGU5NDA3Y2JiNTljZDA4ZWQ=" },
|
|
29
|
+
{ options: { "encodeHashAsBase64": true, "iterations": 1, "keySize": 8 }, password: "中文密码🔐", salt: "a1b2c3d4e5f60718", encoded: "YTFiMmMzZDRlNWY2MDcxOGI2MTgyZGI1YWFkOThjMDNmOGRlZDllYTNkYjUzNTVlM2YwZDhlMmU0NDQ3ZTE5ZjY5NDBjOWUzOTRlOTE1ODM=" },
|
|
30
|
+
];
|
|
31
|
+
class TestEncoder extends password_encoder_1.Pbkdf2PasswordEncoder {
|
|
32
|
+
constructor(options = {}, newIterations = 1000) {
|
|
33
|
+
super();
|
|
34
|
+
this.newIterations = newIterations;
|
|
35
|
+
Object.defineProperty(this, 'options', { value: options });
|
|
36
|
+
}
|
|
37
|
+
get iterations() {
|
|
38
|
+
return this.newIterations;
|
|
39
|
+
}
|
|
40
|
+
/** What the crypto-js implementation stored for a fixed salt. */
|
|
41
|
+
async legacyHash(rawPassword, salt) {
|
|
42
|
+
var _a;
|
|
43
|
+
const text = await this.legacyEncode(rawPassword, salt);
|
|
44
|
+
return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.encodeHashAsBase64) ? Buffer.from(text, 'utf8').toString('base64') : text;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const name = (v) => `${JSON.stringify(v.options)} ${JSON.stringify(v.password)}`;
|
|
48
|
+
(0, bun_test_1.describe)('Pbkdf2PasswordEncoder', () => {
|
|
49
|
+
(0, bun_test_1.describe)('legacy hashes of the crypto-js implementation', () => {
|
|
50
|
+
for (const vector of LEGACY) {
|
|
51
|
+
(0, bun_test_1.it)(`match, and a wrong password does not: ${name(vector)}`, async () => {
|
|
52
|
+
const encoder = new TestEncoder(vector.options);
|
|
53
|
+
(0, chai_1.expect)(await encoder.matches(vector.password, vector.encoded)).to.equal(true);
|
|
54
|
+
(0, chai_1.expect)(await encoder.matches(`${vector.password}x`, vector.encoded)).to.equal(false);
|
|
55
|
+
(0, chai_1.expect)(await encoder.matches('', vector.encoded)).to.equal(false);
|
|
56
|
+
});
|
|
57
|
+
(0, bun_test_1.it)(`are reproduced byte for byte: ${name(vector)}`, async () => {
|
|
58
|
+
(0, chai_1.expect)(await new TestEncoder(vector.options).legacyHash(vector.password, vector.salt)).to.equal(vector.encoded);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
(0, bun_test_1.it)('need an upgrade', () => {
|
|
62
|
+
for (const vector of LEGACY) {
|
|
63
|
+
(0, chai_1.expect)(new TestEncoder(vector.options).needsUpgrade(vector.encoded)).to.equal(true);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
(0, bun_test_1.it)('only match with the secret they were made with (none means the text "undefined")', async () => {
|
|
67
|
+
const vector = LEGACY.find(v => v.options.secret === undefined && v.options.encodeHashAsBase64);
|
|
68
|
+
(0, chai_1.expect)(await new TestEncoder({ ...vector.options, secret: 'undefined' }).matches(vector.password, vector.encoded)).to.equal(true);
|
|
69
|
+
(0, chai_1.expect)(await new TestEncoder({ ...vector.options, secret: 'pepper' }).matches(vector.password, vector.encoded)).to.equal(false);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
(0, bun_test_1.describe)('new hashes', () => {
|
|
73
|
+
(0, bun_test_1.it)('record their parameters and use a fresh salt', async () => {
|
|
74
|
+
const encoder = new TestEncoder({ encodeHashAsBase64: true });
|
|
75
|
+
const a = await encoder.encode('secret');
|
|
76
|
+
const b = await encoder.encode('secret');
|
|
77
|
+
(0, chai_1.expect)(a).to.match(/^pbkdf2-sha256\$1000\$[A-Za-z0-9+/]{22}==\$[A-Za-z0-9+/]{43}=$/);
|
|
78
|
+
(0, chai_1.expect)(a).to.not.equal(b);
|
|
79
|
+
});
|
|
80
|
+
(0, bun_test_1.it)('match the right password only', async () => {
|
|
81
|
+
const encoder = new TestEncoder();
|
|
82
|
+
const hash = await encoder.encode('中文密码🔐');
|
|
83
|
+
(0, chai_1.expect)(await encoder.matches('中文密码🔐', hash)).to.equal(true);
|
|
84
|
+
(0, chai_1.expect)(await encoder.matches('中文密码', hash)).to.equal(false);
|
|
85
|
+
});
|
|
86
|
+
(0, bun_test_1.it)('do not depend on encodeHashAsBase64, and a missing secret is not the text "undefined"', async () => {
|
|
87
|
+
const hash = await new TestEncoder({ encodeHashAsBase64: true }).encode('secret');
|
|
88
|
+
(0, chai_1.expect)(await new TestEncoder({ encodeHashAsBase64: false }).matches('secret', hash)).to.equal(true);
|
|
89
|
+
(0, chai_1.expect)(await new TestEncoder({ secret: 'undefined' }).matches('secret', hash)).to.equal(false);
|
|
90
|
+
});
|
|
91
|
+
(0, bun_test_1.it)('mix the secret in', async () => {
|
|
92
|
+
const hash = await new TestEncoder({ secret: 'pepper' }).encode('secret');
|
|
93
|
+
(0, chai_1.expect)(await new TestEncoder({ secret: 'pepper' }).matches('secret', hash)).to.equal(true);
|
|
94
|
+
(0, chai_1.expect)(await new TestEncoder({ secret: 'other' }).matches('secret', hash)).to.equal(false);
|
|
95
|
+
(0, chai_1.expect)(await new TestEncoder().matches('secret', hash)).to.equal(false);
|
|
96
|
+
});
|
|
97
|
+
(0, bun_test_1.it)('check with the iterations they record, and need an upgrade when that is fewer than new hashes get', async () => {
|
|
98
|
+
const old = await new TestEncoder({}, 1000).encode('secret');
|
|
99
|
+
const encoder = new TestEncoder({}, 2000);
|
|
100
|
+
(0, chai_1.expect)(await encoder.matches('secret', old)).to.equal(true);
|
|
101
|
+
(0, chai_1.expect)(encoder.needsUpgrade(old)).to.equal(true);
|
|
102
|
+
(0, chai_1.expect)(encoder.needsUpgrade(await encoder.encode('secret'))).to.equal(false);
|
|
103
|
+
});
|
|
104
|
+
(0, bun_test_1.it)('get 600000 iterations by default', async () => {
|
|
105
|
+
(0, chai_1.expect)(await new password_encoder_1.Pbkdf2PasswordEncoder().encode('secret')).to.match(/^pbkdf2-sha256\$600000\$/);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
(0, bun_test_1.it)('rejects malformed hashes instead of throwing', async () => {
|
|
109
|
+
for (const options of [{ encodeHashAsBase64: true }, { encodeHashAsBase64: false }]) {
|
|
110
|
+
const encoder = new TestEncoder(options);
|
|
111
|
+
for (const hash of ['', 'abc', '!!!!', '0123456789abcdef', 'pbkdf2-sha256$x$a$b', 'pbkdf2-sha256$1000$$', 'pbkdf2-sha256$1000$YQ==$YQ==',
|
|
112
|
+
'pbkdf2-sha256$1000$YQ==$YQ==$x', undefined, null]) {
|
|
113
|
+
(0, chai_1.expect)(await encoder.matches('secret', hash), String(hash)).to.equal(false);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
(0, bun_test_1.describe)('upgradePasswordHash', () => {
|
|
118
|
+
const legacy = LEGACY.find(v => v.options.encodeHashAsBase64 && v.options.secret === undefined);
|
|
119
|
+
const user = () => ({ username: 'tom', password: legacy.encoded });
|
|
120
|
+
const logger = (warnings) => ({ warn: (m) => warnings.push(m) });
|
|
121
|
+
(0, bun_test_1.it)('stores a new hash of a legacy one through UserService.updatePassword', async () => {
|
|
122
|
+
const encoder = new TestEncoder(legacy.options);
|
|
123
|
+
const stored = [];
|
|
124
|
+
const service = { load: async () => user(), updatePassword: async (_, hash) => { stored.push(hash); } };
|
|
125
|
+
await (0, authentication_provider_1.upgradePasswordHash)(encoder, service, user(), legacy.password, logger([]));
|
|
126
|
+
(0, chai_1.expect)(stored).to.have.length(1);
|
|
127
|
+
(0, chai_1.expect)(encoder.needsUpgrade(stored[0])).to.equal(false);
|
|
128
|
+
(0, chai_1.expect)(await encoder.matches(legacy.password, stored[0])).to.equal(true);
|
|
129
|
+
});
|
|
130
|
+
(0, bun_test_1.it)('does nothing when the hash is current or the UserService cannot store passwords', async () => {
|
|
131
|
+
const encoder = new TestEncoder(legacy.options);
|
|
132
|
+
const stored = [];
|
|
133
|
+
const service = { load: async () => user(), updatePassword: async (_, hash) => { stored.push(hash); } };
|
|
134
|
+
await (0, authentication_provider_1.upgradePasswordHash)(encoder, service, { ...user(), password: await encoder.encode(legacy.password) }, legacy.password, logger([]));
|
|
135
|
+
await (0, authentication_provider_1.upgradePasswordHash)(encoder, { load: async () => user() }, user(), legacy.password, logger([]));
|
|
136
|
+
(0, chai_1.expect)(stored).to.have.length(0);
|
|
137
|
+
});
|
|
138
|
+
(0, bun_test_1.it)('logs a failure to store instead of failing the login', async () => {
|
|
139
|
+
const warnings = [];
|
|
140
|
+
const service = { load: async () => user(), updatePassword: async () => { throw new Error('read-only'); } };
|
|
141
|
+
await (0, authentication_provider_1.upgradePasswordHash)(new TestEncoder(legacy.options), service, user(), legacy.password, logger(warnings));
|
|
142
|
+
(0, chai_1.expect)(warnings).to.have.length(1);
|
|
143
|
+
(0, chai_1.expect)(warnings[0]).to.include('read-only');
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
//# sourceMappingURL=password-encoder.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-encoder.spec.js","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AC;YACtG,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,IAAA,aAAE,EAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;YAClE,MAAM,QAAQ,GAAa,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,cAAc,EAAE,KAAK,IAAI,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5G,MAAM,IAAA,6CAAmB,EAAC,IAAI,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC/G,IAAA,aAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACnC,IAAA,aAAM,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -2,5 +2,11 @@ export declare const PasswordEncoder: unique symbol;
|
|
|
2
2
|
export interface PasswordEncoder {
|
|
3
3
|
encode(rawPassword: string): Promise<string>;
|
|
4
4
|
matches(rawPassword: string, encodedPassword: string): Promise<boolean>;
|
|
5
|
+
/**
|
|
6
|
+
* Whether a stored hash should be replaced by `encode()` of the password once it matched (a legacy
|
|
7
|
+
* format, or weaker parameters than new hashes get). Login does so when the UserService can
|
|
8
|
+
* store passwords (`UserService.updatePassword`).
|
|
9
|
+
*/
|
|
10
|
+
needsUpgrade?(encodedPassword: string): boolean;
|
|
5
11
|
}
|
|
6
12
|
//# sourceMappingURL=password-protocol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password-protocol.d.ts","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,eAA4B,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC5B,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"password-protocol.d.ts","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,eAA4B,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC5B,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACxE;;;;OAIG;IACH,YAAY,CAAC,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;CACnD"}
|
package/lib/node/module.d.ts
CHANGED
package/lib/node/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC"}
|
package/lib/node/module.js
CHANGED
package/lib/node/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,mBAAiB;kBAEF,IAAA,eAAQ,GAAE"}
|
|
@@ -5,6 +5,11 @@ export declare const UserMapper: unique symbol;
|
|
|
5
5
|
export declare const USER_MIDDLEWARE_PRIORITY: number;
|
|
6
6
|
export interface UserService<R, U extends User> {
|
|
7
7
|
load(userRequest: R): Promise<U>;
|
|
8
|
+
/**
|
|
9
|
+
* Stores a new password hash of `user`. Optional: when a service has it, a login whose stored hash
|
|
10
|
+
* `PasswordEncoder.needsUpgrade()` saves the hash in the current format.
|
|
11
|
+
*/
|
|
12
|
+
updatePassword?(user: U, encodedPassword: string): Promise<void>;
|
|
8
13
|
}
|
|
9
14
|
export interface UserChecker {
|
|
10
15
|
check(user: User): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/user/user-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,eAAO,MAAM,WAAW,eAAwB,CAAC;AACjD,eAAO,MAAM,WAAW,eAAwB,CAAC;AACjD,eAAO,MAAM,UAAU,eAAuB,CAAC;AAE/C,eAAO,MAAM,wBAAwB,QAA6C,CAAC;AAEnF,MAAM,WAAW,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,IAAI;IAC1C,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"user-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/user/user-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,eAAO,MAAM,WAAW,eAAwB,CAAC;AACjD,eAAO,MAAM,WAAW,eAAwB,CAAC;AACjD,eAAO,MAAM,UAAU,eAAuB,CAAC;AAE/C,eAAO,MAAM,wBAAwB,QAA6C,CAAC;AAEnF,MAAM,WAAW,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,IAAI;IAC1C,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjC;;;OAGG;IACH,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpE;AAED,MAAM,WAAW,WAAW;IACxB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,UAAU;IACvB,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC"}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import { UserService } from './user-protocol';
|
|
2
|
+
import { Logger, ApplicationLifecycle, Application } from '@celljs/core';
|
|
2
3
|
import { User } from '../../common';
|
|
4
|
+
/** The one user of `cell.security.username` / `password`, when they are configured. */
|
|
3
5
|
export declare class UserServiceImpl implements UserService<string, User> {
|
|
4
6
|
protected readonly options: any;
|
|
7
|
+
/** Whether `cell.security` configures a user. */
|
|
8
|
+
get hasConfiguredUser(): boolean;
|
|
5
9
|
load(username: string): Promise<User>;
|
|
6
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Warns at startup when the login (form or Basic) has no user to check: the default UserService is in
|
|
13
|
+
* use and `cell.security` configures no user. A warning, not an error: an application may log in with
|
|
14
|
+
* OAuth2 only, or use @celljs/security for authorization alone.
|
|
15
|
+
*/
|
|
16
|
+
export declare class UserSourceCheck implements ApplicationLifecycle<Application> {
|
|
17
|
+
protected readonly userService: UserService<string, User>;
|
|
18
|
+
protected readonly logger: Logger;
|
|
19
|
+
initialize(): void;
|
|
20
|
+
}
|
|
7
21
|
//# sourceMappingURL=user-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-service.d.ts","sourceRoot":"","sources":["../../../src/node/user/user-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"user-service.d.ts","sourceRoot":"","sources":["../../../src/node/user/user-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAA+B,MAAM,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEtG,OAAO,EAAE,IAAI,EAAY,MAAM,cAAc,CAAC;AAE9C,uFAAuF;AACvF,qBACa,eAAgB,YAAW,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC;IAG7D,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IAEhC,iDAAiD;IACjD,IAAI,iBAAiB,IAAI,OAAO,CAE/B;IAEK,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAe1C;CACJ;AAED;;;;GAIG;AACH,qBACa,eAAgB,YAAW,oBAAoB,CAAC,WAAW,CAAC;IAGrE,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAG1D,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAElC,UAAU,IAAI,IAAI,CAOjB;CACJ"}
|
|
@@ -9,14 +9,20 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.UserServiceImpl = void 0;
|
|
12
|
+
exports.UserSourceCheck = exports.UserServiceImpl = void 0;
|
|
13
13
|
const user_protocol_1 = require("./user-protocol");
|
|
14
14
|
const core_1 = require("@celljs/core");
|
|
15
15
|
const error_1 = require("../error");
|
|
16
16
|
const common_1 = require("../../common");
|
|
17
|
+
/** The one user of `cell.security.username` / `password`, when they are configured. */
|
|
17
18
|
let UserServiceImpl = class UserServiceImpl {
|
|
19
|
+
/** Whether `cell.security` configures a user. */
|
|
20
|
+
get hasConfiguredUser() {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
return !!((_a = this.options) === null || _a === void 0 ? void 0 : _a.username) && !!((_b = this.options) === null || _b === void 0 ? void 0 : _b.password);
|
|
23
|
+
}
|
|
18
24
|
async load(username) {
|
|
19
|
-
if (this.options.username === username) {
|
|
25
|
+
if (this.hasConfiguredUser && this.options.username === username) {
|
|
20
26
|
return {
|
|
21
27
|
type: common_1.UserType.Memery,
|
|
22
28
|
username,
|
|
@@ -39,4 +45,29 @@ __decorate([
|
|
|
39
45
|
exports.UserServiceImpl = UserServiceImpl = __decorate([
|
|
40
46
|
(0, core_1.Component)(user_protocol_1.UserService)
|
|
41
47
|
], UserServiceImpl);
|
|
48
|
+
/**
|
|
49
|
+
* Warns at startup when the login (form or Basic) has no user to check: the default UserService is in
|
|
50
|
+
* use and `cell.security` configures no user. A warning, not an error: an application may log in with
|
|
51
|
+
* OAuth2 only, or use @celljs/security for authorization alone.
|
|
52
|
+
*/
|
|
53
|
+
let UserSourceCheck = class UserSourceCheck {
|
|
54
|
+
initialize() {
|
|
55
|
+
if (this.userService instanceof UserServiceImpl && !this.userService.hasConfiguredUser) {
|
|
56
|
+
this.logger.warn('No user can log in: @celljs/security has no built-in user. Set cell.security.username and cell.security.password ' +
|
|
57
|
+
'(a hash made by the PasswordEncoder) in cell.yml, or bind a UserService of your own.');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.UserSourceCheck = UserSourceCheck;
|
|
62
|
+
__decorate([
|
|
63
|
+
(0, core_1.Autowired)(user_protocol_1.UserService),
|
|
64
|
+
__metadata("design:type", Object)
|
|
65
|
+
], UserSourceCheck.prototype, "userService", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
(0, core_1.Autowired)(core_1.Logger),
|
|
68
|
+
__metadata("design:type", Object)
|
|
69
|
+
], UserSourceCheck.prototype, "logger", void 0);
|
|
70
|
+
exports.UserSourceCheck = UserSourceCheck = __decorate([
|
|
71
|
+
(0, core_1.Component)(core_1.ApplicationLifecycle)
|
|
72
|
+
], UserSourceCheck);
|
|
42
73
|
//# sourceMappingURL=user-service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-service.js","sourceRoot":"","sources":["../../../src/node/user/user-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"user-service.js","sourceRoot":"","sources":["../../../src/node/user/user-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA8C;AAC9C,uCAAsG;AACtG,oCAAiD;AACjD,yCAA8C;AAE9C,uFAAuF;AAEhF,IAAM,eAAe,GAArB,MAAM,eAAe;IAKxB,iDAAiD;IACjD,IAAI,iBAAiB;;QACjB,OAAO,CAAC,EAAC,MAAA,IAAI,CAAC,OAAO,0CAAE,QAAQ,CAAA,IAAI,CAAC,EAAC,MAAA,IAAI,CAAC,OAAO,0CAAE,QAAQ,CAAA,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAgB;QACvB,IAAI,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC/D,OAAO;gBACH,IAAI,EAAE,iBAAQ,CAAC,MAAM;gBACrB,QAAQ;gBACR,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;gBAC/B,iBAAiB,EAAE,IAAI;gBACvB,gBAAgB,EAAE,IAAI;gBACtB,qBAAqB,EAAE,IAAI;gBAC3B,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,EAAE;aACf,CAAC;QACN,CAAC;QAED,MAAM,IAAI,6BAAqB,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;IACnE,CAAC;CACJ,CAAA;;AAvBsB;IADlB,IAAA,YAAK,EAAC,eAAe,CAAC;;gDACS;0BAHvB,eAAe;IAD3B,IAAA,gBAAS,EAAC,2BAAW,CAAC;GACV,eAAe,CA0B3B;AAED;;;;GAIG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAQxB,UAAU;QACN,IAAI,IAAI,CAAC,WAAW,YAAY,eAAe,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,iBAAiB,EAAE,CAAC;YACrF,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ,mHAAmH;gBACnH,sFAAsF,CACzF,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAA;;AAbsB;IADlB,IAAA,gBAAS,EAAC,2BAAW,CAAC;;oDACmC;AAGvC;IADlB,IAAA,gBAAS,EAAC,aAAM,CAAC;;+CACgB;0BANzB,eAAe;IAD3B,IAAA,gBAAS,EAAC,2BAAoB,CAAC;GACnB,eAAe,CAgB3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-service.spec.d.ts","sourceRoot":"","sources":["../../../src/node/user/user-service.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const chai_1 = require("chai");
|
|
5
|
+
const user_service_1 = require("./user-service");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
function check(userService) {
|
|
8
|
+
const warnings = [];
|
|
9
|
+
const lifecycle = new user_service_1.UserSourceCheck();
|
|
10
|
+
Object.assign(lifecycle, { userService, logger: { warn: (m) => warnings.push(m) } });
|
|
11
|
+
lifecycle.initialize();
|
|
12
|
+
return warnings;
|
|
13
|
+
}
|
|
14
|
+
function service(options) {
|
|
15
|
+
return Object.assign(new user_service_1.UserServiceImpl(), { options });
|
|
16
|
+
}
|
|
17
|
+
(0, bun_test_1.describe)('UserServiceImpl', () => {
|
|
18
|
+
(0, bun_test_1.it)('has no built-in user', async () => {
|
|
19
|
+
let error;
|
|
20
|
+
try {
|
|
21
|
+
await service({}).load('admin');
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
error = e;
|
|
25
|
+
}
|
|
26
|
+
(0, chai_1.expect)(error).to.be.instanceOf(error_1.UsernameNotFoundError);
|
|
27
|
+
});
|
|
28
|
+
(0, bun_test_1.it)('loads the user of cell.security', async () => {
|
|
29
|
+
const user = await service({ username: 'tom', password: 'hash' }).load('tom');
|
|
30
|
+
(0, chai_1.expect)(user.username).to.equal('tom');
|
|
31
|
+
(0, chai_1.expect)(user.password).to.equal('hash');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
(0, bun_test_1.describe)('UserSourceCheck', () => {
|
|
35
|
+
(0, bun_test_1.it)('warns when the default UserService has no configured user', () => {
|
|
36
|
+
(0, chai_1.expect)(check(service({}))).to.have.length(1);
|
|
37
|
+
(0, chai_1.expect)(check(service({ username: 'tom' }))).to.have.length(1);
|
|
38
|
+
});
|
|
39
|
+
(0, bun_test_1.it)('is quiet with a configured user or a UserService of the application', () => {
|
|
40
|
+
(0, chai_1.expect)(check(service({ username: 'tom', password: 'hash' }))).to.have.length(0);
|
|
41
|
+
(0, chai_1.expect)(check({ load: async () => ({}) })).to.have.length(0);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=user-service.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-service.spec.js","sourceRoot":"","sources":["../../../src/node/user/user-service.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,+BAA8B;AAC9B,iDAAkE;AAClE,oCAAiD;AAEjD,SAAS,KAAK,CAAC,WAAoB;IAC/B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,SAAS,GAAG,IAAI,8BAAe,EAAE,CAAC;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