Exemplo n.º 1
0
void testInvalidLicenseFile(void)
{
	CFDataRef invalidLicenseFileData = CFDataCreate(NULL,
													(const UInt8 *)invalidLicenseFileContents,
													(CFIndex)strlen(invalidLicenseFileContents));
	Boolean licenseIsValid = APVerifyLicenseData(invalidLicenseFileData);
	CFRelease(invalidLicenseFileData);
	
	if (!licenseIsValid) {
		CFShow(CFSTR("Test OK: Invalid file recognised as invalid"));
	} else {
		CFShow(CFSTR("Test FAILED: Invalid file not recognised as invalid"));
	}
}
Exemplo n.º 2
0
void testValidPemKey(void)
{
	CFStringRef pemKey = CFStringCreateWithCString(kCFAllocatorDefault, pemEncodedKey, kCFStringEncodingUTF8);
	APSetKey(pemKey);
	CFRelease(pemKey);
	
	CFDataRef exampleLicenseFileData = CFDataCreate(NULL,
													(const UInt8 *)exampleLicenseFileContents,
													(CFIndex)strlen(exampleLicenseFileContents));
	Boolean licenseIsValid = APVerifyLicenseData(exampleLicenseFileData);
	CFRelease(exampleLicenseFileData);
	
	if (licenseIsValid) {
		CFShow(CFSTR("Test OK: Valid file recognised using PEM encoded key"));
	} else {
		CFShow(CFSTR("Test FAILED: Valid file not recognised using PEM encoded key"));
	}
}
Exemplo n.º 3
0
int main (int argc, const char * argv[]) {
	// This string was generated by the AquaticPrime Developer tool.
	// (I've converted it to use CoreFoundation instead of Foundation, however, as the
	//  AP Dev tool doesn't generate CF-based string obfuscation yet.)
	// *** Begin Public Key ***
	CFMutableStringRef exampleKey = CFStringCreateMutable(NULL, 0);
	CFStringAppend(exampleKey, CFSTR("0xC21727A4604EF3C70959D8645FDA"));
	CFStringAppend(exampleKey, CFSTR("C3C5FD49F"));
	CFStringAppend(exampleKey, CFSTR("E"));
	CFStringAppend(exampleKey, CFSTR("E"));
	CFStringAppend(exampleKey, CFSTR("02E46DC154A74B302C0"));
	CFStringAppend(exampleKey, CFSTR("041C"));
	CFStringAppend(exampleKey, CFSTR("3"));
	CFStringAppend(exampleKey, CFSTR("3"));
	CFStringAppend(exampleKey, CFSTR("F26028D0F3BF120A262B5E53"));
	CFStringAppend(exampleKey, CFSTR("E3CA86528D702E40F4B5"));
	CFStringAppend(exampleKey, CFSTR("2"));
	CFStringAppend(exampleKey, CFSTR("2"));
	CFStringAppend(exampleKey, CFSTR("BFBCAEA6"));
	CFStringAppend(exampleKey, CFSTR("3E9D31FD6976DC6C"));
	CFStringAppend(exampleKey, CFSTR("7"));
	CFStringAppend(exampleKey, CFSTR("7"));
	CFStringAppend(exampleKey, CFSTR("97D8354F3629"));
	CFStringAppend(exampleKey, CFSTR("DEFEB572AFA4A"));
	CFStringAppend(exampleKey, CFSTR("2"));
	CFStringAppend(exampleKey, CFSTR("2"));
	CFStringAppend(exampleKey, CFSTR("96F24DAB115EE71"));
	CFStringAppend(exampleKey, CFSTR("C06"));
	CFStringAppend(exampleKey, CFSTR("1"));
	CFStringAppend(exampleKey, CFSTR("1"));
	CFStringAppend(exampleKey, CFSTR("5BF0CF6E4383ACB9EA4473396"));
	CFStringAppend(exampleKey, CFSTR("49397BE"));
	CFStringAppend(exampleKey, CFSTR("D"));
	CFStringAppend(exampleKey, CFSTR("D"));
	CFStringAppend(exampleKey, CFSTR("48F556054DD9274A85448"));
	CFStringAppend(exampleKey, CFSTR("69BADE5F51EF06D897"));
	// *** End Public Key ***
	
	// Convert the example license file string to a CFData.
	// In a real app, you'd get this from somewhere else (e.g. a server), or use 
	// one of the file-based AP methods.
	CFDataRef exampleLicenseFileData = CFDataCreate(NULL,
													(const UInt8 *)exampleLicenseFileContents,
													(CFIndex)strlen(exampleLicenseFileContents));
	
	// Now, verify the license.
	// Try changing the example license file contents above and see what happens.
	
	// Let AP know what our public key is, so it can verify the signature.
	APSetKey(exampleKey);
	
	// You can just get back a boolean whether the license data is valid or not:
	Boolean licenseIsValid = APVerifyLicenseData(exampleLicenseFileData);
	if(licenseIsValid)
		CFShow(CFSTR("License passed boolean verification!\n"));
	else
		CFShow(CFSTR("License failed boolean verification!\n"));
	
	// Or, you can get back a full dictionary:
	CFDictionaryRef licenseDictionary = APCreateDictionaryForLicenseData(exampleLicenseFileData);
	if(licenseDictionary) {
		CFShow(licenseDictionary);
		CFRelease(licenseDictionary);
	} else {
		CFShow(CFSTR("No license dictionary results.\n"));
	}
	
	CFRelease(exampleLicenseFileData);
	CFRelease(exampleKey);

    return 0;
}