auth-centric-firewall 0.1.2 → 0.2.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
  SHA256:
3
- metadata.gz: fa83cf63aef7579194a4afd61f67fa84b0297a4f41f31ad75ec62bb2ae83a958
4
- data.tar.gz: 3178e1eb516b2f0bfc1c9cc4d9dd8b8b2137e445bdeeddd4d790b4928374d918
3
+ metadata.gz: 6b0b8e31fe34345f545a3c4896d91eca03c805ace909dd71ba6286f15038770b
4
+ data.tar.gz: 20ca9c8cea11b5266bd62f8beecf732c2301cd7b0ea553e59c64f95b3876b9d1
5
5
  SHA512:
6
- metadata.gz: 13e77b2efc5455543311dd8f46cf83fe7301803c9e240ad66b9aa4024fc551c34efd160c85c9659aff990d4313a3de13e16f2493733c7266d04b49b3ebd6b846
7
- data.tar.gz: 1b38cd09deaf5630699d7b84f83eb48dc68cad3f89d1ee6b6b32b0a0ee0d071dca85bcb6b47c55690c0420ee55f7cf547324703ab3eb6a08dc73667efdd428c0
6
+ metadata.gz: 6d6767cccf9c465b35b2cdbbeb7fb98851eb02489f4ddb153a265f2af894d9cb2e20b5d5759149180744d603903b0f78c46d59bd4a400a87865a3d226d2202fb
7
+ data.tar.gz: a4bf16a35820835621ae8243c06cd467e4ac5cebfa64e3a7f3174712b952408b92d969b17b0b46edfddd67aa34b76689e8315e43db2715064be877bfe212316e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Released]
2
2
 
3
+ ## [0.2.0] - 2025-09-13
4
+
5
+ - Update RBS
6
+ - Refactor common codes
7
+ - Retrieve Captcha
8
+ - Verify Captcha code
9
+
3
10
  ## [0.1.1, 0.1.2] - 2025-05-17
4
11
 
5
12
  - Try to find real I.P
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auth
4
+ module Centric
5
+ module Captcha
6
+ module CheckCode
7
+ def verify_code?(id:, code:)
8
+ return true unless enabled?
9
+
10
+ payload = {
11
+ security_captcha: {
12
+ ip: @ip_address,
13
+ code:,
14
+ session_id: @session_id
15
+ }
16
+ }
17
+
18
+ http = HTTP
19
+ .timeout(timeout_seconds)
20
+ .headers(apikey:)
21
+ .post(check_code_path(id), json: payload)
22
+
23
+ case http.status
24
+ when 202
25
+ return true
26
+ when 404, 406
27
+ return false
28
+ else
29
+ raise Error, "#{http.status}: #{http.body}"
30
+ end
31
+ rescue HTTP::TimeoutError
32
+ false
33
+ end
34
+
35
+ def check_code_path(id)
36
+ [host, "api/v1/security_captchas/#{id}/check_code"].join('/')
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auth
4
+ module Centric
5
+ module Captcha
6
+ module Retrieve
7
+ def retrieve_captcha
8
+ return true unless enabled?
9
+
10
+ payload = {
11
+ security_captcha: {
12
+ ip: @ip_address,
13
+ session_id: @session_id
14
+ }
15
+ }
16
+
17
+ http = HTTP
18
+ .timeout(timeout_seconds)
19
+ .headers(apikey:)
20
+ .post(find_or_create_path, json: payload)
21
+
22
+ case http.status
23
+ when 200..202
24
+ JSON.parse(http.body)['data']['attributes'].except('session_id', 'ip')
25
+ when 422
26
+ raise Error, http.body.to_s
27
+ else
28
+ raise Error, "#{http.status}: #{http.body}"
29
+ end
30
+ rescue HTTP::TimeoutError
31
+ true
32
+ end
33
+
34
+ def find_or_create_path
35
+ [host, 'api/v1/security_captchas'].join('/')
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Auth
4
+ module Centric
5
+ module Common
6
+ module Settings
7
+ def host
8
+ @host ||= ENV['AUTH_CENTRIC_HOST'] || 'http://localhost:3003'
9
+ end
10
+
11
+ def apikey
12
+ @apikey ||= ENV['AUTH_CENTRIC_API_KEY'] || 'EsRx0-rLseNPjXuXj_FEa-xxzY0isi26'
13
+ end
14
+
15
+ def timeout_seconds
16
+ @timeout_seconds ||= (ENV['AUTH_CENTRIC_TIMEOUT_SECONDS'] || 3).to_i
17
+ end
18
+
19
+ def enabled?
20
+ @enabled ||= %w[true 1 yes on enabled].include?(ENV['AUTH_CENTRIC_ENABLED']&.downcase)
21
+ end
22
+
23
+ def ip(request)
24
+ @ip ||= InternetProtocol.new(request).ip
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -7,11 +7,12 @@ module Auth
7
7
  class CaptureRequest
8
8
  def initialize(request)
9
9
  @request = request
10
+ nil
10
11
  end
11
12
 
12
13
  def as_json
13
14
  {
14
- ip:,
15
+ ip: ip(@request),
15
16
  domain:,
16
17
  url:,
17
18
  query_string:,
@@ -24,10 +25,6 @@ module Auth
24
25
  }
25
26
  end
26
27
 
27
- def ip
28
- @ip ||= InternetProtocol.new(@request).ip
29
- end
30
-
31
28
  def domain
32
29
  @request.domain || @request.headers.env['HTTP_HOST']
33
30
  end
@@ -3,7 +3,7 @@
3
3
  module Auth
4
4
  module Centric
5
5
  module Firewall
6
- VERSION = '0.1.2'
6
+ VERSION = '0.2.0'
7
7
  end
8
8
  end
9
9
  end
@@ -5,6 +5,7 @@ require 'http'
5
5
 
6
6
  require_relative 'firewall/version'
7
7
  require_relative 'firewall/constants'
8
+ require_relative 'common/settings'
8
9
  require_relative 'firewall/capture_request'
9
10
  require_relative 'firewall/internet_protocol'
10
11
 
@@ -12,6 +13,8 @@ module Auth
12
13
  module Centric
13
14
  # Client firewall module
14
15
  module Firewall
16
+ include Auth::Centric::Common::Settings
17
+
15
18
  class Error < StandardError; end
16
19
 
17
20
  def log_firewall(request, forced: false, exception: nil)
@@ -60,14 +63,6 @@ module Auth
60
63
 
61
64
  private
62
65
 
63
- def host
64
- @host ||= ENV['AUTH_CENTRIC_HOST'] || 'http://localhost:3003'
65
- end
66
-
67
- def apikey
68
- @apikey ||= ENV['AUTH_CENTRIC_API_KEY'] || 'EsRx0-rLseNPjXuXj_FEa-xxzY0isi26'
69
- end
70
-
71
66
  def ip_status_path(ip_address)
72
67
  [host, "api/v1/internet_protocols/status?ip=#{ip_address}"].join('/')
73
68
  end
@@ -75,14 +70,20 @@ module Auth
75
70
  def capture_path
76
71
  @capture_path ||= [host, 'api/v1/incoming_requests/capture'].join('/')
77
72
  end
73
+ end
78
74
 
79
- def timeout_seconds
80
- @timeout_seconds ||= (ENV['AUTH_CENTRIC_TIMEOUT_SECONDS'] || 3).to_i
81
- end
75
+ class SecurityCaptcha
76
+ require_relative 'captcha/retrieve'
77
+ require_relative 'captcha/check_code'
82
78
 
83
- def enabled?
84
- @enabled ||= %w[true 1 yes on enabled].include?(ENV['AUTH_CENTRIC_ENABLED']&.downcase)
85
- end
79
+ include Auth::Centric::Common::Settings
80
+ include Auth::Centric::Captcha::Retrieve
81
+ include Auth::Centric::Captcha::CheckCode
82
+
83
+ def initialize(ip_address:, session_id:)
84
+ @ip_address = ip_address
85
+ @session_id = session_id
86
+ end
86
87
  end
87
88
  end
88
89
  end
@@ -0,0 +1,10 @@
1
+ module Auth
2
+ module Centric
3
+ module Captcha
4
+ module CheckCode
5
+ def verify_code?: -> bool
6
+ def check_code_path: -> string
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module Auth
2
+ module Centric
3
+ module Captcha
4
+ module Retrieve
5
+ def find_or_create_path: -> tring
6
+ def retrieve_captcha: -> {
7
+ "id" => "uuid7",
8
+ "failed_count" => int,
9
+ "image" => { "url" => string },
10
+ "fail_limit" => int
11
+ }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Auth
2
+ module Centric
3
+ module Common
4
+ module Settings
5
+ @apikey: string
6
+ @enabled: bool
7
+ @host: string
8
+ @ip: string
9
+ @timeout_seconds: int
10
+
11
+ def apikey: -> string
12
+ def enabled?: -> bool
13
+ def host: -> string
14
+ def ip: -> string
15
+ def timeout_seconds: -> int
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,24 +2,29 @@ module Auth
2
2
  module Centric
3
3
  module Firewall
4
4
  class CaptureRequest
5
- @ip: string
6
- @request: Net::HTTPRequest
7
-
8
- def as_json: -> { }
5
+ def as_json: ->
6
+ {
7
+ ip: string,
8
+ domain: string,
9
+ url: string,
10
+ query_string: string,
11
+ request_method: string,
12
+ request_post_body: string,
13
+ user_agent: string,
14
+ language: string,
15
+ request_formats: string,
16
+ headers: {}
17
+ }
9
18
 
10
19
  def domain: -> string
11
20
 
12
- def headers: -> { }
13
-
14
- def ip: -> string
21
+ def headers: -> string
15
22
 
16
23
  def language: -> string
17
24
 
18
25
  def query_string: -> string
19
26
 
20
- def remote_ip: -> string
21
-
22
- def request_formats: -> [ ]
27
+ def request_formats: -> string
23
28
 
24
29
  def request_method: -> string
25
30
 
@@ -3,7 +3,6 @@ module Auth
3
3
  module Firewall
4
4
  class InternetProtocol
5
5
  @ip: string
6
- @request: Net::HTTPRequest
7
6
 
8
7
  def ip: -> string
9
8
  def is_ipv6?: -> bool
@@ -1,26 +1,21 @@
1
1
  module Auth
2
2
  module Centric
3
3
  module Firewall
4
+ IGNORE_HEADER_KEYS: []
5
+ IGNORE_REQUEST: []
6
+ IGNORE_IP: []
7
+
4
8
  VERSION: string
5
9
 
6
- @host: string
7
- @apikey: string
8
- @enabled: bool
9
10
  @capture_path: string
10
- @timeout_seconds: int
11
11
 
12
12
  def log_firewall: -> bool
13
13
  def valid_ip?: -> bool
14
14
 
15
15
  private
16
16
 
17
-
18
- def host: -> string
19
- def apikey: -> string
20
- def enabled?: -> bool
21
17
  def capture_path: -> string
22
18
  def ip_status_path: -> string
23
- def timeout_seconds: -> int
24
19
  end
25
20
  end
26
21
  end
@@ -0,0 +1,8 @@
1
+ module Auth
2
+ module Centric
3
+ class SecurityCaptcha
4
+ @ip_address: string
5
+ @session_id: string
6
+ end
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auth-centric-firewall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saimon Lovell
@@ -51,20 +51,22 @@ files:
51
51
  - LICENSE.txt
52
52
  - README.md
53
53
  - Rakefile
54
+ - lib/auth/centric/captcha/check_code.rb
55
+ - lib/auth/centric/captcha/retrieve.rb
56
+ - lib/auth/centric/common/settings.rb
54
57
  - lib/auth/centric/firewall.rb
55
58
  - lib/auth/centric/firewall/capture_request.rb
56
59
  - lib/auth/centric/firewall/constants.rb
57
60
  - lib/auth/centric/firewall/internet_protocol.rb
58
61
  - lib/auth/centric/firewall/version.rb
59
62
  - public/403.html
63
+ - sig/auth/centric/captcha/check_code.rbs
64
+ - sig/auth/centric/captcha/retrieve.rbs
65
+ - sig/auth/centric/common/settings.rbs
60
66
  - sig/auth/centric/firewall.rbs
61
67
  - sig/auth/centric/firewall/capture_request.rbs
62
- - sig/auth/centric/firewall/check_ip.rbs
63
- - sig/auth/centric/firewall/constants.rbs
64
68
  - sig/auth/centric/firewall/internet_protocol.rbs
65
- - sig/ignore_header_keys.rbs
66
- - sig/ignore_ip.rbs
67
- - sig/ignore_request.rbs
69
+ - sig/auth/centric/security_captcha.rbs
68
70
  homepage: https://gitlab.com/authcentric/auth-centric-firewall
69
71
  licenses:
70
72
  - MIT
@@ -88,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
90
  - !ruby/object:Gem::Version
89
91
  version: '0'
90
92
  requirements: []
91
- rubygems_version: 3.6.9
93
+ rubygems_version: 3.7.2
92
94
  specification_version: 4
93
95
  summary: Use artificial intelligence to find hackers.
94
96
  test_files: []
@@ -1,11 +0,0 @@
1
- module Auth
2
- module Centric
3
- module Firewall
4
- class CheckIp
5
- @ip: string
6
-
7
- def is_valid?: -> bool
8
- end
9
- end
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- module Auth
2
- module Centric
3
- module Firewall
4
- IGNORE_HEADER_KEYS: []
5
- IGNORE_REQUEST: []
6
- IGNORE_IP: []
7
- end
8
- end
9
- end
@@ -1 +0,0 @@
1
- IGNORE_HEADER_KEYS: []
data/sig/ignore_ip.rbs DELETED
@@ -1 +0,0 @@
1
- IGNORE_IP: []
@@ -1 +0,0 @@
1
- IGNORE_REQUEST: []