infinispan 0.8.0 → 0.10.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/Jenkinsfile-release +1 -1
- package/README.md +31 -907
- package/documentation/asciidoc/stories/assembly_client_usage_examples.adoc +10 -0
- package/documentation/asciidoc/stories/assembly_installation_configuration.adoc +20 -0
- package/documentation/asciidoc/titles/js_client.asciidoc +28 -0
- package/documentation/asciidoc/titles/stories.adoc +5 -0
- package/documentation/asciidoc/topics/attributes/community-attributes.adoc +8 -0
- package/documentation/asciidoc/topics/attributes/downstream-attributes.adoc +2 -0
- package/documentation/asciidoc/topics/code_examples/authentication-digest.js +12 -0
- package/documentation/asciidoc/topics/code_examples/authentication-external.js +15 -0
- package/documentation/asciidoc/topics/code_examples/authentication-oauthbearer.js +10 -0
- package/documentation/asciidoc/topics/code_examples/authentication-plain.js +11 -0
- package/documentation/asciidoc/topics/code_examples/authentication-scram.js +11 -0
- package/documentation/asciidoc/topics/code_examples/await-multiple-entries.js +36 -0
- package/documentation/asciidoc/topics/code_examples/await-single-entries.js +29 -0
- package/documentation/asciidoc/topics/code_examples/conditional-operations.js +57 -0
- package/documentation/asciidoc/topics/code_examples/connection-multiple-servers.js +23 -0
- package/documentation/asciidoc/topics/code_examples/connection-xsite-cluster-switch.js +39 -0
- package/documentation/asciidoc/topics/code_examples/connection-xsite.js +13 -0
- package/documentation/asciidoc/topics/code_examples/data-types.js +30 -0
- package/documentation/asciidoc/topics/code_examples/encryption-crypto-store.js +11 -0
- package/documentation/asciidoc/topics/code_examples/encryption-private-key.js +13 -0
- package/documentation/asciidoc/topics/code_examples/encryption-sni-hostname.js +9 -0
- package/documentation/asciidoc/topics/code_examples/encryption-trust-certs.js +8 -0
- package/documentation/asciidoc/topics/code_examples/ephemeral-data.js +52 -0
- package/documentation/asciidoc/topics/code_examples/hello-world.js +42 -0
- package/documentation/asciidoc/topics/code_examples/key-value-converter.js +67 -0
- package/documentation/asciidoc/topics/code_examples/logging-configuration.js +2 -0
- package/documentation/asciidoc/topics/code_examples/multiple-entries.js +64 -0
- package/documentation/asciidoc/topics/code_examples/register-event-listener.js +64 -0
- package/documentation/asciidoc/topics/code_examples/sample-script-execute.js +33 -0
- package/documentation/asciidoc/topics/code_examples/sample-script.js +3 -0
- package/documentation/asciidoc/topics/code_examples/single-entries.js +49 -0
- package/documentation/asciidoc/topics/config_examples/logging.json +14 -0
- package/documentation/asciidoc/topics/proc_configuring_authentication.adoc +16 -0
- package/documentation/asciidoc/topics/proc_configuring_connections.adoc +25 -0
- package/documentation/asciidoc/topics/proc_configuring_connections_xsite.adoc +18 -0
- package/documentation/asciidoc/topics/proc_configuring_data_formats.adoc +30 -0
- package/documentation/asciidoc/topics/proc_configuring_encryption.adoc +15 -0
- package/documentation/asciidoc/topics/proc_configuring_logging.adoc +28 -0
- package/documentation/asciidoc/topics/proc_installing_clients.adoc +58 -0
- package/documentation/asciidoc/topics/proc_switching_clusters.adoc +17 -0
- package/documentation/asciidoc/topics/ref_authentication_mechanisms.adoc +68 -0
- package/documentation/asciidoc/topics/ref_client_usage.adoc +116 -0
- package/documentation/asciidoc/topics/ref_encryption.adoc +71 -0
- package/lib/codec.js +153 -2
- package/lib/infinispan.js +33 -1
- package/lib/io.js +23 -16
- package/lib/protocols.js +165 -68
- package/lib/protostream/message-wrapping.proto +134 -0
- package/lib/protostream/query.proto +122 -0
- package/lib/sasl/bitops.js +24 -0
- package/lib/sasl/digest.js +188 -0
- package/lib/sasl/external.js +54 -0
- package/lib/sasl/factory.js +71 -0
- package/lib/sasl/oauthbearer.js +63 -0
- package/lib/sasl/plain.js +65 -0
- package/lib/sasl/scram.js +135 -0
- package/lib/utils.js +1 -1
- package/memory-profiling/helper.js +9 -0
- package/memory-profiling/infinispan_memory_many_get.js +1 -3
- package/memory-profiling/infinispan_memory_one_get.js +6 -4
- package/package.json +7 -13
- package/run-servers.sh +17 -8
- package/run-testsuite.sh +1 -1
- package/smoke-tests.sh +8 -2
- package/spec/codec_spec.js +7 -7
- package/spec/configs/infinispan-clustered.xml +17 -14
- package/spec/configs/infinispan-ssl.xml +25 -22
- package/spec/configs/infinispan-xsite-EARTH.xml +17 -14
- package/spec/configs/infinispan-xsite-MOON.xml +14 -11
- package/spec/configs/infinispan.xml +22 -13
- package/spec/infinispan_auth_spec.js +16 -37
- package/spec/protostream_spec.js +237 -0
- package/spec/utils/testing.js +1 -3
- package/lib/bitops.js +0 -26
- package/lib/scram.js +0 -116
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
//'use strict';
|
|
2
|
+
|
|
3
|
+
var _ = require('underscore');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var long = require('long');
|
|
6
|
+
|
|
7
|
+
var t = require('./utils/testing'); // Testing dependency
|
|
8
|
+
var protobuf = require('protobufjs');
|
|
9
|
+
const { iteratee } = require('underscore');
|
|
10
|
+
var ispn = require('../lib/infinispan');
|
|
11
|
+
|
|
12
|
+
var myMsg = `package awesomepackage;
|
|
13
|
+
syntax = "proto3";
|
|
14
|
+
/**
|
|
15
|
+
* @TypeId(1000043)
|
|
16
|
+
*/
|
|
17
|
+
message AwesomeMessage {
|
|
18
|
+
string awesome_field = 1;
|
|
19
|
+
}`
|
|
20
|
+
|
|
21
|
+
var myMsg2 = `package awesomepackage;
|
|
22
|
+
/**
|
|
23
|
+
* @TypeId(1000043)
|
|
24
|
+
*/
|
|
25
|
+
message AwesomeMessage {
|
|
26
|
+
required string awesome_field = 1;
|
|
27
|
+
}`
|
|
28
|
+
|
|
29
|
+
var myMsg3 = `package awesomepackage;
|
|
30
|
+
/**
|
|
31
|
+
* @TypeId(1000044)
|
|
32
|
+
*/
|
|
33
|
+
message AwesomeUser {
|
|
34
|
+
required string name = 1;
|
|
35
|
+
required int64 age = 2;
|
|
36
|
+
required bool isVerified =3;
|
|
37
|
+
}`
|
|
38
|
+
|
|
39
|
+
var p30 = t.protocol30({
|
|
40
|
+
dataFormat: {
|
|
41
|
+
keyType: 'text/plain',
|
|
42
|
+
valueType: 'application/x-protostream'
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('Protobuf encoding', function () {
|
|
47
|
+
var expectedArray = [0x0a, 0x0d, 0x41, 0x77, 0x65, 0x73, 0x6f, 0x6d, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67];
|
|
48
|
+
var expectedBuffer = Buffer.from(expectedArray);
|
|
49
|
+
it("Encodes a proto message", function () {
|
|
50
|
+
root = protobuf.parse(myMsg).root;
|
|
51
|
+
|
|
52
|
+
// Obtain a message type
|
|
53
|
+
var AwesomeMessage = root.lookupType(".awesomepackage.AwesomeMessage");
|
|
54
|
+
var payload = { awesomeField: "AwesomeString" };
|
|
55
|
+
var errMsg = AwesomeMessage.verify(payload);
|
|
56
|
+
expect(errMsg === null).toBeTruthy();
|
|
57
|
+
var message = AwesomeMessage.create(payload); // or use .fromObject if conversion is necessary
|
|
58
|
+
var buffer = AwesomeMessage.encode(message).finish();
|
|
59
|
+
expect(Buffer.compare(buffer, expectedBuffer)).toBe(0);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
describe('Protostream encoding', function () {
|
|
65
|
+
p30.registerProtostreamType(".awesomepackage.AwesomeMessage", 1000043);
|
|
66
|
+
|
|
67
|
+
it("Returns the Protostream type", function () {
|
|
68
|
+
var psType = p30.lookupProtostreamTypeByName(".awesomepackage.AwesomeMessage");
|
|
69
|
+
expect(psType).toBe(1000043);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("Encodes a Protostream message", function () {
|
|
73
|
+
root = protobuf.parse(myMsg).root;
|
|
74
|
+
protobuf.loadSync(path.join(__dirname + '/../lib/protostream/message-wrapping.proto'), root);
|
|
75
|
+
// Obtain message types
|
|
76
|
+
var AwesomeMessage = root.lookupType(".awesomepackage.AwesomeMessage");
|
|
77
|
+
var WrappedMessage = root.lookupType(".org.infinispan.protostream.WrappedMessage");
|
|
78
|
+
// Build input message
|
|
79
|
+
var payload = { awesomeField: "AwesomeString" };
|
|
80
|
+
var errMsg = AwesomeMessage.verify(payload);
|
|
81
|
+
expect(errMsg === null).toBeTruthy();
|
|
82
|
+
var message = AwesomeMessage.create(payload);
|
|
83
|
+
// Build manually WrappedMessage
|
|
84
|
+
var buffer = AwesomeMessage.encode(message).finish();
|
|
85
|
+
var wmPayload = {
|
|
86
|
+
wrappedMessage: buffer,
|
|
87
|
+
wrappedTypeId: 1000043
|
|
88
|
+
};
|
|
89
|
+
errMsg = WrappedMessage.verify(wmPayload);
|
|
90
|
+
expect(errMsg === null).toBeTruthy();
|
|
91
|
+
var wmMessage = WrappedMessage.create(wmPayload);
|
|
92
|
+
var expectedWMBuffer = WrappedMessage.encode(wmMessage).finish();
|
|
93
|
+
|
|
94
|
+
// Call client API for encoding
|
|
95
|
+
var outBuf = t.newByteBuf(32);
|
|
96
|
+
p30.encodeMediaValue(message)(outBuf);
|
|
97
|
+
// outBuf contains the WM encoded by the client
|
|
98
|
+
|
|
99
|
+
// Removing buf length at the beginning for comparison
|
|
100
|
+
var trimmed = outBuf.buf.slice(1, outBuf.offset);
|
|
101
|
+
// check the client produces same byte buffer
|
|
102
|
+
expect(Buffer.compare(trimmed, expectedWMBuffer)).toBe(0);
|
|
103
|
+
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
describe("Put/Get protostream object to/from Infinispan", function () {
|
|
109
|
+
it("Puts protostream on Infinispan", async function (done) {
|
|
110
|
+
var root = protobuf.parse(myMsg).root;
|
|
111
|
+
var AwesomeMessage = root.lookupType(".awesomepackage.AwesomeMessage");
|
|
112
|
+
try {
|
|
113
|
+
var protoMetaClient = await ispn.client(t.local, { authentication: t.authOpts.authentication, cacheName: '___protobuf_metadata', dataFormat: { keyType: "text/plain", valueType: "text/plain" } });
|
|
114
|
+
var client = await t.client(t.local, { authentication: t.authOpts.authentication, cacheName: 'protoStreamCache', dataFormat: { keyType: "text/plain", valueType: "application/x-protostream" } });
|
|
115
|
+
var payload = { awesomeField: "AwesomeString" };
|
|
116
|
+
var errMsg = AwesomeMessage.verify(payload);
|
|
117
|
+
expect(errMsg === null).toBeTruthy();
|
|
118
|
+
var message = AwesomeMessage.create(payload);
|
|
119
|
+
|
|
120
|
+
await protoMetaClient.put("awesomepackage/AwesomeMessage.proto", myMsg2);
|
|
121
|
+
|
|
122
|
+
await client.clear();
|
|
123
|
+
expect(await client.size()).toBe(0);
|
|
124
|
+
await client.put("myKey", message);
|
|
125
|
+
expect(await client.size()).toBe(1);
|
|
126
|
+
await client.put("myKey1", 1.2);
|
|
127
|
+
await client.put("myKey2","string");
|
|
128
|
+
await client.put("myKey3",true);
|
|
129
|
+
await client.put("myKey4",new ArrayBuffer(8));
|
|
130
|
+
expect(await client.size()).toBe(5);
|
|
131
|
+
|
|
132
|
+
protoMetaClient.disconnect();
|
|
133
|
+
client.disconnect();
|
|
134
|
+
done();
|
|
135
|
+
} catch (error) {
|
|
136
|
+
protoMetaClient.disconnect();
|
|
137
|
+
client.disconnect();
|
|
138
|
+
done(new Error(error));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
it("Gets protostream on Infinispan", async function (done) {
|
|
144
|
+
try {
|
|
145
|
+
var protoMetaClient = await ispn.client(t.local, { authentication: t.authOpts.authentication, cacheName: '___protobuf_metadata', dataFormat: { keyType: "text/plain", valueType: "text/plain" } });
|
|
146
|
+
var client = await t.client(t.local, { authentication: t.authOpts.authentication, cacheName: 'protoStreamCache', dataFormat: { keyType: "text/plain", valueType: "application/x-protostream" } });
|
|
147
|
+
client.registerProtostreamRoot(root);
|
|
148
|
+
var myObj=await client.get("myKey");
|
|
149
|
+
var myObj1=await client.get("myKey1");
|
|
150
|
+
var myObj2=await client.get("myKey2");
|
|
151
|
+
var myObj3=await client.get("myKey3");
|
|
152
|
+
var myObj4=await client.get("myKey4");
|
|
153
|
+
protoMetaClient.disconnect();
|
|
154
|
+
await client.clear();
|
|
155
|
+
client.disconnect();
|
|
156
|
+
done();
|
|
157
|
+
} catch (error) {
|
|
158
|
+
protoMetaClient.disconnect();
|
|
159
|
+
client.disconnect();
|
|
160
|
+
done(new Error(error));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('Querying in application/x-protostream format',function () {
|
|
167
|
+
var root = protobuf.parse(myMsg).root;
|
|
168
|
+
var AwesomeMessage = root.lookupType(".awesomepackage.AwesomeMessage");
|
|
169
|
+
var root2 = protobuf.parse(myMsg3).root;
|
|
170
|
+
var AwesomeUser = root2.lookupType(".awesomepackage.AwesomeUser");
|
|
171
|
+
it("Queries the server without projection", async function (done) {
|
|
172
|
+
try{
|
|
173
|
+
var protoMetaClient = await ispn.client(t.local, { authentication: t.authOpts.authentication, cacheName: '___protobuf_metadata', dataFormat: { keyType: "text/plain", valueType: "text/plain" } });
|
|
174
|
+
var client = await t.client(t.local, { authentication: t.authOpts.authentication, cacheName: 'protoStreamCache', dataFormat: { keyType: "application/x-protostream", valueType: "application/x-protostream" } });
|
|
175
|
+
await protoMetaClient.put("awesomepackage/AwesomeMessage.proto", myMsg2);
|
|
176
|
+
await client.clear();
|
|
177
|
+
for(let i=0;i<10;i++){
|
|
178
|
+
var payload = { awesomeField: "AwesomeString"+i };
|
|
179
|
+
var message = AwesomeMessage.create(payload);
|
|
180
|
+
await client.put(i,message)
|
|
181
|
+
}
|
|
182
|
+
var queryResp1 = await client.query({queryString:`from awesomepackage.AwesomeMessage ORDER BY awesome_field`});
|
|
183
|
+
expect(queryResp1.length).toBe(10);
|
|
184
|
+
var queryResp2 = await client.query({queryString:`from awesomepackage.AwesomeMessage a where a.awesome_field='AwesomeString1'`});
|
|
185
|
+
expect(queryResp2.length).toBe(1);
|
|
186
|
+
expect(queryResp2[0].awesomeField).toEqual('AwesomeString1');
|
|
187
|
+
var queryResp3 = await client.query({queryString:`from awesomepackage.AwesomeMessage a where a.awesome_field='AwesomeString100'`});
|
|
188
|
+
expect(queryResp3.length).toEqual(0);
|
|
189
|
+
protoMetaClient.disconnect();
|
|
190
|
+
await client.clear();
|
|
191
|
+
client.disconnect();
|
|
192
|
+
done();
|
|
193
|
+
}catch (error) {
|
|
194
|
+
protoMetaClient.disconnect();
|
|
195
|
+
client.disconnect();
|
|
196
|
+
done(new Error(error));
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("Queries the server with projection", async function (done) {
|
|
201
|
+
try{
|
|
202
|
+
var protoMetaClient = await ispn.client(t.local, { authentication: t.authOpts.authentication, cacheName: '___protobuf_metadata', dataFormat: { keyType: "text/plain", valueType: "text/plain" } });
|
|
203
|
+
var client = await t.client(t.local, { authentication: t.authOpts.authentication, cacheName: 'protoStreamCache', dataFormat: { keyType: "application/x-protostream", valueType: "application/x-protostream" } });
|
|
204
|
+
await protoMetaClient.put("awesomepackage/AwesomeUser.proto", myMsg3);
|
|
205
|
+
client.registerProtostreamRoot(root2);
|
|
206
|
+
client.registerProtostreamType(".awesomepackage.AwesomeUser",1000044);
|
|
207
|
+
await client.clear();
|
|
208
|
+
for (let i = 0; i < 10; i++){
|
|
209
|
+
var payload = { name: "AwesomeString"+i , age : i , isVerified: (Math.random()<0.5)};
|
|
210
|
+
var message = AwesomeUser.create(payload);
|
|
211
|
+
await client.put(i,message)
|
|
212
|
+
}
|
|
213
|
+
var query1 = await client.query({ queryString: `select u.name,u.age from awesomepackage.AwesomeUser u where u.age<20 order by u.name asc` });
|
|
214
|
+
expect(query1.length).toBe(10);
|
|
215
|
+
expect(query1[0].length).toBe(2);
|
|
216
|
+
for (let i = 0; i < 10; i++) {
|
|
217
|
+
expect(_.isEqual(query1[i][1], long.fromValue(i))).toBeTruthy();
|
|
218
|
+
}
|
|
219
|
+
var query2 = await client.query({queryString:`select u.name from awesomepackage.AwesomeUser u where u.age=2`});
|
|
220
|
+
expect(query2[0][0]).toBe("AwesomeString2");
|
|
221
|
+
|
|
222
|
+
var query3 = await client.query({queryString:`select u.name from awesomepackage.AwesomeUser u where u.age>20`});
|
|
223
|
+
expect(query3.length).toBe(0);
|
|
224
|
+
|
|
225
|
+
protoMetaClient.disconnect();
|
|
226
|
+
await client.clear();
|
|
227
|
+
client.disconnect();
|
|
228
|
+
done();
|
|
229
|
+
}catch (error) {
|
|
230
|
+
protoMetaClient.disconnect();
|
|
231
|
+
client.disconnect();
|
|
232
|
+
done(new Error(error));
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
}
|
|
237
|
+
);
|
package/spec/utils/testing.js
CHANGED
|
@@ -4,9 +4,6 @@ var _ = require('underscore');
|
|
|
4
4
|
|
|
5
5
|
var log4js = require('log4js');
|
|
6
6
|
|
|
7
|
-
var promiseFinally = require('promise.prototype.finally');
|
|
8
|
-
promiseFinally.shim(); // will be a no-op if not needed
|
|
9
|
-
|
|
10
7
|
var readFile = require('fs').readFile;
|
|
11
8
|
var httpRequest = require('request');
|
|
12
9
|
var util = require('util');
|
|
@@ -96,6 +93,7 @@ exports.client = function(args, opts) {
|
|
|
96
93
|
exports.protocol25 = function() { return protocols.version25(); };
|
|
97
94
|
|
|
98
95
|
exports.protocol29 = function(clientOpts) { return protocols.version29(clientOpts); };
|
|
96
|
+
exports.protocol30 = function(clientOpts) { return protocols.version30(clientOpts); };
|
|
99
97
|
|
|
100
98
|
exports.put = function(k, v, opts) {
|
|
101
99
|
return function(client) { return client.put(k, v, opts); }
|
package/lib/bitops.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
var createHash = require('create-hash');
|
|
2
|
-
var createHmac = require('create-hmac');
|
|
3
|
-
var xor = require('bitwise-xor');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.XOR = xor;
|
|
7
|
-
|
|
8
|
-
exports.H = function (text) {
|
|
9
|
-
return createHash('sha1').update(text).digest();
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
exports.HMAC = function (key, msg) {
|
|
13
|
-
return createHmac('sha1', key).update(msg).digest();
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
exports.Hi = function (text, salt, iterations) {
|
|
17
|
-
var ui1 = exports.HMAC(text, Buffer.from([salt, Buffer.from([0, 0, 0, 1], 'binary')]));
|
|
18
|
-
var ui = ui1;
|
|
19
|
-
for (var i = 0; i < iterations - 1; i++) {
|
|
20
|
-
ui1 = exports.HMAC(text, ui1);
|
|
21
|
-
ui = exports.XOR(ui, ui1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return ui;
|
|
25
|
-
};
|
|
26
|
-
|
package/lib/scram.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
var bitops = require('./bitops');
|
|
2
|
-
var utils = require('./utils');
|
|
3
|
-
|
|
4
|
-
var RESP = {};
|
|
5
|
-
var CLIENT_KEY = 'Client Key';
|
|
6
|
-
var SERVER_KEY = 'Server Key';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function Mechanism(options) {
|
|
10
|
-
options = options || {};
|
|
11
|
-
this._genNonce = options.genNonce || utils.genNonce;
|
|
12
|
-
this._stage = 'initial';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Conform to the SASL lib's expectations
|
|
16
|
-
Mechanism.Mechanism = Mechanism;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Mechanism.prototype.name = 'SCRAM-SHA-1';
|
|
20
|
-
Mechanism.prototype.clientFirst = true;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Mechanism.prototype.response = function (cred) {
|
|
24
|
-
return RESP[this._stage](this, cred);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
Mechanism.prototype.challenge = function (chal) {
|
|
28
|
-
var values = utils.parse(chal);
|
|
29
|
-
this._salt = Buffer.from(values.s, 'base64');
|
|
30
|
-
this._iterationCount = parseInt(values.i, 10);
|
|
31
|
-
this._nonce = values.r;
|
|
32
|
-
this._verifier = values.v;
|
|
33
|
-
this._error = values.e;
|
|
34
|
-
this._challenge = chal;
|
|
35
|
-
|
|
36
|
-
return this;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
RESP.initial = function (mech, cred) {
|
|
41
|
-
mech._cnonce = mech._genNonce();
|
|
42
|
-
|
|
43
|
-
var authzid = '';
|
|
44
|
-
if (cred.authzid) {
|
|
45
|
-
authzid = 'a=' + utils.saslname(cred.authzid);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
mech._gs2Header = 'n,' + authzid + ',';
|
|
49
|
-
|
|
50
|
-
var nonce = 'r=' + mech._cnonce;
|
|
51
|
-
var username = 'n=' + utils.saslname(cred.username || '');
|
|
52
|
-
|
|
53
|
-
mech._clientFirstMessageBare = username + ',' + nonce;
|
|
54
|
-
var result = mech._gs2Header + mech._clientFirstMessageBare;
|
|
55
|
-
|
|
56
|
-
mech._stage = 'challenge';
|
|
57
|
-
|
|
58
|
-
return result;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
RESP.challenge = function (mech, cred) {
|
|
63
|
-
var gs2Header = Buffer.from(mech._gs2Header).toString('base64');
|
|
64
|
-
mech._clientFinalMessageWithoutProof = 'c=' + gs2Header + ',r=' + mech._nonce;
|
|
65
|
-
|
|
66
|
-
var saltedPassword, clientKey, serverKey;
|
|
67
|
-
|
|
68
|
-
// If our cached salt is the same, we can reuse cached credentials to speed
|
|
69
|
-
// up the hashing process.
|
|
70
|
-
if (cred.salt && Buffer.compare(cred.salt, mech._salt) === 0) {
|
|
71
|
-
if (cred.clientKey && cred.serverKey) {
|
|
72
|
-
clientKey = cred.clientKey;
|
|
73
|
-
serverKey = cred.serverKey;
|
|
74
|
-
} else if (cred.saltedPassword) {
|
|
75
|
-
saltedPassword = cred.saltedPassword;
|
|
76
|
-
clientKey = bitops.HMAC(saltedPassword, CLIENT_KEY);
|
|
77
|
-
serverKey = bitops.HMAC(saltedPassword, SERVER_KEY);
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
saltedPassword = bitops.Hi(cred.password || '', mech._salt, mech._iterationCount);
|
|
81
|
-
clientKey = bitops.HMAC(saltedPassword, CLIENT_KEY);
|
|
82
|
-
serverKey = bitops.HMAC(saltedPassword, SERVER_KEY);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
var storedKey = bitops.H(clientKey);
|
|
86
|
-
var authMessage = mech._clientFirstMessageBare + ',' +
|
|
87
|
-
mech._challenge + ',' +
|
|
88
|
-
mech._clientFinalMessageWithoutProof;
|
|
89
|
-
var clientSignature = bitops.HMAC(storedKey, authMessage);
|
|
90
|
-
|
|
91
|
-
var clientProof = bitops.XOR(clientKey, clientSignature).toString('base64');
|
|
92
|
-
|
|
93
|
-
mech._serverSignature = bitops.HMAC(serverKey, authMessage);
|
|
94
|
-
|
|
95
|
-
var result = mech._clientFinalMessageWithoutProof + ',p=' + clientProof;
|
|
96
|
-
|
|
97
|
-
mech._stage = 'final';
|
|
98
|
-
|
|
99
|
-
mech.cache = {
|
|
100
|
-
salt: mech._salt,
|
|
101
|
-
saltedPassword: saltedPassword,
|
|
102
|
-
clientKey: clientKey,
|
|
103
|
-
serverKey: serverKey
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
return result;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
RESP.final = function () {
|
|
110
|
-
// TODO: Signal errors
|
|
111
|
-
return '';
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
module.exports = Mechanism;
|