Class: WebBotAuth::MessageSignature

Inherits:
Object
  • Object
show all
Defined in:
app/services/web_bot_auth/message_signature.rb

Overview

Builds an RFC 9421 HTTP Message Signature over a fixed set of covered
components, signed with the Web Bot Auth Ed25519 Key.

The same machinery serves both signature flavours:

  • the directory response signature (covers +@authority;req+,
    tag +http-message-signatures-directory+)
  • outbound request signatures (covers +@authority+ + +signature-agent+,
    tag +web-bot-auth+)

Defined Under Namespace

Classes: Component

Instance Method Summary collapse

Constructor Details

#initialize(label:, components:, created:, expires:, keyid:, tag:, alg: WebBotAuth::ALG) ⇒ MessageSignature

Returns a new instance of MessageSignature.

Parameters:

  • label (String)

    the signature label (Dictionary key), e.g. "sig1"

  • components (Array<Component>)

    the covered components, in order

  • created (Integer)

    unix timestamp the signature was created

  • expires (Integer)

    unix timestamp the signature expires

  • keyid (String)

    the signing key thumbprint

  • tag (String)

    the RFC 9421 application tag

  • alg (String) (defaults to: WebBotAuth::ALG)

    the signature algorithm identifier



31
32
33
34
35
36
37
38
39
# File 'app/services/web_bot_auth/message_signature.rb', line 31

def initialize(label:, components:, created:, expires:, keyid:, tag:, alg: WebBotAuth::ALG)
  @label = label
  @components = components
  @created = created
  @expires = expires
  @keyid = keyid
  @tag = tag
  @alg = alg
end

Instance Method Details

#headersHash{String=>String}

The +Signature-Input+ and +Signature+ header pair for this signature.

Returns:

  • (Hash{String=>String})


44
45
46
47
48
49
50
# File 'app/services/web_bot_auth/message_signature.rb', line 44

def headers
  signature = Base64.strict_encode64(WebBotAuth::Key.sign(signature_base))
  {
    'Signature-Input' => "#{@label}=#{signature_params}",
    'Signature' => "#{@label}=:#{signature}:"
  }
end

#signature_baseString

The RFC 9421 signature base — the exact bytes that get signed.

Returns:

  • (String)


55
56
57
58
59
# File 'app/services/web_bot_auth/message_signature.rb', line 55

def signature_base
  lines = @components.map { |component| "#{component_id(component)}: #{component.value}" }
  lines << %("@signature-params": #{signature_params})
  lines.join("\n")
end

#signature_paramsString

The serialised signature parameters (inner list + parameters), used both in
the +@signature-params+ line and as the +Signature-Input+ value.

Returns:

  • (String)


65
66
67
68
69
# File 'app/services/web_bot_auth/message_signature.rb', line 65

def signature_params
  inner_list = "(#{@components.map { |component| component_id(component) }.join(' ')})"
  "#{inner_list};created=#{@created};keyid=#{sf_string(@keyid)}" \
    ";alg=#{sf_string(@alg)};expires=#{@expires};tag=#{sf_string(@tag)}"
end