trustcaptcha-ruby 1.0.2 → 1.2.1.pre.beta.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 +4 -4
- data/lib/trustcaptcha/captcha_manager.rb +24 -26
- data/lib/trustcaptcha/model/verification_token.rb +4 -4
- metadata +18 -12
- data/lib/trustcaptcha/aes_encryption.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85c2a1d3d39713b0c116048f58290ff9f8c4a956f40dba2ef7b21543578a4aa5
|
4
|
+
data.tar.gz: c02bb27309d204dd5500be1a63f55748dc0622c14dc9b8f7e6b7a594a84f3daa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a2ddec2f1102a1ec1806d09417eb3d634aa1009473211be6aacc4f9752e3238505c3508357f138e5cf8b0cebe87d755e3e3d9ce8fff3d71f8b6dab1dc25fdc9
|
7
|
+
data.tar.gz: 004e0c46553f38c85b2c88ada9263ddad9c7023eea1d18a0f8989d0393fc1452f53d9ee469cc809431bc5c049e46358636eae0f3f46681d1e143202dfd6c9721
|
@@ -1,51 +1,49 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'uri'
|
3
3
|
require 'json'
|
4
|
-
require_relative 'aes_encryption'
|
5
4
|
require_relative 'model/verification_token'
|
6
5
|
require_relative 'model/verification_result'
|
7
6
|
|
8
7
|
class CaptchaManager
|
8
|
+
|
9
9
|
class SecretKeyInvalidException < StandardError; end
|
10
|
-
class TokenDecryptionFailedException < StandardError; end
|
11
10
|
class VerificationTokenInvalidException < StandardError; end
|
12
11
|
class VerificationNotFoundException < StandardError; end
|
12
|
+
class VerificationNotFinishedException < StandardError; end
|
13
13
|
|
14
|
-
def self.get_verification_result(
|
14
|
+
def self.get_verification_result(secret_key, base64_verification_token)
|
15
15
|
verification_token = get_verification_token(base64_verification_token)
|
16
|
-
secret_key
|
17
|
-
decrypted_access_token = decrypt_access_token(secret_key, verification_token)
|
18
|
-
fetch_verification_result(verification_token, decrypted_access_token)
|
16
|
+
fetch_verification_result(verification_token, secret_key)
|
19
17
|
end
|
20
18
|
|
21
19
|
private
|
22
20
|
|
23
|
-
def self.
|
24
|
-
|
25
|
-
rescue StandardError => e
|
26
|
-
raise SecretKeyInvalidException, "Invalid secret key: #{e.message}"
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.get_verification_token(verification_token)
|
30
|
-
VerificationToken.from_base64(verification_token)
|
21
|
+
def self.get_verification_token(base64_verification_token)
|
22
|
+
VerificationToken.from_base64(base64_verification_token)
|
31
23
|
rescue StandardError => e
|
32
24
|
raise VerificationTokenInvalidException, "Invalid verification token: #{e.message}"
|
33
25
|
end
|
34
26
|
|
35
|
-
def self.decrypt_access_token(secret_key, verification_token)
|
36
|
-
AesEncryption.decrypt_to_string(secret_key, verification_token.encrypted_access_token)
|
37
|
-
rescue StandardError => e
|
38
|
-
raise TokenDecryptionFailedException, "Failed to decrypt access token: #{e.message}"
|
39
|
-
end
|
40
|
-
|
41
27
|
def self.fetch_verification_result(verification_token, access_token)
|
42
|
-
url = URI("#{verification_token.api_endpoint}/verifications/#{verification_token.verification_id}/assessments
|
43
|
-
|
44
|
-
|
45
|
-
|
28
|
+
url = URI("#{verification_token.api_endpoint}/verifications/#{verification_token.verification_id}/assessments")
|
29
|
+
headers = {
|
30
|
+
"tc-authorization" => access_token,
|
31
|
+
"tc-library-language" => "ruby",
|
32
|
+
"tc-library-version" => "1.2"
|
33
|
+
}
|
34
|
+
response = Net::HTTP.get_response(url, headers)
|
35
|
+
|
36
|
+
case response.code.to_i
|
37
|
+
when 403
|
38
|
+
raise SecretKeyInvalidException, "Secret key is invalid"
|
39
|
+
when 404
|
40
|
+
raise VerificationNotFoundException, "Verification not found"
|
41
|
+
when 423
|
42
|
+
raise VerificationNotFinishedException, "Verification not finished"
|
43
|
+
else
|
44
|
+
raise "Failed to retrieve verification result: HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess)
|
45
|
+
end
|
46
46
|
|
47
47
|
VerificationResult.from_json(response.body)
|
48
|
-
rescue StandardError => e
|
49
|
-
raise "Failed to retrieve verification result: #{e.message}"
|
50
48
|
end
|
51
49
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'securerandom'
|
3
|
+
require 'base64'
|
3
4
|
|
4
5
|
class VerificationToken
|
5
|
-
attr_reader :api_endpoint, :verification_id
|
6
|
+
attr_reader :api_endpoint, :verification_id
|
6
7
|
|
7
|
-
def initialize(api_endpoint, verification_id
|
8
|
+
def initialize(api_endpoint, verification_id)
|
8
9
|
@api_endpoint = api_endpoint
|
9
10
|
@verification_id = verification_id
|
10
|
-
@encrypted_access_token = encrypted_access_token
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.from_base64(base64_string)
|
14
14
|
json_string = Base64.decode64(base64_string)
|
15
15
|
data = JSON.parse(json_string)
|
16
|
-
new(data['apiEndpoint'], data['verificationId']
|
16
|
+
new(data['apiEndpoint'], data['verificationId'])
|
17
17
|
end
|
18
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trustcaptcha-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.1.pre.beta.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- TrustComponent
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -38,24 +38,30 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description: This gem provides integration with
|
41
|
+
description: This gem provides integration with TrustCaptcha for Ruby applications,
|
42
42
|
offering CAPTCHA verification with a focus on security and privacy.
|
43
43
|
email:
|
44
|
-
- mail@
|
44
|
+
- mail@trustcomponent.com
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
- lib/trustcaptcha/aes_encryption.rb
|
50
49
|
- lib/trustcaptcha/captcha_manager.rb
|
51
50
|
- lib/trustcaptcha/model/verification_result.rb
|
52
51
|
- lib/trustcaptcha/model/verification_token.rb
|
53
|
-
homepage: https://www.
|
52
|
+
homepage: https://www.trustcomponent.com/en/products/captcha/integrations/ruby-captcha
|
54
53
|
licenses:
|
55
54
|
- Apache-2.0
|
56
55
|
metadata:
|
57
|
-
|
58
|
-
post_install_message:
|
56
|
+
deprecated_in_favor_of: trustcaptcha
|
57
|
+
post_install_message: |
|
58
|
+
⚠️ The `trustcaptcha-ruby` gem is DEPRECATED in favor of `trustcaptcha` (v2.0.0+).
|
59
|
+
|
60
|
+
To upgrade, update your Gemfile:
|
61
|
+
|
62
|
+
gem 'trustcaptcha', '~> 2.0'
|
63
|
+
|
64
|
+
Then run `bundle update trustcaptcha` or `gem install trustcaptcha`.
|
59
65
|
rdoc_options: []
|
60
66
|
require_paths:
|
61
67
|
- lib
|
@@ -66,12 +72,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
72
|
version: '0'
|
67
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
74
|
requirements:
|
69
|
-
- - "
|
75
|
+
- - ">"
|
70
76
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
77
|
+
version: 1.3.1
|
72
78
|
requirements: []
|
73
79
|
rubygems_version: 3.3.7
|
74
80
|
signing_key:
|
75
81
|
specification_version: 4
|
76
|
-
summary: Trustcaptcha library for Ruby
|
82
|
+
summary: "(DEPRECATED) Trustcaptcha library for Ruby"
|
77
83
|
test_files: []
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'openssl'
|
2
|
-
require 'base64'
|
3
|
-
|
4
|
-
class AesEncryption
|
5
|
-
STANDARD_BLOCK_SIZE = 16
|
6
|
-
|
7
|
-
def self.to_aes_secret_key(key_string)
|
8
|
-
Base64.decode64(key_string)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.decrypt_to_string(key, encrypted_text)
|
12
|
-
decoded = Base64.decode64(encrypted_text)
|
13
|
-
decrypt(key, decoded)
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.decrypt(key, encrypted_data)
|
17
|
-
iv = encrypted_data[0, STANDARD_BLOCK_SIZE]
|
18
|
-
cipher_text = encrypted_data[STANDARD_BLOCK_SIZE..-1]
|
19
|
-
decipher = OpenSSL::Cipher::AES256.new(:CBC)
|
20
|
-
decipher.decrypt
|
21
|
-
decipher.key = key
|
22
|
-
decipher.iv = iv
|
23
|
-
decrypted = decipher.update(cipher_text) + decipher.final
|
24
|
-
decrypted.force_encoding('UTF-8')
|
25
|
-
end
|
26
|
-
end
|