jens@0
|
1 |
//
|
jens@0
|
2 |
// BLIPEndpoint.m
|
jens@0
|
3 |
// MYNetwork
|
jens@0
|
4 |
//
|
jens@0
|
5 |
// Created by Jens Alfke on 5/14/08.
|
jens@0
|
6 |
// Copyright 2008 Jens Alfke. All rights reserved.
|
jens@0
|
7 |
//
|
jens@0
|
8 |
|
jens@0
|
9 |
#import "TCPEndpoint.h"
|
jens@26
|
10 |
#import "Test.h"
|
jens@26
|
11 |
#import "CollectionUtils.h"
|
jens@0
|
12 |
#import "ExceptionUtils.h"
|
jens@26
|
13 |
#import <Security/Security.h>
|
jens@0
|
14 |
|
jens@0
|
15 |
|
jens@0
|
16 |
NSString* const kTCPPropertySSLClientSideAuthentication = @"kTCPPropertySSLClientSideAuthentication";
|
jens@0
|
17 |
|
jens@0
|
18 |
|
jens@0
|
19 |
@implementation TCPEndpoint
|
jens@0
|
20 |
|
jens@0
|
21 |
|
jens@0
|
22 |
- (void) dealloc
|
jens@0
|
23 |
{
|
jens@0
|
24 |
[_sslProperties release];
|
jens@0
|
25 |
[super dealloc];
|
jens@0
|
26 |
}
|
jens@0
|
27 |
|
jens@0
|
28 |
|
jens@0
|
29 |
- (NSMutableDictionary*) SSLProperties {return _sslProperties;}
|
jens@0
|
30 |
|
jens@0
|
31 |
- (void) setSSLProperties: (NSMutableDictionary*)props
|
jens@0
|
32 |
{
|
jens@0
|
33 |
if( props != _sslProperties ) {
|
jens@0
|
34 |
[_sslProperties release];
|
jens@0
|
35 |
_sslProperties = [props mutableCopy];
|
jens@0
|
36 |
}
|
jens@0
|
37 |
}
|
jens@0
|
38 |
|
jens@0
|
39 |
- (void) setSSLProperty: (id)value forKey: (NSString*)key
|
jens@0
|
40 |
{
|
jens@0
|
41 |
if( value ) {
|
jens@0
|
42 |
if( ! _sslProperties )
|
jens@0
|
43 |
_sslProperties = [[NSMutableDictionary alloc] init];
|
jens@0
|
44 |
[_sslProperties setObject: value forKey: key];
|
jens@0
|
45 |
} else
|
jens@0
|
46 |
[_sslProperties removeObjectForKey: key];
|
jens@0
|
47 |
}
|
jens@0
|
48 |
|
jens@0
|
49 |
- (NSString*) securityLevel {return [_sslProperties objectForKey: (id)kCFStreamSSLLevel];}
|
jens@0
|
50 |
- (void) setSecurityLevel: (NSString*)level {[self setSSLProperty: level forKey: (id)kCFStreamSSLLevel];}
|
jens@0
|
51 |
|
jens@26
|
52 |
- (void) setPeerToPeerIdentity: (SecIdentityRef)identity {
|
jens@26
|
53 |
Assert(identity);
|
jens@26
|
54 |
self.SSLProperties = $mdict(
|
jens@26
|
55 |
{(id)kCFStreamSSLLevel, NSStreamSocketSecurityLevelTLSv1},
|
jens@26
|
56 |
{kTCPPropertySSLCertificates, $array((id)identity)},
|
jens@26
|
57 |
{kTCPPropertySSLAllowsAnyRoot, $true},
|
jens@26
|
58 |
{kTCPPropertySSLPeerName, [NSNull null]},
|
jens@26
|
59 |
{kTCPPropertySSLClientSideAuthentication, $object(kTCPAlwaysAuthenticate)});
|
jens@26
|
60 |
}
|
jens@0
|
61 |
|
jens@0
|
62 |
- (void) tellDelegate: (SEL)selector withObject: (id)param
|
jens@0
|
63 |
{
|
jens@0
|
64 |
if( [_delegate respondsToSelector: selector] ) {
|
jens@0
|
65 |
@try{
|
jens@0
|
66 |
[_delegate performSelector: selector withObject: self withObject: param];
|
jens@0
|
67 |
}catchAndReport(@"%@ delegate",self.class);
|
jens@0
|
68 |
}
|
jens@0
|
69 |
}
|
jens@0
|
70 |
|
jens@0
|
71 |
|
jens@0
|
72 |
@end
|
jens@0
|
73 |
|
jens@0
|
74 |
|
jens@0
|
75 |
/*
|
jens@0
|
76 |
Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
|
jens@0
|
77 |
|
jens@0
|
78 |
Redistribution and use in source and binary forms, with or without modification, are permitted
|
jens@0
|
79 |
provided that the following conditions are met:
|
jens@0
|
80 |
|
jens@0
|
81 |
* Redistributions of source code must retain the above copyright notice, this list of conditions
|
jens@0
|
82 |
and the following disclaimer.
|
jens@0
|
83 |
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
jens@0
|
84 |
and the following disclaimer in the documentation and/or other materials provided with the
|
jens@0
|
85 |
distribution.
|
jens@0
|
86 |
|
jens@0
|
87 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
jens@0
|
88 |
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
jens@0
|
89 |
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
|
jens@0
|
90 |
BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
jens@0
|
91 |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
jens@0
|
92 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
jens@0
|
93 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
jens@0
|
94 |
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
jens@0
|
95 |
*/
|