Skip to content

Commit

Permalink
daemon: error out when using drkey endpoints without configured drkey (
Browse files Browse the repository at this point in the history
…scionproto#4453)

I found a bug in the SCION daemon. If you create a SCION daemon connection and call one of the drkey endpoints without first setting the configuration value "drkey_level2_db.Connection" to something meaningful, the SCION daemon will encounter an error like that and crash:
```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xb82d33]
```
This bug can easily be reproduced by running a code snippet like this for a SCION daemon that has no drkey configured:
```
sd, _ := daemon.NewService(daemonAddr).Connect(ctx)
sd.DRKeyGetASHostKey(ctx, drkey.ASHostMeta{})
```
The problem is that in the file "daemon/internal/servers/grpc.go", when the drkey endpoints are called, DaemonServer.DRKeyClient is nil if it is not configured as described above.

Fixed by explicitly checking whether DRKey is available and erroring out if it is not.
  • Loading branch information
rohrerj authored Dec 7, 2023
1 parent 7fc08e4 commit 85b8a13
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions daemon/internal/servers/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ func (s *DaemonServer) DRKeyASHost(
req *pb_daemon.DRKeyASHostRequest,
) (*pb_daemon.DRKeyASHostResponse, error) {

if s.DRKeyClient == nil {
return nil, serrors.New("DRKey is not available")
}
meta, err := requestToASHostMeta(req)
if err != nil {
return nil, serrors.WrapStr("parsing protobuf ASHostReq", err)
Expand All @@ -378,6 +381,9 @@ func (s *DaemonServer) DRKeyHostAS(
req *pb_daemon.DRKeyHostASRequest,
) (*pb_daemon.DRKeyHostASResponse, error) {

if s.DRKeyClient == nil {
return nil, serrors.New("DRKey is not available")
}
meta, err := requestToHostASMeta(req)
if err != nil {
return nil, serrors.WrapStr("parsing protobuf HostASReq", err)
Expand All @@ -400,6 +406,9 @@ func (s *DaemonServer) DRKeyHostHost(
req *pb_daemon.DRKeyHostHostRequest,
) (*pb_daemon.DRKeyHostHostResponse, error) {

if s.DRKeyClient == nil {
return nil, serrors.New("DRKey is not available")
}
meta, err := requestToHostHostMeta(req)
if err != nil {
return nil, serrors.WrapStr("parsing protobuf HostHostReq", err)
Expand Down

0 comments on commit 85b8a13

Please sign in to comment.