Adium: BEAST mitigations for 10.8.5
[siplcs.git] / src / adium / ESSIPEAccountViewController.m
blobb6f4fbd907e0c9290927b05df747d7749dae4e4e
1 //
2 //  ESSIPEAccountViewController.m
3 //  SIPEAdiumPlugin
4 //
5 //  Created by Matt Meissner on 10/30/09.
6 //  Modified by Michael Lamb on 2/27/13
7 //  Copyright 2013 Michael Lamb/Harris Kauffman. All rights reserved.
8 //
10 #import <AdiumLibpurple/CBPurpleAccount.h>
11 #import <ESDebugAILog.h>
12 #import "ESSIPEAccountViewController.h"
14 #include "prpl.h"
15 #include "ESPurpleSIPEAccount.h"
17 // Gotta define these here, because they're not yet in the 10.9 SDK.  :(
18 #define NSAppKitVersionNumber10_8 1187
19 #define NSAppKitVersionNumber10_8_5 1187.4
20 #define NSAppKitVersionNumber10_9 1265
22 @implementation ESSIPEAccountViewController
24 - (id)init {
25     [super init];
26     
27     sipe_key_to_gui =
28     [[NSDictionary alloc] initWithObjectsAndKeys:
29      textField_windowsLogin,     KEY_SIPE_WINDOWS_LOGIN,
30      textField_password,         KEY_SIPE_PASSWORD,
31      textField_server,           KEY_SIPE_CONNECT_HOST,
32      popup_connectionType,       KEY_SIPE_CONNECTION_TYPE,
33      popup_authenticationScheme, KEY_SIPE_AUTH_SCHEME,
34      textField_userAgent,        KEY_SIPE_USER_AGENT,
35      checkBox_singleSignOn,      KEY_SIPE_SINGLE_SIGN_ON,
36      checkbox_beastDisable,      KEY_SIPE_BEAST_DISABLE,
37      textField_groupchatUser,    KEY_SIPE_GROUP_CHAT_PROXY,
38      textField_emailURL,         KEY_SIPE_EMAIL_URL,
39      textField_email,            KEY_SIPE_EMAIL,
40      textField_emailLogin,       KEY_SIPE_EMAIL_LOGIN,
41      textField_emailPassword,    KEY_SIPE_EMAIL_PASSWORD,
42      checkbox_dontPublish,       KEY_SIPE_DONT_PUBLISH,
43      nil
44      ];
45     
46     return self;
49 - (void)dealloc
51     [sipe_key_to_gui release];
52     [super dealloc];
55 - (NSString *)nibName{
56     return @"ESSIPEAccountView";
59 #pragma mark Configuration methods
60 - (void)configureForAccount:(AIAccount *)inAccount
62     [super configureForAccount:inAccount];
64     // BEAST mitigation for Mavericks and 10.8.5 users (with Security Update 2014-001)
65     if (NSAppKitVersionNumber < NSAppKitVersionNumber10_8_5) {
66         // We are not running on an OS with BEAST mitigations - Don't display this as a configuration option
67         [checkbox_beastDisable setHidden:YES];
68     }
69     
70     // Only need 1 hash for both connection & auth since there are no overlapping keys
71     NSDictionary *conn_auth_dict =
72     [NSDictionary dictionaryWithObjectsAndKeys:
73      @"NTLM",@"ntlm",
74      @"Kerberos",@"krb5",
75      @"TLS-DSK",@"tls-dsk",
76      @"Auto",@"auto",
77      @"SSL/TLS",@"tls",
78      @"TCP",@"tcp",
79      nil];
80     
81     for (NSString* key in sipe_key_to_gui) {
82         id value = [sipe_key_to_gui objectForKey:key];
83         
84         if ([value isKindOfClass:[NSTextField class]]) {
85             NSString *tmp = [account preferenceForKey:key group:GROUP_ACCOUNT_STATUS];
86             [value setStringValue:(tmp ? tmp : @"")];
87         } else if ([value isKindOfClass:[NSPopUpButton class]]) {
88             // NSPopUpButton *MUST* appear before NSButton in the if/else
89             //   because  NSPopUpButton is a NSButton...
90             NSString *tmp_key = [account preferenceForKey:key group:GROUP_ACCOUNT_STATUS];
91             NSString *tmp = [key isEqualToString:KEY_SIPE_CONNECTION_TYPE] ? @"auto" : @"ntlm";
92             
93             if (conn_auth_dict[tmp_key])
94                 tmp = conn_auth_dict[tmp_key];
95             
96             [value selectItemWithTitle:tmp];
97         } else if ([value isKindOfClass:[NSButton class]]) {
98             [value setState:[[account preferenceForKey:key group:GROUP_ACCOUNT_STATUS] boolValue]];
99         } else {
100             AILog(@"(ESSIPEAccountViewController) Unknown class %@ for key %@", [value class], key);
101         }
102     }
105 - (void)saveConfiguration
107     [super saveConfiguration];
108     
109     // Only need 1 hash for both connection & auth since there are no overlapping keys
110     NSDictionary *conn_auth_dict =
111     [NSDictionary dictionaryWithObjectsAndKeys:
112      @"ntlm",@"NTLM",
113      @"krb5",@"Kerberos",
114      @"tls-dsk",@"TLS-DSK",
115      @"auto",@"Auto",
116      @"tls",@"SSL/TLS",
117      @"tcp",@"TCP",
118      nil];
119     
120     for (NSString* key in sipe_key_to_gui) {
121         id value = [sipe_key_to_gui objectForKey:key];
122         
123         if ([value isKindOfClass:[NSTextField class]]) {
124             [account
125              setPreference:[[value stringValue] length] ? [value stringValue] : @""
126              forKey:key
127              group:GROUP_ACCOUNT_STATUS];
128         } else if ([value isKindOfClass:[NSPopUpButton class]]) {
129             // NSPopUpButton *MUST* appear before NSButton in the if/else
130             //   because  NSPopUpButton is a NSButton...
131             NSString *tmp = conn_auth_dict[[[value selectedItem] title]];
132             [account
133              setPreference:tmp
134              forKey:key
135              group:GROUP_ACCOUNT_STATUS];
136         } else if ([value isKindOfClass:[NSButton class]]) {
137             [account
138              setPreference:[NSNumber numberWithBool:[value state]]
139              forKey:key
140              group:GROUP_ACCOUNT_STATUS];
141         } else {
142             AILog(@"(ESSIPEAccountViewController) Unknown class %@ for key %@", [value class], key);
143         }
144     }
147 @end