/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. #import <SenTestingKit/SenTestingKit.h>
  9. #import "PlistSigner.h"
  10. #import "Signer.h"
  11. static unsigned char private_key_der[] = {
  12. 0x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xf1,
  13. 0x66, 0x86, 0xc8, 0xca, 0x65, 0xb5, 0x40, 0x31, 0x1c, 0xd1, 0x10, 0x62,
  14. 0x46, 0xcb, 0x60, 0x01, 0xd3, 0x32, 0x80, 0xb8, 0x2f, 0x75, 0x2a, 0x46,
  15. 0xbd, 0x42, 0xb1, 0xb6, 0xcf, 0x81, 0xd9, 0xe9, 0xb9, 0xdd, 0x02, 0xbf,
  16. 0xf6, 0xfa, 0x6f, 0x9e, 0x06, 0x16, 0x22, 0xb8, 0x95, 0x1a, 0x53, 0xba,
  17. 0xdb, 0x6e, 0x55, 0x66, 0x94, 0xfb, 0xe8, 0xab, 0xcd, 0xfa, 0xd2, 0x05,
  18. 0xdf, 0xf4, 0xfd, 0x9c, 0x08, 0x3a, 0x23, 0x9c, 0xe3, 0x95, 0xc3, 0x59,
  19. 0x17, 0xe9, 0xfb, 0xea, 0xf1, 0x6c, 0x3f, 0x42, 0xc8, 0xfb, 0xfb, 0x0e,
  20. 0x6a, 0x6c, 0xec, 0x40, 0x0d, 0x0d, 0x1f, 0x31, 0x5c, 0xa8, 0x94, 0x7b,
  21. 0x54, 0x0e, 0x44, 0xf0, 0x27, 0xa3, 0xb1, 0x72, 0xbb, 0x5d, 0x78, 0xd4,
  22. 0x76, 0x05, 0x1c, 0x78, 0x9d, 0x12, 0xae, 0x37, 0xff, 0x45, 0x9f, 0x57,
  23. 0xf9, 0x98, 0xdc, 0xd0, 0x03, 0xec, 0xa3, 0x02, 0x03, 0x01, 0x00, 0x01,
  24. 0x02, 0x81, 0x80, 0x24, 0x5a, 0xfa, 0x85, 0x96, 0xe5, 0xc6, 0x6c, 0x4a,
  25. 0x79, 0x3a, 0x8b, 0x2b, 0x21, 0xda, 0x53, 0x35, 0x33, 0x27, 0x71, 0xf7,
  26. 0x4b, 0x3e, 0x6c, 0x05, 0x87, 0x4f, 0x5a, 0x10, 0x5c, 0x24, 0x04, 0x3b,
  27. 0x8d, 0x00, 0x59, 0xff, 0xab, 0x24, 0x80, 0x56, 0xde, 0x37, 0xcb, 0x36,
  28. 0xdd, 0x4d, 0xbf, 0xba, 0x6e, 0x7d, 0xa9, 0x62, 0xef, 0xa1, 0x18, 0xa3,
  29. 0x77, 0x3c, 0x05, 0x11, 0x59, 0x6f, 0x3d, 0xcf, 0xb6, 0x1f, 0x54, 0x21,
  30. 0x84, 0xbe, 0xb6, 0xbd, 0x03, 0x4c, 0x4e, 0x9d, 0x4c, 0x56, 0x4f, 0x60,
  31. 0x81, 0xf7, 0xeb, 0x28, 0x08, 0xd3, 0xfd, 0xbe, 0x1b, 0x0b, 0xea, 0x4e,
  32. 0x8c, 0xdd, 0x01, 0x6b, 0xbd, 0x1e, 0xae, 0xa6, 0xb1, 0x63, 0x6b, 0x9d,
  33. 0xcf, 0xbc, 0x29, 0x59, 0xc1, 0x3e, 0xa1, 0x36, 0xe7, 0x17, 0x8f, 0x00,
  34. 0x3c, 0xd6, 0x8c, 0x8f, 0x3b, 0xe1, 0x08, 0x57, 0xb4, 0xbc, 0x61, 0x02,
  35. 0x41, 0x00, 0xfb, 0x1e, 0x15, 0x06, 0x51, 0xcc, 0x9b, 0x11, 0xc1, 0xcb,
  36. 0x3a, 0xf5, 0x8a, 0x8c, 0xab, 0x86, 0xe2, 0x0e, 0x16, 0xa7, 0x7e, 0x84,
  37. 0x2b, 0xc0, 0xf2, 0xd9, 0x49, 0x2d, 0x33, 0xde, 0x09, 0xbf, 0x01, 0xee,
  38. 0xe3, 0x8a, 0x74, 0x19, 0xb3, 0x63, 0x79, 0x28, 0x6a, 0x55, 0xc3, 0x26,
  39. 0x8e, 0xa7, 0xb8, 0xda, 0x40, 0x4e, 0xc9, 0x09, 0xe0, 0x38, 0xaa, 0x95,
  40. 0xa1, 0x55, 0x37, 0x63, 0x41, 0x4b, 0x02, 0x41, 0x00, 0xf6, 0x18, 0x14,
  41. 0x25, 0x1a, 0xb8, 0x5a, 0xba, 0x00, 0x72, 0xac, 0x61, 0xaf, 0x87, 0x77,
  42. 0x88, 0x6c, 0xba, 0xe2, 0x7e, 0xfb, 0x6f, 0x76, 0x2b, 0x81, 0xad, 0xb8,
  43. 0xb4, 0x8f, 0x13, 0x5b, 0x14, 0x1e, 0x7f, 0x4c, 0xf8, 0xb2, 0xba, 0xa0,
  44. 0x21, 0xf4, 0x17, 0x97, 0xdc, 0x9f, 0xd8, 0x81, 0x3b, 0xe8, 0x29, 0xc7,
  45. 0xc9, 0xba, 0xb3, 0x07, 0x43, 0xc5, 0x80, 0x2d, 0xfd, 0xf4, 0x50, 0x43,
  46. 0x09, 0x02, 0x41, 0x00, 0xa2, 0xb4, 0x80, 0x0c, 0xe3, 0x2d, 0x3e, 0x00,
  47. 0x48, 0x5f, 0x84, 0xa9, 0x19, 0x87, 0x41, 0x90, 0x18, 0xa1, 0xe6, 0x3d,
  48. 0xca, 0x34, 0x9b, 0x20, 0xde, 0x78, 0xb8, 0xf8, 0x27, 0xd6, 0x22, 0xdc,
  49. 0x76, 0xc5, 0x30, 0xfb, 0x41, 0x74, 0x71, 0x8d, 0xef, 0x2f, 0xa7, 0x8e,
  50. 0x3f, 0xee, 0x98, 0x99, 0xc5, 0xa4, 0xeb, 0xeb, 0xe0, 0x48, 0x9c, 0xd6,
  51. 0x3a, 0x78, 0xce, 0xda, 0xa7, 0x13, 0x91, 0x77, 0x02, 0x40, 0x60, 0xdd,
  52. 0x71, 0x70, 0x79, 0x67, 0xff, 0x2e, 0x1f, 0x67, 0x03, 0xbb, 0x1f, 0xa0,
  53. 0x2e, 0xc8, 0xa0, 0x23, 0x9f, 0x6b, 0x64, 0x04, 0xa7, 0x7a, 0xd0, 0x7c,
  54. 0x54, 0xab, 0x9d, 0x75, 0x7c, 0xf0, 0x1a, 0x60, 0xf9, 0x27, 0x1b, 0x12,
  55. 0xa2, 0x5d, 0x3a, 0xfa, 0xde, 0x67, 0x94, 0xf3, 0x5f, 0x4a, 0xf9, 0x43,
  56. 0x18, 0xc4, 0xaa, 0x9c, 0x35, 0x4b, 0xd3, 0xbd, 0x74, 0x5c, 0xf5, 0x81,
  57. 0x72, 0x21, 0x02, 0x40, 0x28, 0x37, 0x6e, 0x33, 0xfe, 0x31, 0x15, 0x7e,
  58. 0x39, 0xa0, 0x55, 0x02, 0x33, 0x84, 0x0f, 0x25, 0xa0, 0xad, 0x27, 0xd3,
  59. 0x47, 0x04, 0xf1, 0x62, 0x6b, 0x30, 0x7b, 0x45, 0xe7, 0x8c, 0x8c, 0xbb,
  60. 0xb6, 0x80, 0xfb, 0xfb, 0x4d, 0x6e, 0x9e, 0x4f, 0x5c, 0x39, 0xfd, 0x6c,
  61. 0xee, 0xfd, 0x63, 0xa0, 0x12, 0x76, 0x81, 0x4e, 0x9e, 0x94, 0x69, 0xb4,
  62. 0x42, 0xac, 0x01, 0xdf, 0xac, 0xff, 0x39, 0x02
  63. };
  64. static unsigned int private_key_der_len = 608;
  65. static unsigned char public_key_der[] = {
  66. 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
  67. 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81,
  68. 0x89, 0x02, 0x81, 0x81, 0x00, 0xf1, 0x66, 0x86, 0xc8, 0xca, 0x65, 0xb5,
  69. 0x40, 0x31, 0x1c, 0xd1, 0x10, 0x62, 0x46, 0xcb, 0x60, 0x01, 0xd3, 0x32,
  70. 0x80, 0xb8, 0x2f, 0x75, 0x2a, 0x46, 0xbd, 0x42, 0xb1, 0xb6, 0xcf, 0x81,
  71. 0xd9, 0xe9, 0xb9, 0xdd, 0x02, 0xbf, 0xf6, 0xfa, 0x6f, 0x9e, 0x06, 0x16,
  72. 0x22, 0xb8, 0x95, 0x1a, 0x53, 0xba, 0xdb, 0x6e, 0x55, 0x66, 0x94, 0xfb,
  73. 0xe8, 0xab, 0xcd, 0xfa, 0xd2, 0x05, 0xdf, 0xf4, 0xfd, 0x9c, 0x08, 0x3a,
  74. 0x23, 0x9c, 0xe3, 0x95, 0xc3, 0x59, 0x17, 0xe9, 0xfb, 0xea, 0xf1, 0x6c,
  75. 0x3f, 0x42, 0xc8, 0xfb, 0xfb, 0x0e, 0x6a, 0x6c, 0xec, 0x40, 0x0d, 0x0d,
  76. 0x1f, 0x31, 0x5c, 0xa8, 0x94, 0x7b, 0x54, 0x0e, 0x44, 0xf0, 0x27, 0xa3,
  77. 0xb1, 0x72, 0xbb, 0x5d, 0x78, 0xd4, 0x76, 0x05, 0x1c, 0x78, 0x9d, 0x12,
  78. 0xae, 0x37, 0xff, 0x45, 0x9f, 0x57, 0xf9, 0x98, 0xdc, 0xd0, 0x03, 0xec,
  79. 0xa3, 0x02, 0x03, 0x01, 0x00, 0x01
  80. };
  81. static unsigned int public_key_der_len = 162;
  82. static NSString *const kSignedPlist =
  83. @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  84. @"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
  85. @"<plist version=\"1.0\">"
  86. @"<dict>"
  87. @" <key>Rules</key>"
  88. @" <array>"
  89. @" <dict>"
  90. @" <key>Codebase</key>"
  91. @" <string>http://macfuse.googlecode.com/svn/releases/MacFUSE-1.7.dmg</string>"
  92. @" <key>Hash</key>"
  93. @" <string>9I5CFGd/dHClCLycl2UJlvW3LKg=</string>"
  94. @" <key>Predicate</key>"
  95. @" <string>1 == 1</string>"
  96. @" <key>ProductID</key>"
  97. @" <string>com.google.filesystems.fusefs</string>"
  98. @" <key>Size</key>"
  99. @" <string>1732368</string>"
  100. @" <key>Version</key>"
  101. @" <string>1.7.1</string>"
  102. @" </dict>"
  103. @" </array>"
  104. @" <key>Signature</key>"
  105. @" <data>"
  106. @" juw5jH4IfedUlYYZI+I8D2p5V95pzwFElFVC5U3q34HpLG0gSNDvEFaPMdkhenv4Chgd"
  107. @" dGBufYefSMA9qQrSkUWVXTeENAzJJ765Wt82D+ttJ6l3vAvh9GzdUe3rchJGTFnB71lZ"
  108. @" ChS8nOXZRvmsS4PT+5Bx2mRq/FJQPzgadD8="
  109. @" </data>"
  110. @"</dict>"
  111. @"</plist>"
  112. ;
  113. static NSString *const kSignedTigerPlist =
  114. @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  115. @"<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
  116. @"<plist version=\"1.0\">"
  117. @"<dict>"
  118. @" <key>Rules</key>"
  119. @" <array>"
  120. @" <dict>"
  121. @" <key>Codebase</key>"
  122. @" <string>http://macfuse.googlecode.com/svn/releases/MacFUSE-1.7.dmg</string>"
  123. @" <key>Hash</key>"
  124. @" <string>9I5CFGd/dHClCLycl2UJlvW3LKg=</string>"
  125. @" <key>Predicate</key>"
  126. @" <string>1 == 1</string>"
  127. @" <key>ProductID</key>"
  128. @" <string>com.google.filesystems.fusefs</string>"
  129. @" <key>Size</key>"
  130. @" <string>1732368</string>"
  131. @" <key>Version</key>"
  132. @" <string>1.7.1</string>"
  133. @" </dict>"
  134. @" </array>"
  135. @" <key>Signature</key>"
  136. @" <data>"
  137. @" juw5jH4IfedUlYYZI+I8D2p5V95pzwFElFVC5U3q34HpLG0gSNDvEFaPMdkhenv4Chgd"
  138. @" dGBufYefSMA9qQrSkUWVXTeENAzJJ765Wt82D+ttJ6l3vAvh9GzdUe3rchJGTFnB71lZ"
  139. @" ChS8nOXZRvmsS4PT+5Bx2mRq/FJQPzgadD8="
  140. @" </data>"
  141. @"</dict>"
  142. @"</plist>"
  143. ;
  144. @interface PlistSignerTest : SenTestCase {
  145. @private
  146. Signer *signer_;
  147. }
  148. @end
  149. @implementation PlistSignerTest
  150. - (void)setUp {
  151. NSData *publicKey = [NSData dataWithBytes:public_key_der
  152. length:public_key_der_len];
  153. NSData *privateKey = [NSData dataWithBytes:private_key_der
  154. length:private_key_der_len];
  155. signer_ = [[Signer alloc] initWithPublicKey:publicKey privateKey:privateKey];
  156. }
  157. - (void)tearDown {
  158. [signer_ release];
  159. }
  160. - (void)testCreation {
  161. PlistSigner *plistSigner = [[[PlistSigner alloc] init] autorelease];
  162. STAssertNil(plistSigner, nil);
  163. plistSigner = [[[PlistSigner alloc] initWithSigner:nil plist:nil] autorelease];
  164. STAssertNil(plistSigner, nil);
  165. plistSigner = [[[PlistSigner alloc] initWithSigner:signer_
  166. plist:nil] autorelease];
  167. STAssertNil(plistSigner, nil);
  168. plistSigner = [[[PlistSigner alloc] initWithSigner:nil
  169. plist:[NSDictionary dictionary]] autorelease];
  170. STAssertNil(plistSigner, nil);
  171. plistSigner = [[[PlistSigner alloc] initWithSigner:signer_
  172. plist:[NSDictionary dictionary]] autorelease];
  173. STAssertNotNil(plistSigner, nil);
  174. }
  175. - (void)ensureUnsignedPlist:(NSDictionary *)plist {
  176. PlistSigner *plistSigner = [[[PlistSigner alloc]
  177. initWithSigner:signer_
  178. plist:plist] autorelease];
  179. STAssertNotNil(plistSigner, nil);
  180. STAssertFalse([plistSigner isPlistSigned], nil);
  181. STAssertTrue([plistSigner signPlist], nil);
  182. STAssertTrue([plistSigner isPlistSigned], nil);
  183. STAssertTrue([plistSigner unsignedPlist], nil);
  184. STAssertFalse([plistSigner isPlistSigned], nil);
  185. STAssertEqualObjects([plistSigner plist], plist, nil);
  186. }
  187. - (void)testSigningEmpty {
  188. [self ensureUnsignedPlist:[NSDictionary dictionary]];
  189. }
  190. - (void)testSigningOneKey {
  191. NSDictionary *plist = [NSDictionary dictionaryWithObject:@"foo"
  192. forKey:@"bar"];
  193. [self ensureUnsignedPlist:plist];
  194. }
  195. - (void)testSigningMultipleKeys {
  196. NSDictionary *plist = [NSDictionary dictionaryWithObjectsAndKeys:
  197. @"foo", @"bar",
  198. @"baz", @"quux",
  199. @"blah", @"greeble",
  200. nil];
  201. [self ensureUnsignedPlist:plist];
  202. }
  203. - (void)testRulesPlist {
  204. NSDictionary *plist = [kSignedPlist propertyList];
  205. PlistSigner *plistSigner = [[[PlistSigner alloc]
  206. initWithSigner:signer_
  207. plist:plist] autorelease];
  208. STAssertNotNil(plistSigner, nil);
  209. STAssertTrue([plistSigner isPlistSigned], nil);
  210. }
  211. - (void)testTigerRulesPlist {
  212. NSDictionary *plist = [kSignedTigerPlist propertyList];
  213. PlistSigner *plistSigner = [[[PlistSigner alloc]
  214. initWithSigner:signer_
  215. plist:plist] autorelease];
  216. STAssertNotNil(plistSigner, nil);
  217. STAssertTrue([plistSigner isPlistSigned], nil);
  218. }
  219. @end