/core/autoinstaller/UpdateEngineExtensions/SignedPlistServer.m

http://macfuse.googlecode.com/ · Objective C · 91 lines · 66 code · 13 blank · 12 comment · 4 complexity · 43ecd0304066a368e8d722e95f678468 MD5 · raw file

  1. //
  2. // SignedPlistServer.m
  3. // autoinstaller
  4. //
  5. // Created by Greg Miller on 7/15/08.
  6. // Copyright 2008 Google Inc. All rights reserved.
  7. //
  8. #import "SignedPlistServer.h"
  9. #import "Signer.h"
  10. #import "PlistSigner.h"
  11. #import "GTMLogger.h"
  12. // Public Key for officially signed MacFUSE rules plists
  13. static unsigned char macfuse_public_der[] = {
  14. 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
  15. 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81,
  16. 0x89, 0x02, 0x81, 0x81, 0x00, 0xc6, 0xed, 0xf8, 0x40, 0x75, 0xd0, 0x86,
  17. 0xe8, 0xd5, 0xc7, 0x9d, 0xd8, 0xba, 0x10, 0x91, 0x23, 0xd1, 0xfa, 0x3a,
  18. 0x2a, 0x1f, 0xb8, 0xe9, 0xbf, 0x3e, 0x55, 0xe2, 0x67, 0x30, 0x2f, 0xa1,
  19. 0x43, 0x51, 0xe4, 0xe3, 0xdb, 0x71, 0x7a, 0x30, 0x1d, 0xb3, 0xe8, 0x3d,
  20. 0x74, 0x1f, 0x07, 0x57, 0xf7, 0x17, 0x69, 0x3d, 0x1b, 0xda, 0x0a, 0x61,
  21. 0x78, 0x59, 0x27, 0xa5, 0x59, 0x56, 0x77, 0xcc, 0xa8, 0x09, 0x96, 0xd0,
  22. 0x6f, 0xe7, 0xfb, 0x3a, 0xd0, 0x0a, 0xed, 0x0b, 0xad, 0x2c, 0xc7, 0x83,
  23. 0x1d, 0x53, 0x07, 0xf4, 0x17, 0x5b, 0x1c, 0x39, 0x8e, 0x47, 0x42, 0x8b,
  24. 0x53, 0xc4, 0xd1, 0x11, 0x68, 0x1c, 0x69, 0x11, 0x2a, 0x22, 0xc9, 0x5b,
  25. 0x4e, 0xda, 0xf6, 0x39, 0x98, 0x46, 0x91, 0xf9, 0x13, 0x1f, 0x11, 0xb8,
  26. 0xaf, 0x5e, 0x10, 0xa5, 0x2f, 0x40, 0x83, 0x27, 0x77, 0x7a, 0x67, 0x00,
  27. 0x01, 0x02, 0x03, 0x01, 0x00, 0x01
  28. };
  29. static unsigned int macfuse_public_der_len = 162;
  30. @implementation SignedPlistServer
  31. - (id)initWithURL:(NSURL *)url params:(NSDictionary *)params {
  32. // By default, this class will create a SignedPlistServer customized with
  33. // the appropriate public key for the signature of MacFUSE rules plists.
  34. NSData *pubKey = [NSData dataWithBytes:macfuse_public_der
  35. length:macfuse_public_der_len];
  36. Signer *macfuseSigner = [Signer signerWithPublicKey:pubKey privateKey:nil];
  37. return [self initWithURL:url signer:macfuseSigner];
  38. }
  39. - (id)initWithURL:(NSURL *)url signer:(Signer *)signer {
  40. if ((self = [super initWithURL:url params:nil])) {
  41. signer_ = [signer retain];
  42. if (signer_ == nil) {
  43. [self release];
  44. return nil;
  45. }
  46. }
  47. return self;
  48. }
  49. - (void)dealloc {
  50. [signer_ release];
  51. [super dealloc];
  52. }
  53. - (NSArray *)updateInfosForResponse:(NSURLResponse *)response
  54. data:(NSData *)data {
  55. // Decode the response |data| into a plist
  56. NSString *body = [[[NSString alloc]
  57. initWithData:data
  58. encoding:NSUTF8StringEncoding] autorelease];
  59. NSDictionary *plist = nil;
  60. @try {
  61. // This method can throw if |body| isn't a valid plist
  62. plist = [body propertyList];
  63. }
  64. @catch (id ex) {
  65. GTMLoggerError(@"Failed to parse response into plist: %@", ex);
  66. return nil;
  67. }
  68. PlistSigner *plistSigner = [[[PlistSigner alloc]
  69. initWithSigner:signer_
  70. plist:plist] autorelease];
  71. if (![plistSigner isPlistSigned]) {
  72. GTMLoggerInfo(@"Ignoring plist with bad signature (plistSigner=%@)\n%@",
  73. plistSigner, body);
  74. return nil;
  75. }
  76. return [super updateInfosForResponse:response data:data];
  77. }
  78. @end