recaptcha 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d8c84c84605f3b19d067af5b08d173f5dd681f2
4
- data.tar.gz: c0126d1350d3da2dda33a8d4a2932a0b1ad5f504
3
+ metadata.gz: 15a8d9b4ffc50fb479df2f03065310e3b85be5f4
4
+ data.tar.gz: 1d2412b3ce72619d131388e77e9b82a4b1e9de46
5
5
  SHA512:
6
- metadata.gz: 2ee980f5953e85425572add41e07b142b323743f8f0c14824145604a8f20176b6a54b5d365852f4dbadd283ecc3e67bf203599e8f03c4c9afc5a5d58c541c5a4
7
- data.tar.gz: 8a8677420abff0ceac5f2674fd58da71623b980ff3336c6a2aaf196562adce8d295257d73c964cf220ed98ea1119f4723ea794c7acd7c4b004ff83edcda1fa10
6
+ metadata.gz: f1a53822196216dc231d60369edcce9719e724e4e66a35b57e35b7b57ca8104b2d5211a07231616fad499c13420daa3eb584b5337e87dd47631d40e61d801721
7
+ data.tar.gz: e3fef919669e86e48de71216c3def51609e1d525d1fe7cebc5ada112f5f9613d96783625c0d675cddfeafce97d7783006665371db42be17f027248945784ebc6
data/lib/recaptcha.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'recaptcha/configuration'
2
2
  require 'recaptcha/client_helper'
3
3
  require 'recaptcha/verify'
4
+ require 'recaptcha/token'
4
5
 
5
6
  module Recaptcha
6
7
  CONFIG =
@@ -78,16 +78,7 @@ module Recaptcha
78
78
  data_attributes[:sitekey] = public_key
79
79
 
80
80
  if options[:stoken] != false
81
- stoken_json = hash_to_json({'session_id' => SecureRandom.uuid, 'ts_ms' => (Time.now.to_f * 1000).to_i})
82
- cipher = OpenSSL::Cipher::AES128.new(:ECB)
83
- private_key_digest = Digest::SHA1.digest(private_key)[0...16]
84
-
85
- cipher.encrypt
86
- cipher.key = private_key_digest
87
- encrypted_stoken = cipher.update(stoken_json) << cipher.final
88
- encoded_stoken = Base64.urlsafe_encode64(encrypted_stoken).gsub(/\=+\Z/, '')
89
-
90
- data_attributes[:stoken] = encoded_stoken
81
+ data_attributes[:stoken] = Recaptcha::Token.secure_token
91
82
  end
92
83
 
93
84
  data_attributes = data_attributes.map {|k,v| %{data-#{k.to_s.gsub(/_/,'-')}="#{v}"} }.join(" ")
@@ -0,0 +1,24 @@
1
+ require 'json'
2
+ require 'recaptcha'
3
+ require 'base64'
4
+ require 'securerandom'
5
+ require 'openssl'
6
+
7
+ module Recaptcha
8
+ module Token
9
+
10
+ def self.secure_token
11
+ private_key = Recaptcha.configuration.private_key
12
+ raise RecaptchaError, "No private key specified." unless private_key
13
+
14
+ stoken_json = {'session_id' => SecureRandom.uuid, 'ts_ms' => (Time.now.to_f * 1000).to_i}.to_json
15
+ cipher = OpenSSL::Cipher::AES128.new(:ECB)
16
+ private_key_digest = Digest::SHA1.digest(private_key)[0...16]
17
+
18
+ cipher.encrypt
19
+ cipher.key = private_key_digest
20
+ encrypted_stoken = cipher.update(stoken_json) << cipher.final
21
+ Base64.urlsafe_encode64(encrypted_stoken).gsub(/\=+\Z/, '')
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Recaptcha
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason L Perry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -136,6 +136,7 @@ files:
136
136
  - lib/recaptcha/client_helper.rb
137
137
  - lib/recaptcha/configuration.rb
138
138
  - lib/recaptcha/rails.rb
139
+ - lib/recaptcha/token.rb
139
140
  - lib/recaptcha/verify.rb
140
141
  - lib/recaptcha/version.rb
141
142
  homepage: http://github.com/ambethia/recaptcha