08-27-周三_17-09-29
This commit is contained in:
18
node_modules/cryptiles/.npmignore
generated
vendored
Normal file
18
node_modules/cryptiles/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
.idea
|
||||
*.iml
|
||||
npm-debug.log
|
||||
dump.rdb
|
||||
node_modules
|
||||
results.tap
|
||||
results.xml
|
||||
npm-shrinkwrap.json
|
||||
config.json
|
||||
.DS_Store
|
||||
*/.DS_Store
|
||||
*/*/.DS_Store
|
||||
._*
|
||||
*/._*
|
||||
*/*/._*
|
||||
coverage.*
|
||||
lib-cov
|
||||
|
8
node_modules/cryptiles/.travis.yml
generated
vendored
Normal file
8
node_modules/cryptiles/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- 0.10
|
||||
- 4.0
|
||||
|
||||
sudo: false
|
||||
|
28
node_modules/cryptiles/LICENSE
generated
vendored
Normal file
28
node_modules/cryptiles/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
Copyright (c) 2014, Eran Hammer and other contributors.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* The names of any contributors may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
* * *
|
||||
|
||||
The complete list of contributors can be found at: https://github.com/hueniverse/cryptiles/graphs/contributors
|
16
node_modules/cryptiles/README.md
generated
vendored
Normal file
16
node_modules/cryptiles/README.md
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
cryptiles
|
||||
=========
|
||||
|
||||
General purpose crypto utilities
|
||||
|
||||
[](http://travis-ci.org/hapijs/cryptiles)
|
||||
|
||||
Lead Maintainer - [C J Silverio](https://github.com/ceejbot)
|
||||
|
||||
## Methods
|
||||
|
||||
### `randomString(<Number> size)`
|
||||
Returns a cryptographically strong pseudo-random data string. Takes a size argument for the length of the string.
|
||||
|
||||
### `fixedTimeComparison(<String> a, <String> b)`
|
||||
Compare two strings using fixed time algorithm (to prevent time-based analysis of MAC digest match). Returns `true` if the strings match, `false` if they differ.
|
68
node_modules/cryptiles/lib/index.js
generated
vendored
Normal file
68
node_modules/cryptiles/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
// Load modules
|
||||
|
||||
var Crypto = require('crypto');
|
||||
var Boom = require('boom');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
|
||||
|
||||
// Generate a cryptographically strong pseudo-random data
|
||||
|
||||
exports.randomString = function (size) {
|
||||
|
||||
var buffer = exports.randomBits((size + 1) * 6);
|
||||
if (buffer instanceof Error) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
var string = buffer.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
|
||||
return string.slice(0, size);
|
||||
};
|
||||
|
||||
|
||||
exports.randomBits = function (bits) {
|
||||
|
||||
if (!bits ||
|
||||
bits < 0) {
|
||||
|
||||
return Boom.internal('Invalid random bits count');
|
||||
}
|
||||
|
||||
var bytes = Math.ceil(bits / 8);
|
||||
try {
|
||||
return Crypto.randomBytes(bytes);
|
||||
}
|
||||
catch (err) {
|
||||
return Boom.internal('Failed generating random bits: ' + err.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Compare two strings using fixed time algorithm (to prevent time-based analysis of MAC digest match)
|
||||
|
||||
exports.fixedTimeComparison = function (a, b) {
|
||||
|
||||
if (typeof a !== 'string' ||
|
||||
typeof b !== 'string') {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
var mismatch = (a.length === b.length ? 0 : 1);
|
||||
if (mismatch) {
|
||||
b = a;
|
||||
}
|
||||
|
||||
for (var i = 0, il = a.length; i < il; ++i) {
|
||||
var ac = a.charCodeAt(i);
|
||||
var bc = b.charCodeAt(i);
|
||||
mismatch |= (ac ^ bc);
|
||||
}
|
||||
|
||||
return (mismatch === 0);
|
||||
};
|
||||
|
||||
|
101
node_modules/cryptiles/package.json
generated
vendored
Normal file
101
node_modules/cryptiles/package.json
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "cryptiles",
|
||||
"raw": "cryptiles@2.x.x",
|
||||
"rawSpec": "2.x.x",
|
||||
"scope": null,
|
||||
"spec": ">=2.0.0 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/root/gitbook/node_modules/hawk"
|
||||
]
|
||||
],
|
||||
"_from": "cryptiles@>=2.0.0 <3.0.0",
|
||||
"_id": "cryptiles@2.0.5",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/cryptiles",
|
||||
"_nodeVersion": "4.0.0",
|
||||
"_npmUser": {
|
||||
"email": "eran@hammer.io",
|
||||
"name": "hueniverse"
|
||||
},
|
||||
"_npmVersion": "2.14.2",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "cryptiles",
|
||||
"raw": "cryptiles@2.x.x",
|
||||
"rawSpec": "2.x.x",
|
||||
"scope": null,
|
||||
"spec": ">=2.0.0 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/hawk"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz",
|
||||
"_shasum": "3bdfecdc608147c1c67202fa291e7dca59eaa3b8",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "cryptiles@2.x.x",
|
||||
"_where": "/root/gitbook/node_modules/hawk",
|
||||
"bugs": {
|
||||
"url": "https://github.com/hapijs/cryptiles/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"boom": "2.x.x"
|
||||
},
|
||||
"deprecated": "This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).",
|
||||
"description": "General purpose crypto utilities",
|
||||
"devDependencies": {
|
||||
"code": "1.x.x",
|
||||
"lab": "5.x.x"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"integrity": "sha512-FFN5KwpvvQTTS5hWPxrU8/QE4kQUc6uwZcrnlMBN82t1MgAtq8mnoDwINBly9Tdr02seeIIhtdF+UH1feBYGog==",
|
||||
"shasum": "3bdfecdc608147c1c67202fa291e7dca59eaa3b8",
|
||||
"signatures": [
|
||||
{
|
||||
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
|
||||
"sig": "MEUCIQC0/EgdU1Azoem6o15MxdHE9O5V6mTe9Qbehlq9FJLBgAIgElqGQ5gCpOgD0b4K2gvFbLGJWvEPAzkHMG7zE6YuFak="
|
||||
}
|
||||
],
|
||||
"tarball": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.40"
|
||||
},
|
||||
"gitHead": "9bc5a852f01cd51e615814e1cb255fe2df810649",
|
||||
"homepage": "https://github.com/hapijs/cryptiles#readme",
|
||||
"keywords": [
|
||||
"cryptography",
|
||||
"security",
|
||||
"utilites"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "lib/index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "eran@hueniverse.com",
|
||||
"name": "hueniverse"
|
||||
},
|
||||
{
|
||||
"email": "ceejceej@gmail.com",
|
||||
"name": "ceejbot"
|
||||
}
|
||||
],
|
||||
"name": "cryptiles",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/hapijs/cryptiles.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "lab -a code -t 100 -L",
|
||||
"test-cov-html": "lab -a code -r html -o coverage.html"
|
||||
},
|
||||
"version": "2.0.5"
|
||||
}
|
102
node_modules/cryptiles/test/index.js
generated
vendored
Normal file
102
node_modules/cryptiles/test/index.js
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
// Load modules
|
||||
|
||||
var Code = require('code');
|
||||
var Cryptiles = require('..');
|
||||
var Lab = require('lab');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
|
||||
|
||||
// Test shortcuts
|
||||
|
||||
var lab = exports.lab = Lab.script();
|
||||
var describe = lab.describe;
|
||||
var it = lab.it;
|
||||
var expect = Code.expect;
|
||||
|
||||
|
||||
describe('randomString()', function () {
|
||||
|
||||
it('should generate the right length string', function (done) {
|
||||
|
||||
for (var i = 1; i <= 1000; ++i) {
|
||||
expect(Cryptiles.randomString(i).length).to.equal(i);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('returns an error on invalid bits size', function (done) {
|
||||
|
||||
expect(Cryptiles.randomString(99999999999999999999).message).to.match(/Failed generating random bits/);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('randomBits()', function () {
|
||||
|
||||
it('returns an error on invalid input', function (done) {
|
||||
|
||||
expect(Cryptiles.randomBits(0).message).to.equal('Invalid random bits count');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('fixedTimeComparison()', function () {
|
||||
|
||||
var a = Cryptiles.randomString(50000);
|
||||
var b = Cryptiles.randomString(150000);
|
||||
|
||||
it('should take the same amount of time comparing different string sizes', function (done) {
|
||||
|
||||
var now = Date.now();
|
||||
Cryptiles.fixedTimeComparison(b, a);
|
||||
var t1 = Date.now() - now;
|
||||
|
||||
now = Date.now();
|
||||
Cryptiles.fixedTimeComparison(b, b);
|
||||
var t2 = Date.now() - now;
|
||||
|
||||
expect(t2 - t1).to.be.within(-20, 20);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return true for equal strings', function (done) {
|
||||
|
||||
expect(Cryptiles.fixedTimeComparison(a, a)).to.equal(true);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return false for different strings (size, a < b)', function (done) {
|
||||
|
||||
expect(Cryptiles.fixedTimeComparison(a, a + 'x')).to.equal(false);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return false for different strings (size, a > b)', function (done) {
|
||||
|
||||
expect(Cryptiles.fixedTimeComparison(a + 'x', a)).to.equal(false);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return false for different strings (size, a = b)', function (done) {
|
||||
|
||||
expect(Cryptiles.fixedTimeComparison(a + 'x', a + 'y')).to.equal(false);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return false when not a string', function (done) {
|
||||
|
||||
expect(Cryptiles.fixedTimeComparison('x', null)).to.equal(false);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should return false when not a string (left)', function (done) {
|
||||
|
||||
expect(Cryptiles.fixedTimeComparison(null, 'x')).to.equal(false);
|
||||
done();
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user