Repository navigation
refactor!: Signing and verification API refactored - #166
Conversation
…thanks to the updated api
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #166 +/- ##
==========================================
+ Coverage 96.70% 97.67% +0.97%
==========================================
Files 19 20 +1
Lines 1153 1377 +224
==========================================
+ Hits 1115 1345 +230
+ Misses 38 32 -6 ☔ View full report in Codecov by Harness. |
|
@mariusor, @jvongxay0308: This PR addresses the FRs you both submitted. Would you be willing to review the PR and try out the updated API? I'd be particularly interested in your feedback:
Looking forward to hearing your thoughts. Thanks in advance for taking the time! |
|
@newtosh, @rosylilly, @faustbrian: Since you're also using |
…ions for accept signature builder
|
Thanks for the ping, and for this PR! For context, I use httpsig in my ActivityPub server (mycroblog/my) as the RFC 9421 sign/verify primitive. The acceptance policy lives outside the library, since keys are fetched from remote actors and the fediverse doesn't use tags. How it feels: Good. I tried porting my adapter to this branch in a local copy. The change was small and confined to one file, and my adapter and federation tests pass. Per-call Claude Code helped me review this PR and translate this comment into English. Feedback on the API
Small things I noticed in the code
Not blockers, but they would remove workarounds on my side. These API shapes are only suggestions.
If you'd like any of these API changes or fixes, just mention me and I'll open a PR. Separately, I found an issue in an existing check, unrelated to this PR, that I'd rather not discuss publicly first. Could you email me at rosylilly@aduca.org ? I'll send you the details and my test code. |
… to Accept-Signature builder
|
@rosylilly Awesome! Thanks for the detailed feedback, and especially for testing the changes! As you can see from the updates above, your feedback has already led to a few changes. Both bugs are fixed, Regarding the order of As for the three nice-to-have API additions, would you mind opening a separate feature request for each of them? I'd prefer to discuss these independently of this PR, and it would also give other users a chance to share their thoughts. For I'll also follow up with you separately by email. |
|
@dadrus Thanks for the quick fixes! I've opened the three feature requests: #168 , #169 , and #170 . On the order of |
|
I'd prefer to keep the order unspecified for now and make that explicit in the GoDoc. Nevertheless, I'm curious: why would you need the same order as in |
|
So everything is fine, the test errors were related to the changes to the nonce and the 👍 from me. |
|
@mariusor Cool, thanks! Btw. the party is still ongoing - so, you're not too late ;) The README has also received a bigger update. Feedback is appreciated ;) Your last comment was pretty brief :) Does that mean the challenge you described in #130 is now resolved? Is there anything else you think we should address, beyond the points raised by @rosylilly? |
|
@dadrus yes, I think so. I can now do something like this in the alg, ok := sigInfo.Parameters.Alg()
if !ok {
// defaults to PKCSv1 for RSA, and takes key size into consideration
alg = rfcAlgorithmFromPublicKey(pkey)
}
key.Alg = algI don't think there is something better that can be done. |
|
(Unrelated, and sorry for shilling: @rosylilly I don't know if you stumbled upon my library when you started the work on your project, but it's meant to solve exactly the problems you're dealing with right now :D. If you're interested in some collaboration there's a mailing list where you can reach me: https://lists.sr.ht/~mariusor/go-activitypub-discuss) |
Related FRs
closes #130
closes #153
Summary
Refactored the public API to provide richer signature context, clearer separation of responsibilities, and reusable signing and verification configurations.
Accept-Signaturenegotiation.Core API
Key{KeyID, Key, Algorithm}Key{Material, Algorithm}. Set the signature'skeyidseparately withWithKeyID(...).ResolveKey(ctx, keyID string) (Key, error)ResolveKey(ctx, info SignatureInfo) (KeyInfo, error). The resolver receives the message, signature label, covered components, and parameters. It returns a trusted key and optional metadata.Verify(msg) errorVerify(msg) (VerificationResult, error). Successful verification returns aVerifiedSignaturefor each selected signature, including components, parameters, label, and resolver metadata. No partial result is returned on failure.Sign(msg)Sign(msg, ...SignOption).WithLabel(...)andWithParameter(...)can provide values for an individual call. Extension parameters can also be configured onNewSigner().WithNonce(NonceGetter)Sign(msg, WithParameter("nonce", value)).algparameterWithAlg()onNewSigner().NonceChecker,NonceValue,NonceCheckerFunc,WithNonceChecker(...)Security boundary:
SignatureInfois supplied to the key resolver before cryptographic verification and must be treated as untrusted. The values returned inVerificationResultare available only after successful verification. Signature labels remain unsigned technical identifiers.Option migration
WithRequiredComponents(...)WithComponents(...)WithCreatedTimestampRequired(...),WithExpiredTimestampRequired(...)WithCreatedTimestamp(...),WithExpiredTimestamp(...)WithExpectedKey(Key{KeyID, Algorithm})WithKeyID(...)andWithSignatureAlgorithm(...)WithExpectedLabel,WithExpectedComponents,WithExpectedTag,WithExpectedCreatedTimestamp,WithExpectedExpiresTimestampWithLabel,WithComponents,WithTag,WithCreatedTimestamp,WithExpiredTimestampWithExpectedNonce(getter); automatic nonce by defaultWithNonceGetter(getter)orBuild(ctx, header, WithParameter("nonce", value)). No automatic nonce by default; an explicit value overrides the configured getter.WithRequestedKey,WithRequestedNonce,WithRequestedLabel,WithRequestedContentDigestAlgorithmPreferencesWithKeyID+WithSignatureAlgorithm,WithNonceGetter,WithLabel,WithContentDigestAlgorithmPreferencesAdditionally,
WithRequiredTag("")is now rejected during verifier construction.SignatureParametersandTokenare exposed for inspecting typed Structured Fields values, including extension parameters.