Class: PxModule::PerimeterxTokenV1

Inherits:
PerimeterxPayload show all
Defined in:
lib/perimeterx/internal/payload/perimeter_x_token_v1.rb

Instance Attribute Summary collapse

Attributes inherited from PerimeterxPayload

#cookie_secret, #decoded_cookie, #px_cookie

Instance Method Summary collapse

Methods inherited from PerimeterxPayload

#cookie_time, #cookie_uuid, #cookie_vid, #decode, #decrypt, #deserialize, #expired?, #high_score?, #hmac_valid?, #is_valid?, px_cookie_factory, #secure_compare

Constructor Details

#initialize(px_config, px_ctx) ⇒ PerimeterxTokenV1

Returns a new instance of PerimeterxTokenV1.



6
7
8
9
10
11
12
# File 'lib/perimeterx/internal/payload/perimeter_x_token_v1.rb', line 6

def initialize(px_config, px_ctx)
  super(px_config)
  @px_ctx = px_ctx
  @px_cookie = px_ctx.get_px_cookie
  @cookie_secret = px_config[:cookie_key]
  @logger.debug('PerimeterxTokenV1[initialize]')
end

Instance Attribute Details

#px_configObject

Returns the value of attribute px_config.



4
5
6
# File 'lib/perimeterx/internal/payload/perimeter_x_token_v1.rb', line 4

def px_config
  @px_config
end

#px_ctxObject

Returns the value of attribute px_ctx.



4
5
6
# File 'lib/perimeterx/internal/payload/perimeter_x_token_v1.rb', line 4

def px_ctx
  @px_ctx
end

Instance Method Details



26
27
28
# File 'lib/perimeterx/internal/payload/perimeter_x_token_v1.rb', line 26

def cookie_block_action
  return 'c'
end


18
19
20
# File 'lib/perimeterx/internal/payload/perimeter_x_token_v1.rb', line 18

def cookie_hmac
  return @decoded_cookie[:h]
end


14
15
16
# File 'lib/perimeterx/internal/payload/perimeter_x_token_v1.rb', line 14

def cookie_score
  return @decoded_cookie[:s][:b]
end

#secured?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/perimeterx/internal/payload/perimeter_x_token_v1.rb', line 30

def secured?
  hmac_str = "#{cookie_time}#{@decoded_cookie[:s][:a]}#{cookie_score}#{cookie_uuid}#{cookie_vid}"

  return hmac_valid?(hmac_str, cookie_hmac)
end

#valid_format?(cookie) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/perimeterx/internal/payload/perimeter_x_token_v1.rb', line 22

def valid_format?(cookie)
  return cookie.key?(:t) && cookie.key?(:s) && cookie[:s].key?(:b) && cookie.key?(:s) && cookie.key?(:v) && cookie.key?(:h)
end