Skip to content

Commit

Permalink
sync: Add machine_id field to facilitate a GRPC version of the protoc…
Browse files Browse the repository at this point in the history
…ol (#1390)
  • Loading branch information
pmarkowsky authored Jul 9, 2024
1 parent 7f86366 commit 208b4a6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Source/santasyncservice/SNTSyncEventUpload.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ - (BOOL)sync {
- (BOOL)uploadEvents:(NSArray *)events {
google::protobuf::Arena arena;
auto req = google::protobuf::Arena::Create<::pbv1::EventUploadRequest>(&arena);
req->set_machine_id(NSStringToUTF8String(self.syncState.machineID));

google::protobuf::RepeatedPtrField<::pbv1::Event> *uploadEvents = req->mutable_events();

NSMutableSet *eventIds = [NSMutableSet setWithCapacity:events.count];
Expand Down
4 changes: 4 additions & 0 deletions Source/santasyncservice/SNTSyncPostflight.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

#import "Source/common/SNTSyncConstants.h"
#import "Source/common/SNTXPCControlInterface.h"
#import "Source/common/String.h"
#import "Source/santasyncservice/SNTSyncState.h"

#include <google/protobuf/arena.h>
#include "Source/santasyncservice/syncv1.pb.h"
namespace pbv1 = ::santa::sync::v1;

using santa::NSStringToUTF8String;

@implementation SNTSyncPostflight

- (NSURL *)stageURL {
Expand All @@ -34,6 +37,7 @@ - (NSURL *)stageURL {
- (BOOL)sync {
google::protobuf::Arena arena;
auto req = google::protobuf::Arena::Create<::pbv1::PostflightRequest>(&arena);
req->set_machine_id(NSStringToUTF8String(self.syncState.machineID));
req->set_rules_received(self.syncState.rulesReceived);
req->set_rules_processed(self.syncState.rulesProcessed);

Expand Down
1 change: 1 addition & 0 deletions Source/santasyncservice/SNTSyncPreflight.mm
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ - (NSURL *)stageURL {
- (BOOL)sync {
google::protobuf::Arena arena;
auto req = google::protobuf::Arena::Create<::pbv1::PreflightRequest>(&arena);
req->set_machine_id(NSStringToUTF8String(self.syncState.machineID));
req->set_serial_number(NSStringToUTF8String([SNTSystemInfo serialNumber]));
req->set_hostname(NSStringToUTF8String([SNTSystemInfo longHostname]));
req->set_os_version(NSStringToUTF8String([SNTSystemInfo osVersion]));
Expand Down
3 changes: 3 additions & 0 deletions Source/santasyncservice/SNTSyncRuleDownload.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Source/santasyncservice/syncv1.pb.h"
namespace pbv1 = ::santa::sync::v1;

using santa::NSStringToUTF8String;
using santa::StringToNSString;

SNTRuleCleanup SyncTypeToRuleCleanup(SNTSyncType syncType) {
Expand Down Expand Up @@ -104,6 +105,8 @@ - (BOOL)sync {

do {
auto req = google::protobuf::Arena::Create<::pbv1::RuleDownloadRequest>(&arena);
req->set_machine_id(NSStringToUTF8String(self.syncState.machineID));

if (!cursor.empty()) {
req->set_cursor(cursor);
}
Expand Down
8 changes: 8 additions & 0 deletions Source/santasyncservice/syncv1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ message PreflightRequest {
uint32 teamid_rule_count = 15;
uint32 signingid_rule_count = 16;
uint32 cdhash_rule_count = 17;
// The UUID of the machine that is sending this preflight.
string machine_id = 18;
}

message PreflightResponse {
Expand Down Expand Up @@ -202,6 +204,8 @@ message Event {

message EventUploadRequest {
repeated Event events = 1;
// The UUID of the machine where the event(s) occurred
string machine_id = 2;
}

message EventUploadResponse {
Expand Down Expand Up @@ -257,6 +261,8 @@ message Rule {

message RuleDownloadRequest {
string cursor = 1;
// The UUID of the machine that is requesting the rules.
string machine_id = 2;
}

message RuleDownloadResponse {
Expand All @@ -267,6 +273,8 @@ message RuleDownloadResponse {
message PostflightRequest {
uint64 rules_received = 1;
uint64 rules_processed = 2;
// The UUID of the machine that is sending this postflight.
string machine_id = 3;
}

message PostflightResponse { }
Expand Down

0 comments on commit 208b4a6

Please sign in to comment.