Compare commits

..

No commits in common. "e4c4d0b9eb301a8e12e6d4ab22f79f52d40af164" and "ad6b987c913425a0d3d35b56ca68ea8ea0d6372f" have entirely different histories.

3 changed files with 220 additions and 1583 deletions

View file

@ -272,20 +272,6 @@ func (m *MsgPackHandler) parseCommand(frame []byte, command *protocol.Command) e
}
command.Command = signCertificateCommand
case messages.CmdRevokeCertificate:
revokeCertificateCommand, err := m.parseRevokeCertificateCommand(frame)
if err != nil {
return err
}
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)
}
@ -396,30 +382,6 @@ func (m *MsgPackHandler) handleSignCertificateCommand(
return &messages.SignCertificateResponse{CertificateData: res.Certificate.Raw}, nil
}
func (m *MsgPackHandler) parseRevokeCertificateCommand(frame []byte) (*messages.RevokeCertificateCommand, error) {
var command messages.RevokeCertificateCommand
if err := msgpack.Unmarshal(frame, &command); err != nil {
m.logger.WithError(err).Errorf("unmarshal failed")
return nil, errors.New("could not unmarshal revoke certificate command")
}
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

@ -150,8 +150,8 @@ type CAInfoCommand struct {
Name string `msgpack:"name"`
}
func (c *CAInfoCommand) String() string {
return fmt.Sprintf("name=%s", c.Name)
func (r *CAInfoCommand) String() string {
return fmt.Sprintf("name=%s", r.Name)
}
type CAInfoResponse struct {
@ -161,8 +161,16 @@ type CAInfoResponse struct {
Profiles []CAProfile `msgpack:"profiles"`
}
func (r CAInfoResponse) String() string {
return fmt.Sprintf("certificate name=%s, signing=%t, profiles=[%s]", r.Name, r.Signing, r.Profiles)
func (i CAInfoResponse) String() string {
return fmt.Sprintf("certificate name=%s, signing=%t, profiles=[%s]", i.Name, i.Signing, i.Profiles)
}
type ErrorResponse struct {
Message string `msgpack:"message"`
}
func (e *ErrorResponse) String() string {
return fmt.Sprintf("message=%s", e.Message)
}
type FetchCRLCommand struct {
@ -170,13 +178,13 @@ type FetchCRLCommand struct {
LastKnownID []byte `msgpack:"last_known_id"`
}
func (c *FetchCRLCommand) String() string {
func (f *FetchCRLCommand) String() string {
builder := &strings.Builder{}
_, _ = fmt.Fprintf(builder, "issuerId='%s'", c.IssuerID)
_, _ = fmt.Fprintf(builder, "issuerId='%s'", f.IssuerID)
if c.LastKnownID != nil {
_, _ = fmt.Fprintf(builder, ", lastKnownId=0x%x", new(big.Int).SetBytes(c.LastKnownID))
if f.LastKnownID != nil {
_, _ = fmt.Fprintf(builder, ", lastKnownId=0x%x", new(big.Int).SetBytes(f.LastKnownID))
}
return builder.String()
@ -238,7 +246,7 @@ func (r *FetchCRLResponse) String() string {
type HealthCommand struct{}
func (c *HealthCommand) String() string {
func (h *HealthCommand) String() string {
return ""
}
@ -281,14 +289,14 @@ type HealthResponse struct {
Info []*HealthInfo
}
func (r *HealthResponse) String() string {
func (h *HealthResponse) String() string {
builder := &strings.Builder{}
_, _ = fmt.Fprintf(builder, "signer version=%s, healthy=%v, health data=[", r.Version, r.Healthy)
_, _ = fmt.Fprintf(builder, "signer version=%s, healthy=%v, health data=[", h.Version, h.Healthy)
infos := make([]string, len(r.Info))
infos := make([]string, len(h.Info))
for i, info := range r.Info {
for i, info := range h.Info {
infos[i] = fmt.Sprintf("{%s}", info)
}
@ -311,33 +319,33 @@ type SignCertificateCommand struct {
PreferredHash crypto.Hash `msgpack:"preferred_hash"`
}
func (c *SignCertificateCommand) String() string {
func (s *SignCertificateCommand) String() string {
builder := &strings.Builder{}
_, _ = fmt.Fprintf(
builder, "issuer_id=%s, profile_name=%s, cn=%s", c.IssuerID, c.ProfileName, c.CommonName,
builder, "issuer_id=%s, profile_name=%s, cn=%s", s.IssuerID, s.ProfileName, s.CommonName,
)
if c.Organization != "" {
_, _ = fmt.Fprintf(builder, ", o=%s", c.Organization)
if s.Organization != "" {
_, _ = fmt.Fprintf(builder, ", o=%s", s.Organization)
}
if c.OrganizationalUnit != "" {
_, _ = fmt.Fprintf(builder, ", ou=%s", c.OrganizationalUnit)
if s.OrganizationalUnit != "" {
_, _ = fmt.Fprintf(builder, ", ou=%s", s.OrganizationalUnit)
}
if len(c.Hostnames) > 0 {
if len(s.Hostnames) > 0 {
builder.WriteString(", hostnames=[")
builder.WriteString(strings.Join(c.Hostnames, ", "))
builder.WriteString(strings.Join(s.Hostnames, ", "))
builder.WriteRune(']')
}
if len(c.EmailAddresses) > 0 {
if len(s.EmailAddresses) > 0 {
builder.WriteString(", email_addresses=[")
builder.WriteString(strings.Join(c.EmailAddresses, ", "))
builder.WriteString(strings.Join(s.Hostnames, ", "))
builder.WriteRune(']')
}
@ -352,79 +360,3 @@ type SignCertificateResponse struct {
func (r *SignCertificateResponse) String() string {
return fmt.Sprintf("cert_data of %d bytes", len(r.CertificateData))
}
type RevokeCertificateCommand struct {
IssuerID string `msgpack:"issuer_id"`
Serial []byte `msgpack:"serial_number"`
Reason string `msgpack:"reason"`
}
func (c *RevokeCertificateCommand) String() string {
builder := &strings.Builder{}
_, _ = fmt.Fprintf(
builder,
"issuerID=%s, serial=0x%s", c.IssuerID, new(big.Int).SetBytes(c.Serial).Text(16),
)
if c.Reason != "" {
_, _ = fmt.Fprintf(builder, ", reason=%s", c.Reason)
}
return builder.String()
}
type RevokeCertificateResponse struct {
IssuerID string `msgpack:"issuer_id"`
Serial []byte `msgpack:"serial_number"`
RevokedAt time.Time `msgpack:"revoked_at"`
}
func (r *RevokeCertificateResponse) String() string {
return fmt.Sprintf(
"issuerID=%s, serial=0x%s, revoked_at=%s",
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))
}
type ErrorResponse struct {
Message string `msgpack:"message"`
}
func (r *ErrorResponse) String() string {
return fmt.Sprintf("message=%s", r.Message)
}

File diff suppressed because it is too large Load diff