-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add transitive whitelisting to Santa #224
Changes from 25 commits
8f972eb
48b656d
1a9d07b
0d77a2c
a594175
881322f
7a32d31
0f9d63a
163ac9b
47a981e
16092cd
0b106e4
9c4c7fa
6348fd1
04d8f41
fef9351
0e840d2
c4b47e1
43ce8aa
83649ee
079a6d3
dc10e23
d35f0b5
6cb4ad5
aa01a79
a08e7f8
88b0972
0cb3d6a
1cd9551
8f82370
1b687a1
d2df097
340f59d
b9c7585
c293d5d
a9201dd
91c5d71
e583712
75de096
6d295c9
ca00a28
e0bf6dd
16769e8
93a7e86
bba1aee
21561ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,17 +19,37 @@ @implementation SNTRule | |
- (instancetype)initWithShasum:(NSString *)shasum | ||
state:(SNTRuleState)state | ||
type:(SNTRuleType)type | ||
customMsg:(NSString *)customMsg { | ||
customMsg:(NSString *)customMsg | ||
timestamp:(NSUInteger)timestamp { | ||
self = [super init]; | ||
if (self) { | ||
_shasum = shasum; | ||
_state = state; | ||
_type = type; | ||
_customMsg = customMsg; | ||
_timestamp = timestamp; | ||
} | ||
return self; | ||
} | ||
|
||
- (instancetype)initWithShasum:(NSString *)shasum | ||
state:(SNTRuleState)state | ||
type:(SNTRuleType)type | ||
customMsg:(NSString *)customMsg { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra new line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
self = [self initWithShasum:shasum | ||
state:state | ||
type:type | ||
customMsg:customMsg | ||
timestamp:0]; | ||
// Initialize timestamp to current time if rule is transitive. | ||
if (self && state == SNTRuleStateWhitelistTransitive) { | ||
[self resetTimestamp]; | ||
} | ||
return self; | ||
} | ||
|
||
|
||
#pragma mark NSSecureCoding | ||
|
||
#define ENCODE(obj, key) if (obj) [coder encodeObject:obj forKey:key] | ||
|
@@ -44,6 +64,7 @@ - (void)encodeWithCoder:(NSCoder *)coder { | |
ENCODE(@(self.state), @"state"); | ||
ENCODE(@(self.type), @"type"); | ||
ENCODE(self.customMsg, @"custommsg"); | ||
ENCODE(@(self.timestamp), @"timestamp"); | ||
} | ||
|
||
- (instancetype)initWithCoder:(NSCoder *)decoder { | ||
|
@@ -53,6 +74,7 @@ - (instancetype)initWithCoder:(NSCoder *)decoder { | |
_state = [DECODE(NSNumber, @"state") intValue]; | ||
_type = [DECODE(NSNumber, @"type") intValue]; | ||
_customMsg = DECODE(NSString, @"custommsg"); | ||
_timestamp = [DECODE(NSNumber, @"timestamp") unsignedIntegerValue]; | ||
} | ||
return self; | ||
} | ||
|
@@ -64,7 +86,9 @@ - (BOOL)isEqual:(id)other { | |
if (other == self) return YES; | ||
if (![other isKindOfClass:[SNTRule class]]) return NO; | ||
SNTRule *o = other; | ||
return ([self.shasum isEqual:o.shasum] && self.state == o.state && self.type == o.type); | ||
return ([self.shasum isEqual:o.shasum] && | ||
self.state == o.state && | ||
self.type == o.type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these conditions should fit back on one line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
|
||
- (NSUInteger)hash { | ||
|
@@ -73,12 +97,19 @@ - (NSUInteger)hash { | |
result = prime * result + [self.shasum hash]; | ||
result = prime * result + self.state; | ||
result = prime * result + self.type; | ||
result = prime * result + self.timestamp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are not using the timestamp in isEqual we probably shouldn't use it here either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, forgot to remove this. |
||
return result; | ||
} | ||
|
||
- (NSString *)description { | ||
return [NSString stringWithFormat:@"SNTRule: SHA-256: %@, State: %ld, Type: %ld", | ||
self.shasum, self.state, self.type]; | ||
return [NSString stringWithFormat:@"SNTRule: SHA-256: %@, State: %ld, Type: %ld, Timestamp: %lu", | ||
self.shasum, self.state, self.type, (unsigned long)self.timestamp]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indent +3 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
|
||
# pragma mark Last-access Timestamp | ||
|
||
- (void)resetTimestamp { | ||
_timestamp = (NSUInteger)[[NSDate date] timeIntervalSinceReferenceDate]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is not an initialization method properties should be accessed using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There doesn't seem to be any corresponding keys in the .m for this, so it's not configurable in a mobileconfig or persisted between runs from a sync server. I think it should probably be one of those keys that can be configured with a mobileconfig but can be overridden by a server, so you'll need to add a key constant and add it to both the arrays in init.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. added key to both with a DEBUG guard around the syncServerKeys entry to be removed when the sync server supports it.