truefactor 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/truefactor.rb +49 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07dda32f616666fd71208ad070a37540beadf6ae
4
- data.tar.gz: a90c9aa9e20a6def7bf68eb0e66f9ad36771e3e9
3
+ metadata.gz: d72749bf6d165774fc2a29843be94b61ac35b322
4
+ data.tar.gz: 88e23b243b8d1778b3aed687a497b392e8e5321c
5
5
  SHA512:
6
- metadata.gz: c5c7683aedf24c291842c0eb533963d9345869530b08ae3ce343f8861455be7aa8836fb817d7de06e6acf4b6832ca14a5b374f12caec071018e67327611af5ce
7
- data.tar.gz: 80c2e680da8b77ea7e1d72a95c4a7b483e58f6fd36a0301e1263bb693244a7df5a5f179b57a315fc88ca65cb43a26d47ab93ff1c989f425736f504bc9e39ec54
6
+ metadata.gz: 7fda1eaeea85d3c40cc0d0923a3b677141b8912a17ce00734c562b15e96e414778c9ac111e72ff526720c493dc8b718877951eea6b8e9220dd39ac05575064a0
7
+ data.tar.gz: 62546f537cea77c609e95372c7c1493d5cebaf1eee48c2836da56e32fa88543164408a5e9c3a31e3838d2e33b3ff334294e9d21ba621230c4e19689152aaf58a
data/lib/truefactor.rb CHANGED
@@ -1,5 +1,50 @@
1
- class Truefactor
2
- def self.hi
3
- puts "Hello world!"
1
+ module Truefactor
2
+ class User
3
+ def truefactor_signatures(challenge, raw = false)
4
+ prefix, seed1, seed2 = self.encrypted_password.split(':')
5
+ unless raw
6
+ stamp = Time.now.to_i / 120
7
+ challenge = "#{challenge}:#{stamp}"
8
+ end
9
+ [to_otp(challenge, seed1), to_otp(challenge, seed2)]
10
+ end
11
+
12
+ def valid_truefactor?(challenge, str)
13
+ sig1, sig2 = str.gsub(/\s/,'').split(':')
14
+
15
+ real_sig = to_otp(truefactor_signatures(challenge).join)
16
+
17
+ sig1 = to_digits(sig1)
18
+ sig2 = to_digits(sig2)
19
+
20
+ sig1 = to_otp(sig1 + sig2) if !sig2.blank?
21
+
22
+ real_sig == sig1
23
+ end
24
+
25
+ require 'openssl'
26
+
27
+ def to_otp(m, secret = false)
28
+ hex = if secret
29
+ OpenSSL::HMAC.hexdigest('sha256', secret, m)
30
+ else
31
+ OpenSSL::Digest::SHA256.hexdigest(m)
32
+ end
33
+
34
+ code = (hex.to_i(16) % 10**12).to_s
35
+
36
+ '0'*(12-code.length) + code
37
+ end
38
+
39
+ def to_digits(s)
40
+ s = s.to_s
41
+ if s.length == 8
42
+ s.to_i(32).to_s.rjust(12,'0')
43
+ else
44
+ s
45
+ end
46
+ end
4
47
  end
5
- end
48
+ end
49
+
50
+ #curl -u homakov https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials; chmod 0600 ~/.gem/credentials
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truefactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Egor Homakov
@@ -10,7 +10,7 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple hello world gem
13
+ description: Truefactor.io - open authentication platform
14
14
  email: homakov@gmail.com
15
15
  executables: []
16
16
  extensions: []