@secrez/core 1.0.6 → 1.0.7
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 +9 -5
- package/coverage.report +12 -19
- package/package.json +4 -4
- package/src/Secrez.js +2 -114
- package/src/_Secrez.js +0 -43
- package/src/config/index.js +0 -5
package/README.md
CHANGED
|
@@ -20,6 +20,10 @@ API documentation
|
|
|
20
20
|
|
|
21
21
|
## History
|
|
22
22
|
|
|
23
|
+
**1.0.7**
|
|
24
|
+
|
|
25
|
+
- remove legacy shared-secret / second-factor authentication API (`sharedSignin`, `generateSharedSecrets`, `recoverSharedSecrets`, `removeSharedSecret`, `getSecondFactorData`, and related config); sign-in now requires only the master key
|
|
26
|
+
|
|
23
27
|
**0.8.5**
|
|
24
28
|
|
|
25
29
|
- improve \_Secrez and Secrez encapsulation of private data
|
|
@@ -28,16 +32,16 @@ API documentation
|
|
|
28
32
|
## Test coverage
|
|
29
33
|
|
|
30
34
|
```
|
|
31
|
-
|
|
35
|
+
54 passing (929ms)
|
|
32
36
|
|
|
33
37
|
-----------------|---------|----------|---------|---------|-------------------
|
|
34
38
|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
35
39
|
-----------------|---------|----------|---------|---------|-------------------
|
|
36
|
-
All files | 99.
|
|
37
|
-
src |
|
|
40
|
+
All files | 99.39 | 93.49 | 98.5 | 99.39 |
|
|
41
|
+
src | 99.61 | 95.58 | 98.24 | 99.61 |
|
|
38
42
|
Entry.js | 100 | 95.65 | 100 | 100 | 39
|
|
39
|
-
Secrez.js | 100 | 96.
|
|
40
|
-
_Secrez.js |
|
|
43
|
+
Secrez.js | 100 | 96.66 | 100 | 100 | 207,330
|
|
44
|
+
_Secrez.js | 98.93 | 91.3 | 95.65 | 98.93 | 101
|
|
41
45
|
src/config | 98.57 | 84.84 | 100 | 98.57 |
|
|
42
46
|
ConfigUtils.js | 98.48 | 84.84 | 100 | 98.48 | 137
|
|
43
47
|
booleans.js | 100 | 100 | 100 | 100 |
|
package/coverage.report
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @secrez/core@1.0.
|
|
2
|
+
> @secrez/core@1.0.7 test /Users/francescosullo/Projects/Secrez/secrez/packages/core
|
|
3
3
|
> cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js --exit
|
|
4
4
|
|
|
5
5
|
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
derivePassword
|
|
30
30
|
✓ should derive a password and obtain a predeterminded hash
|
|
31
31
|
signup and signin
|
|
32
|
-
✓ should signup the user and signin without saving the iterations (
|
|
32
|
+
✓ should signup the user and signin without saving the iterations (46ms)
|
|
33
33
|
✓ should signup in two instances without conflicts
|
|
34
34
|
✓ should signup the user and signin saved the iterations
|
|
35
|
-
✓ should signup with version one, and signin and upgrade to version two
|
|
35
|
+
✓ should signup with version one, and signin and upgrade to version two (40ms)
|
|
36
36
|
✓ should signup the user, change password and signin
|
|
37
|
-
✓ should signup the user, change iterations and signin
|
|
38
|
-
✓ should signup the user, change password and iterations and signin (
|
|
37
|
+
✓ should signup the user, change iterations and signin (45ms)
|
|
38
|
+
✓ should signup the user, change password and iterations and signin (184ms)
|
|
39
39
|
should throw an error
|
|
40
40
|
✓ trying to signup if Secrez has not been initiated
|
|
41
41
|
✓ trying to signin if Secrez has not been initiated
|
|
@@ -64,13 +64,6 @@
|
|
|
64
64
|
preEncryptData and preDecryptData
|
|
65
65
|
✓ should encrypt some data with the derivedPassword and decrypt it
|
|
66
66
|
✓ should throw trying to get the master key
|
|
67
|
-
generateSharedSecrets && recoverSharedSecrets
|
|
68
|
-
✓ should set up a second factor (43ms)
|
|
69
|
-
✓ should set up a second factor and then upgrade from derivationVersion 1 to 2
|
|
70
|
-
✓ should set up a second factor and a recovery code and remove them (40ms)
|
|
71
|
-
✓ should set up a second factor and a recovery code and remove the recovery code (43ms)
|
|
72
|
-
✓ should throw if wrong secret
|
|
73
|
-
✓ should throw if wrong authenticator
|
|
74
67
|
#readConf
|
|
75
68
|
✓ should encrypt some data with the derivedPassword and decrypt it
|
|
76
69
|
✓ should throw trying to get the master key
|
|
@@ -91,22 +84,22 @@
|
|
|
91
84
|
✓ #getEnv should return the environment
|
|
92
85
|
|
|
93
86
|
|
|
94
|
-
|
|
87
|
+
54 passing (929ms)
|
|
95
88
|
|
|
96
89
|
-----------------|---------|----------|---------|---------|-------------------
|
|
97
90
|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
98
91
|
-----------------|---------|----------|---------|---------|-------------------
|
|
99
|
-
All files | 99.
|
|
100
|
-
src |
|
|
92
|
+
All files | 99.39 | 93.49 | 98.5 | 99.39 |
|
|
93
|
+
src | 99.61 | 95.58 | 98.24 | 99.61 |
|
|
101
94
|
Entry.js | 100 | 95.65 | 100 | 100 | 39
|
|
102
|
-
Secrez.js | 100 | 96.
|
|
103
|
-
_Secrez.js |
|
|
95
|
+
Secrez.js | 100 | 96.66 | 100 | 100 | 207,330
|
|
96
|
+
_Secrez.js | 98.93 | 91.3 | 95.65 | 98.93 | 101
|
|
104
97
|
src/config | 98.57 | 84.84 | 100 | 98.57 |
|
|
105
98
|
ConfigUtils.js | 98.48 | 84.84 | 100 | 98.48 | 137
|
|
106
99
|
booleans.js | 100 | 100 | 100 | 100 |
|
|
107
100
|
index.js | 100 | 100 | 100 | 100 |
|
|
108
101
|
-----------------|---------|----------|---------|---------|-------------------
|
|
109
102
|
|
|
110
|
-
> @secrez/core@1.0.
|
|
111
|
-
> nyc check-coverage --statements 99 --branches
|
|
103
|
+
> @secrez/core@1.0.7 posttest /Users/francescosullo/Projects/Secrez/secrez/packages/core
|
|
104
|
+
> nyc check-coverage --statements 99 --branches 93 --functions 98 --lines 99
|
|
112
105
|
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secrez/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@secrez/crypto": "~1.0.
|
|
9
|
+
"@secrez/crypto": "~1.0.6",
|
|
10
10
|
"@secrez/utils": "~1.0.5",
|
|
11
11
|
"fs-extra": "^9.1.0",
|
|
12
12
|
"homedir": "^0.6.0",
|
|
13
13
|
"lodash": "^4.17.21"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@secrez/test-helpers": "~2.0.
|
|
16
|
+
"@secrez/test-helpers": "~2.0.2",
|
|
17
17
|
"chai": "^4.5.0",
|
|
18
18
|
"cross-env": "^7.0.3",
|
|
19
19
|
"mocha": "^7.2.0",
|
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
"all-tests": "find test/** -name '*.test.js' | xargs ./node_modules/.bin/mocha -R spec",
|
|
37
37
|
"test-only": "cross-env NODE_ENV=test ./node_modules/.bin/mocha test/*.test.js test/**/*.test.js --exit",
|
|
38
38
|
"test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js --exit",
|
|
39
|
-
"posttest": "nyc check-coverage --statements 99 --branches
|
|
39
|
+
"posttest": "nyc check-coverage --statements 99 --branches 93 --functions 98 --lines 99"
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/Secrez.js
CHANGED
|
@@ -83,45 +83,10 @@ module.exports = function () {
|
|
|
83
83
|
_secrez = new _Secrez(this);
|
|
84
84
|
await _secrez.init(password, iterations);
|
|
85
85
|
/* istanbul ignore if */
|
|
86
|
-
if (!data.key
|
|
86
|
+
if (!data.key) {
|
|
87
87
|
throw new Error("No valid data found");
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
let masterKeyHash = await _secrez.signin(data);
|
|
91
|
-
this.setMasterKeyHash(conf, masterKeyHash);
|
|
92
|
-
} else {
|
|
93
|
-
throw new Error("A second factor is required");
|
|
94
|
-
}
|
|
95
|
-
return 0;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async sharedSignin(authenticator, secret) {
|
|
99
|
-
if (
|
|
100
|
-
!this.config ||
|
|
101
|
-
!this.config.keysPath ||
|
|
102
|
-
!_secrez ||
|
|
103
|
-
!_secrez.isInitiated()
|
|
104
|
-
) {
|
|
105
|
-
throw new Error(
|
|
106
|
-
"A standard sign in must be run before to initiate Secrez"
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
const conf = await this.readConf();
|
|
110
|
-
const data = conf.data;
|
|
111
|
-
/* istanbul ignore if */
|
|
112
|
-
if (!data.keys) {
|
|
113
|
-
throw new Error("No second factor registered");
|
|
114
|
-
}
|
|
115
|
-
if (!data.keys[authenticator]) {
|
|
116
|
-
throw new Error(
|
|
117
|
-
`No second factor registered with the authenticator ${authenticator}`
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
let masterKeyHash = await _secrez.sharedSignin(
|
|
121
|
-
data,
|
|
122
|
-
authenticator,
|
|
123
|
-
secret
|
|
124
|
-
);
|
|
89
|
+
let masterKeyHash = await _secrez.signin(data);
|
|
125
90
|
this.setMasterKeyHash(conf, masterKeyHash);
|
|
126
91
|
return 0;
|
|
127
92
|
}
|
|
@@ -142,61 +107,6 @@ module.exports = function () {
|
|
|
142
107
|
await ConfigUtils.putEnv(this.config, env);
|
|
143
108
|
}
|
|
144
109
|
|
|
145
|
-
generateSharedSecrets(secret) {
|
|
146
|
-
return _secrez.generateSharedSecrets(secret);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async removeSharedSecret(authenticator, all) {
|
|
150
|
-
let data = _secrez.conf.data;
|
|
151
|
-
let code = 1;
|
|
152
|
-
let removeAll = true;
|
|
153
|
-
if (!all) {
|
|
154
|
-
if (data.keys && data.keys[authenticator]) {
|
|
155
|
-
delete data.keys[authenticator];
|
|
156
|
-
}
|
|
157
|
-
for (let authenticator in data.keys) {
|
|
158
|
-
if (
|
|
159
|
-
data.keys[authenticator].type === this.config.sharedKeys.FIDO2_KEY
|
|
160
|
-
) {
|
|
161
|
-
removeAll = false;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (removeAll) {
|
|
167
|
-
code = 2;
|
|
168
|
-
_secrez.restoreKey();
|
|
169
|
-
}
|
|
170
|
-
let conf = await this.signAndSave(data);
|
|
171
|
-
_secrez.setConf(conf, DO_NOT_VERIFY);
|
|
172
|
-
return code;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async saveSharedSecrets(sharedData) {
|
|
176
|
-
let conf = await this.readConf();
|
|
177
|
-
if (!conf.data.keys) {
|
|
178
|
-
conf.data.keys = {};
|
|
179
|
-
}
|
|
180
|
-
let authenticator = sharedData.authenticator;
|
|
181
|
-
delete sharedData.authenticator;
|
|
182
|
-
if (sharedData.id) {
|
|
183
|
-
sharedData.id = this.preEncryptData(sharedData.id);
|
|
184
|
-
}
|
|
185
|
-
if (sharedData.salt) {
|
|
186
|
-
sharedData.salt = this.preEncryptData(sharedData.salt);
|
|
187
|
-
}
|
|
188
|
-
if (sharedData.credential) {
|
|
189
|
-
sharedData.credential = this.preEncryptData(sharedData.credential);
|
|
190
|
-
}
|
|
191
|
-
conf.data.keys[authenticator] = sharedData;
|
|
192
|
-
if (conf.data.key) {
|
|
193
|
-
delete conf.data.key;
|
|
194
|
-
}
|
|
195
|
-
conf = await this.signAndSave(conf.data);
|
|
196
|
-
_secrez.setConf(conf, DO_NOT_VERIFY);
|
|
197
|
-
return conf;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
110
|
getConf() {
|
|
201
111
|
return _secrez.conf;
|
|
202
112
|
}
|
|
@@ -239,28 +149,6 @@ module.exports = function () {
|
|
|
239
149
|
);
|
|
240
150
|
}
|
|
241
151
|
|
|
242
|
-
async getSecondFactorData(authenticator) {
|
|
243
|
-
if (
|
|
244
|
-
!this.config ||
|
|
245
|
-
!this.config.keysPath ||
|
|
246
|
-
!_secrez ||
|
|
247
|
-
!_secrez.isInitiated()
|
|
248
|
-
) {
|
|
249
|
-
throw new Error(
|
|
250
|
-
"A standard sign in must be run before to initiate Secrez"
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
const conf = await this.readConf();
|
|
254
|
-
let data = conf.data.keys[authenticator];
|
|
255
|
-
if (data) {
|
|
256
|
-
return data;
|
|
257
|
-
} else {
|
|
258
|
-
throw new Error(
|
|
259
|
-
`No registered data with the authenticator ${authenticator}`
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
152
|
setMasterKeyHash(conf, masterKeyHash) {
|
|
265
153
|
/* istanbul ignore if */
|
|
266
154
|
if (!_secrez.setConf(conf)) {
|
package/src/_Secrez.js
CHANGED
|
@@ -122,11 +122,6 @@ module.exports = function () {
|
|
|
122
122
|
return data;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
async restoreKey() {
|
|
126
|
-
delete this.conf.data.keys;
|
|
127
|
-
this.conf.data.key = this.preEncrypt(__.masterKey);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
125
|
setConf(conf, doNotVerify) {
|
|
131
126
|
/* istanbul ignore if */
|
|
132
127
|
if (!doNotVerify && !this.verifySavedData(conf)) {
|
|
@@ -200,50 +195,12 @@ module.exports = function () {
|
|
|
200
195
|
}
|
|
201
196
|
}
|
|
202
197
|
|
|
203
|
-
async sharedSignin(data, authenticator, secret) {
|
|
204
|
-
let key = data.keys[authenticator];
|
|
205
|
-
try {
|
|
206
|
-
let masterKey = this.recoverSharedSecrets(key.parts, secret);
|
|
207
|
-
/* istanbul ignore if */
|
|
208
|
-
if (!utils.secureCompare(Crypto.b64Hash(masterKey), data.hash)) {
|
|
209
|
-
throw new Error("Hash on file does not match the master key");
|
|
210
|
-
}
|
|
211
|
-
__.masterKey = masterKey;
|
|
212
|
-
__.masterKeyArray = Crypto.bs64.decode(__.masterKey);
|
|
213
|
-
__.masterKeyHash = data.hash;
|
|
214
|
-
__.boxPublicKey = Crypto.bs64.decode(data.box.secretKey);
|
|
215
|
-
__.boxPrivateKey = __.decrypt(data.box.secretKey, RETURN_UINT8_ARRAY);
|
|
216
|
-
__.signPublicKey = Crypto.bs64.decode(data.sign.secretKey);
|
|
217
|
-
__.signPrivateKey = __.decrypt(data.sign.secretKey, RETURN_UINT8_ARRAY);
|
|
218
|
-
__.encryptedBoxPrivateKey = data.box.secretKey;
|
|
219
|
-
__.encryptedSignPrivateKey = data.sign.secretKey;
|
|
220
|
-
return data.hash;
|
|
221
|
-
} catch (e) {
|
|
222
|
-
throw new Error("Wrong data/secret");
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
198
|
static async derivePassword(password = __.password, iterations) {
|
|
227
199
|
password = Crypto.SHA3(password);
|
|
228
200
|
let salt = Crypto.SHA3(password + iterations.toString());
|
|
229
201
|
return bs64.encode(Crypto.deriveKey(password, salt, iterations, 32));
|
|
230
202
|
}
|
|
231
203
|
|
|
232
|
-
generateSharedSecrets(secret) {
|
|
233
|
-
let parts = Crypto.splitSecret(__.masterKey, 2, 2);
|
|
234
|
-
parts[1] = this.preEncrypt(parts["1"]);
|
|
235
|
-
parts[2] = Crypto.encrypt(parts["2"], Crypto.SHA3(secret));
|
|
236
|
-
return parts;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
recoverSharedSecrets(parts, secret) {
|
|
240
|
-
parts = {
|
|
241
|
-
1: __.preDecrypt(parts[1], RETURN_UINT8_ARRAY),
|
|
242
|
-
2: Crypto.decrypt(parts[2], Crypto.SHA3(secret), RETURN_UINT8_ARRAY),
|
|
243
|
-
};
|
|
244
|
-
return Crypto.joinSecret(parts);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
204
|
signData(data) {
|
|
248
205
|
const signature = this.signMessage(JSON.stringify(this.sortObj(data)));
|
|
249
206
|
const conf = {
|