Revision: 1871
Author:
lieven....@gmail.com
Date: Thu May 23 23:59:05 2013
Log: On the multiple_ssl_impls branch:
Reimplement the code to show the CertificateTrustPanel in Objective C file
for
clarity. Also put the dialog in front and give it the focus.
* buckets/sectrans_helper.m
(showTrustCertificateDialog): New class method, opens the
CertificateTrust-
Dialog.
* buckets/sectrans_buckets.c
(show_trust_certificate_dialog): Use the new showTrustCertificateDialog
helper function.
http://code.google.com/p/serf/source/detail?r=1871
Modified:
/branches/multiple_ssl_impls/buckets/sectrans_buckets.c
/branches/multiple_ssl_impls/buckets/sectrans_helper.m
=======================================
--- /branches/multiple_ssl_impls/buckets/sectrans_buckets.c Thu May 23
14:35:06 2013
+++ /branches/multiple_ssl_impls/buckets/sectrans_buckets.c Thu May 23
23:59:05 2013
@@ -542,65 +542,18 @@
const char *ok_button,
const char *cancel_button)
{
- CFStringRef OkButtonLbl, CancelButtonLbl = NULL, MessageLbl;
- void *nsapp_cls, *stp_cls, *stp;
- long result;
-
- /* Function can only be called from the callback to validate the
- server certificate or server certificate chain! */
sectrans_context_t *ssl_ctx = impl_ctx;
SecTrustRef trust = ssl_ctx->trust;
- if (!trust)
- return APR_EGENERAL; /* TODO */
+ apr_status_t status;
- MessageLbl = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault,
- (unsigned char *)message, strlen(message),
- kCFStringEncodingMacRoman, false, kCFAllocatorNull);
- if (cancel_button)
- CancelButtonLbl =
CFStringCreateWithBytesNoCopy(kCFAllocatorDefault,
- (unsigned char *)cancel_button,
- strlen(cancel_button),
- kCFStringEncodingMacRoman,
- false,
- kCFAllocatorNull);
- OkButtonLbl = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault,
- (unsigned char *)ok_button, strlen(ok_button),
- kCFStringEncodingMacRoman, false, kCFAllocatorNull);
+ void *sectrans_cls = objc_getClass("SecTrans_Buckets");
+ id tmp = objc_msgSend(sectrans_cls,
+ sel_getUid("showTrustCertificateDialog:message:"
+ "ok_button:cancel_button:"),
+ trust, message, ok_button, cancel_button);
+ status = (apr_status_t)(SInt64)tmp;
- /* Creates an NSApplication object (enables GUI for cocoa apps) if one
- doesn't exist already. */
- nsapp_cls = objc_getClass("NSApplication");
- (void) objc_msgSend(nsapp_cls,sel_registerName("sharedApplication"));
-
- stp_cls = objc_getClass("SFCertificateTrustPanel");
- stp = objc_msgSend(stp_cls, sel_registerName("alloc"));
- stp = objc_msgSend(stp, sel_registerName("init"));
-
- /* TODO: find a way to get the panel in front of all other windows. */
-
- /* Don't use these methods as is, they create a small application
window
- and have no effect on the z-order of the modal dialog. */
-#if 0
- objc_msgSend(obj, sel_getUid("orderFrontRegardless"));
- objc_msgSend (obj, sel_getUid ("makeKeyAndOrderFront:"), app);
-
- objc_msgSend (nsapp, sel_getUid ("activateIgnoringOtherApps:"), 1);
- objc_msgSend (stp, sel_getUid ("makeKeyWindow"));
-#endif
-
- /* Setting name of the cancel button also makes it visible on the
panel. */
- objc_msgSend(stp, sel_getUid("setDefaultButtonTitle:"), OkButtonLbl);
- objc_msgSend(stp, sel_getUid("setAlternateButtonTitle:"),
CancelButtonLbl);
-
- result = (long)objc_msgSend(stp,
sel_getUid("runModalForTrust:message:"),
- trust, MessageLbl);
- serf__log(SSL_VERBOSE, __FILE__, "User clicked %s button.\n",
- result ? "Accept" : "Cancel");
-
- if (result) /* NSOKButton = 1 */
- return APR_SUCCESS;
- else /* NSCancelButton = 0 */
- return SERF_ERROR_SSL_USER_DENIED_CERT;
+ return status;
}
/* Show a SFChooseIdentityPanel. This is the Mac OS X default dialog to
=======================================
--- /branches/multiple_ssl_impls/buckets/sectrans_helper.m Thu May 23
14:35:06 2013
+++ /branches/multiple_ssl_impls/buckets/sectrans_helper.m Thu May 23
23:59:05 2013
@@ -1,6 +1,10 @@
/*
*/
+#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
+#import <SecurityInterface/SFCertificateTrustPanel.h>
+
+#import "serf.h"
@interface SecTrans_Buckets : NSObject
{
@@ -8,6 +12,10 @@
+ (OSStatus) evaluate:(SecTrustRef)trust
trustResult:(SecTrustResultType *)trustResult;
++ (apr_status_t) showTrustCertificateDialog:(SecTrustRef)trust
+ message:(const char *)message
+ ok_button:(const char *)ok_button
+ cancel_button:(const char *)cancel_button;
@end
@implementation SecTrans_Buckets
@@ -31,4 +39,44 @@
return osstatus;
}
++ (apr_status_t) showTrustCertificateDialog:(SecTrustRef)trust
+ message:(const char *)message
+ ok_button:(const char *)ok_button
+ cancel_button:(const char *)cancel_button
+{
+ NSString *MessageLbl = [[NSString alloc] initWithUTF8String:message];
+ NSString *OkButtonLbl = [[NSString alloc]
initWithUTF8String:ok_button];
+ NSString *CancelButtonLbl;
+
+ if (cancel_button)
+ CancelButtonLbl = [[NSString alloc]
initWithUTF8String:cancel_button];
+
+ SFCertificateTrustPanel *panel;
+ NSApplication *app = [NSApplication sharedApplication];
+
+ panel = [SFCertificateTrustPanel sharedCertificateTrustPanel];
+
+ /* Put the dialog in front of the application, and give it the focus.
*/
+ [app setActivationPolicy:NSApplicationActivationPolicyRegular];
+ [app activateIgnoringOtherApps:YES];
+
+ [panel setShowsHelp:YES];
+ [panel setDefaultButtonTitle:OkButtonLbl];
+ if (cancel_button)
+ [panel setAlternateButtonTitle:CancelButtonLbl];
+
+ NSInteger result = [panel runModalForTrust:trust
+ message:MessageLbl];
+
+ [panel release];
+ [MessageLbl release];
+ [OkButtonLbl release];
+ if (cancel_button)
+ [CancelButtonLbl release];
+
+ if (result)
+ return APR_SUCCESS;
+ else
+ return SERF_ERROR_SSL_USER_DENIED_CERT;
+}
@end