Class: Signature4Verifier

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-common/Signature4Verifier.rb

Overview

Entry point of AdScore signature v4 verification library. It expose verify method allowing to verify AdScore signature against given set of ipAddress(es) for given zone.

Constant Summary collapse

DEFAULT_EXPIRY_TIME_SEC =
60

Class Method Summary collapse

Class Method Details

.verify(signature, user_agent, key, ip_addresses, expiry: DEFAULT_EXPIRY_TIME_SEC, is_key_base64_encoded: false) ⇒ Signature4VerificationResult

Default request and signature expiration is set to 60s

Parameters:

  • signature (String)

    which we want to verify

  • user_agent (String)

    with full description of user agent like ‘Mozilla/5.0 (Linux; Android 9; SM-J530F)…’

  • key (String)

    containing related zone key

  • ip_addresses (Array<String>)

    containing ip4 or ip6 addresses against which we check signature. Usually, is fulfilled from httpXForwardForIpAddresses or/and remoteIpAddresses header. All possible ip addresses may be provided at once, in case of correct result, verifier returns list of chosen ip addresses that matched with the signature.

  • expiry (Number) (defaults to: DEFAULT_EXPIRY_TIME_SEC)

    which is time in seconds. IF signatureTime + expiry > CurrentDateInSeconds THEN result is expired

  • is_key_base64_encoded (Boolean) (defaults to: false)

    defining if passed key is base64 encoded or not. Default is set to false.

Returns:

Raises:

  • (VersionError)

    if there is an error related to version parsing or compatibility.

  • (ParseError)

    if there is an error parsing the signature or during decryption process

  • (VerifyError)

    if there is an error during verify decrypted Signature



25
26
27
# File 'lib/ruby-common/Signature4Verifier.rb', line 25

def self.verify(signature, user_agent, key, ip_addresses, expiry: DEFAULT_EXPIRY_TIME_SEC, is_key_base64_encoded: false)
  Signature4VerifierService.verifySignature(signature, user_agent, key, ip_addresses, expiry, is_key_base64_encoded)
end