awakesecurity / gRPC-haskell

Haskell gRPC support
https://hackage.haskell.org/package/grpc-haskell
Apache License 2.0
236 stars 74 forks source link

Untyped serialized protobuf handlers/hooks/middlewares #121

Open tim2CF opened 3 years ago

tim2CF commented 3 years ago

Are there any handlers/hooks/middlewares to work with untyped serialized request/response grpc payloads? Motivation is to do efficient signing and signature verification of request/response. Signature might be passed as metadata. Without such handlers/hooks/middlewares deterministic signing and verification is not efficient (need to serialize manually) and even not possible in general case, because proto3 standard does not guarantee deterministic serialization. We can do workarounds using libraries like this https://github.com/coingaming/signable#readme but in most cases being able to work with untyped payload is much more easier.

Gabriella439 commented 3 years ago

@tim2CF: I might be misunderstanding the question, but he only way to deal with untyped gRPC payloads is to treat them as opaque ByteStrings. In the absence of a schema there isn't a weakly-typed representation that you can fall back on to decode the payload.

tim2CF commented 3 years ago

@Gabriel439 Yes, exactly! Some sort of middleware with payload as opaque ByteString is what I do want. Then we can sign it and put signature into metadata in case of client, and get signature from metadata and verify signature for given ByteString payload in case of server.

Gabriella439 commented 3 years ago

@tim2CF: So I believe this is possible with the underlying grpc-haskell-core package. Specifically, what I think you want to use is the Network.GRPC.LowLevel.Server.Unregistered and Network.GRPC.LowLevel.Client.Unregistered modules. Those operate in terms of raw ByteStrings