Skip to content

Commit c69c511

Browse files
committed
Add dependency on axolotl-crypto and add integration tests
Now that we can use real crypto in the integration tests, it's possible to use real test vectors to show the implementation is correct. Fixes #5
1 parent 83d8833 commit c69c511

14 files changed

+2934
-370
lines changed

.travis.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
language: node_js
22
node_js:
33
- "0.10"
4-
before_install: npm install -g grunt-cli
4+
before_install:
5+
- "npm install -g grunt-cli"
6+
- "npm install -g bower"
7+
- "export DISPLAY=:99.0"
8+
- "sh -e /etc/init.d/xvfb start"
9+
- "bower install"

Gruntfile.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module.exports = function(grunt) {
44
grunt.loadNpmTasks("grunt-mocha-test"); // For server-side testing
5-
grunt.loadNpmTasks("grunt-mocha"); // For client-side testing
5+
grunt.loadNpmTasks("grunt-karma"); // For client-side testing
66
grunt.loadNpmTasks("grunt-pure-cjs");
77
grunt.loadNpmTasks("grunt-contrib-jshint");
88
grunt.loadNpmTasks("grunt-blanket");
@@ -51,7 +51,7 @@ module.exports = function(grunt) {
5151
}
5252
},
5353
integrationTests: {
54-
src: ["test/integration/**/*.js"],
54+
src: ["test/integration/node/**/*.js"],
5555
options: {
5656
clearRequireCache: true
5757
}
@@ -66,11 +66,10 @@ module.exports = function(grunt) {
6666
}
6767
}
6868
},
69-
mocha: {
69+
karma: {
7070
integrationTests: {
71-
src: ["test/integration/**/*.html"],
7271
options: {
73-
reporter: "Spec"
72+
configFile: "karma.conf.js"
7473
}
7574
}
7675
},
@@ -89,6 +88,9 @@ module.exports = function(grunt) {
8988
"traceur-runtime": {
9089
global: "1",
9190
id: "__external_2"
91+
},
92+
"axolotl-crypto": {
93+
global: "axolotlCrypto"
9294
}
9395
}
9496
}
@@ -129,5 +131,5 @@ module.exports = function(grunt) {
129131
grunt.registerTask("test", ["clean", "check", "mochaTest:unitTests"]);
130132
grunt.registerTask("default", ["test"]);
131133
grunt.registerTask("dist", ["default", "traceur", "pure_cjs", "concat"]);
132-
grunt.registerTask("integration-test", ["dist", "mochaTest:integrationTests", "mocha:integrationTests"]);
134+
grunt.registerTask("integration-test", ["dist", "mochaTest:integrationTests", "karma:integrationTests"]);
133135
};

README.md

+4-129
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ window.axolotl(...)
4848
### Dependencies
4949

5050
libaxolotl-javascript depends on [traceur-runtime](https://github.com/google/traceur-compiler) and
51-
[protobuf.js](https://github.com/dcodeIO/ProtoBuf.js). These dependencies are not included in the distributed package.
52-
If you installed libaxolotl-javascript using npm then there is nothing more you need to do - npm will download these
53-
dependencies for you.
51+
[protobuf.js](https://github.com/dcodeIO/ProtoBuf.js) and [cryptographic primitives](blob/master/doc/crypto.md).
52+
These dependencies are not included in the distributed package. If you installed libaxolotl-javascript using npm then
53+
there is nothing more you need to do - npm will download these dependencies for you.
5454

5555
If you are using libaxolotl-javascript in the browser, you will have to provide the library's dependencies yourself. If
5656
you're using AMD, then simply provide the location of these dependencies in your AMD configuration. Otherwise, include
@@ -192,137 +192,12 @@ Name|Type|Description
192192
`identity`|Identity|The identity.
193193
`sessionState`|String|The serialised session state.
194194

195-
### The Crypto interface
196-
197-
You need to provide an implementation of the `Crypto` interface when instantiating Axolotl. This is an object that
198-
has the following methods.
199-
200-
*Note that all methods may return a Promise if the operation is asynchronous.*
201-
202-
#### generateKeyPair
203-
204-
```
205-
generateKeyPair() → {KeyPair}
206-
```
207-
208-
Generate a fresh, random [Curve25519](http://en.wikipedia.org/wiki/Curve25519) public/private key pair suitable for use
209-
with Diffie-Hellman key agreements. The returned private key should be an ArrayBuffer consisting of 32 bytes. The
210-
returned public key should be an ArrayBuffer consisting of 33 bytes, where the first byte is equal to `0x05`.
211-
212-
#### calculateAgreement
213-
214-
```
215-
calculateAgreement(theirPublicKey, ourPrivateKey) → {ArrayBuffer}
216-
```
217-
218-
Compute a [Curve25519](http://en.wikipedia.org/wiki/Curve25519) Diffie-Hellman key agreement.
219-
220-
##### Parameters
221-
222-
Name|Type|Description
223-
:---|:---|:----------
224-
`theirPublicKey`|ArrayBuffer|Their 33 byte public key.
225-
`ourPrivateKey`|ArrayBuffer|Our 32 byte private key.
226-
227-
#### randomBytes
228-
229-
```
230-
randomBytes(byteCount) → {ArrayBuffer}
231-
```
232-
233-
Generate `byteCount` bytes of cryptographically secure random data and return as an ArrayBuffer.
234-
235-
##### Parameters
236-
237-
Name|Type|Description
238-
:---|:---|:----------
239-
`byteCount`|Number|The number of bytes to generate.
240-
241-
#### sign
242-
243-
```
244-
sign(privateKey, dataToSign) → {ArrayBuffer}
245-
```
246-
247-
Produce an [Ed25519](http://en.wikipedia.org/wiki/EdDSA) signature. The returned signature should be an ArrayBuffer
248-
consisting of 64 bytes.
249-
250-
##### Parameters
251-
252-
Name|Type|Description
253-
:---|:---|:----------
254-
`privateKey`|ArrayBuffer|The 32 byte private key to use to generate the signature.
255-
`dataToSign`|ArrayBuffer|The data to be signed. May be any length.
256-
257-
#### verifySignature
258-
259-
```
260-
verifySignature(publicKey, dataToSign, purportedSignature) → {Boolean}
261-
```
262-
263-
Verify an [Ed25519](http://en.wikipedia.org/wiki/EdDSA) signature.
264-
265-
##### Parameters
266-
267-
Name|Type|Description
268-
:---|:---|:----------
269-
`privateKey`|ArrayBuffer|The 33 byte public half of the key used to produce the signature.
270-
`dataToSign`|ArrayBuffer|The data that was signed. May be any length.
271-
`purportedSignature`|ArrayBuffer|The purported signature to check.
272-
273-
#### hmac
274-
275-
```
276-
hmac(key, data) → {ArrayBuffer}
277-
```
278-
279-
Produce a HMAC-HASH using SHA-256. The returned ArrayBuffer should consist of 32 bytes.
280-
281-
##### Parameters
282-
283-
Name|Type|Description
284-
:---|:---|:----------
285-
`key`|ArrayBuffer|The mac key. May be any length.
286-
`data`|ArrayBuffer|The data to be hashed. May be any length.
287-
288-
#### encrypt
289-
290-
```
291-
encrypt(key, plaintext, iv) → {ArrayBuffer}
292-
```
293-
294-
Encrypt the `plaintext` using AES-256-CBC.
295-
296-
##### Parameters
297-
298-
Name|Type|Description
299-
:---|:---|:----------
300-
`key`|ArrayBuffer|The 32 byte cipher key.
301-
`plaintext`|ArrayBuffer|The data to be encrypted. May be any length.
302-
`iv`|ArrayBuffer|A 16 byte random initialisation vector.
303-
304-
#### decrypt
305-
306-
```
307-
decrypt(key, ciphertext, iv) → {ArrayBuffer}
308-
```
309-
310-
Decrypt the `ciphertext` using AES-256-CBC.
311-
312-
##### Parameters
313-
314-
Name|Type|Description
315-
:---|:---|:----------
316-
`key`|ArrayBuffer|The 32 byte cipher key used to encrypt the data.
317-
`ciphertext`|ArrayBuffer|The data to be decrypted. Should have a length that is a multiple of 16 bytes.
318-
`iv`|ArrayBuffer|The 16 byte initialisation vector used to encrypt the data.
319-
320195
### Using Axolotl
321196

322197
Start by instantiating Axolotl:
323198

324199
```javascript
325-
var axol = axolotl(crypto, store);
200+
var axol = axolotl(store);
326201
```
327202

328203
When your application is first installed, the client will likely need to register with the server. To do this, a number

bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
],
3535
"dependencies": {
3636
"protobuf": "~3.8.2",
37-
"traceur-runtime": "~0.0.79"
37+
"traceur-runtime": "~0.0.79",
38+
"axolotl-crypto": "~1.1.0"
3839
}
3940
}

0 commit comments

Comments
 (0)