fingerprintjs-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fingerprintjs-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Valentin Vasilyev
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ fingerprintJS
2
+ =============
3
+
4
+ Fast browser fingerprint library. Written in pure JavaScript, no dependencies.
5
+ By default uses [Murmur hashing][murmur] and returns a 32bit integer number.
6
+ Hashing function can be easily replaced.
7
+ Feather weight: only **843** bytes when gzipped.
8
+
9
+ ## What is fingerprinting?
10
+
11
+ Fingerprinting is a technique, outlined in [the research by Electronic Frontier Foundation][research], of
12
+ anonymously identifying a web browser with accuracy of up to 94%.
13
+
14
+
15
+ Browser is queried its agent string, screen resolution and color depth,
16
+ installed plugins with supported mime types, timezone offset and other capabilities,
17
+ such as local storage and session storage. Then these values are passed through a hashing function
18
+ to produce a fingerprint that gives weak guarantees of uniqueness.
19
+
20
+ No cookies are stored to identify a browser.
21
+
22
+ It's worth noting that a mobile share of browsers is much more uniform, so fingerprinting should be used
23
+ only as a supplementary identifying mechanism there.
24
+
25
+ ### Installation
26
+
27
+ Add this to your Gemfile
28
+ `
29
+ gem 'fingerprintjs-rails'
30
+ `
31
+ and
32
+
33
+ `bundle install`
34
+
35
+ After that you can add the file to sprockets:
36
+
37
+ `
38
+ //= require fingerprint
39
+ `
40
+
41
+ ### Usage
42
+
43
+ ```javascript
44
+ var fingerprint = new Fingerprint().get();
45
+ ```
46
+
47
+ Using custom hashing function
48
+
49
+ ``` javascript
50
+ var hasher = new function(value, seed){ return value.length % seed; }
51
+ var fingerprint = new Fingerprint(hasher).get();
52
+ ```
53
+
54
+ ### Licence
55
+
56
+ This code is [MIT][mit] licenced:
57
+
58
+ Copyright (c) 2013 Valentin Vasilyev
59
+
60
+ 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:
61
+
62
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
63
+
64
+ 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.
65
+
66
+
67
+
68
+ [mit]: http://www.opensource.org/licenses/mit-license.php
69
+ [murmur]: http://en.wikipedia.org/wiki/MurmurHash
70
+ [research]: https://panopticlick.eff.org/browser-uniqueness.pdf
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,128 @@
1
+ /*
2
+ * fingerprintJS 0.1 - Fast browser fingerprint library
3
+ * https://github.com/Valve/fingerprintJS
4
+ * Copyright (c) 2013 Valentin Vasilyev (iamvalentin@gmail.com)
5
+ * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
6
+ */
7
+ function Fingerprint(hasher){
8
+ var nativeForEach = Array.prototype.forEach;
9
+ var nativeMap = Array.prototype.map;
10
+ this.each = function(obj, iterator, context) {
11
+ if (obj == null) return;
12
+ if (nativeForEach && obj.forEach === nativeForEach) {
13
+ obj.forEach(iterator, context);
14
+ } else if (obj.length === +obj.length) {
15
+ for (var i = 0, l = obj.length; i < l; i++) {
16
+ if (iterator.call(context, obj[i], i, obj) === {}) return;
17
+ }
18
+ } else {
19
+ for (var key in obj) {
20
+ if (obj.hasOwnProperty(key)) {
21
+ if (iterator.call(context, obj[key], key, obj) === {}) return;
22
+ }
23
+ }
24
+ }
25
+ };
26
+ this.map = function(obj, iterator, context) {
27
+ var results = [];
28
+ if (obj == null) return results;
29
+ if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
30
+ this.each(obj, function(value, index, list) {
31
+ results[results.length] = iterator.call(context, value, index, list);
32
+ });
33
+ return results;
34
+ };
35
+
36
+ if(hasher){
37
+ this.hasher = hasher;
38
+ }
39
+ }
40
+
41
+ Fingerprint.prototype = {
42
+
43
+ get: function(){
44
+ keys = [];
45
+ keys.push(navigator.userAgent);
46
+ keys.push([screen.height, screen.width, screen.colorDepth].join('x'));
47
+ keys.push(new Date().getTimezoneOffset());
48
+ keys.push(!!window.sessionStorage);
49
+ keys.push(!!window.localStorage);
50
+ var pluginsString = this.map(navigator.plugins, function(p){
51
+ var mimeTypes = this.map(p, function(mt){
52
+ return [mt.type, mt.suffixes].join('~');
53
+ }).join(',');
54
+ return [p.name, p.description, mimeTypes].join('::');
55
+ }, this).join(';');
56
+ keys.push(pluginsString);
57
+ if(this.hasher){
58
+ return this.hasher(keys.join('###'), 31);
59
+ } else {
60
+ return this.murmurhash3_32_gc(keys.join('###'), 31);
61
+ }
62
+ },
63
+
64
+ /**
65
+ * JS Implementation of MurmurHash3 (r136) (as of May 20, 2011)
66
+ *
67
+ * @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
68
+ * @see http://github.com/garycourt/murmurhash-js
69
+ * @author <a href="mailto:aappleby@gmail.com">Austin Appleby</a>
70
+ * @see http://sites.google.com/site/murmurhash/
71
+ *
72
+ * @param {string} key ASCII only
73
+ * @param {number} seed Positive integer only
74
+ * @return {number} 32-bit positive integer hash
75
+ */
76
+
77
+ murmurhash3_32_gc: function(key, seed) {
78
+ var remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i;
79
+
80
+ remainder = key.length & 3; // key.length % 4
81
+ bytes = key.length - remainder;
82
+ h1 = seed;
83
+ c1 = 0xcc9e2d51;
84
+ c2 = 0x1b873593;
85
+ i = 0;
86
+
87
+ while (i < bytes) {
88
+ k1 =
89
+ ((key.charCodeAt(i) & 0xff)) |
90
+ ((key.charCodeAt(++i) & 0xff) << 8) |
91
+ ((key.charCodeAt(++i) & 0xff) << 16) |
92
+ ((key.charCodeAt(++i) & 0xff) << 24);
93
+ ++i;
94
+
95
+ k1 = ((((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16))) & 0xffffffff;
96
+ k1 = (k1 << 15) | (k1 >>> 17);
97
+ k1 = ((((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16))) & 0xffffffff;
98
+
99
+ h1 ^= k1;
100
+ h1 = (h1 << 13) | (h1 >>> 19);
101
+ h1b = ((((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16))) & 0xffffffff;
102
+ h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16));
103
+ }
104
+
105
+ k1 = 0;
106
+
107
+ switch (remainder) {
108
+ case 3: k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
109
+ case 2: k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
110
+ case 1: k1 ^= (key.charCodeAt(i) & 0xff);
111
+
112
+ k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;
113
+ k1 = (k1 << 15) | (k1 >>> 17);
114
+ k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff;
115
+ h1 ^= k1;
116
+ }
117
+
118
+ h1 ^= key.length;
119
+
120
+ h1 ^= h1 >>> 16;
121
+ h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff;
122
+ h1 ^= h1 >>> 13;
123
+ h1 = ((((h1 & 0xffff) * 0xc2b2ae35) + ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff;
124
+ h1 ^= h1 >>> 16;
125
+
126
+ return h1 >>> 0;
127
+ }
128
+ }
@@ -0,0 +1 @@
1
+ function Fingerprint(e){var r=Array.prototype.forEach,t=Array.prototype.map;this.each=function(e,t,n){if(null!=e)if(r&&e.forEach===r)e.forEach(t,n);else if(e.length===+e.length){for(var h=0,s=e.length;s>h;h++)if(t.call(n,e[h],h,e)==={})return}else for(var a in e)if(e.hasOwnProperty(a)&&t.call(n,e[a],a,e)==={})return},this.map=function(e,r,n){var h=[];return null==e?h:t&&e.map===t?e.map(r,n):(this.each(e,function(e,t,s){h[h.length]=r.call(n,e,t,s)}),h)},e&&(this.hasher=e)}Fingerprint.prototype={get:function(){keys=[],keys.push(navigator.userAgent),keys.push([screen.height,screen.width,screen.colorDepth].join("x")),keys.push((new Date).getTimezoneOffset()),keys.push(!!window.sessionStorage),keys.push(!!window.localStorage);var e=this.map(navigator.plugins,function(e){var r=this.map(e,function(e){return[e.type,e.suffixes].join("~")}).join(",");return[e.name,e.description,r].join("::")},this).join(";");return keys.push(e),this.hasher?this.hasher(keys.join("###"),31):this.murmurhash3_32_gc(keys.join("###"),31)},murmurhash3_32_gc:function(e,r){var t,n,h,s,a,i,o,c;for(t=3&e.length,n=e.length-t,h=r,a=3432918353,i=461845907,c=0;n>c;)o=255&e.charCodeAt(c)|(255&e.charCodeAt(++c))<<8|(255&e.charCodeAt(++c))<<16|(255&e.charCodeAt(++c))<<24,++c,o=4294967295&(65535&o)*a+((65535&(o>>>16)*a)<<16),o=o<<15|o>>>17,o=4294967295&(65535&o)*i+((65535&(o>>>16)*i)<<16),h^=o,h=h<<13|h>>>19,s=4294967295&5*(65535&h)+((65535&5*(h>>>16))<<16),h=(65535&s)+27492+((65535&(s>>>16)+58964)<<16);switch(o=0,t){case 3:o^=(255&e.charCodeAt(c+2))<<16;case 2:o^=(255&e.charCodeAt(c+1))<<8;case 1:o^=255&e.charCodeAt(c),o=4294967295&(65535&o)*a+((65535&(o>>>16)*a)<<16),o=o<<15|o>>>17,o=4294967295&(65535&o)*i+((65535&(o>>>16)*i)<<16),h^=o}return h^=e.length,h^=h>>>16,h=4294967295&2246822507*(65535&h)+((65535&2246822507*(h>>>16))<<16),h^=h>>>13,h=4294967295&3266489909*(65535&h)+((65535&3266489909*(h>>>16))<<16),h^=h>>>16,h>>>0}};
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "fingerprintjs-rails"
7
+ gem.version = "0.1.0"
8
+ gem.authors = ["Valentin Vasilyev"]
9
+ gem.email = ["iamvalentin@gmail.com"]
10
+ gem.description = "fingerprintjs for rails asset pipeline"
11
+ gem.summary = ""
12
+ gem.homepage = "http://valve.github.com/fingerprintJS/"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.require_paths = ["lib"]
16
+ end
@@ -0,0 +1,5 @@
1
+
2
+ module Fingerprintjs
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fingerprintjs-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Valentin Vasilyev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: fingerprintjs for rails asset pipeline
15
+ email:
16
+ - iamvalentin@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - app/assets/javascripts/fingerprint.js
27
+ - app/assets/javascripts/fingerprint.min.js
28
+ - fingerprintjs-rails.gemspec
29
+ - lib/fingerprintjs-rails.rb
30
+ homepage: http://valve.github.com/fingerprintJS/
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.23
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: ''
54
+ test_files: []
55
+ has_rdoc: