AccAdvancedSipVC.mm 18.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
/*
 *  Copyright (C) 2015-2018 Savoir-faire Linux Inc.
 *  Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
 *  Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 */
#define OUTGOING_TLS_SERVER_TAG 0
#define NEGOTIATION_TIMOUT_TAG 1
#define REGISTRATION_TAG 2
#define LOCALPORT_TAG 3
#define CUSTOM_PORT_TAG 4
#define CUSTOM_ADDRESS_TAG 5
#define MINAUDIO_TAG 6
#define MAXAUDIO_TAG 7
#define MINVIDEO_TAG 8
#define MAXVIDEO_TAG 9

#import "AccAdvancedSipVC.h"

//LRC
#import <api/lrc.h>
#import <api/newaccountmodel.h>

@interface AccAdvancedSipVC () {
    __unsafe_unretained IBOutlet NSButton *encryptMediaButton;
    __unsafe_unretained IBOutlet NSButton *enableSDESButton;
    __unsafe_unretained IBOutlet NSButton *fallbackEncryptionFailureButton;
    __unsafe_unretained IBOutlet NSButton *encryptNegotiationButton;
    __unsafe_unretained IBOutlet NSButton *checkIncomingCertificatesButton;
    __unsafe_unretained IBOutlet NSButton *checkAnswerCertificatesButton;
    __unsafe_unretained IBOutlet NSButton *requereIncomingCertificateButton;
    __unsafe_unretained IBOutlet NSPopUpButton *tlsProtocolsList;
    __unsafe_unretained IBOutlet NSTextField *outgoingTlsServerNameField;
    __unsafe_unretained IBOutlet NSStepper *negotiationTimeoutStepper;
    __unsafe_unretained IBOutlet NSTextField *negotiationTimeoutField;
    __unsafe_unretained IBOutlet NSStepper *registrationTimeoutStepper;
    __unsafe_unretained IBOutlet NSTextField *registrationTimeoutField;
    __unsafe_unretained IBOutlet NSStepper *networkStepper;
    __unsafe_unretained IBOutlet NSTextField *networkField;
    __unsafe_unretained IBOutlet NSTextField *customAddressField;
    __unsafe_unretained IBOutlet NSButton *useCustomAddressButton;
    __unsafe_unretained IBOutlet NSStepper *customPortStepper;
    __unsafe_unretained IBOutlet NSTextField *customPortField;
    __unsafe_unretained IBOutlet NSStepper *minAudioPortStepper;
    __unsafe_unretained IBOutlet NSStepper *maxAudioPortStepper;
    __unsafe_unretained IBOutlet NSStepper *minVideoPortStepper;
    __unsafe_unretained IBOutlet NSStepper *maxVideoPortStepper;
    __unsafe_unretained IBOutlet NSTextField *minAudioRTPRange;
    __unsafe_unretained IBOutlet NSTextField *maxAudioRTPRange;
    __unsafe_unretained IBOutlet NSTextField *minVideoRTPRange;
    __unsafe_unretained IBOutlet NSTextField *maxVideoRTPRange;
}

@end

@implementation AccAdvancedSipVC

NSString *TLS_PROTOCOL_DEFAULT = @"Default";
NSString *TLS_PROTOCOL_TLSv1 = @"TLSv1";
NSString *TLS_PROTOCOL_TLSv1_1 = @"TLSv1_1";
NSString *TLS_PROTOCOL_TLSv1_2 = @"TLSv1_2";

@synthesize privateKeyPaswordField;
@synthesize selectCACertificateButton, selectUserCertificateButton, selectPrivateKeyButton;

- (void)awakeFromNib
{
    [super awakeFromNib];
    [negotiationTimeoutStepper setTag:NEGOTIATION_TIMOUT_TAG];
    [negotiationTimeoutField setTag:NEGOTIATION_TIMOUT_TAG];
    [registrationTimeoutStepper setTag:REGISTRATION_TAG];
    [registrationTimeoutField setTag:REGISTRATION_TAG];
    [networkStepper setTag:LOCALPORT_TAG];
    [networkField setTag:LOCALPORT_TAG];
    [customAddressField setTag: CUSTOM_ADDRESS_TAG];
    [outgoingTlsServerNameField setTag: OUTGOING_TLS_SERVER_TAG];
    [customPortStepper setTag: CUSTOM_PORT_TAG];
    [customPortField setTag: CUSTOM_PORT_TAG];
    [minAudioPortStepper setTag:MINAUDIO_TAG];
    [maxAudioPortStepper setTag:MAXAUDIO_TAG];
    [minVideoPortStepper setTag:MINVIDEO_TAG];
    [maxVideoPortStepper setTag:MAXVIDEO_TAG];
    [minAudioRTPRange setTag:MINAUDIO_TAG];
    [maxAudioRTPRange setTag:MAXAUDIO_TAG];
    [minVideoRTPRange setTag:MINVIDEO_TAG];
    [maxVideoRTPRange setTag:MAXVIDEO_TAG];
100 101
    [[self view] setAutoresizingMask: NSViewMinXMargin | NSViewMaxXMargin | NSViewHeightSizable];

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
}

-(void)viewDidLoad {
    [super viewDidLoad];
    NSMenu *tlsMethods = [[NSMenu alloc] initWithTitle:@""];
    [tlsMethods addItem: [[NSMenuItem alloc] initWithTitle: TLS_PROTOCOL_DEFAULT action:nil keyEquivalent:@""]];
    [tlsMethods addItem: [[NSMenuItem alloc] initWithTitle: TLS_PROTOCOL_TLSv1 action:nil keyEquivalent:@""]];
    [tlsMethods addItem: [[NSMenuItem alloc] initWithTitle: TLS_PROTOCOL_TLSv1_1 action:nil keyEquivalent:@""]];
    [tlsMethods addItem: [[NSMenuItem alloc] initWithTitle: TLS_PROTOCOL_TLSv1_2 action:nil keyEquivalent:@""]];
    tlsProtocolsList.menu = tlsMethods;
    [self updateView];
}

- (void) setSelectedAccount:(std::string) account {
    [super setSelectedAccount: account];
    [self updateView];
}

- (void) updateView {
    auto accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    [encryptMediaButton setState: accountProperties.SRTP.enable];
    [enableSDESButton setState: accountProperties.SRTP.keyExchange == lrc::api::account::KeyExchangeProtocol::SDES ? NSControlStateValueOn : NSControlStateValueOff];
    [fallbackEncryptionFailureButton setState: accountProperties.SRTP.rtpFallback];
    [encryptNegotiationButton setState: accountProperties.TLS.enable];
    [selectCACertificateButton setEnabled: accountProperties.TLS.enable];
    [selectUserCertificateButton setEnabled: accountProperties.TLS.enable];
    [selectPrivateKeyButton setEnabled: accountProperties.TLS.enable];
    [privateKeyPaswordField setEnabled: accountProperties.TLS.enable];
    [checkIncomingCertificatesButton setState: accountProperties.TLS.verifyServer];
    [checkAnswerCertificatesButton setState: accountProperties.TLS.verifyClient];
    [requereIncomingCertificateButton setState: accountProperties.TLS.requireClientCertificate];
    switch (accountProperties.TLS.method) {
        case lrc::api::account::TlsMethod::DEFAULT:
            [tlsProtocolsList selectItemWithTitle:TLS_PROTOCOL_DEFAULT];
            break;
        case lrc::api::account::TlsMethod::TLSv1:
            [tlsProtocolsList selectItemWithTitle:TLS_PROTOCOL_TLSv1];
            break;
        case lrc::api::account::TlsMethod::TLSv1_1:
            [tlsProtocolsList selectItemWithTitle:TLS_PROTOCOL_TLSv1_1];
            break;
        case lrc::api::account::TlsMethod::TLSv1_2:
            [tlsProtocolsList selectItemWithTitle:TLS_PROTOCOL_TLSv1_2];
            break;

        default:
            break;
    }
    [negotiationTimeoutStepper setIntegerValue: accountProperties.TLS.negotiationTimeoutSec];
    [negotiationTimeoutField setIntegerValue: accountProperties.TLS.negotiationTimeoutSec];
    [registrationTimeoutStepper setIntegerValue: accountProperties.Registration.expire];
    [registrationTimeoutField setIntegerValue: accountProperties.Registration.expire];
    [networkStepper setIntegerValue: accountProperties.localPort];
    [networkField setIntegerValue: accountProperties.localPort];
    [customAddressField setEnabled:!accountProperties.publishedSameAsLocal];
    [customPortField setEnabled:!accountProperties.publishedSameAsLocal];
    [customPortStepper setEnabled:!accountProperties.publishedSameAsLocal];
    [useCustomAddressButton setState:!accountProperties.publishedSameAsLocal];
    [customPortStepper setIntegerValue: accountProperties.publishedPort];
    [customPortField setIntegerValue: accountProperties.publishedPort];
    [customAddressField setStringValue: @(accountProperties.publishedAddress.c_str())];
    [minAudioPortStepper setIntegerValue: accountProperties.Audio.audioPortMin];
    [minAudioRTPRange setIntegerValue: accountProperties.Audio.audioPortMin];
    [maxAudioPortStepper setIntegerValue: accountProperties.Audio.audioPortMax];
    [maxAudioRTPRange setIntegerValue: accountProperties.Audio.audioPortMax];
    [minVideoPortStepper setIntegerValue: accountProperties.Video.videoPortMin];
    [minVideoRTPRange setIntegerValue: accountProperties.Video.videoPortMin];
Kateryna Kostiuk's avatar
Kateryna Kostiuk committed
169 170
    [maxVideoPortStepper setIntegerValue: accountProperties.Video.videoPortMax];
    [maxVideoRTPRange setIntegerValue: accountProperties.Video.videoPortMax];
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
}

#pragma mark - Actions

- (IBAction)toggleEnableSDES:(id)sender {
    auto accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    lrc::api::account::KeyExchangeProtocol newState = [sender state] == NSControlStateValueOn ? lrc::api::account::KeyExchangeProtocol::SDES : lrc::api::account::KeyExchangeProtocol::NONE;
    if(accountProperties.SRTP.keyExchange != newState) {
        accountProperties.SRTP.keyExchange = newState;
        self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
    }
}
- (IBAction)toggleEncryptMedia:(id)sender {
    auto accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    if(accountProperties.SRTP.enable!= [sender state]) {
        accountProperties.SRTP.enable = [sender state];
        self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
    }
}
- (IBAction)toggleFallbackEncryptionFailure:(id)sender {
    auto accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    if(accountProperties.SRTP.rtpFallback != [sender state]) {
        accountProperties.SRTP.rtpFallback = [sender state];
        self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
    }
}
- (IBAction)toggleEncryptNegotiation:(id)sender {
    auto accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    if(accountProperties.TLS.enable != [sender state]) {
        accountProperties.TLS.enable = [sender state];
        self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
        [selectCACertificateButton setEnabled: [sender state]];
        [selectUserCertificateButton setEnabled: [sender state]];
        [selectPrivateKeyButton setEnabled: [sender state]];
        [privateKeyPaswordField setEnabled: [sender state]];
    }
}
- (IBAction)toggleVerifyServerCertificate:(id)sender {
    auto accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    if(accountProperties.TLS.verifyServer != [sender state]) {
        accountProperties.TLS.verifyServer = [sender state];
        self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
    }
}
- (IBAction)toggleVerifyClientCertificate:(id)sender {
    lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    if(accountProperties.TLS.verifyClient != [sender state]) {
        accountProperties.TLS.verifyClient = [sender state];
        self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
    }
}
- (IBAction)toggleCertForIncomingConnection:(id)sender {
    lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    if(accountProperties.TLS.requireClientCertificate != [sender state]) {
        accountProperties.TLS.requireClientCertificate = [sender state];
        self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
    }
}

- (IBAction)enableCustomAddress:(id)sender {
    lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    if(accountProperties.publishedSameAsLocal != ![sender state]) {
        accountProperties.publishedSameAsLocal = ![sender state];
        self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
        [customAddressField setEnabled:[sender state]];
        [customPortField setEnabled:[sender state]];
        [customPortStepper setEnabled:[sender state]];
    }
}

- (IBAction)chooseTlsProtocol:(id)sender {
    int index = [sender indexOfSelectedItem];
    if(index < 0) {
        return;
    }
    NSString *title = [[tlsProtocolsList.menu itemAtIndex:index] title];
    lrc::api::account::TlsMethod method;

    if(title == TLS_PROTOCOL_DEFAULT) {
        method = lrc::api::account::TlsMethod::DEFAULT;
    } else if(title == TLS_PROTOCOL_TLSv1) {
        method = lrc::api::account::TlsMethod::TLSv1;
    } else if(title == TLS_PROTOCOL_TLSv1_1) {
        method = lrc::api::account::TlsMethod::TLSv1_1;
    } else if(title == TLS_PROTOCOL_TLSv1_2) {
        method = lrc::api::account::TlsMethod::TLSv1_2;
    } else {
        return;
    }
    auto accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);
    if(accountProperties.TLS.method != method) {
        accountProperties.TLS.method = method;
        self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
    }
}

- (IBAction) valueDidChange: (id) sender
{
    lrc::api::account::ConfProperties_t accountProperties = self.accountModel->getAccountConfig(self.selectedAccountID);

    switch ([sender tag]) {
        case OUTGOING_TLS_SERVER_TAG:
            if(accountProperties.TLS.serverName != [[sender stringValue] UTF8String]) {
                accountProperties.TLS.serverName = [[sender stringValue] UTF8String];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
            }
            return;
        case NEGOTIATION_TIMOUT_TAG:
            if(accountProperties.TLS.negotiationTimeoutSec != [[sender stringValue] integerValue]) {
                accountProperties.TLS.negotiationTimeoutSec = [[sender stringValue] integerValue];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
                [negotiationTimeoutStepper setIntegerValue: [[sender stringValue] integerValue]];
                [negotiationTimeoutField setIntegerValue: [[sender stringValue] integerValue]];
            }
            return;
        case REGISTRATION_TAG:
            if(accountProperties.Registration.expire != [[sender stringValue] integerValue]) {
                accountProperties.Registration.expire = [[sender stringValue] integerValue];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
                [registrationTimeoutStepper setIntegerValue: [[sender stringValue] integerValue]];
                [registrationTimeoutField setIntegerValue: [[sender stringValue] integerValue]];
            }
            return;
        case LOCALPORT_TAG:
            if(accountProperties.localPort != [[sender stringValue] integerValue]) {
                accountProperties.localPort = [[sender stringValue] integerValue];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
                [networkStepper setIntegerValue: [[sender stringValue] integerValue]];
                [networkField setIntegerValue: [[sender stringValue] integerValue]];
            }
            return;
        case CUSTOM_ADDRESS_TAG:
            if(accountProperties.publishedAddress != [[sender stringValue] UTF8String]) {
                NSString *name = [sender stringValue];
                accountProperties.publishedAddress = [[sender stringValue] UTF8String];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
            }
            return;
        case CUSTOM_PORT_TAG:
            if(accountProperties.publishedPort != [[sender stringValue] integerValue]) {
                accountProperties.publishedPort = [[sender stringValue] integerValue];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
                [customPortStepper setIntegerValue: [[sender stringValue] integerValue]];
                [customPortField setIntegerValue: [[sender stringValue] integerValue]];
            }
            return;
        case MINAUDIO_TAG:
            if(accountProperties.Audio.audioPortMin != [[sender stringValue] integerValue]) {
                accountProperties.Audio.audioPortMin = [[sender stringValue] integerValue];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
                [minAudioPortStepper setIntegerValue: [[sender stringValue] integerValue]];
                [minAudioRTPRange setIntegerValue: [[sender stringValue] integerValue]];
            }
            return;
        case MAXAUDIO_TAG:
            if(accountProperties.Audio.audioPortMax != [[sender stringValue] integerValue]) {
                accountProperties.Audio.audioPortMax = [[sender stringValue] integerValue];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
                [maxAudioPortStepper setIntegerValue: [[sender stringValue] integerValue]];
                [maxAudioRTPRange setIntegerValue: [[sender stringValue] integerValue]];
            }
            return;
        case MINVIDEO_TAG:
            if(accountProperties.Video.videoPortMin != [[sender stringValue] integerValue]) {
                accountProperties.Video.videoPortMin = [[sender stringValue] integerValue];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
                [minVideoPortStepper setIntegerValue: [[sender stringValue] integerValue]];
                [minVideoRTPRange setIntegerValue: [[sender stringValue] integerValue]];
            }
            return;
        case MAXVIDEO_TAG:
            if(accountProperties.Video.videoPortMax != [[sender stringValue] integerValue]) {
                accountProperties.Video.videoPortMax = [[sender stringValue] integerValue];
                self.accountModel->setAccountConfig(self.selectedAccountID, accountProperties);
                [maxVideoPortStepper setIntegerValue: [[sender stringValue] integerValue]];
                [maxVideoRTPRange setIntegerValue: [[sender stringValue] integerValue]];
            }
            return;
        default:
            break;
    }
    [super valueDidChange:sender];
}

#pragma mark - NSTextFieldDelegate methods

-(void)controlTextDidChange:(NSNotification *)notif
{
    NSTextField *textField = [notif object];
    NSRange test = [[textField currentEditor] selectedRange];

    [self valueDidChange:textField];
}

@end