Examples of fun abuse with your favourite language

Soldato
Joined
13 Jan 2003
Posts
24,680
For me it's this: Objective-C on OSX and using invalid SSL Certificates with HTTPS for development.

The reason is simple, there's no official method to call to tell the system to ignore the certificate validity through public APIs. (you'd have thought sub-classing and overriding the method would work too.. but that's no go too).

So the only way around it is to override an undocumented and unpublished class method on NSURLRequest called allowsAnyHTTPSCertificateForHost: so that when it's called to validate the server SSL cert it returns "valid" (YES).

Code:
@implementation NicksClass

// my class method which returns YES. 
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host { 
	return YES;
}

- (bool)installInsecureNoCheckValidation {
	// setup the SSL certificate validation bypass.

	Method methodCertCheck = class_getClassMethod([NSURLRequest class], @selector(allowsAnyHTTPSCertificateForHost:));
	Method methodCertNoCheck = class_getClassMethod([NicksClass class], @selector(allowsAnyHTTPSCertificateForHost:));		
			
	if( !methodCertCheck ) {
		NSLog(@"failed to locate NSURLRequest allowsAnyHTTPSCertificateForHost: implementation");
		return NO;
	}

	if( !methodCertNoCheck ) {
		NSLog(@"failed to locate NicksClass allowsAnyHTTPSCertificateForHost: implementation");
		return NO;
	}
			
	method_exchangeImplementations(methodCertCheck, methodCertNoCheck);
	return YES;
}
@end // end of class implementation

So what does this do? Well it takes the method implementation location for the original SSL Certificate check class method and then switches it for the location of the non-validating check class method I've defined in the class runtime. Class reprogramming on the fly.
So in short if my application uses any HTTPS now then it will call the method I've defined to allow my HTTPS to point to development services instead without needing a valid SSL certificate. Definitely not something todo on live boxes but still very useful.
 
I'm not sure how you do it on OSX but on Windows I generated my own SSL certificate for testing Apache with. I then installed the certificate into my certificate store, thus making it completely valid throughout Windows in all browsers and I assume all programs which tried to use it.


try this: http://www.itg.ias.edu/howinstallacertificatemacosx
 
I'm not sure how you do it on OSX but on Windows I generated my own SSL certificate for testing Apache with. I then installed the certificate into my certificate store, thus making it completely valid throughout Windows in all browsers and I assume all programs which tried to use it.

try this: http://www.itg.ias.edu/howinstallacertificatemacosx

I should have been more specific - the OSX in question is iPhoneOS. The server is running MS HomeServer and is attached to the internet. The cert is valid for internet access but not for internal WiFi from the same network using just an IPv4 address as the address differs from the cert.
Also the server is a mates who doesn't want to install insecure certs. Being able to switch off certs also helps if we want to run the iPhone against a different machine.
I know it sounds around the houses.. hence 'abuse'.
 
Last edited:
Back
Top Bottom