PageRenderTime 101ms CodeModel.GetById 16ms app.highlight 81ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1//
  2//  SignedPlistTest.m
  3//  autoinstaller
  4//
  5//  Created by Greg Miller on 7/18/08.
  6//  Copyright 2008 Google Inc. All rights reserved.
  7//
  8
  9#import <SenTestingKit/SenTestingKit.h>
 10#import "PlistSigner.h"
 11#import "Signer.h"
 12
 13
 14static unsigned char private_key_der[] = {
 150x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xf1,
 160x66, 0x86, 0xc8, 0xca, 0x65, 0xb5, 0x40, 0x31, 0x1c, 0xd1, 0x10, 0x62,
 170x46, 0xcb, 0x60, 0x01, 0xd3, 0x32, 0x80, 0xb8, 0x2f, 0x75, 0x2a, 0x46,
 180xbd, 0x42, 0xb1, 0xb6, 0xcf, 0x81, 0xd9, 0xe9, 0xb9, 0xdd, 0x02, 0xbf,
 190xf6, 0xfa, 0x6f, 0x9e, 0x06, 0x16, 0x22, 0xb8, 0x95, 0x1a, 0x53, 0xba,
 200xdb, 0x6e, 0x55, 0x66, 0x94, 0xfb, 0xe8, 0xab, 0xcd, 0xfa, 0xd2, 0x05,
 210xdf, 0xf4, 0xfd, 0x9c, 0x08, 0x3a, 0x23, 0x9c, 0xe3, 0x95, 0xc3, 0x59,
 220x17, 0xe9, 0xfb, 0xea, 0xf1, 0x6c, 0x3f, 0x42, 0xc8, 0xfb, 0xfb, 0x0e,
 230x6a, 0x6c, 0xec, 0x40, 0x0d, 0x0d, 0x1f, 0x31, 0x5c, 0xa8, 0x94, 0x7b,
 240x54, 0x0e, 0x44, 0xf0, 0x27, 0xa3, 0xb1, 0x72, 0xbb, 0x5d, 0x78, 0xd4,
 250x76, 0x05, 0x1c, 0x78, 0x9d, 0x12, 0xae, 0x37, 0xff, 0x45, 0x9f, 0x57,
 260xf9, 0x98, 0xdc, 0xd0, 0x03, 0xec, 0xa3, 0x02, 0x03, 0x01, 0x00, 0x01,
 270x02, 0x81, 0x80, 0x24, 0x5a, 0xfa, 0x85, 0x96, 0xe5, 0xc6, 0x6c, 0x4a,
 280x79, 0x3a, 0x8b, 0x2b, 0x21, 0xda, 0x53, 0x35, 0x33, 0x27, 0x71, 0xf7,
 290x4b, 0x3e, 0x6c, 0x05, 0x87, 0x4f, 0x5a, 0x10, 0x5c, 0x24, 0x04, 0x3b,
 300x8d, 0x00, 0x59, 0xff, 0xab, 0x24, 0x80, 0x56, 0xde, 0x37, 0xcb, 0x36,
 310xdd, 0x4d, 0xbf, 0xba, 0x6e, 0x7d, 0xa9, 0x62, 0xef, 0xa1, 0x18, 0xa3,
 320x77, 0x3c, 0x05, 0x11, 0x59, 0x6f, 0x3d, 0xcf, 0xb6, 0x1f, 0x54, 0x21,
 330x84, 0xbe, 0xb6, 0xbd, 0x03, 0x4c, 0x4e, 0x9d, 0x4c, 0x56, 0x4f, 0x60,
 340x81, 0xf7, 0xeb, 0x28, 0x08, 0xd3, 0xfd, 0xbe, 0x1b, 0x0b, 0xea, 0x4e,
 350x8c, 0xdd, 0x01, 0x6b, 0xbd, 0x1e, 0xae, 0xa6, 0xb1, 0x63, 0x6b, 0x9d,
 360xcf, 0xbc, 0x29, 0x59, 0xc1, 0x3e, 0xa1, 0x36, 0xe7, 0x17, 0x8f, 0x00,
 370x3c, 0xd6, 0x8c, 0x8f, 0x3b, 0xe1, 0x08, 0x57, 0xb4, 0xbc, 0x61, 0x02,
 380x41, 0x00, 0xfb, 0x1e, 0x15, 0x06, 0x51, 0xcc, 0x9b, 0x11, 0xc1, 0xcb,
 390x3a, 0xf5, 0x8a, 0x8c, 0xab, 0x86, 0xe2, 0x0e, 0x16, 0xa7, 0x7e, 0x84,
 400x2b, 0xc0, 0xf2, 0xd9, 0x49, 0x2d, 0x33, 0xde, 0x09, 0xbf, 0x01, 0xee,
 410xe3, 0x8a, 0x74, 0x19, 0xb3, 0x63, 0x79, 0x28, 0x6a, 0x55, 0xc3, 0x26,
 420x8e, 0xa7, 0xb8, 0xda, 0x40, 0x4e, 0xc9, 0x09, 0xe0, 0x38, 0xaa, 0x95,
 430xa1, 0x55, 0x37, 0x63, 0x41, 0x4b, 0x02, 0x41, 0x00, 0xf6, 0x18, 0x14,
 440x25, 0x1a, 0xb8, 0x5a, 0xba, 0x00, 0x72, 0xac, 0x61, 0xaf, 0x87, 0x77,
 450x88, 0x6c, 0xba, 0xe2, 0x7e, 0xfb, 0x6f, 0x76, 0x2b, 0x81, 0xad, 0xb8,
 460xb4, 0x8f, 0x13, 0x5b, 0x14, 0x1e, 0x7f, 0x4c, 0xf8, 0xb2, 0xba, 0xa0,
 470x21, 0xf4, 0x17, 0x97, 0xdc, 0x9f, 0xd8, 0x81, 0x3b, 0xe8, 0x29, 0xc7,
 480xc9, 0xba, 0xb3, 0x07, 0x43, 0xc5, 0x80, 0x2d, 0xfd, 0xf4, 0x50, 0x43,
 490x09, 0x02, 0x41, 0x00, 0xa2, 0xb4, 0x80, 0x0c, 0xe3, 0x2d, 0x3e, 0x00,
 500x48, 0x5f, 0x84, 0xa9, 0x19, 0x87, 0x41, 0x90, 0x18, 0xa1, 0xe6, 0x3d,
 510xca, 0x34, 0x9b, 0x20, 0xde, 0x78, 0xb8, 0xf8, 0x27, 0xd6, 0x22, 0xdc,
 520x76, 0xc5, 0x30, 0xfb, 0x41, 0x74, 0x71, 0x8d, 0xef, 0x2f, 0xa7, 0x8e,
 530x3f, 0xee, 0x98, 0x99, 0xc5, 0xa4, 0xeb, 0xeb, 0xe0, 0x48, 0x9c, 0xd6,
 540x3a, 0x78, 0xce, 0xda, 0xa7, 0x13, 0x91, 0x77, 0x02, 0x40, 0x60, 0xdd,
 550x71, 0x70, 0x79, 0x67, 0xff, 0x2e, 0x1f, 0x67, 0x03, 0xbb, 0x1f, 0xa0,
 560x2e, 0xc8, 0xa0, 0x23, 0x9f, 0x6b, 0x64, 0x04, 0xa7, 0x7a, 0xd0, 0x7c,
 570x54, 0xab, 0x9d, 0x75, 0x7c, 0xf0, 0x1a, 0x60, 0xf9, 0x27, 0x1b, 0x12,
 580xa2, 0x5d, 0x3a, 0xfa, 0xde, 0x67, 0x94, 0xf3, 0x5f, 0x4a, 0xf9, 0x43,
 590x18, 0xc4, 0xaa, 0x9c, 0x35, 0x4b, 0xd3, 0xbd, 0x74, 0x5c, 0xf5, 0x81,
 600x72, 0x21, 0x02, 0x40, 0x28, 0x37, 0x6e, 0x33, 0xfe, 0x31, 0x15, 0x7e,
 610x39, 0xa0, 0x55, 0x02, 0x33, 0x84, 0x0f, 0x25, 0xa0, 0xad, 0x27, 0xd3,
 620x47, 0x04, 0xf1, 0x62, 0x6b, 0x30, 0x7b, 0x45, 0xe7, 0x8c, 0x8c, 0xbb,
 630xb6, 0x80, 0xfb, 0xfb, 0x4d, 0x6e, 0x9e, 0x4f, 0x5c, 0x39, 0xfd, 0x6c,
 640xee, 0xfd, 0x63, 0xa0, 0x12, 0x76, 0x81, 0x4e, 0x9e, 0x94, 0x69, 0xb4,
 650x42, 0xac, 0x01, 0xdf, 0xac, 0xff, 0x39, 0x02
 66};
 67static unsigned int private_key_der_len = 608;
 68
 69
 70static unsigned char public_key_der[] = {
 710x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
 720x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81,
 730x89, 0x02, 0x81, 0x81, 0x00, 0xf1, 0x66, 0x86, 0xc8, 0xca, 0x65, 0xb5,
 740x40, 0x31, 0x1c, 0xd1, 0x10, 0x62, 0x46, 0xcb, 0x60, 0x01, 0xd3, 0x32,
 750x80, 0xb8, 0x2f, 0x75, 0x2a, 0x46, 0xbd, 0x42, 0xb1, 0xb6, 0xcf, 0x81,
 760xd9, 0xe9, 0xb9, 0xdd, 0x02, 0xbf, 0xf6, 0xfa, 0x6f, 0x9e, 0x06, 0x16,
 770x22, 0xb8, 0x95, 0x1a, 0x53, 0xba, 0xdb, 0x6e, 0x55, 0x66, 0x94, 0xfb,
 780xe8, 0xab, 0xcd, 0xfa, 0xd2, 0x05, 0xdf, 0xf4, 0xfd, 0x9c, 0x08, 0x3a,
 790x23, 0x9c, 0xe3, 0x95, 0xc3, 0x59, 0x17, 0xe9, 0xfb, 0xea, 0xf1, 0x6c,
 800x3f, 0x42, 0xc8, 0xfb, 0xfb, 0x0e, 0x6a, 0x6c, 0xec, 0x40, 0x0d, 0x0d,
 810x1f, 0x31, 0x5c, 0xa8, 0x94, 0x7b, 0x54, 0x0e, 0x44, 0xf0, 0x27, 0xa3,
 820xb1, 0x72, 0xbb, 0x5d, 0x78, 0xd4, 0x76, 0x05, 0x1c, 0x78, 0x9d, 0x12,
 830xae, 0x37, 0xff, 0x45, 0x9f, 0x57, 0xf9, 0x98, 0xdc, 0xd0, 0x03, 0xec,
 840xa3, 0x02, 0x03, 0x01, 0x00, 0x01
 85};
 86static unsigned int public_key_der_len = 162;
 87
 88
 89static NSString *const kSignedPlist = 
 90@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
 91@"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
 92@"<plist version=\"1.0\">"
 93@"<dict>"
 94@"	<key>Rules</key>"
 95@"	<array>"
 96@"		<dict>"
 97@"			<key>Codebase</key>"
 98@"			<string>http://macfuse.googlecode.com/svn/releases/MacFUSE-1.7.dmg</string>"
 99@"			<key>Hash</key>"
100@"			<string>9I5CFGd/dHClCLycl2UJlvW3LKg=</string>"
101@"			<key>Predicate</key>"
102@"			<string>1 == 1</string>"
103@"			<key>ProductID</key>"
104@"			<string>com.google.filesystems.fusefs</string>"
105@"			<key>Size</key>"
106@"			<string>1732368</string>"
107@"			<key>Version</key>"
108@"			<string>1.7.1</string>"
109@"		</dict>"
110@"	</array>"
111@"	<key>Signature</key>"
112@"	<data>"
113@"	juw5jH4IfedUlYYZI+I8D2p5V95pzwFElFVC5U3q34HpLG0gSNDvEFaPMdkhenv4Chgd"
114@"	dGBufYefSMA9qQrSkUWVXTeENAzJJ765Wt82D+ttJ6l3vAvh9GzdUe3rchJGTFnB71lZ"
115@"	ChS8nOXZRvmsS4PT+5Bx2mRq/FJQPzgadD8="
116@"	</data>"
117@"</dict>"
118@"</plist>"
119;
120
121static NSString *const kSignedTigerPlist = 
122@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
123@"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
124@"<plist version=\"1.0\">"
125@"<dict>"
126@"	<key>Rules</key>"
127@"	<array>"
128@"		<dict>"
129@"			<key>Codebase</key>"
130@"			<string>http://macfuse.googlecode.com/svn/releases/MacFUSE-1.7.dmg</string>"
131@"			<key>Hash</key>"
132@"			<string>9I5CFGd/dHClCLycl2UJlvW3LKg=</string>"
133@"			<key>Predicate</key>"
134@"			<string>1 == 1</string>"
135@"			<key>ProductID</key>"
136@"			<string>com.google.filesystems.fusefs</string>"
137@"			<key>Size</key>"
138@"			<string>1732368</string>"
139@"			<key>Version</key>"
140@"			<string>1.7.1</string>"
141@"		</dict>"
142@"	</array>"
143@"	<key>Signature</key>"
144@"	<data>"
145@"	juw5jH4IfedUlYYZI+I8D2p5V95pzwFElFVC5U3q34HpLG0gSNDvEFaPMdkhenv4Chgd"
146@"	dGBufYefSMA9qQrSkUWVXTeENAzJJ765Wt82D+ttJ6l3vAvh9GzdUe3rchJGTFnB71lZ"
147@"	ChS8nOXZRvmsS4PT+5Bx2mRq/FJQPzgadD8="
148@"	</data>"
149@"</dict>"
150@"</plist>"
151;
152
153
154@interface PlistSignerTest : SenTestCase {
155 @private
156  Signer *signer_;
157}
158@end
159
160@implementation PlistSignerTest
161
162- (void)setUp {
163  NSData *publicKey = [NSData dataWithBytes:public_key_der
164                                     length:public_key_der_len];
165  NSData *privateKey = [NSData dataWithBytes:private_key_der
166                                      length:private_key_der_len];  
167  signer_ = [[Signer alloc] initWithPublicKey:publicKey privateKey:privateKey];
168}
169
170- (void)tearDown {
171  [signer_ release];
172}
173
174- (void)testCreation {
175  PlistSigner *plistSigner = [[[PlistSigner alloc] init] autorelease];
176  STAssertNil(plistSigner, nil);
177  
178  plistSigner = [[[PlistSigner alloc] initWithSigner:nil plist:nil] autorelease];
179  STAssertNil(plistSigner, nil);
180  
181  plistSigner = [[[PlistSigner alloc] initWithSigner:signer_
182                                               plist:nil] autorelease];
183  STAssertNil(plistSigner, nil);
184  
185  plistSigner = [[[PlistSigner alloc] initWithSigner:nil
186                                               plist:[NSDictionary dictionary]] autorelease];
187  STAssertNil(plistSigner, nil);
188  
189  plistSigner = [[[PlistSigner alloc] initWithSigner:signer_
190                                               plist:[NSDictionary dictionary]] autorelease];
191  STAssertNotNil(plistSigner, nil);
192}
193
194- (void)ensureUnsignedPlist:(NSDictionary *)plist {
195  PlistSigner *plistSigner = [[[PlistSigner alloc]
196                               initWithSigner:signer_
197                                        plist:plist] autorelease];
198  STAssertNotNil(plistSigner, nil);
199  STAssertFalse([plistSigner isPlistSigned], nil);
200  STAssertTrue([plistSigner signPlist], nil);
201  STAssertTrue([plistSigner isPlistSigned], nil);
202  STAssertTrue([plistSigner unsignedPlist], nil);
203  STAssertFalse([plistSigner isPlistSigned], nil);
204  STAssertEqualObjects([plistSigner plist], plist, nil);
205}
206
207- (void)testSigningEmpty {
208  [self ensureUnsignedPlist:[NSDictionary dictionary]];
209}
210
211- (void)testSigningOneKey {
212  NSDictionary *plist = [NSDictionary dictionaryWithObject:@"foo"
213                                                    forKey:@"bar"];
214  [self ensureUnsignedPlist:plist];
215}
216
217- (void)testSigningMultipleKeys {
218  NSDictionary *plist = [NSDictionary dictionaryWithObjectsAndKeys:
219                         @"foo", @"bar",
220                         @"baz", @"quux",
221                         @"blah", @"greeble",
222                         nil];
223  [self ensureUnsignedPlist:plist];
224}
225
226- (void)testRulesPlist {
227  NSDictionary *plist = [kSignedPlist propertyList];
228  PlistSigner *plistSigner = [[[PlistSigner alloc]
229                               initWithSigner:signer_
230                               plist:plist] autorelease];
231  STAssertNotNil(plistSigner, nil);
232  STAssertTrue([plistSigner isPlistSigned], nil);
233}
234
235- (void)testTigerRulesPlist {
236  NSDictionary *plist = [kSignedTigerPlist propertyList];
237  PlistSigner *plistSigner = [[[PlistSigner alloc]
238                               initWithSigner:signer_
239                               plist:plist] autorelease];
240  STAssertNotNil(plistSigner, nil);
241  STAssertTrue([plistSigner isPlistSigned], nil);
242}
243
244@end