Skip to content

Commit

Permalink
Add a new keyless protocol error type for remote configuration issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Leland Garofalo committed Sep 19, 2023
1 parent cd7a781 commit 79bb6d0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion client/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"crypto/subtle"
"errors"
"fmt"
"github.com/cloudflare/gokeyless/server"
"io"
"net"

Expand Down Expand Up @@ -117,7 +118,7 @@ func (key *PrivateKey) execute(ctx context.Context, op protocol.Op, msg []byte)

conn, err := r.Dial(key.client)
if err != nil {
return nil, err
return nil, server.RemoteConfigurationErr{Err: err}
}

// We explicitly do NOT want to fill in JaegerSpan here, since the remote keyless server
Expand Down
2 changes: 2 additions & 0 deletions protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ const (
ErrCertNotFound
// ErrExpired indicates that the sealed blob is no longer unsealable.
ErrExpired
// ErrRemoteConfiguration indicates that a remote keyserver was not configured correctly.
ErrRemoteConfiguration
)

func (e Error) Error() string {
Expand Down
9 changes: 9 additions & 0 deletions server/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package server

type RemoteConfigurationErr struct {
Err error
}

func (rce RemoteConfigurationErr) Error() string {
return rce.Error()
}
21 changes: 18 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,15 @@ func (s *Server) unlimitedDo(pkt *protocol.Packet, connName string) response {
sig, err := key.Sign(rand.Reader, pkt.Operation.Payload, crypto.Hash(0))
if err != nil {
log.Errorf("Connection: %s: Signing error: %v", connName, protocol.ErrCrypto, err)
return makeErrResponse(pkt, protocol.ErrCrypto)
// This indicates that a remote keyserver is being used
var remoteConfigurationErr RemoteConfigurationErr
if errors.As(err, &remoteConfigurationErr) {
log.Errorf("Connection %v: %s: Signing error: %v\n", connName, protocol.ErrRemoteConfiguration, err)
return makeErrResponse(pkt, protocol.ErrRemoteConfiguration)
} else {
log.Errorf("Connection %v: %s: Signing error: %v\n", connName, protocol.ErrCrypto, err)
return makeErrResponse(pkt, protocol.ErrCrypto)
}
}
return makeRespondResponse(pkt, sig)

Expand Down Expand Up @@ -486,8 +494,15 @@ func (s *Server) unlimitedDo(pkt *protocol.Packet, connName string) response {
continue
} else {
tracing.LogError(span, err)
log.Errorf("Connection %v: %s: Signing error: %v\n", connName, protocol.ErrCrypto, err)
return makeErrResponse(pkt, protocol.ErrCrypto)
// This indicates that a remote keyserver is being used
var remoteConfigurationErr RemoteConfigurationErr
if errors.As(err, &remoteConfigurationErr) {
log.Errorf("Connection %v: %s: Signing error: %v\n", connName, protocol.ErrRemoteConfiguration, err)
return makeErrResponse(pkt, protocol.ErrRemoteConfiguration)
} else {
log.Errorf("Connection %v: %s: Signing error: %v\n", connName, protocol.ErrCrypto, err)
return makeErrResponse(pkt, protocol.ErrCrypto)
}
}
}
break
Expand Down

0 comments on commit 79bb6d0

Please sign in to comment.