|
|
@ -31,7 +31,7 @@ module SignatureVerification
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
account = ResolveRemoteAccountService.new.call(signature_params['keyId'].gsub(/\Aacct:/, ''))
|
|
|
|
account = account_from_key_id(signature_params['keyId'])
|
|
|
|
|
|
|
|
|
|
|
|
if account.nil?
|
|
|
|
if account.nil?
|
|
|
|
@signed_request_account = nil
|
|
|
|
@signed_request_account = nil
|
|
|
@ -49,6 +49,10 @@ module SignatureVerification
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def request_body
|
|
|
|
|
|
|
|
@request_body ||= request.raw_post
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
|
|
def build_signed_string(signed_headers)
|
|
|
|
def build_signed_string(signed_headers)
|
|
|
@ -57,6 +61,8 @@ module SignatureVerification
|
|
|
|
signed_headers.split(' ').map do |signed_header|
|
|
|
|
signed_headers.split(' ').map do |signed_header|
|
|
|
|
if signed_header == Request::REQUEST_TARGET
|
|
|
|
if signed_header == Request::REQUEST_TARGET
|
|
|
|
"#{Request::REQUEST_TARGET}: #{request.method.downcase} #{request.path}"
|
|
|
|
"#{Request::REQUEST_TARGET}: #{request.method.downcase} #{request.path}"
|
|
|
|
|
|
|
|
elsif signed_header == 'digest'
|
|
|
|
|
|
|
|
"digest: #{body_digest}"
|
|
|
|
else
|
|
|
|
else
|
|
|
|
"#{signed_header}: #{request.headers[to_header_name(signed_header)]}"
|
|
|
|
"#{signed_header}: #{request.headers[to_header_name(signed_header)]}"
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -73,6 +79,10 @@ module SignatureVerification
|
|
|
|
(Time.now.utc - time_sent).abs <= 30
|
|
|
|
(Time.now.utc - time_sent).abs <= 30
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def body_digest
|
|
|
|
|
|
|
|
"SHA-256=#{Digest::SHA256.base64digest(request_body)}"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def to_header_name(name)
|
|
|
|
def to_header_name(name)
|
|
|
|
name.split(/-/).map(&:capitalize).join('-')
|
|
|
|
name.split(/-/).map(&:capitalize).join('-')
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -81,7 +91,14 @@ module SignatureVerification
|
|
|
|
signature_params['keyId'].blank? ||
|
|
|
|
signature_params['keyId'].blank? ||
|
|
|
|
signature_params['signature'].blank? ||
|
|
|
|
signature_params['signature'].blank? ||
|
|
|
|
signature_params['algorithm'].blank? ||
|
|
|
|
signature_params['algorithm'].blank? ||
|
|
|
|
signature_params['algorithm'] != 'rsa-sha256' ||
|
|
|
|
signature_params['algorithm'] != 'rsa-sha256'
|
|
|
|
!signature_params['keyId'].start_with?('acct:')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def account_from_key_id(key_id)
|
|
|
|
|
|
|
|
if key_id.start_with?('acct:')
|
|
|
|
|
|
|
|
ResolveRemoteAccountService.new.call(key_id.gsub(/\Aacct:/, ''))
|
|
|
|
|
|
|
|
elsif !ActivityPub::TagManager.instance.local_uri?(key_id)
|
|
|
|
|
|
|
|
ActivityPub::FetchRemoteAccountService.new.call(key_id)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|