PageRenderTime 42ms CodeModel.GetById 13ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

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