frequenz-floss / frequenz-client-base-python

Base gRPC client
https://frequenz-floss.github.io/frequenz-client-base-python/
MIT License
0 stars 3 forks source link

Implement request signing #65

Open llucax opened 3 months ago

llucax commented 3 months ago

What's needed?

Services will soon start require requests to be signed, so client should be able to do this signing.

Proposed solution

Implement signing requests somehow in ApiClientBase or utility functions/classes like GrpcStreamBroadcaster or call_stub_method. Ideally signing should be as transparent as possible to client implementers.

Signing works as follows:

Signature parts

The following request parts are used to generate the signature:

The signature is stored in the metadata key sig.

Algorithm

The algorithm uses HMAC with SHA-256 as the hashing algorithm. The resulting signature is encoded using URL-safe base64 without padding.

The algorithm can be outlined in pseudocode as follows:

hmac = Hmac(Sha256)
hmac.update(key)
hmac.update(secret)
hmac.update(ts)
hmac.update(nonce)
hmac.update(rpc_method)
hmac.update(msg_body)
signature = hmac.finalize()
encoded_sig = base64.url_safe_no_pad(signature)

Resources