Skip to content
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

Consider updating iat as default behavior on sign. #28

Open
zamicol opened this issue Oct 27, 2024 · 0 comments
Open

Consider updating iat as default behavior on sign. #28

zamicol opened this issue Oct 27, 2024 · 0 comments

Comments

@zamicol
Copy link
Contributor

zamicol commented Oct 27, 2024

For singing, when iat is present (not empty) in pay, automatically populate with time.Now().Unix().

For implementation, a global can configure the behavior. Something like UpdateIat:true which can then be set to false.

This follows the behavior of the online tool, which defaults to updating iat, but is configurable using a toggle (and can be set using a URL parameter as well).

For example,

{
    "msg": "Coze Rocks",
    "alg": "ES256",
    "iat": 1623132000,
    "tmb": "cLj8vsYtMBwYkzoFVZHBZo6SNL8wSdCIjCKAwXNuhOk",
    "typ": "cyphr.me/msg"
}

would be update to:

{
    "msg": "Coze Rocks",
    "alg": "ES256",
    "iat": 1730065126,
    "tmb": "cLj8vsYtMBwYkzoFVZHBZo6SNL8wSdCIjCKAwXNuhOk",
    "typ": "cyphr.me/msg"
}

As best practice when setting values on a new struct, to signify that iat should be populated with a new value in the future on signing, the value 0 should be used to denote the explicit intention to trigger an update.

(As as minor aside, the value 1 may be considered over 0. This would be done in hopes neophytes unfamiliar with the semantics of omitempty don't anticipate iat's removal when zero. My perspective is that following idiomatic Go is better; omitempty will only omit an integer value when the pointer value is nil. The zero value 0 is non-empty. Also, the value 1 also has meaning to rvk, which could be confusing.)

Alternatively, as it stands now, iat must be manually set. A line like pay.Iat = time.Now().Unix() is found all throughout Cyphr.me's codebase. This change would allow omitting that line, as int64 is not an uninitialized pointer in type Coze so it will be populated with the current timestamp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant