pax_global_header00006660000000000000000000000064132302744430014514gustar00rootroot0000000000000052 comment=4496ae0795ef0fb6303184e1f44370546663e2e4 node-cookie-signature-1.1.0/000077500000000000000000000000001323027444300157065ustar00rootroot00000000000000node-cookie-signature-1.1.0/.gitignore000066400000000000000000000000151323027444300176720ustar00rootroot00000000000000node_modules node-cookie-signature-1.1.0/.npmignore000066400000000000000000000000351323027444300177030ustar00rootroot00000000000000support test examples *.sock node-cookie-signature-1.1.0/History.md000066400000000000000000000015321323027444300176720ustar00rootroot000000000000001.1.0 / 2018-01-18 ================== * switch to built-in `crypto.timingSafeEqual` for validation instead of previous double-hash method (thank you @jodevsa!) 1.0.6 / 2015-02-03 ================== * use `npm test` instead of `make test` to run tests * clearer assertion messages when checking input 1.0.5 / 2014-09-05 ================== * add license to package.json 1.0.4 / 2014-06-25 ================== * corrected avoidance of timing attacks (thanks @tenbits!) 1.0.3 / 2014-01-28 ================== * [incorrect] fix for timing attacks 1.0.2 / 2014-01-28 ================== * fix missing repository warning * fix typo in test 1.0.1 / 2013-04-15 ================== * Revert "Changed underlying HMAC algo. to sha512." * Revert "Fix for timing attacks on MAC verification." 0.0.1 / 2010-01-03 ================== * Initial release node-cookie-signature-1.1.0/Readme.md000066400000000000000000000027221323027444300174300ustar00rootroot00000000000000 # cookie-signature Sign and unsign cookies. ## Example ```js var cookie = require('cookie-signature'); var val = cookie.sign('hello', 'tobiiscool'); val.should.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI'); var val = cookie.sign('hello', 'tobiiscool'); cookie.unsign(val, 'tobiiscool').should.equal('hello'); cookie.unsign(val, 'luna').should.be.false; ``` ## License (The MIT License) Copyright (c) 2012 LearnBoost <tj@learnboost.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.node-cookie-signature-1.1.0/index.js000066400000000000000000000023451323027444300173570ustar00rootroot00000000000000/** * Module dependencies. */ var crypto = require('crypto'); /** * Sign the given `val` with `secret`. * * @param {String} val * @param {String} secret * @return {String} * @api private */ exports.sign = function(val, secret){ if ('string' != typeof val) throw new TypeError("Cookie value must be provided as a string."); if ('string' != typeof secret) throw new TypeError("Secret string must be provided."); return val + '.' + crypto .createHmac('sha256', secret) .update(val) .digest('base64') .replace(/\=+$/, ''); }; /** * Unsign and decode the given `val` with `secret`, * returning `false` if the signature is invalid. * * @param {String} val * @param {String} secret * @return {String|Boolean} * @api private */ exports.unsign = function(val, secret){ if ('string' != typeof val) throw new TypeError("Signed cookie string must be provided."); if ('string' != typeof secret) throw new TypeError("Secret string must be provided."); var str = val.slice(0, val.lastIndexOf('.')) , mac = exports.sign(str, secret) , macBuffer = Buffer.from(mac) , valBuffer = Buffer.alloc(macBuffer.length); valBuffer.write(val); return crypto.timingSafeEqual(macBuffer, valBuffer) ? str : false; }; node-cookie-signature-1.1.0/package.json000066400000000000000000000010411323027444300201700ustar00rootroot00000000000000{ "name": "cookie-signature", "version": "1.1.0", "description": "Sign and unsign cookies", "keywords": ["cookie", "sign", "unsign"], "author": "TJ Holowaychuk ", "license": "MIT", "repository": { "type": "git", "url": "https://github.com/visionmedia/node-cookie-signature.git" }, "dependencies": {}, "engines": { "node": ">=6.6.0" }, "devDependencies": { "mocha": "*", "should": "*" }, "scripts": { "test": "mocha --require should --reporter spec" }, "main": "index" } node-cookie-signature-1.1.0/test/000077500000000000000000000000001323027444300166655ustar00rootroot00000000000000node-cookie-signature-1.1.0/test/index.js000066400000000000000000000012261323027444300203330ustar00rootroot00000000000000/** * Module dependencies. */ var cookie = require('..'); describe('.sign(val, secret)', function(){ it('should sign the cookie', function(){ var val = cookie.sign('hello', 'tobiiscool'); val.should.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI'); var val = cookie.sign('hello', 'luna'); val.should.not.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI'); }) }) describe('.unsign(val, secret)', function(){ it('should unsign the cookie', function(){ var val = cookie.sign('hello', 'tobiiscool'); cookie.unsign(val, 'tobiiscool').should.equal('hello'); cookie.unsign(val, 'luna').should.be.false; }) })