From ec34657ff190ac135c0cd4a4530ec470754851ec Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 29 Nov 2018 17:23:09 +0100 Subject: [PATCH] Added certificate dialog. --- client/Mac/CMakeLists.txt | 2 + client/Mac/CertificateDialog.h | 56 +++++++++++++ client/Mac/CertificateDialog.m | 118 ++++++++++++++++++++++++++ client/Mac/CertificateDialog.xib | 175 +++++++++++++++++++++++++++++++++++++++ client/Mac/MRDPView.m | 21 ++++- client/Mac/PasswordDialog.m | 6 +- 6 files changed, 373 insertions(+), 5 deletions(-) create mode 100644 client/Mac/CertificateDialog.h create mode 100644 client/Mac/CertificateDialog.m create mode 100644 client/Mac/CertificateDialog.xib diff --git a/client/Mac/CMakeLists.txt b/client/Mac/CMakeLists.txt index 29f98b3..94d7775 100644 --- a/client/Mac/CMakeLists.txt +++ b/client/Mac/CMakeLists.txt @@ -41,6 +41,7 @@ set(${MODULE_PREFIX}_OBJECTIVE_SOURCES MRDPView.m Keyboard.m Clipboard.m + CertificateDialog.m PasswordDialog.m) list(APPEND ${MODULE_PREFIX}_SOURCES ${${MODULE_PREFIX}_OBJECTIVE_SOURCES}) @@ -52,6 +53,7 @@ set(${MODULE_PREFIX}_HEADERS MRDPView.h Keyboard.h Clipboard.h + CertificateDialog.h PasswordDialog.h) set(${MODULE_PREFIX}_RESOURCES "en.lproj/InfoPlist.strings") diff --git a/client/Mac/CertificateDialog.h b/client/Mac/CertificateDialog.h new file mode 100644 index 0000000..d89cf25 --- /dev/null +++ b/client/Mac/CertificateDialog.h @@ -0,0 +1,56 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * MacFreeRDP + * + * Copyright 2018 Armin Novak + * Copyright 2018 Thicast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@interface CertificateDialog : NSWindowController +{ +@public + NSTextField* textCommonName; + NSTextField* textSubject; + NSTextField* textIssuer; + NSTextField* textFingerprint; + NSTextField* messageLabel; + NSString* serverHostname; + + BOOL hostMismatch; + int result; +} +@property(retain) IBOutlet NSTextField* textCommonName; +@property(retain) IBOutlet NSTextField* textSubject; +@property(retain) IBOutlet NSTextField* textIssuer; +@property(retain) IBOutlet NSTextField* textFingerprint; +@property(retain) IBOutlet NSTextField* messageLabel; + +- (IBAction)onAccept:(NSObject*)sender; +- (IBAction)onTemporary:(NSObject*)sender; +- (IBAction)onCancel:(NSObject*)sender; + +@property(retain) NSString* serverHostname; +@property(retain) NSString* commonName; +@property(retain) NSString* subject; +@property(retain) NSString* issuer; +@property(retain) NSString* fingerprint; +@property BOOL hostMismatch; +@property(readonly) int result; + +- (int) runModal:(NSWindow*)mainWindow; + +@end diff --git a/client/Mac/CertificateDialog.m b/client/Mac/CertificateDialog.m new file mode 100644 index 0000000..2495405 --- /dev/null +++ b/client/Mac/CertificateDialog.m @@ -0,0 +1,118 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * MacFreeRDP + * + * Copyright 2018 Armin Novak + * Copyright 2018 Thicast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "CertificateDialog.h" +#import + +#import + +@interface CertificateDialog() + + @property int result; + +@end + +@implementation CertificateDialog + +@synthesize textCommonName; +@synthesize textFingerprint; +@synthesize textIssuer; +@synthesize textSubject; +@synthesize messageLabel; +@synthesize serverHostname; +@synthesize commonName; +@synthesize fingerprint; +@synthesize issuer; +@synthesize subject; +@synthesize hostMismatch; + +- (id)init +{ + return [self initWithWindowNibName:@"CertificateDialog"]; +} + +- (void)windowDidLoad +{ + [super windowDidLoad]; + // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. + [self.window setTitle:self.serverHostname]; + [self.messageLabel setStringValue:[NSString stringWithFormat:@"Certificate for %@", + self.serverHostname]]; + + [self.textCommonName setStringValue:self.commonName]; + [self.textFingerprint setStringValue:self.fingerprint]; + [self.textIssuer setStringValue:self.issuer]; + [self.textSubject setStringValue:self.subject]; +} + +- (IBAction)onAccept:(NSObject*)sender +{ + [NSApp stopModalWithCode:1]; +} + +- (IBAction)onTemporary:(NSObject*)sender +{ + [NSApp stopModalWithCode:2]; +} + +- (IBAction)onCancel:(NSObject*)sender +{ + [NSApp stopModalWithCode:0]; +} + +- (int)runModal:(NSWindow*)mainWindow +{ + if ([mainWindow respondsToSelector:@selector(beginSheet:completionHandler:)]) + { + [mainWindow beginSheet:self.window completionHandler:nil]; + self.result = [NSApp runModalForWindow: self.window]; + [mainWindow endSheet: self.window]; + } + else + { + [NSApp beginSheet: self.window + modalForWindow: mainWindow + modalDelegate: nil + didEndSelector: nil + contextInfo: nil]; + self.result = [NSApp runModalForWindow: self.window]; + [NSApp endSheet: self.window]; + } + + [self.window orderOut:nil]; + return self.result; +} + +- (void)dealloc +{ + [textCommonName release]; + [textFingerprint release]; + [textIssuer release]; + [textSubject release]; + [messageLabel release]; + [serverHostname release]; + [commonName release]; + [fingerprint release]; + [issuer release]; + [subject release]; + [super dealloc]; +} + +@end diff --git a/client/Mac/CertificateDialog.xib b/client/Mac/CertificateDialog.xib new file mode 100644 index 0000000..27f215d --- /dev/null +++ b/client/Mac/CertificateDialog.xib @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index 8cd643a..52b333b 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -25,6 +25,7 @@ #import "MRDPCursor.h" #import "Clipboard.h" #import "PasswordDialog.h" +#import "CertificateDialog.h" #include #include @@ -1026,8 +1027,24 @@ BOOL mac_gw_authenticate(freerdp* instance, char** username, char** password, DWORD mac_verify_certificate(freerdp* instance, const char* common_name, const char* subject, const char* issuer, const char* fingerprint, BOOL host_mismatch) { - WLog_WARN(TAG, "TODO: Implement %s, accepting everything", __FUNCTION__); - return 2; + mfContext* mfc = (mfContext*) instance->context; + MRDPView* view = (MRDPView*) mfc->view; + CertificateDialog* dialog = [CertificateDialog new]; + dialog.serverHostname = [NSString stringWithCString:subject encoding: + NSUTF8StringEncoding];; + dialog.commonName = [NSString stringWithCString:common_name encoding: + NSUTF8StringEncoding];; + dialog.subject = [NSString stringWithCString:subject encoding: + NSUTF8StringEncoding];; + dialog.issuer = [NSString stringWithCString:issuer encoding: + NSUTF8StringEncoding];; + dialog.fingerprint = [NSString stringWithCString:fingerprint encoding: + NSUTF8StringEncoding];; + dialog.hostMismatch = host_mismatch; + [dialog performSelectorOnMainThread:@selector(runModal:) withObject:[view + window] waitUntilDone:TRUE]; + + return dialog.result; } DWORD mac_verify_changed_certificate(freerdp* instance, const char* common_name, const char* subject, const char* issuer, const char* fingerprint, const char* old_subject, const char* old_issuer, const char* old_fingerprint) diff --git a/client/Mac/PasswordDialog.m b/client/Mac/PasswordDialog.m index ab73699..2eecea4 100644 --- a/client/Mac/PasswordDialog.m +++ b/client/Mac/PasswordDialog.m @@ -49,7 +49,7 @@ [super windowDidLoad]; // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. [self.window setTitle:self.serverHostname]; - [messageLabel setStringValue:[NSString stringWithFormat:@"Authenticate to %@", + [self.messageLabel setStringValue:[NSString stringWithFormat:@"Authenticate to %@", self.serverHostname]]; NSMutableString* domainUser = [[NSMutableString alloc] initWithString:@""]; @@ -63,10 +63,10 @@ if (self.username != nil) { [domainUser appendString:self.username]; - [self.window makeFirstResponder:passwordText]; + [self.window makeFirstResponder:self.passwordText]; } - [usernameText setStringValue:domainUser]; + [self.usernameText setStringValue:domainUser]; } - (IBAction)onOK:(NSObject*)sender -- 2.7.4