@signature_verification_failure_reason='Signed request date outside acceptable time window'
@signed_request_account=nil
return
end
raw_signature=request.headers['Signature']
signature_params={}
raw_signature.split(',').eachdo|part|
parsed_parts=part.match(/([a-z]+)="([^"]+)"/i)
nextifparsed_parts.nil?||parsed_parts.size!=3
signature_params[parsed_parts[1]]=parsed_parts[2]
end
raiseSignatureVerificationError,'Request not signed'unlesssigned_request?
raiseSignatureVerificationError,'Incompatible request signature. keyId and signature are required'ifmissing_required_signature_parameters?
raiseSignatureVerificationError,'Unsupported signature algorithm (only rsa-sha256 and hs2019 are supported)'unless%w(rsa-sha256 hs2019).include?(signature_algorithm)
raiseSignatureVerificationError,'Signed request date outside acceptable time window'unlessmatches_time_window?
@signature_verification_failure_reason="Verification failed for #{account.username}@#{account.domain}#{account.uri}"
@signature_verification_failure_reason="Verification failed for #{account.username}@#{account.domain}#{account.uri} using rsa-sha256 (RSASSA-PKCS1-v1_5 with SHA-256)"
raiseSignatureVerificationError,'Mastodon requires the Date header or (created) pseudo-header to be signed'unlesssigned_headers.include?('date')||signed_headers.include?('(created)')
raiseSignatureVerificationError,'Mastodon requires the Digest header or (request-target) pseudo-header to be signed'unlesssigned_headers.include?(Request::REQUEST_TARGET)||signed_headers.include?('digest')
raiseSignatureVerificationError,'Mastodon requires the Host header to be signed when doing a GET request'ifrequest.get?&&!signed_headers.include?('host')
raiseSignatureVerificationError,'Mastodon requires the Digest header to be signed when doing a POST request'ifrequest.post?&&!signed_headers.include?('digest')