Add tests for aborting on code signed xattr's

This commit is contained in:
Zorg committed 2015-05-05 22:04:18 -04:00
1 parent 4dd4548be4
commit 61d43f860a
3 files changed
+46 -3

No files matched your search

+4
View File
@@ -16,6 +16,10 @@
#define IS_VALID_PERMISSIONS(mode) \
(((mode & PERMISSION_FLAGS) == 0755) || ((mode & PERMISSION_FLAGS) == 0644))
#define APPLE_CODE_SIGN_XATTR_CODE_DIRECTORY_KEY "com.apple.cs.CodeDirectory"
#define APPLE_CODE_SIGN_XATTR_CODE_REQUIREMENTS_KEY "com.apple.cs.CodeRequirements"
#define APPLE_CODE_SIGN_XATTR_CODE_SIGNATURE_KEY "com.apple.cs.CodeSignature"
#define BINARY_DELTA_ATTRIBUTES_KEY "binary-delta-attributes"
#define MAJOR_DIFF_VERSION_KEY "major-version"
#define MINOR_DIFF_VERSION_KEY "minor-version"
+3 -3
View File
@@ -121,9 +121,9 @@ static bool codeSignatureExtendedAttributeExists(const FTSENT *ent)
if (buffer[characterIndex] == '\0') {
char *attribute = &buffer[startCharacterIndex];
size_t length = characterIndex - startCharacterIndex;
if (strncmp("com.apple.cs.CodeDirectory", attribute, length) == 0 ||
strncmp("com.apple.cs.CodeRequirements", attribute, length) == 0 ||
strncmp("com.apple.cs.CodeSignature", attribute, length) == 0) {
if (strncmp(APPLE_CODE_SIGN_XATTR_CODE_DIRECTORY_KEY, attribute, length) == 0 ||
strncmp(APPLE_CODE_SIGN_XATTR_CODE_REQUIREMENTS_KEY, attribute, length) == 0 ||
strncmp(APPLE_CODE_SIGN_XATTR_CODE_SIGNATURE_KEY, attribute, length) == 0) {
free(buffer);
return true;
}
+39
View File
@@ -12,6 +12,7 @@
#import "SUBinaryDeltaCreate.h"
#import "SUBinaryDeltaApply.h"
#import <sys/stat.h>
#include <sys/xattr.h>
@interface SUBinaryDeltaTest : XCTestCase
@@ -930,4 +931,42 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
}];
}
- (void)testInvalidCodeSignatureExtendedAttributeInBeforeTree
{
BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]);
XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]);
// the actual data doesn't matter for testing purposes
const char xattrValue[] = "hello";
XCTAssertEqual(0, setxattr([sourceFile fileSystemRepresentation], APPLE_CODE_SIGN_XATTR_CODE_DIRECTORY_KEY, xattrValue, sizeof(xattrValue), 0, XATTR_CREATE));
XCTAssertEqual(0, setxattr([sourceFile fileSystemRepresentation], APPLE_CODE_SIGN_XATTR_CODE_REQUIREMENTS_KEY, xattrValue, sizeof(xattrValue), 0, XATTR_CREATE));
XCTAssertEqual(0, setxattr([sourceFile fileSystemRepresentation], APPLE_CODE_SIGN_XATTR_CODE_SIGNATURE_KEY, xattrValue, sizeof(xattrValue), 0, XATTR_CREATE));
} afterDiffHandler:nil];
XCTAssertFalse(success);
}
- (void)testInvalidCodeSignatureExtendedAttributeInAfterTree
{
BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]);
XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]);
// the actual data doesn't matter for testing purposes
const char xattrValue[] = "hello";
XCTAssertEqual(0, setxattr([destinationFile fileSystemRepresentation], APPLE_CODE_SIGN_XATTR_CODE_DIRECTORY_KEY, xattrValue, sizeof(xattrValue), 0, XATTR_CREATE));
XCTAssertEqual(0, setxattr([destinationFile fileSystemRepresentation], APPLE_CODE_SIGN_XATTR_CODE_REQUIREMENTS_KEY, xattrValue, sizeof(xattrValue), 0, XATTR_CREATE));
XCTAssertEqual(0, setxattr([destinationFile fileSystemRepresentation], APPLE_CODE_SIGN_XATTR_CODE_SIGNATURE_KEY, xattrValue, sizeof(xattrValue), 0, XATTR_CREATE));
} afterDiffHandler:nil];
XCTAssertFalse(success);
}
@end