Skip to content

Commit d8785c5

Browse files
lgarofaloLeland Garofalo
and
Leland Garofalo
authored
Add a new keyless protocol error type for remote configuration issues (#404)
Co-authored-by: Leland Garofalo <[email protected]>
1 parent 28396a8 commit d8785c5

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

client/keys.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/cloudflare/cfssl/log"
1515
"github.com/cloudflare/gokeyless/protocol"
16+
"github.com/cloudflare/gokeyless/server"
1617
"github.com/cloudflare/gokeyless/tracing"
1718
"github.com/opentracing/opentracing-go"
1819
"github.com/opentracing/opentracing-go/ext"
@@ -112,12 +113,12 @@ func (key *PrivateKey) execute(ctx context.Context, op protocol.Op, msg []byte)
112113
for attempts := 2; attempts > 0; attempts-- {
113114
r, err := key.client.getRemote(key.keyserver)
114115
if err != nil {
115-
return nil, err
116+
return nil, server.RemoteConfigurationErr{Err: err}
116117
}
117118

118119
conn, err := r.Dial(key.client)
119120
if err != nil {
120-
return nil, err
121+
return nil, server.RemoteConfigurationErr{Err: err}
121122
}
122123

123124
// We explicitly do NOT want to fill in JaegerSpan here, since the remote keyless server

protocol/protocol.go

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ const (
161161
ErrCertNotFound
162162
// ErrExpired indicates that the sealed blob is no longer unsealable.
163163
ErrExpired
164+
// ErrRemoteConfiguration indicates that a remote keyserver was not configured correctly.
165+
ErrRemoteConfiguration
164166
)
165167

166168
func (e Error) Error() string {
@@ -191,6 +193,8 @@ func (e Error) String() string {
191193
return "certificate not found"
192194
case ErrExpired:
193195
return "sealing key expired"
196+
case ErrRemoteConfiguration:
197+
return "remote configuration error"
194198
default:
195199
return "unknown error"
196200
}

server/errors.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package server
2+
3+
type RemoteConfigurationErr struct {
4+
Err error
5+
}
6+
7+
func (rce RemoteConfigurationErr) Error() string {
8+
return rce.Err.Error()
9+
}

server/server.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,15 @@ func (s *Server) unlimitedDo(pkt *protocol.Packet, connName string) response {
377377
sig, err := key.Sign(rand.Reader, pkt.Operation.Payload, crypto.Hash(0))
378378
if err != nil {
379379
log.Errorf("Connection: %s: Signing error: %v", connName, protocol.ErrCrypto, err)
380-
return makeErrResponse(pkt, protocol.ErrCrypto)
380+
// This indicates that a remote keyserver is being used
381+
var remoteConfigurationErr RemoteConfigurationErr
382+
if errors.As(err, &remoteConfigurationErr) {
383+
log.Errorf("Connection %v: %s: Signing error: %v\n", connName, protocol.ErrRemoteConfiguration, err)
384+
return makeErrResponse(pkt, protocol.ErrRemoteConfiguration)
385+
} else {
386+
log.Errorf("Connection %v: %s: Signing error: %v\n", connName, protocol.ErrCrypto, err)
387+
return makeErrResponse(pkt, protocol.ErrCrypto)
388+
}
381389
}
382390
return makeRespondResponse(pkt, sig)
383391

@@ -486,8 +494,15 @@ func (s *Server) unlimitedDo(pkt *protocol.Packet, connName string) response {
486494
continue
487495
} else {
488496
tracing.LogError(span, err)
489-
log.Errorf("Connection %v: %s: Signing error: %v\n", connName, protocol.ErrCrypto, err)
490-
return makeErrResponse(pkt, protocol.ErrCrypto)
497+
// This indicates that a remote keyserver is being used
498+
var remoteConfigurationErr RemoteConfigurationErr
499+
if errors.As(err, &remoteConfigurationErr) {
500+
log.Errorf("Connection %v: %s: Signing error: %v\n", connName, protocol.ErrRemoteConfiguration, err)
501+
return makeErrResponse(pkt, protocol.ErrRemoteConfiguration)
502+
} else {
503+
log.Errorf("Connection %v: %s: Signing error: %v\n", connName, protocol.ErrCrypto, err)
504+
return makeErrResponse(pkt, protocol.ErrCrypto)
505+
}
491506
}
492507
}
493508
break

0 commit comments

Comments
 (0)