forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.go
61 lines (51 loc) · 1.33 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package http_comms
import (
"context"
"fmt"
"sync"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
crypto_client "www.velocidex.com/golang/velociraptor/crypto/client"
"www.velocidex.com/golang/velociraptor/executor"
"www.velocidex.com/golang/velociraptor/services/writeback"
"www.velocidex.com/golang/velociraptor/utils"
)
func StartHttpCommunicatorService(
ctx context.Context,
wg *sync.WaitGroup,
config_obj *config_proto.Config,
exe executor.Executor,
on_error func(ctx context.Context, config_obj *config_proto.Config)) (
*HTTPCommunicator, error) {
if config_obj.Client == nil {
return nil, nil
}
writeback_service := writeback.GetWritebackService()
writeback, err := writeback_service.GetWriteback(config_obj)
if err != nil {
return nil, err
}
crypto_manager, err := crypto_client.NewClientCryptoManager(
config_obj, []byte(writeback.PrivateKey))
if err != nil {
return nil, err
}
// Now start the communicator so we can talk with the server.
comm, err := NewHTTPCommunicator(
ctx,
config_obj,
crypto_manager,
exe,
config_obj.Client.ServerUrls,
func() { on_error(ctx, config_obj) },
utils.RealClock{},
)
if err != nil {
return nil, fmt.Errorf("Can not create HTTPCommunicator: %w", err)
}
wg.Add(1)
go func() {
defer wg.Done()
comm.Run(ctx, wg)
}()
return comm, nil
}