|
|
|
@ -111,54 +111,63 @@ func (s *SignerClientHandler) ResponseData(ctx context.Context, in <-chan []byte
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
return nil
|
|
|
|
|
case frame := <-in:
|
|
|
|
|
switch response.Announce.Code {
|
|
|
|
|
case messages.RespHealth:
|
|
|
|
|
var resp messages.HealthResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal health response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
err := handleIncomingFrame(response, frame)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
case <-time.After(s.config.ResponseDataTimeout):
|
|
|
|
|
return protocol.ErrResponseDataTimeoutExpired
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
case messages.RespCAInfo:
|
|
|
|
|
var resp messages.CAInfoResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal CA info response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
case messages.RespFetchCRL:
|
|
|
|
|
var resp messages.FetchCRLResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal fetch CRL response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
func handleIncomingFrame(response *protocol.Response, frame []byte) error {
|
|
|
|
|
switch response.Announce.Code {
|
|
|
|
|
case messages.RespHealth:
|
|
|
|
|
var resp messages.HealthResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal health response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
case messages.RespSignCertificate:
|
|
|
|
|
var resp messages.SignCertificateResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal sign certificate response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
case messages.RespCAInfo:
|
|
|
|
|
var resp messages.CAInfoResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal CA info response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
case messages.RespSignOpenPGP:
|
|
|
|
|
var resp messages.SignOpenPGPResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal sign OpenPGP response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
case messages.RespFetchCRL:
|
|
|
|
|
var resp messages.FetchCRLResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal fetch CRL response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
case messages.RespError:
|
|
|
|
|
var resp messages.ErrorResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal error response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
case messages.RespSignCertificate:
|
|
|
|
|
var resp messages.SignCertificateResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal sign certificate response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("unhandled response code %s", response.Announce.Code)
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
case messages.RespSignOpenPGP:
|
|
|
|
|
var resp messages.SignOpenPGPResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal sign OpenPGP response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
case <-time.After(s.config.ResponseDataTimeout):
|
|
|
|
|
return protocol.ErrResponseDataTimeoutExpired
|
|
|
|
|
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
case messages.RespError:
|
|
|
|
|
var resp messages.ErrorResponse
|
|
|
|
|
if err := msgpack.Unmarshal(frame, &resp); err != nil {
|
|
|
|
|
return fmt.Errorf("could not unmarshal error response data: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.Response = &resp
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("unhandled response code %s", response.Announce.Code)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|