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
…#404)

Co-authored-by: Leland Garofalo <[email protected]>
  • Loading branch information
lgarofalo and Leland Garofalo authored Sep 21, 2023
1 parent 28396a8 commit d8785c5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
5 changes: 3 additions & 2 deletions client/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/cloudflare/cfssl/log"
"github.com/cloudflare/gokeyless/protocol"
"github.com/cloudflare/gokeyless/server"
"github.com/cloudflare/gokeyless/tracing"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
Expand Down Expand Up @@ -112,12 +113,12 @@ func (key *PrivateKey) execute(ctx context.Context, op protocol.Op, msg []byte)
for attempts := 2; attempts > 0; attempts-- {
r, err := key.client.getRemote(key.keyserver)
if err != nil {
return nil, err
return nil, server.RemoteConfigurationErr{Err: err}
}

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
4 changes: 4 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 Expand Up @@ -191,6 +193,8 @@ func (e Error) String() string {
return "certificate not found"
case ErrExpired:
return "sealing key expired"
case ErrRemoteConfiguration:
return "remote configuration error"
default:
return "unknown error"
}
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.Err.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 d8785c5

Please sign in to comment.