Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Make the sync client content encoding a tunable #1076

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Source/common/SNTCommonEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ typedef NS_ENUM(NSInteger, SNTSyncStatusType) {
SNTSyncStatusTypeUnknown,
};

typedef NS_ENUM(NSInteger, SNTSyncContentEncoding) {
SNTSyncContentEncodingNone,
SNTSyncContentEncodingDeflate,
SNTSyncContentEncodingGzip,
};

typedef NS_ENUM(NSInteger, SNTMetricFormatType) {
SNTMetricFormatTypeUnknown,
SNTMetricFormatTypeRawJSON,
Expand Down
8 changes: 8 additions & 0 deletions Source/common/SNTConfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@
///
@property(nonatomic) BOOL syncCleanRequired;

#pragma mark - USB Settings

///
/// USB Mount Blocking. Defaults to false.
///
Expand Down Expand Up @@ -520,6 +522,12 @@
///
@property(readonly, nonatomic) BOOL enableBackwardsCompatibleContentEncoding;

///
/// If set, "santactl sync" will use the supplied "Content-Encoding", possible
/// settings include "gzip", "deflate", "none". If empty defaults to "deflate".
///
@property(readonly, nonatomic) SNTSyncContentEncoding syncClientContentEncoding;

///
/// Contains the FCM project name.
///
Expand Down
30 changes: 17 additions & 13 deletions Source/common/SNTConfigurator.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/// limitations under the License.

#import "Source/common/SNTConfigurator.h"
#import "Source/common/SNTCommonEnums.h"

#include <sys/stat.h>

Expand Down Expand Up @@ -108,8 +109,7 @@ @implementation SNTConfigurator
static NSString *const kIgnoreOtherEndpointSecurityClients = @"IgnoreOtherEndpointSecurityClients";
static NSString *const kEnableDebugLogging = @"EnableDebugLogging";

static NSString *const kEnableBackwardsCompatibleContentEncoding =
@"EnableBackwardsCompatibleContentEncoding";
static NSString *const kClientContentEncoding = @"SyncClientContentEncoding";

static NSString *const kFCMProject = @"FCMProject";
static NSString *const kFCMEntity = @"FCMEntity";
Expand All @@ -129,7 +129,6 @@ @implementation SNTConfigurator
static NSString *const kEnableAllEventUploadKey = @"EnableAllEventUpload";
static NSString *const kDisableUnknownEventUploadKey = @"DisableUnknownEventUpload";

// TODO(markowsky): move these to sync server only.
static NSString *const kMetricFormat = @"MetricFormat";
static NSString *const kMetricURL = @"MetricURL";
static NSString *const kMetricExportInterval = @"MetricExportInterval";
Expand Down Expand Up @@ -200,6 +199,7 @@ - (instancetype)init {
kClientAuthCertificatePasswordKey : string,
kClientAuthCertificateCNKey : string,
kClientAuthCertificateIssuerKey : string,
kClientContentEncoding : string,
kServerAuthRootsDataKey : data,
kServerAuthRootsFileKey : string,
kMachineOwnerKey : string,
Expand All @@ -221,7 +221,6 @@ - (instancetype)init {
kEnableForkAndExitLogging : number,
kIgnoreOtherEndpointSecurityClients : number,
kEnableDebugLogging : number,
kEnableBackwardsCompatibleContentEncoding : number,
kFCMProject : string,
kFCMEntity : string,
kFCMAPIKey : string,
Expand Down Expand Up @@ -463,10 +462,6 @@ + (NSSet *)keyPathsForValuesAffectingEnableDebugLogging {
return [self configStateSet];
}

+ (NSSet *)keyPathsForValuesAffectingEnableBackwardsCompatibleContentEncoding {
return [self configStateSet];
}

+ (NSSet *)keyPathsForValuesAffectingFcmProject {
return [self configStateSet];
}
Expand Down Expand Up @@ -715,6 +710,20 @@ - (NSString *)syncClientAuthCertificateIssuer {
return self.configState[kClientAuthCertificateIssuerKey];
}

- (SNTSyncContentEncoding)syncClientContentEncoding {
NSString *contentEncoding = [self.configState[kClientContentEncoding] lowercaseString];
if ([contentEncoding isEqualToString:@"deflate"]) {
return SNTSyncContentEncodingDeflate;
} else if ([contentEncoding isEqualToString:@"gzip"]) {
return SNTSyncContentEncodingGzip;
} else if ([contentEncoding isEqualToString:@"none"]) {
return SNTSyncContentEncodingNone;
} else {
// Ensure we have the same default zlib behavior Santa's always had otherwise.
return SNTSyncContentEncodingDeflate;
}
}

- (NSData *)syncServerAuthRootsData {
return self.configState[kServerAuthRootsDataKey];
}
Expand Down Expand Up @@ -888,11 +897,6 @@ - (BOOL)enableDebugLogging {
return [number boolValue] || self.debugFlag;
}

- (BOOL)enableBackwardsCompatibleContentEncoding {
NSNumber *number = self.configState[kEnableBackwardsCompatibleContentEncoding];
return number ? [number boolValue] : NO;
}

- (NSString *)fcmProject {
return self.configState[kFCMProject];
}
Expand Down
5 changes: 1 addition & 4 deletions Source/santasyncservice/SNTSyncManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,7 @@ - (SNTSyncState *)createSyncStateWithStatus:(SNTSyncStatusType *)status {

syncState.session = [authURLSession session];
syncState.daemonConn = self.daemonConn;

syncState.compressedContentEncoding =
config.enableBackwardsCompatibleContentEncoding ? @"zlib" : @"deflate";

syncState.contentEncoding = config.syncClientContentEncoding;
syncState.pushNotificationsToken = self.pushNotifications.token;

return syncState;
Expand Down
22 changes: 20 additions & 2 deletions Source/santasyncservice/SNTSyncStage.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/// limitations under the License.

#import "Source/santasyncservice/SNTSyncStage.h"
#include "Source/common/SNTCommonEnums.h"

#import <MOLXPCConnection/MOLXPCConnection.h>

Expand Down Expand Up @@ -70,10 +71,27 @@ - (NSMutableURLRequest *)requestWithDictionary:(NSDictionary *)dictionary {
NSString *xsrfHeader = self.syncState.xsrfTokenHeader ?: kDefaultXSRFTokenHeader;
[req setValue:self.syncState.xsrfToken forHTTPHeaderField:xsrfHeader];

NSData *compressed = [requestBody zlibCompressed];
NSData *compressed;
NSString *contentEncodingHeader;

switch (self.syncState.contentEncoding) {
case SNTSyncContentEncodingNone: break;
case SNTSyncContentEncodingGzip:
compressed = [requestBody gzipCompressed];
contentEncodingHeader = @"gzip";
break;
case SNTSyncContentEncodingDeflate:
compressed = [requestBody zlibCompressed];
contentEncodingHeader = @"deflate";
break;
default:
// This would be a programming error.
LOGD(@"Unexpected value for content encoding %ld", self.syncState.contentEncoding);
}

if (compressed) {
requestBody = compressed;
[req setValue:self.syncState.compressedContentEncoding forHTTPHeaderField:@"Content-Encoding"];
[req setValue:contentEncodingHeader forHTTPHeaderField:@"Content-Encoding"];
}

[req setHTTPBody:requestBody];
Expand Down
5 changes: 2 additions & 3 deletions Source/santasyncservice/SNTSyncState.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@
/// Array of bundle IDs to find binaries for.
@property NSArray *bundleBinaryRequests;

/// The header value for ContentEncoding when sending compressed content.
/// Either "deflate" (default) or "zlib".
@property(copy) NSString *compressedContentEncoding;
/// The content-encoding to use for the client uploads during the sync session.
@property SNTSyncContentEncoding contentEncoding;

@end
1 change: 1 addition & 0 deletions docs/deployment/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ also known as mobileconfig files, which are in an Apple-specific XML format.
| RemountUSBMode | Array | Array of strings for arguments to pass to mount -o (any of "rdonly", "noexec", "nosuid", "nobrowse", "noowners", "nodev", "async", "-j"). when forcibly remounting devices. No default. |
| FileAccessPolicyPlist | String | (BETA) Path to a file access configuration plist. |
| FileAccessPolicyUpdateIntervalSec | Integer | (BETA) Number of seconds between re-reading the file access policy config and policies/monitored paths updated. |
| SyncClientContentEncoding | String | Sets the Content-Encoding header for requests sent to the sync service. Acceptable values are "deflate", "gzip", "none" (Defaults to deflate.) |


\*overridable by the sync server: run `santactl status` to check the current
Expand Down