From 76e1e9a17af56f62119e773909fa0d693d94c11a Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Sat, 14 Oct 2023 15:53:20 -0600 Subject: [PATCH] Fixed verification of authorized signals --- gql_node.go | 36 +++++++++++++++++++++++++----------- node.go | 3 +++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/gql_node.go b/gql_node.go index 1e2b426..3ee6b00 100644 --- a/gql_node.go +++ b/gql_node.go @@ -127,27 +127,38 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([ ctx.Context.Log.Logf("gql", "SENT_READ_SIGNAL to %+s", id) } - ctx.Context.Log.Logf("gql", "Resolved cached nodes: %+v", responses) - + errors := "" + ctx.Context.Log.Logf("gql", "RESP_CHANNELS: %+v", resp_channels) for sig_id, response_chan := range(resp_channels) { // Wait for the response, returning an error on timeout - response, err := WaitForSignal(response_chan, time.Millisecond*100, func(sig *ReadResultSignal)bool{ - return sig.ReqID == sig_id - }) + response, err := WaitForResponse(response_chan, time.Millisecond*100, sig_id) if err != nil { return nil, err } + ctx.Context.Log.Logf("gql", "GQL node response: %+v", response) + + error_signal, is_error := response.(*ErrorSignal) + if is_error { + errors = fmt.Sprintf("%s, %s", errors, error_signal.Error) + continue + } + + read_response, is_read_response := response.(*ReadResultSignal) + if is_read_response == false { + errors = fmt.Sprintf("%s, wrong response type %+v", errors, reflect.TypeOf(response)) + continue + } idx := indices[sig_id] responses[idx] = NodeResult{ - response.NodeID, - response.NodeType, - response.Extensions, + read_response.NodeID, + read_response.NodeType, + read_response.Extensions, } - cache, exists := ctx.NodeCache[response.NodeID] + cache, exists := ctx.NodeCache[read_response.NodeID] if exists == true { - for ext_type, fields := range(response.Extensions) { + for ext_type, fields := range(read_response.Extensions) { cached_fields, exists := cache.Data[ext_type] if exists == true { for field_name, field_value := range(fields) { @@ -156,11 +167,14 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([ } } } else { - ctx.NodeCache[response.NodeID] = responses[idx] + ctx.NodeCache[read_response.NodeID] = responses[idx] } } ctx.Context.Log.Logf("gql", "RESOLVED_NODES %+v - %+v", ids, responses) + if errors != "" { + return nil, fmt.Errorf(errors) + } return responses, nil } diff --git a/node.go b/node.go index 0244fc5..b0185f0 100644 --- a/node.go +++ b/node.go @@ -289,6 +289,9 @@ func nodeLoop(ctx *Context, node *Node) error { } sig_data := append(dst_id_ser, src_id_ser...) sig_data = append(sig_data, ser...) + if msg.Authorization != nil { + sig_data = append(sig_data, msg.Authorization.Signature...) + } validated := ed25519.Verify(msg.Source, sig_data, msg.Signature) if validated == false { ctx.Log.Logf("signal", "SIGNAL_VERIFY_ERR: %s - %+v", node.ID, msg)