Sha256: c1001f555be44ef6ba356fe337e1b73559b5179e38806dad2746d42e61b40206
Contents?: true
Size: 1.58 KB
Versions: 19
Compression:
Stored size: 1.58 KB
Contents
# typed: false # frozen_string_literal: true module Hephaestus module ValidatesFromYetto SHA256_DIGEST = OpenSSL::Digest.new("sha256") extend ActiveSupport::Concern include Hephaestus::Responses included do before_action :from_yetto? end def from_yetto? return bad_request if request.headers.blank? yetto_signature = request.headers.fetch(Hephaestus::Headers::HEADER_SIGNATURE, "") return bad_request unless yetto_signature.start_with?("sha256=") hmac_header = yetto_signature.split("sha256=").last body = request.env.fetch("RAW_POST_DATA", "") calculated_hmac = OpenSSL::HMAC.hexdigest(SHA256_DIGEST, Hephaestus::YETTO_SIGNING_SECRET, body) return true if ActiveSupport::SecurityUtils.secure_compare(calculated_hmac, hmac_header) bad_request end def from_yetto_inline? return bad_request if request.headers.blank? yetto_signature = request.headers.fetch(Hephaestus::Headers::HEADER_SIGNATURE, "") return bad_request unless yetto_signature.start_with?("sha256=") hmac_header = yetto_signature.split("sha256=").last body = params["encrypted_payload"] @payload = T.let(ActiveSupport::MessageEncryptor.new(Hephaestus::YETTO_SIGNING_SECRET, url_safe: true, serializer: :json).decrypt_and_verify(body), T.nilable(String)) calculated_hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), Hephaestus::YETTO_SIGNING_SECRET, @payload) return true if ActiveSupport::SecurityUtils.secure_compare(calculated_hmac, hmac_header) bad_request end end end
Version data entries
19 entries across 19 versions & 1 rubygems