Define command and response for SignOpenPGP

This commit is contained in:
Jan Dittberner 2022-12-11 14:01:48 +01:00
parent c452453c31
commit f92bba5496
2 changed files with 53 additions and 0 deletions

View file

@ -279,6 +279,13 @@ func (m *MsgPackHandler) parseCommand(frame []byte, command *protocol.Command) e
}
command.Command = revokeCertificateCommand
case messages.CmdSignOpenPGP:
signOpenPGPCommand, err := m.parseSignOpenPGPCommand(frame)
if err != nil {
return err
}
command.Command = signOpenPGPCommand
default:
return fmt.Errorf("unhandled command code %s", command.Announce.Code)
}
@ -401,6 +408,18 @@ func (m *MsgPackHandler) parseRevokeCertificateCommand(frame []byte) (*messages.
return &command, nil
}
func (m *MsgPackHandler) parseSignOpenPGPCommand(frame []byte) (*messages.SignOpenPGPCommand, error) {
var command messages.SignOpenPGPCommand
if err := msgpack.Unmarshal(frame, &command); err != nil {
m.logger.WithError(err).Errorf("unmarshal failed")
return nil, errors.New("could not unmarshal sign OpenPGP command")
}
return &command, nil
}
func New(logger *logrus.Logger, handlers ...RegisterHandler) (protocol.ServerHandler, error) {
messages.RegisterGeneratedResolver()

View file

@ -394,3 +394,37 @@ func (r *RevokeCertificateResponse) String() string {
r.IssuerID, new(big.Int).SetBytes(r.Serial).Text(16), r.RevokedAt.Format(time.RFC3339),
)
}
type SignOpenPGPCommand struct {
IssuerID string `msgpack:"issuer_id"`
ProfileName string `msgpack:"profile_name"`
PublicKey []byte `msgpack:"public_key"`
CommonName string `msgpack:"cn"`
EmailAddresses []string `msgpack:"email_addresses"`
}
func (c *SignOpenPGPCommand) String() string {
builder := &strings.Builder{}
_, _ = fmt.Fprintf(
builder, "issuer_id=%s, profile_name=%s, cn=%s", c.IssuerID, c.ProfileName, c.CommonName,
)
if len(c.EmailAddresses) > 0 {
builder.WriteString(", email_addresses=[")
builder.WriteString(strings.Join(c.EmailAddresses, ", "))
builder.WriteRune(']')
}
return builder.String()
}
type SignOpenPGPResponse struct {
SignatureData []byte `msgpack:"signature_data"`
}
func (r *SignOpenPGPResponse) String() string {
return fmt.Sprintf("sig_data of %d bytes", len(r.SignatureData))
}