Compare commits
4 commits
ad6b987c91
...
e4c4d0b9eb
Author | SHA1 | Date | |
---|---|---|---|
e4c4d0b9eb | |||
e35e9e9df6 | |||
f92bba5496 | |||
c452453c31 |
3 changed files with 1583 additions and 220 deletions
|
@ -272,6 +272,20 @@ func (m *MsgPackHandler) parseCommand(frame []byte, command *protocol.Command) e
|
||||||
}
|
}
|
||||||
|
|
||||||
command.Command = signCertificateCommand
|
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:
|
default:
|
||||||
return fmt.Errorf("unhandled command code %s", command.Announce.Code)
|
return fmt.Errorf("unhandled command code %s", command.Announce.Code)
|
||||||
}
|
}
|
||||||
|
@ -382,6 +396,30 @@ func (m *MsgPackHandler) handleSignCertificateCommand(
|
||||||
return &messages.SignCertificateResponse{CertificateData: res.Certificate.Raw}, nil
|
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) {
|
func New(logger *logrus.Logger, handlers ...RegisterHandler) (protocol.ServerHandler, error) {
|
||||||
messages.RegisterGeneratedResolver()
|
messages.RegisterGeneratedResolver()
|
||||||
|
|
||||||
|
|
|
@ -150,8 +150,8 @@ type CAInfoCommand struct {
|
||||||
Name string `msgpack:"name"`
|
Name string `msgpack:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *CAInfoCommand) String() string {
|
func (c *CAInfoCommand) String() string {
|
||||||
return fmt.Sprintf("name=%s", r.Name)
|
return fmt.Sprintf("name=%s", c.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CAInfoResponse struct {
|
type CAInfoResponse struct {
|
||||||
|
@ -161,16 +161,8 @@ type CAInfoResponse struct {
|
||||||
Profiles []CAProfile `msgpack:"profiles"`
|
Profiles []CAProfile `msgpack:"profiles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i CAInfoResponse) String() string {
|
func (r CAInfoResponse) String() string {
|
||||||
return fmt.Sprintf("certificate name=%s, signing=%t, profiles=[%s]", i.Name, i.Signing, i.Profiles)
|
return fmt.Sprintf("certificate name=%s, signing=%t, profiles=[%s]", r.Name, r.Signing, r.Profiles)
|
||||||
}
|
|
||||||
|
|
||||||
type ErrorResponse struct {
|
|
||||||
Message string `msgpack:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *ErrorResponse) String() string {
|
|
||||||
return fmt.Sprintf("message=%s", e.Message)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type FetchCRLCommand struct {
|
type FetchCRLCommand struct {
|
||||||
|
@ -178,13 +170,13 @@ type FetchCRLCommand struct {
|
||||||
LastKnownID []byte `msgpack:"last_known_id"`
|
LastKnownID []byte `msgpack:"last_known_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FetchCRLCommand) String() string {
|
func (c *FetchCRLCommand) String() string {
|
||||||
builder := &strings.Builder{}
|
builder := &strings.Builder{}
|
||||||
|
|
||||||
_, _ = fmt.Fprintf(builder, "issuerId='%s'", f.IssuerID)
|
_, _ = fmt.Fprintf(builder, "issuerId='%s'", c.IssuerID)
|
||||||
|
|
||||||
if f.LastKnownID != nil {
|
if c.LastKnownID != nil {
|
||||||
_, _ = fmt.Fprintf(builder, ", lastKnownId=0x%x", new(big.Int).SetBytes(f.LastKnownID))
|
_, _ = fmt.Fprintf(builder, ", lastKnownId=0x%x", new(big.Int).SetBytes(c.LastKnownID))
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.String()
|
return builder.String()
|
||||||
|
@ -246,7 +238,7 @@ func (r *FetchCRLResponse) String() string {
|
||||||
|
|
||||||
type HealthCommand struct{}
|
type HealthCommand struct{}
|
||||||
|
|
||||||
func (h *HealthCommand) String() string {
|
func (c *HealthCommand) String() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,14 +281,14 @@ type HealthResponse struct {
|
||||||
Info []*HealthInfo
|
Info []*HealthInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HealthResponse) String() string {
|
func (r *HealthResponse) String() string {
|
||||||
builder := &strings.Builder{}
|
builder := &strings.Builder{}
|
||||||
|
|
||||||
_, _ = fmt.Fprintf(builder, "signer version=%s, healthy=%v, health data=[", h.Version, h.Healthy)
|
_, _ = fmt.Fprintf(builder, "signer version=%s, healthy=%v, health data=[", r.Version, r.Healthy)
|
||||||
|
|
||||||
infos := make([]string, len(h.Info))
|
infos := make([]string, len(r.Info))
|
||||||
|
|
||||||
for i, info := range h.Info {
|
for i, info := range r.Info {
|
||||||
infos[i] = fmt.Sprintf("{%s}", info)
|
infos[i] = fmt.Sprintf("{%s}", info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,33 +311,33 @@ type SignCertificateCommand struct {
|
||||||
PreferredHash crypto.Hash `msgpack:"preferred_hash"`
|
PreferredHash crypto.Hash `msgpack:"preferred_hash"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignCertificateCommand) String() string {
|
func (c *SignCertificateCommand) String() string {
|
||||||
builder := &strings.Builder{}
|
builder := &strings.Builder{}
|
||||||
|
|
||||||
_, _ = fmt.Fprintf(
|
_, _ = fmt.Fprintf(
|
||||||
builder, "issuer_id=%s, profile_name=%s, cn=%s", s.IssuerID, s.ProfileName, s.CommonName,
|
builder, "issuer_id=%s, profile_name=%s, cn=%s", c.IssuerID, c.ProfileName, c.CommonName,
|
||||||
)
|
)
|
||||||
|
|
||||||
if s.Organization != "" {
|
if c.Organization != "" {
|
||||||
_, _ = fmt.Fprintf(builder, ", o=%s", s.Organization)
|
_, _ = fmt.Fprintf(builder, ", o=%s", c.Organization)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.OrganizationalUnit != "" {
|
if c.OrganizationalUnit != "" {
|
||||||
_, _ = fmt.Fprintf(builder, ", ou=%s", s.OrganizationalUnit)
|
_, _ = fmt.Fprintf(builder, ", ou=%s", c.OrganizationalUnit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(s.Hostnames) > 0 {
|
if len(c.Hostnames) > 0 {
|
||||||
builder.WriteString(", hostnames=[")
|
builder.WriteString(", hostnames=[")
|
||||||
|
|
||||||
builder.WriteString(strings.Join(s.Hostnames, ", "))
|
builder.WriteString(strings.Join(c.Hostnames, ", "))
|
||||||
|
|
||||||
builder.WriteRune(']')
|
builder.WriteRune(']')
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(s.EmailAddresses) > 0 {
|
if len(c.EmailAddresses) > 0 {
|
||||||
builder.WriteString(", email_addresses=[")
|
builder.WriteString(", email_addresses=[")
|
||||||
|
|
||||||
builder.WriteString(strings.Join(s.Hostnames, ", "))
|
builder.WriteString(strings.Join(c.EmailAddresses, ", "))
|
||||||
|
|
||||||
builder.WriteRune(']')
|
builder.WriteRune(']')
|
||||||
}
|
}
|
||||||
|
@ -360,3 +352,79 @@ type SignCertificateResponse struct {
|
||||||
func (r *SignCertificateResponse) String() string {
|
func (r *SignCertificateResponse) String() string {
|
||||||
return fmt.Sprintf("cert_data of %d bytes", len(r.CertificateData))
|
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
Loading…
Reference in a new issue