Skip to content

Commit

Permalink
sync: Handle parse errors, add UNKNOWN_CLIENT_MODE to enum (#1389)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellhancox authored Jul 9, 2024
1 parent 348ff8c commit 9e78477
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Source/santasyncservice/SNTSyncPreflight.mm
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ - (BOOL)sync {
resp.deprecated_transitive_whitelisting_enabled());
self.syncState.enableAllEventUpload = @(resp.enable_all_event_upload());
self.syncState.disableUnknownEventUpload = @(resp.disable_unknown_event_upload());
self.syncState.eventBatchSize = resp.batch_size();

self.syncState.eventBatchSize = kDefaultEventBatchSize;
if (resp.batch_size() > 0) {
self.syncState.eventBatchSize = resp.batch_size();
}

// Don't let these go too low
uint64_t value = resp.push_notification_full_sync_interval_seconds()
Expand Down
12 changes: 9 additions & 3 deletions Source/santasyncservice/SNTSyncStage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ - (NSMutableURLRequest *)requestWithMessage:(google::protobuf::Message *)message
absl::Status status = google::protobuf::json::MessageToJsonString(*message, &json, options);

if (!status.ok()) {
SLOGE(@"Failed to convert protobuf to JSON: %s", status.ToString().c_str());
NSString *errStr = [NSString
stringWithFormat:@"Failed to convert protobuf to JSON: %s", status.ToString().c_str()];
SLOGE(@"%@", errStr);
return nil;
}

Expand Down Expand Up @@ -220,8 +222,12 @@ - (NSError *)performRequest:(NSURLRequest *)request
absl::Status status =
google::protobuf::json::JsonStringToMessage(NSStringToUTF8String(jsonData), message, options);
if (!status.ok()) {
SLOGE(@"Failed to parse response JSON into message: %s", status.ToString().c_str());
return nil;
NSString *errStr = [NSString stringWithFormat:@"Failed to parse response JSON into message: %s",
status.ToString().c_str()];
SLOGE(@"%@", errStr);
return [NSError errorWithDomain:@"com.google.santa.syncservice"
code:3
userInfo:@{NSLocalizedDescriptionKey : errStr}];
}

return nil;
Expand Down
9 changes: 7 additions & 2 deletions Source/santasyncservice/syncv1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ service SantaSync {

// ClientMode represents the operating mode for an agent.
enum ClientMode {
MONITOR = 0;
LOCKDOWN = 1;
UNKNOWN_CLIENT_MODE = 0;
MONITOR = 1;
LOCKDOWN = 2;
}

message PreflightRequest {
Expand All @@ -54,6 +55,10 @@ message PreflightRequest {
}

message PreflightResponse {
// The client mode that the client should move into at the end of this sync.
// The mode does not change until the Postflight request has been made, to
// ensure the client has received all the needed rules before potentially going
// into Lockdown.
ClientMode client_mode = 1;

// Possible values are "normal" (default if unspecified), "clean", or "clean_all".
Expand Down

0 comments on commit 9e78477

Please sign in to comment.