Skip to content

Commit

Permalink
santactl sync: add config option to enable legacy zlib content encodi…
Browse files Browse the repository at this point in the history
…ng (#522)
  • Loading branch information
tburgin authored Dec 23, 2020
1 parent 532cb37 commit 01e4e15
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Source/common/SNTConfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@
///
@property(readonly, nonatomic) BOOL enableDebugLogging;

///
/// If true, compressed requests from "santactl sync" will set "Content-Encoding" to "zlib"
/// instead of the new default "deflate". If syncing with Upvote deployed at commit 0b4477d
/// or below, set this option to true.
/// Defaults to false.
///
@property(readonly, nonatomic) BOOL enableBackwardsCompatibleContentEncoding;

///
/// Retrieve an initialized singleton configurator object using the default file path.
///
Expand Down
12 changes: 12 additions & 0 deletions Source/common/SNTConfigurator.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ @implementation SNTConfigurator
static NSString *const kIgnoreOtherEndpointSecurityClients = @"IgnoreOtherEndpointSecurityClients";
static NSString *const kEnableDebugLogging = @"EnableDebugLogging";

static NSString *const kEnableBackwardsCompatibleContentEncoding = @"EnableBackwardsCompatibleContentEncoding";

// The keys managed by a sync server or mobileconfig.
static NSString *const kClientModeKey = @"ClientMode";
static NSString *const kEnableTransitiveRulesKey = @"EnableTransitiveRules";
Expand Down Expand Up @@ -158,6 +160,7 @@ - (instancetype)init {
kEnableForkAndExitLogging : number,
kIgnoreOtherEndpointSecurityClients : number,
kEnableDebugLogging : number,
kEnableBackwardsCompatibleContentEncoding : number,
};
_defaults = [NSUserDefaults standardUserDefaults];
[_defaults addSuiteNamed:@"com.google.santa"];
Expand Down Expand Up @@ -341,6 +344,10 @@ + (NSSet *)keyPathsForValuesAffectingEnableDebugLogging {
return [self configStateSet];
}

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

#pragma mark Public Interface

- (SNTClientMode)clientMode {
Expand Down Expand Up @@ -591,6 +598,11 @@ - (BOOL)enableDebugLogging {
return [number boolValue] || self.debugFlag;
}

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

#pragma mark Private

///
Expand Down
3 changes: 3 additions & 0 deletions Source/santactl/Commands/sync/SNTCommandSyncManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ - (SNTCommandSyncState *)createSyncState {
syncState.daemonConn = self.daemonConn;
syncState.daemon = self.daemon;

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

dispatch_group_wait(group, dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC));
return syncState;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/santactl/Commands/sync/SNTCommandSyncStage.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ - (NSMutableURLRequest *)requestWithDictionary:(NSDictionary *)dictionary {
NSData *compressed = [requestBody zlibCompressed];
if (compressed) {
requestBody = compressed;
[req setValue:@"deflate" forHTTPHeaderField:@"Content-Encoding"];
[req setValue:self.syncState.compressedContentEncoding forHTTPHeaderField:@"Content-Encoding"];
}

[req setHTTPBody:requestBody];
Expand Down
4 changes: 4 additions & 0 deletions Source/santactl/Commands/sync/SNTCommandSyncState.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@
/// Reference to the serial operation queue used for accessing allowlistNotifications.
@property(weak) NSOperationQueue *allowlistNotificationQueue;

/// The header value for ContentEncoding when sending compressed content.
/// Either "deflate" (default) or "zlib".
@property(copy) NSString *compressedContentEncoding;

@end
2 changes: 1 addition & 1 deletion version.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""The version for all Santa components."""

SANTA_VERSION = "1.16"
SANTA_VERSION = "1.17"

0 comments on commit 01e4e15

Please sign in to comment.