Class: Linzer::Signature::Profile::WebBotAuth

Inherits:
Base
  • Object
show all
Defined in:
lib/linzer/signature/profile/web_bot_auth.rb

Overview

Web Bot Auth signing profile implementation.

This profile applies the behavior defined in the Web Bot Auth HTTP Message Signatures draft specification.

It mutates a signing context to ensure compliance with the spec requirements, including:

  • selection of required signature components

  • generation of nonce values

  • enforcement of Web Bot Auth signature parameters

  • optional Signature-Agent header injection

## Lifecycle

  1. Context is created

  2. Profile is resolved

  3. #apply mutates signing context

  4. signature is generated using modified context

Constant Summary collapse

REQUIRED_AUTH_COMPONENTS =
%w[@authority @target-uri].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params: :recommended, nonce: :generate, agent: nil) ⇒ WebBotAuth

Creates a new Web Bot Auth signing profile.

Parameters:

  • params (Symbol, nil) (defaults to: :recommended)

    Controls default Web Bot Auth signature parameters.

    • :recommended → apply Web Bot Auth recommended defaults

    • nil → do not modify signature parameters

  • nonce (Symbol, nil) (defaults to: :generate)

    Controls nonce generation behavior.

    • :generate → inject a cryptographically random nonce

    • nil → no nonce is added

  • agent (String, nil) (defaults to: nil)

    Optional Signature-Agent identifier URI.

    When provided, a structured Signature-Agent header is injected and included as a covered signature component.



47
48
49
50
51
52
# File 'lib/linzer/signature/profile/web_bot_auth.rb', line 47

def initialize(params: :recommended, nonce: :generate, agent: nil)
  @params = params
  @nonce  = nonce
  @agent  = agent
  freeze
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



54
55
56
# File 'lib/linzer/signature/profile/web_bot_auth.rb', line 54

def agent
  @agent
end

#nonceObject (readonly)

Returns the value of attribute nonce.



54
55
56
# File 'lib/linzer/signature/profile/web_bot_auth.rb', line 54

def nonce
  @nonce
end

#paramsObject (readonly)

Returns the value of attribute params.



54
55
56
# File 'lib/linzer/signature/profile/web_bot_auth.rb', line 54

def params
  @params
end

Class Method Details

.defaultWebBotAuth

Returns a default Web Bot Auth profile instance.

This represents the standard recommended configuration:

  • recommended signature parameters enabled

  • nonce generation enabled

Returns:



102
103
104
# File 'lib/linzer/signature/profile/web_bot_auth.rb', line 102

def self.default
  new(params: :recommended, nonce: :generate)
end

Instance Method Details

#apply(ctx) ⇒ void

This method returns an undefined value.

Applies the Web Bot Auth profile to a signing context.

This method mutates:

  • signature parameters (ctx.params)

  • covered components (ctx.components)

  • overlay headers (ctx.overlay_headers)

Parameters:

Raises:

  • (Linzer::Error)

    If key or message are incompatible with Web Bot Auth rules



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/linzer/signature/profile/web_bot_auth.rb', line 74

def apply(ctx)
  validate ctx.key, ctx.message

  if @params == :recommended
    set_params!(ctx.key, ctx.components, ctx.params)
  end

  ctx.params[:nonce] = generate_nonce if @nonce == :generate

  if @agent
    set_agent!(
      @agent,
      ctx.params[:label],
      ctx.message,
      ctx.components,
      ctx.overlay_headers
    )
  end
end