-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON::LD::API.toRdf
, when given a Hash as input, may mutate it
#54
Comments
Yes, but I believe this is removing it from a copy of the original input, unless you have a use case that illustrates an actual issue created because of that. That said, the code would probably work using |
Yes, I did run into this issue with an actual use case. Mastodon signs (some of) its activities by using Linked-Data Signatures, so it uses Because not all consumers handle JSON-LD, we ensure that our payloads can be processed as plain JSON, so we attach the signature (computed on the normalized object) to the original hash object. A recent PR aiming to fix a bug in Mastodon introduces nested contexts, which strips a The signature is basically computed like this: def canonicalize(json)
graph = RDF::Graph.new << JSON::LD::API.toRdf(json, documentLoader: method(:load_jsonld_context))
graph.dump(:normalize)
end
def hash(obj)
Digest::SHA256.hexdigest(canonicalize(obj))
end
def sign!(creator, sign_with: nil)
options = {
'type' => 'RsaSignature2017',
'creator' => [ActivityPub::TagManager.instance.uri_for(creator), '#main-key'].join,
'created' => Time.now.utc.iso8601,
}
options_hash = hash(options.without('type', 'id', 'signatureValue').merge('@context' => CONTEXT))
document_hash = hash(@json.without('signature'))
to_be_signed = options_hash + document_hash
keypair = sign_with.present? ? OpenSSL::PKey::RSA.new(sign_with) : creator.keypair
signature = Base64.strict_encode64(keypair.sign(OpenSSL::Digest.new('SHA256'), to_be_signed))
@json.merge('signature' => options.merge('signatureValue' => signature))
end I can easily work around this issue by building my object differently or doing a |
I'll get an update out shortly with a fix. Thanks for the use case. |
I pushed a fix to the develop branch. If that solves your issues, I'll push a new release out. |
It does solve it! Thank you for the quick fix! |
When given a hash with an embedded
@context
, it can end up removing@context
from the nested hash.This seems to be because of
json-ld/lib/json/ld/expand.rb
Line 91 in 9fd51e0
The text was updated successfully, but these errors were encountered: