[#13] services/util: Support server-side stream request verify
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
c378c353d5
commit
da1961cdf9
1 changed files with 19 additions and 5 deletions
|
@ -23,7 +23,26 @@ func NewUnarySignService(key *ecdsa.PrivateKey, handler UnaryHandler) *UnarySign
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *UnarySignService) HandleServerStreamRequest(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return s.verifyAndProc(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *UnarySignService) HandleUnaryRequest(ctx context.Context, req interface{}) (interface{}, error) {
|
func (s *UnarySignService) HandleUnaryRequest(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
// verify and process request
|
||||||
|
resp, err := s.verifyAndProc(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// sign the response
|
||||||
|
if err := signature.SignServiceMessage(s.key, resp); err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not sign response")
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UnarySignService) verifyAndProc(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
// verify request signatures
|
// verify request signatures
|
||||||
if err := signature.VerifyServiceMessage(req); err != nil {
|
if err := signature.VerifyServiceMessage(req); err != nil {
|
||||||
return nil, errors.Wrap(err, "could not verify request")
|
return nil, errors.Wrap(err, "could not verify request")
|
||||||
|
@ -35,10 +54,5 @@ func (s *UnarySignService) HandleUnaryRequest(ctx context.Context, req interface
|
||||||
return nil, errors.Wrap(err, "could not handle request")
|
return nil, errors.Wrap(err, "could not handle request")
|
||||||
}
|
}
|
||||||
|
|
||||||
// sign the response
|
|
||||||
if err := signature.SignServiceMessage(s.key, resp); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not sign response")
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue