Skip to content

Order of fields in asset definition file is significant for hashing #15

@jeffomatic

Description

@jeffomatic

This is a subtle point, but if we're going to use hashing for verifying the asset definition file, then it's probably best that we define a strict ordering and formatting of the JSON so that idiosyncrasies in JSON serialization and/or rendering don't affect the value of the hash.

Given that the asset definition file is JSON, it's likely to be stored as such, and possibly deserialized and re-serialized before being rendered, or after being fetched for verification. JSON as a format doesn't care about indentation, newlines, or field ordering, but the hash operation does care about those things.

Off the top of my head, there are a couple of options:

  1. Treat the asset definition file as a raw string. Encourage providers (issuers) to avoid deserializing the string after extracting it from the data store and encourage verifiers to read the raw HTTP body for hash generation.
  2. Extend the standard to specify pre-processing before calculating the hash. For example, to verify an asset definition file, the verifier would deserialize the contents, re-render them as a string with sorted keys (or some ordering defined in the standard), strip out unnecessary whitespace (most JSON serializers will do this by default), maybe treat blank strings or null values as if the key was removed, and then take the hash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions