/core/autoinstaller/UpdateEngineExtensions/PlistSignerTest.m
http://macfuse.googlecode.com/ · Objective C · 244 lines · 212 code · 25 blank · 7 comment · 0 complexity · 52972df79fa21edf26cd52275cf41d37 MD5 · raw file
- //
- // SignedPlistTest.m
- // autoinstaller
- //
- // Created by Greg Miller on 7/18/08.
- // Copyright 2008 Google Inc. All rights reserved.
- //
- #import <SenTestingKit/SenTestingKit.h>
- #import "PlistSigner.h"
- #import "Signer.h"
- static unsigned char private_key_der[] = {
- 0x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xf1,
- 0x66, 0x86, 0xc8, 0xca, 0x65, 0xb5, 0x40, 0x31, 0x1c, 0xd1, 0x10, 0x62,
- 0x46, 0xcb, 0x60, 0x01, 0xd3, 0x32, 0x80, 0xb8, 0x2f, 0x75, 0x2a, 0x46,
- 0xbd, 0x42, 0xb1, 0xb6, 0xcf, 0x81, 0xd9, 0xe9, 0xb9, 0xdd, 0x02, 0xbf,
- 0xf6, 0xfa, 0x6f, 0x9e, 0x06, 0x16, 0x22, 0xb8, 0x95, 0x1a, 0x53, 0xba,
- 0xdb, 0x6e, 0x55, 0x66, 0x94, 0xfb, 0xe8, 0xab, 0xcd, 0xfa, 0xd2, 0x05,
- 0xdf, 0xf4, 0xfd, 0x9c, 0x08, 0x3a, 0x23, 0x9c, 0xe3, 0x95, 0xc3, 0x59,
- 0x17, 0xe9, 0xfb, 0xea, 0xf1, 0x6c, 0x3f, 0x42, 0xc8, 0xfb, 0xfb, 0x0e,
- 0x6a, 0x6c, 0xec, 0x40, 0x0d, 0x0d, 0x1f, 0x31, 0x5c, 0xa8, 0x94, 0x7b,
- 0x54, 0x0e, 0x44, 0xf0, 0x27, 0xa3, 0xb1, 0x72, 0xbb, 0x5d, 0x78, 0xd4,
- 0x76, 0x05, 0x1c, 0x78, 0x9d, 0x12, 0xae, 0x37, 0xff, 0x45, 0x9f, 0x57,
- 0xf9, 0x98, 0xdc, 0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0x9f, 0x6b, 0x64, 0x04, 0xa7, 0x7a, 0xd0, 0x7c,
- 0x54, 0xab, 0x9d, 0x75, 0x7c, 0xf0, 0x1a, 0x60, 0xf9, 0x27, 0x1b, 0x12,
- 0xa2, 0x5d, 0x3a, 0xfa, 0xde, 0x67, 0x94, 0xf3, 0x5f, 0x4a, 0xf9, 0x43,
- 0x18, 0xc4, 0xaa, 0x9c, 0x35, 0x4b, 0xd3, 0xbd, 0x74, 0x5c, 0xf5, 0x81,
- 0x72, 0x21, 0x02, 0x40, 0x28, 0x37, 0x6e, 0x33, 0xfe, 0x31, 0x15, 0x7e,
- 0x39, 0xa0, 0x55, 0x02, 0x33, 0x84, 0x0f, 0x25, 0xa0, 0xad, 0x27, 0xd3,
- 0x47, 0x04, 0xf1, 0x62, 0x6b, 0x30, 0x7b, 0x45, 0xe7, 0x8c, 0x8c, 0xbb,
- 0xb6, 0x80, 0xfb, 0xfb, 0x4d, 0x6e, 0x9e, 0x4f, 0x5c, 0x39, 0xfd, 0x6c,
- 0xee, 0xfd, 0x63, 0xa0, 0x12, 0x76, 0x81, 0x4e, 0x9e, 0x94, 0x69, 0xb4,
- 0x42, 0xac, 0x01, 0xdf, 0xac, 0xff, 0x39, 0x02
- };
- static unsigned int private_key_der_len = 608;
- static unsigned char public_key_der[] = {
- 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
- 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81,
- 0x89, 0x02, 0x81, 0x81, 0x00, 0xf1, 0x66, 0x86, 0xc8, 0xca, 0x65, 0xb5,
- 0x40, 0x31, 0x1c, 0xd1, 0x10, 0x62, 0x46, 0xcb, 0x60, 0x01, 0xd3, 0x32,
- 0x80, 0xb8, 0x2f, 0x75, 0x2a, 0x46, 0xbd, 0x42, 0xb1, 0xb6, 0xcf, 0x81,
- 0xd9, 0xe9, 0xb9, 0xdd, 0x02, 0xbf, 0xf6, 0xfa, 0x6f, 0x9e, 0x06, 0x16,
- 0x22, 0xb8, 0x95, 0x1a, 0x53, 0xba, 0xdb, 0x6e, 0x55, 0x66, 0x94, 0xfb,
- 0xe8, 0xab, 0xcd, 0xfa, 0xd2, 0x05, 0xdf, 0xf4, 0xfd, 0x9c, 0x08, 0x3a,
- 0x23, 0x9c, 0xe3, 0x95, 0xc3, 0x59, 0x17, 0xe9, 0xfb, 0xea, 0xf1, 0x6c,
- 0x3f, 0x42, 0xc8, 0xfb, 0xfb, 0x0e, 0x6a, 0x6c, 0xec, 0x40, 0x0d, 0x0d,
- 0x1f, 0x31, 0x5c, 0xa8, 0x94, 0x7b, 0x54, 0x0e, 0x44, 0xf0, 0x27, 0xa3,
- 0xb1, 0x72, 0xbb, 0x5d, 0x78, 0xd4, 0x76, 0x05, 0x1c, 0x78, 0x9d, 0x12,
- 0xae, 0x37, 0xff, 0x45, 0x9f, 0x57, 0xf9, 0x98, 0xdc, 0xd0, 0x03, 0xec,
- 0xa3, 0x02, 0x03, 0x01, 0x00, 0x01
- };
- static unsigned int public_key_der_len = 162;
- static NSString *const kSignedPlist =
- @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- @"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
- @"<plist version=\"1.0\">"
- @"<dict>"
- @" <key>Rules</key>"
- @" <array>"
- @" <dict>"
- @" <key>Codebase</key>"
- @" <string>http://macfuse.googlecode.com/svn/releases/MacFUSE-1.7.dmg</string>"
- @" <key>Hash</key>"
- @" <string>9I5CFGd/dHClCLycl2UJlvW3LKg=</string>"
- @" <key>Predicate</key>"
- @" <string>1 == 1</string>"
- @" <key>ProductID</key>"
- @" <string>com.google.filesystems.fusefs</string>"
- @" <key>Size</key>"
- @" <string>1732368</string>"
- @" <key>Version</key>"
- @" <string>1.7.1</string>"
- @" </dict>"
- @" </array>"
- @" <key>Signature</key>"
- @" <data>"
- @" juw5jH4IfedUlYYZI+I8D2p5V95pzwFElFVC5U3q34HpLG0gSNDvEFaPMdkhenv4Chgd"
- @" dGBufYefSMA9qQrSkUWVXTeENAzJJ765Wt82D+ttJ6l3vAvh9GzdUe3rchJGTFnB71lZ"
- @" ChS8nOXZRvmsS4PT+5Bx2mRq/FJQPzgadD8="
- @" </data>"
- @"</dict>"
- @"</plist>"
- ;
- static NSString *const kSignedTigerPlist =
- @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- @"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
- @"<plist version=\"1.0\">"
- @"<dict>"
- @" <key>Rules</key>"
- @" <array>"
- @" <dict>"
- @" <key>Codebase</key>"
- @" <string>http://macfuse.googlecode.com/svn/releases/MacFUSE-1.7.dmg</string>"
- @" <key>Hash</key>"
- @" <string>9I5CFGd/dHClCLycl2UJlvW3LKg=</string>"
- @" <key>Predicate</key>"
- @" <string>1 == 1</string>"
- @" <key>ProductID</key>"
- @" <string>com.google.filesystems.fusefs</string>"
- @" <key>Size</key>"
- @" <string>1732368</string>"
- @" <key>Version</key>"
- @" <string>1.7.1</string>"
- @" </dict>"
- @" </array>"
- @" <key>Signature</key>"
- @" <data>"
- @" juw5jH4IfedUlYYZI+I8D2p5V95pzwFElFVC5U3q34HpLG0gSNDvEFaPMdkhenv4Chgd"
- @" dGBufYefSMA9qQrSkUWVXTeENAzJJ765Wt82D+ttJ6l3vAvh9GzdUe3rchJGTFnB71lZ"
- @" ChS8nOXZRvmsS4PT+5Bx2mRq/FJQPzgadD8="
- @" </data>"
- @"</dict>"
- @"</plist>"
- ;
- @interface PlistSignerTest : SenTestCase {
- @private
- Signer *signer_;
- }
- @end
- @implementation PlistSignerTest
- - (void)setUp {
- NSData *publicKey = [NSData dataWithBytes:public_key_der
- length:public_key_der_len];
- NSData *privateKey = [NSData dataWithBytes:private_key_der
- length:private_key_der_len];
- signer_ = [[Signer alloc] initWithPublicKey:publicKey privateKey:privateKey];
- }
- - (void)tearDown {
- [signer_ release];
- }
- - (void)testCreation {
- PlistSigner *plistSigner = [[[PlistSigner alloc] init] autorelease];
- STAssertNil(plistSigner, nil);
-
- plistSigner = [[[PlistSigner alloc] initWithSigner:nil plist:nil] autorelease];
- STAssertNil(plistSigner, nil);
-
- plistSigner = [[[PlistSigner alloc] initWithSigner:signer_
- plist:nil] autorelease];
- STAssertNil(plistSigner, nil);
-
- plistSigner = [[[PlistSigner alloc] initWithSigner:nil
- plist:[NSDictionary dictionary]] autorelease];
- STAssertNil(plistSigner, nil);
-
- plistSigner = [[[PlistSigner alloc] initWithSigner:signer_
- plist:[NSDictionary dictionary]] autorelease];
- STAssertNotNil(plistSigner, nil);
- }
- - (void)ensureUnsignedPlist:(NSDictionary *)plist {
- PlistSigner *plistSigner = [[[PlistSigner alloc]
- initWithSigner:signer_
- plist:plist] autorelease];
- STAssertNotNil(plistSigner, nil);
- STAssertFalse([plistSigner isPlistSigned], nil);
- STAssertTrue([plistSigner signPlist], nil);
- STAssertTrue([plistSigner isPlistSigned], nil);
- STAssertTrue([plistSigner unsignedPlist], nil);
- STAssertFalse([plistSigner isPlistSigned], nil);
- STAssertEqualObjects([plistSigner plist], plist, nil);
- }
- - (void)testSigningEmpty {
- [self ensureUnsignedPlist:[NSDictionary dictionary]];
- }
- - (void)testSigningOneKey {
- NSDictionary *plist = [NSDictionary dictionaryWithObject:@"foo"
- forKey:@"bar"];
- [self ensureUnsignedPlist:plist];
- }
- - (void)testSigningMultipleKeys {
- NSDictionary *plist = [NSDictionary dictionaryWithObjectsAndKeys:
- @"foo", @"bar",
- @"baz", @"quux",
- @"blah", @"greeble",
- nil];
- [self ensureUnsignedPlist:plist];
- }
- - (void)testRulesPlist {
- NSDictionary *plist = [kSignedPlist propertyList];
- PlistSigner *plistSigner = [[[PlistSigner alloc]
- initWithSigner:signer_
- plist:plist] autorelease];
- STAssertNotNil(plistSigner, nil);
- STAssertTrue([plistSigner isPlistSigned], nil);
- }
- - (void)testTigerRulesPlist {
- NSDictionary *plist = [kSignedTigerPlist propertyList];
- PlistSigner *plistSigner = [[[PlistSigner alloc]
- initWithSigner:signer_
- plist:plist] autorelease];
- STAssertNotNil(plistSigner, nil);
- STAssertTrue([plistSigner isPlistSigned], nil);
- }
- @end