@celljs/security 3.9.0 → 4.1.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 +111 -1
- package/cell.yml +12 -7
- 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 +0 -1
- package/esm/node/access/index.js +0 -1
- package/esm/node/access/index.js.map +1 -1
- package/esm/node/access/policy-provider.js +2 -2
- package/esm/node/access/policy-resolver.d.ts +2 -1
- package/esm/node/access/policy-resolver.js +4 -4
- 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 -5
- 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/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 +0 -1
- 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/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 +0 -1
- package/lib/node/access/index.d.ts.map +1 -1
- package/lib/node/access/index.js +0 -1
- package/lib/node/access/index.js.map +1 -1
- package/lib/node/access/policy-resolver.d.ts +2 -1
- package/lib/node/access/policy-resolver.d.ts.map +1 -1
- package/lib/node/access/policy-resolver.js +1 -1
- 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 -3
- 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/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 +0 -1
- 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 +17 -31
- 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 +0 -1
- package/src/node/access/policy-resolver.ts +2 -2
- package/src/node/access/resource-name-resolver.ts +10 -4
- 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/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
|
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.BasicAuthenticationProvider = exports.UsernamePasswordAuthenticationProvider = void 0;
|
|
13
|
+
exports.upgradePasswordHash = upgradePasswordHash;
|
|
13
14
|
const core_1 = require("@celljs/core");
|
|
14
15
|
const authentication_protocol_1 = require("./authentication-protocol");
|
|
15
16
|
const node_1 = require("@celljs/web/lib/node");
|
|
@@ -18,6 +19,23 @@ const user_1 = require("../user");
|
|
|
18
19
|
const error_1 = require("../error");
|
|
19
20
|
const http_1 = require("@celljs/http");
|
|
20
21
|
const web_1 = require("@celljs/web");
|
|
22
|
+
/**
|
|
23
|
+
* After a password matched: when its stored hash is in a legacy format and the UserService can store
|
|
24
|
+
* passwords, store a new hash of it. A failure is logged and does not fail the login.
|
|
25
|
+
*/
|
|
26
|
+
async function upgradePasswordHash(passwordEncoder, userService, user, rawPassword, logger) {
|
|
27
|
+
var _a;
|
|
28
|
+
var _b;
|
|
29
|
+
if (!userService.updatePassword || !((_a = passwordEncoder.needsUpgrade) === null || _a === void 0 ? void 0 : _a.call(passwordEncoder, user.password))) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
await userService.updatePassword(user, await passwordEncoder.encode(rawPassword));
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
logger.warn(`Could not upgrade the password hash of ${user.username}: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
21
39
|
let UsernamePasswordAuthenticationProvider = class UsernamePasswordAuthenticationProvider {
|
|
22
40
|
constructor() {
|
|
23
41
|
this.priority = authentication_protocol_1.USERNAME_PASSWORD_AUTHENTICATION_PROVIDER_PRIORITY;
|
|
@@ -33,6 +51,7 @@ let UsernamePasswordAuthenticationProvider = class UsernamePasswordAuthenticatio
|
|
|
33
51
|
if (!await this.passwordEncoder.matches(password, user.password)) {
|
|
34
52
|
throw new error_1.BadCredentialsError('Bad credentials');
|
|
35
53
|
}
|
|
54
|
+
await upgradePasswordHash(this.passwordEncoder, this.userService, user, password, this.logger);
|
|
36
55
|
await this.userMapper.map(user);
|
|
37
56
|
return {
|
|
38
57
|
name: user.username,
|
|
@@ -88,6 +107,10 @@ __decorate([
|
|
|
88
107
|
(0, core_1.Autowired)(node_1.RedirectStrategy),
|
|
89
108
|
__metadata("design:type", Object)
|
|
90
109
|
], UsernamePasswordAuthenticationProvider.prototype, "redirectStrategy", void 0);
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, core_1.Autowired)(core_1.Logger),
|
|
112
|
+
__metadata("design:type", Object)
|
|
113
|
+
], UsernamePasswordAuthenticationProvider.prototype, "logger", void 0);
|
|
91
114
|
exports.UsernamePasswordAuthenticationProvider = UsernamePasswordAuthenticationProvider = __decorate([
|
|
92
115
|
(0, core_1.Component)(authentication_protocol_1.AuthenticationProvider)
|
|
93
116
|
], UsernamePasswordAuthenticationProvider);
|
|
@@ -107,7 +130,7 @@ let BasicAuthenticationProvider = class BasicAuthenticationProvider {
|
|
|
107
130
|
throw new error_1.BadCredentialsError('Invalid basic authentication token');
|
|
108
131
|
}
|
|
109
132
|
const username = token.substring(0, delim);
|
|
110
|
-
const password = token.substring(delim);
|
|
133
|
+
const password = token.substring(delim + 1);
|
|
111
134
|
if (!password || !username) {
|
|
112
135
|
throw new error_1.BadCredentialsError('Bad credentials');
|
|
113
136
|
}
|
|
@@ -116,6 +139,7 @@ let BasicAuthenticationProvider = class BasicAuthenticationProvider {
|
|
|
116
139
|
if (!await this.passwordEncoder.matches(password, user.password)) {
|
|
117
140
|
throw new error_1.BadCredentialsError('Bad credentials');
|
|
118
141
|
}
|
|
142
|
+
await upgradePasswordHash(this.passwordEncoder, this.userService, user, password, this.logger);
|
|
119
143
|
await this.userMapper.map(user);
|
|
120
144
|
return {
|
|
121
145
|
name: user.username,
|
|
@@ -168,6 +192,10 @@ __decorate([
|
|
|
168
192
|
(0, core_1.Autowired)(node_1.RedirectStrategy),
|
|
169
193
|
__metadata("design:type", Object)
|
|
170
194
|
], BasicAuthenticationProvider.prototype, "redirectStrategy", void 0);
|
|
195
|
+
__decorate([
|
|
196
|
+
(0, core_1.Autowired)(core_1.Logger),
|
|
197
|
+
__metadata("design:type", Object)
|
|
198
|
+
], BasicAuthenticationProvider.prototype, "logger", void 0);
|
|
171
199
|
exports.BasicAuthenticationProvider = BasicAuthenticationProvider = __decorate([
|
|
172
200
|
(0, core_1.Component)(authentication_protocol_1.AuthenticationProvider)
|
|
173
201
|
], BasicAuthenticationProvider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-provider.js","sourceRoot":"","sources":["../../../src/node/authentication/authentication-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authentication-provider.js","sourceRoot":"","sources":["../../../src/node/authentication/authentication-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,uCAAmE;AACnE,uEAC0G;AAC1G,+CAAiF;AACjF,sCAA4C;AAC5C,kCAA+D;AAC/D,oCAA+C;AAC/C,uCAA2C;AAC3C,qCAA2C;AAI3C;;;GAGG;AACI,KAA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AA;;AA3EsB;IADlB,IAAA,gBAAS,EAAC,wBAAe,CAAC;;oEACyB;AAGjC;IADlB,IAAA,gBAAS,EAAC,kBAAW,CAAC;;gEACmC;AAGvC;IADlB,IAAA,gBAAS,EAAC,kBAAW,CAAC;;gEACqB;AAGzB;IADlB,IAAA,gBAAS,EAAC,iBAAU,CAAC;;+DACoB;AAGvB;IADlB,IAAA,gBAAS,EAAC,qBAAc,CAAC;;mEACwB;AAG/B;IADlB,IAAA,gBAAS,EAAC,kBAAY,CAAC;;iEACsB;AAG3B;IADlB,IAAA,gBAAS,EAAC,uBAAgB,CAAC;;qEAC0B;AAGnC;IADlB,IAAA,gBAAS,EAAC,aAAM,CAAC;;2DACgB;sCAxBzB,2BAA2B;IADvC,IAAA,gBAAS,EAAC,gDAAsB,CAAC;GACrB,2BAA2B,CA8EvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-success-handler.d.ts","sourceRoot":"","sources":["../../../src/node/authentication/authentication-success-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,EAA+B,MAAM,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAW,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,qBACa,mCAAoC,YAAW,4BAA4B;IAGpF,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IAG9C,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAG3C,SAAS,CAAC,QAAQ,CAAC,wBAAwB,EAAE,OAAO,CAAC;IAGrD,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAGvC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAGlC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAGtD,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IAExC,uBAAuB,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"authentication-success-handler.d.ts","sourceRoot":"","sources":["../../../src/node/authentication/authentication-success-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,EAA+B,MAAM,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAW,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,qBACa,mCAAoC,YAAW,4BAA4B;IAGpF,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IAG9C,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAG3C,SAAS,CAAC,QAAQ,CAAC,wBAAwB,EAAE,OAAO,CAAC;IAGrD,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAGvC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAGlC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAGtD,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IAExC,uBAAuB,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB1E;IAEF,UAAgB,kBAAkB,CAAC,cAAc,EAAE,cAAc,mBAkChE;CAEJ"}
|
|
@@ -17,6 +17,10 @@ const http_1 = require("@celljs/http");
|
|
|
17
17
|
const cache_1 = require("../cache");
|
|
18
18
|
let DefaultAuthenticationSuccessHandler = class DefaultAuthenticationSuccessHandler {
|
|
19
19
|
async onAuthenticationSuccess(authentication) {
|
|
20
|
+
// Authentication that goes on to the requested resource (Basic): nothing to redirect to.
|
|
21
|
+
if (authentication.next) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
20
24
|
const response = node_1.Context.getResponse();
|
|
21
25
|
if (node_1.Context.getRequest().get(http_1.HttpHeaders.X_REQUESTED_WITH) === http_1.XML_HTTP_REQUEST) {
|
|
22
26
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-success-handler.js","sourceRoot":"","sources":["../../../src/node/authentication/authentication-success-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uEAAyF;AACzF,uCAAmE;AACnE,+CAAiE;AACjE,uCAA6D;AAC7D,oCAAwC;AAGjC,IAAM,mCAAmC,GAAzC,MAAM,mCAAmC;IAuB5C,KAAK,CAAC,uBAAuB,CAAC,cAA8B;QACxD,MAAM,QAAQ,GAAG,cAAO,CAAC,WAAW,EAAE,CAAC;QACvC,IAAI,cAAO,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,kBAAW,CAAC,gBAAgB,CAAC,KAAK,uBAAgB,EAAE,CAAC;YAC9E,OAAO;QACX,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,OAAO;QACX,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;QAChE,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;YACzB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8DAA8D,SAAS,EAAE,CAAC,CAAC;YAC7F,OAAO;QACX,CAAC;QACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IAEQ,KAAK,CAAC,kBAAkB,CAAC,cAA8B;QAC7D,IAAI,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,eAAe,CAAC;QAChC,CAAC;QAED,IAAI,SAA6B,CAAC;QAClC,MAAM,OAAO,GAAG,cAAO,CAAC,UAAU,EAAE,CAAC;QACrC,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC1B,SAAS,GAAuB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YACvE,IAAI,SAAS,EAAE,CAAC;gBACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wCAAwC,SAAS,EAAE,CAAC,CAAC;gBACvE,OAAO,SAAS,CAAC;YACrB,CAAC;QACL,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAW,CAAC,OAAO,CAAC,CAAC;YACjD,SAAS,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,EAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,SAAS,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;QACnD,IAAI,YAAY,EAAE,CAAC;YACf,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;YACjC,SAAS,GAAG,YAAY,CAAC,WAAW,CAAC;YACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oCAAoC,SAAS,EAAE,CAAC,CAAC;QACvE,CAAC;QAED,IAAI,CAAC,SAAS,EAAE,CAAC;YACb,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC;YACjC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,SAAS,CAAC;IACrB,CAAC;CAEJ,CAAA;;
|
|
1
|
+
{"version":3,"file":"authentication-success-handler.js","sourceRoot":"","sources":["../../../src/node/authentication/authentication-success-handler.ts"],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AC0B;AAGnC;IADlB,IAAA,gBAAS,EAAC,oBAAY,CAAC;;yEACsB;8CArBrC,mCAAmC;IAD/C,IAAA,gBAAS,EAAC,sDAA4B,CAAC;GAC3B,mCAAmC,CA+E/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-authentication.spec.d.ts","sourceRoot":"","sources":["../../../src/node/authentication/basic-authentication.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 node_1 = require("@celljs/web/lib/node");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const authentication_provider_1 = require("./authentication-provider");
|
|
8
|
+
const authentication_success_handler_1 = require("./authentication-success-handler");
|
|
9
|
+
function inRequest(authorization, fn) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
node_1.Context.run(async () => {
|
|
12
|
+
try {
|
|
13
|
+
const headers = authorization ? { authorization } : {};
|
|
14
|
+
node_1.Context.setCurrent(new node_1.Context({ headers, get: (name) => headers[name.toLowerCase()] }, {}));
|
|
15
|
+
resolve(await fn());
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
reject(error);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const basic = (user, password) => `Basic ${Buffer.from(`${user}:${password}`).toString('base64')}`;
|
|
24
|
+
function provider() {
|
|
25
|
+
const instance = new authentication_provider_1.BasicAuthenticationProvider();
|
|
26
|
+
Object.assign(instance, {
|
|
27
|
+
passwordEncoder: { matches: async (raw, encoded) => raw === encoded },
|
|
28
|
+
userService: { load: async (username) => ({ username, password: 'pa:ss', policies: [] }) },
|
|
29
|
+
userChecker: { check: async () => undefined },
|
|
30
|
+
userMapper: { map: async () => undefined },
|
|
31
|
+
logger: { warn: () => undefined },
|
|
32
|
+
});
|
|
33
|
+
return instance;
|
|
34
|
+
}
|
|
35
|
+
(0, bun_test_1.describe)('BasicAuthenticationProvider', () => {
|
|
36
|
+
(0, bun_test_1.it)('authenticates with the password after the first colon (which may contain colons)', async () => {
|
|
37
|
+
const result = await inRequest(basic('tom', 'pa:ss'), () => provider().authenticate());
|
|
38
|
+
(0, chai_1.expect)(result === null || result === void 0 ? void 0 : result.authenticated).to.equal(true);
|
|
39
|
+
(0, chai_1.expect)(result === null || result === void 0 ? void 0 : result.name).to.equal('tom');
|
|
40
|
+
// Basic goes on to the requested resource.
|
|
41
|
+
(0, chai_1.expect)(result === null || result === void 0 ? void 0 : result.next).to.equal(true);
|
|
42
|
+
});
|
|
43
|
+
(0, bun_test_1.it)('rejects a wrong password', async () => {
|
|
44
|
+
let error;
|
|
45
|
+
await inRequest(basic('tom', 'wrong'), () => provider().authenticate()).catch(e => {
|
|
46
|
+
error = e;
|
|
47
|
+
});
|
|
48
|
+
(0, chai_1.expect)(error).to.be.instanceOf(error_1.BadCredentialsError);
|
|
49
|
+
});
|
|
50
|
+
(0, bun_test_1.it)('is only used with a Basic authorization header', async () => {
|
|
51
|
+
(0, chai_1.expect)(await inRequest(basic('tom', 'x'), () => provider().support())).to.equal(true);
|
|
52
|
+
(0, chai_1.expect)(await inRequest('Bearer abc', () => provider().support())).to.equal(false);
|
|
53
|
+
(0, chai_1.expect)(await inRequest(undefined, () => provider().support())).to.equal(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
(0, bun_test_1.describe)('DefaultAuthenticationSuccessHandler', () => {
|
|
57
|
+
(0, bun_test_1.it)('does not redirect an authentication that goes on to the requested resource', async () => {
|
|
58
|
+
const handler = new authentication_success_handler_1.DefaultAuthenticationSuccessHandler();
|
|
59
|
+
let redirected = false;
|
|
60
|
+
Object.assign(handler, { loginSuccessUrl: '/', redirectStrategy: { send: async () => { redirected = true; } } });
|
|
61
|
+
await inRequest(basic('tom', 'x'), () => handler.onAuthenticationSuccess({ next: true, authenticated: true }));
|
|
62
|
+
(0, chai_1.expect)(redirected).to.equal(false);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=basic-authentication.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-authentication.spec.js","sourceRoot":"","sources":["../../../src/node/authentication/basic-authentication.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,+BAA8B;AAC9B,+CAA+C;AAC/C,oCAA+C;AAC/C,uEAAwE;AACxE,qFAAuF;AAEvF,SAAS,SAAS,CAAI,aAAiC,EAAE,EAAoB;IACzE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,cAAO,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,IAAI,CAAC;gBACD,MAAM,OAAO,GAA2B,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC/E,cAAO,CAAC,UAAU,CAAC,IAAI,cAAO,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAS,EAAE,EAAS,CAAC,CAAC,CAAC;gBACnH,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACxB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,MAAM,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAED,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,QAAgB,EAAE,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;AAEnH,SAAS,QAA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AG,IAAI,oEAAmC,EAAE,CAAC;QAC1D,IAAI,UAAU,GAAG,KAAK,CAAC;QACvB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,GAAG,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACjH,MAAM,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,uBAAuB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAS,CAAC,CAAC,CAAC;QACtH,IAAA,aAAM,EAAC,UAAU,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { StringKeyGenerator } from './keygen-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Random keys (OAuth2 `state`, PKCE `code_verifier`, OIDC `nonce`) in base64url without padding,
|
|
4
|
+
* so they can go into a URL as they are (RFC 7636 §4.1 allows only unreserved characters).
|
|
5
|
+
*/
|
|
2
6
|
export declare class Base64StringKeyGenerator implements StringKeyGenerator {
|
|
3
7
|
protected readonly keyLength: number;
|
|
4
8
|
generateKey(keyLength?: number): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64-string-key-generator.d.ts","sourceRoot":"","sources":["../../../../src/node/crypto/keygen/base64-string-key-generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base64-string-key-generator.d.ts","sourceRoot":"","sources":["../../../../src/node/crypto/keygen/base64-string-key-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGvD;;;GAGG;AACH,qBACa,wBAAyB,YAAW,kBAAkB;IAG/D,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE/B,WAAW,CAAC,SAAS,CAAC,EAAE,MAAM,mBAEnC;CACJ"}
|
|
@@ -10,13 +10,16 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Base64StringKeyGenerator = void 0;
|
|
13
|
+
const node_crypto_1 = require("node:crypto");
|
|
13
14
|
const keygen_protocol_1 = require("./keygen-protocol");
|
|
14
|
-
const crypto_js_1 = require("crypto-js");
|
|
15
15
|
const core_1 = require("@celljs/core");
|
|
16
|
+
/**
|
|
17
|
+
* Random keys (OAuth2 `state`, PKCE `code_verifier`, OIDC `nonce`) in base64url without padding,
|
|
18
|
+
* so they can go into a URL as they are (RFC 7636 §4.1 allows only unreserved characters).
|
|
19
|
+
*/
|
|
16
20
|
let Base64StringKeyGenerator = class Base64StringKeyGenerator {
|
|
17
21
|
async generateKey(keyLength) {
|
|
18
|
-
|
|
19
|
-
return crypto_js_1.enc.Base64.stringify(key);
|
|
22
|
+
return (0, node_crypto_1.randomBytes)(keyLength || this.keyLength).toString('base64url');
|
|
20
23
|
}
|
|
21
24
|
};
|
|
22
25
|
exports.Base64StringKeyGenerator = Base64StringKeyGenerator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64-string-key-generator.js","sourceRoot":"","sources":["../../../../src/node/crypto/keygen/base64-string-key-generator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAuD;AACvD,
|
|
1
|
+
{"version":3,"file":"base64-string-key-generator.js","sourceRoot":"","sources":["../../../../src/node/crypto/keygen/base64-string-key-generator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA0C;AAC1C,uDAAuD;AACvD,uCAAgD;AAEhD;;;GAGG;AAEI,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAKjC,KAAK,CAAC,WAAW,CAAC,SAAkB;QAChC,OAAO,IAAA,yBAAW,EAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC1E,CAAC;CACJ,CAAA;;AALsB;IADlB,IAAA,YAAK,EAAC,qCAAqC,CAAC;;2DACR;mCAH5B,wBAAwB;IADpC,IAAA,gBAAS,EAAC,oCAAkB,CAAC;GACjB,wBAAwB,CAQpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64-string-key-generator.spec.d.ts","sourceRoot":"","sources":["../../../../src/node/crypto/keygen/base64-string-key-generator.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 base64_string_key_generator_1 = require("./base64-string-key-generator");
|
|
6
|
+
(0, bun_test_1.describe)('Base64StringKeyGenerator', () => {
|
|
7
|
+
(0, bun_test_1.it)('generates URL-safe keys of the requested number of random bytes', async () => {
|
|
8
|
+
const generator = Object.assign(new base64_string_key_generator_1.Base64StringKeyGenerator(), { keyLength: 32 });
|
|
9
|
+
const key = await generator.generateKey();
|
|
10
|
+
(0, chai_1.expect)(key).to.match(/^[A-Za-z0-9_-]{43}$/);
|
|
11
|
+
(0, chai_1.expect)(await generator.generateKey(96)).to.match(/^[A-Za-z0-9_-]{128}$/);
|
|
12
|
+
(0, chai_1.expect)(await generator.generateKey()).to.not.equal(key);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=base64-string-key-generator.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64-string-key-generator.spec.js","sourceRoot":"","sources":["../../../../src/node/crypto/keygen/base64-string-key-generator.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,+BAA8B;AAC9B,+EAAyE;AAEzE,IAAA,mBAAQ,EAAC,0BAA0B,EAAE,GAAG,EAAE;IACtC,IAAA,aAAE,EAAC,iEAAiE,EAAE,KAAK,IAAI,EAAE;QAC7E,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,sDAAwB,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;QACnF,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,WAAW,EAAE,CAAC;QAC1C,IAAA,aAAM,EAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAC5C,IAAA,aAAM,EAAC,MAAM,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;QACzE,IAAA,aAAM,EAAC,MAAM,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -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,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,2DAA2D;IAC3D,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,mGAAmG;IACnG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qGAAqG;IACrG,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,qBACa,qBAAsB,YAAW,eAAe;IAEzD,MAAM,CAAC,QAAQ,CAAC,MAAM,mBAAmB;IACzC,MAAM,CAAC,QAAQ,CAAC,UAAU,UAAU;IACpC,MAAM,CAAC,QAAQ,CAAC,UAAU,MAAM;IAChC,MAAM,CAAC,QAAQ,CAAC,SAAS,MAAM;IAE/B,MAAM,CAAC,QAAQ,CAAC,iBAAiB,UAAU;IAC3C,MAAM,CAAC,QAAQ,CAAC,eAAe,KAAK;IACpC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,MAAM;IAGxC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,4BAA4B,GAAG,SAAS,CAAC;IAErE,gCAAgC;IAChC,SAAS,KAAK,UAAU,IAAI,MAAM,CAEjC;IAEK,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAIjD;IAEK,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAK5E;IAED,YAAY,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAK7C;IAED,SAAS,CAAC,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAEpD;IAED,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrC;IAED,UAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAY7F;IAED,UAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,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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