FskErr FskTextFreeTypeInstallFonts(char* fontsPath, char* defaultFont) { FskErr err = kFskErrNone; FskTextEngine fte; char *fromDirectory = NULL; char *fromPath = NULL; FskDirectoryIterator iterator = NULL; char *name = NULL; UInt32 type; err = FskTextEngineNew(&fte, NULL); if (err) goto bail; fromDirectory = FskEnvironmentDoApply(FskStrDoCopy(fontsPath)); if (!fromDirectory) { err = kFskErrMemFull; goto bail; } err = FskDirectoryIteratorNew(fromDirectory, &iterator, 0); if (err) goto bail; while (kFskErrNone == FskDirectoryIteratorGetNext(iterator, &name, &type)) { if (type == kFskDirectoryItemIsFile) { fromPath = FskStrDoCat(fromDirectory, name); if (!fromPath) { err = kFskErrMemFull; goto bail; } FskTextAddFontFile(fte, fromPath); FskMemPtrDisposeAt(&fromPath); } FskMemPtrDisposeAt(&name); } bail: FskTextEngineDispose(fte); FskMemPtrDispose(fromDirectory); FskDirectoryIteratorDispose(iterator); return err; }
void fxOpenProfileFile(txMachine* the, char* theName) { FskFile fref; char *applicationPath = NULL; char *profilePath = NULL; if (the->profileDirectory) profilePath = FskStrDoCat(the->profileDirectory, theName); else { applicationPath = FskEnvironmentDoApply(FskStrDoCopy("[applicationPath]")); profilePath = FskStrDoCat(applicationPath, theName); } FskFileDelete(profilePath); FskFileCreate(profilePath); if (kFskErrNone == FskFileOpen(profilePath, kFskFilePermissionReadWrite, &fref)) the->profileFile = fref; FskMemPtrDispose(profilePath); FskMemPtrDispose(applicationPath); }
FskErr FskTextFreeTypeInstallFonts(char* fontsPath, char* defaultFont) { FskErr err = kFskErrNone; FskTextEngine fte; char *fromDirectory = NULL; char* fromPath = NULL; FskDirectoryIterator iterator = NULL; char *name = NULL; UInt32 type; #if TARGET_OS_ANDROID char *toDirectory = NULL; char* toPath = NULL; FskFileInfo itemInfo; FskFileMapping map = NULL; unsigned char *data; FskInt64 dataSize; FskFile file = NULL; #endif err = FskTextEngineNew(&fte, NULL); if (err) goto bail; fromDirectory = FskEnvironmentDoApply(FskStrDoCopy(fontsPath)); if (!fromDirectory) { err = kFskErrMemFull; goto bail; } #if TARGET_OS_ANDROID if (!FskStrCompareWithLength(fromDirectory, "/data/app/", 10)) { err = FskDirectoryGetSpecialPath(kFskDirectorySpecialTypeApplicationPreference, false, NULL, &toDirectory); if (err) goto bail; } #endif err = FskDirectoryIteratorNew(fromDirectory, &iterator, 0); if (err) goto bail; while (kFskErrNone == FskDirectoryIteratorGetNext(iterator, &name, &type)) { if (type == kFskDirectoryItemIsFile) { fromPath = FskStrDoCat(fromDirectory, name); if (!fromPath) { err = kFskErrMemFull; goto bail; } FskDebugStr("from %s", fromPath); #if TARGET_OS_ANDROID if (toDirectory) { toPath = FskStrDoCat(toDirectory, name); FskDebugStr("to %s", toPath); if (kFskErrNone != FskFileGetFileInfo(toPath, &itemInfo)) { err = FskFileMap(fromPath, &data, &dataSize, 0, &map); if (err) goto bail; err = FskFileCreate(toPath); if (err) goto bail; err = FskFileOpen(toPath, kFskFilePermissionReadWrite, &file); if (err) goto bail; err = FskFileWrite(file, dataSize, data, NULL); if (err) goto bail; FskFileClose(file); file = NULL; FskFileDisposeMap(map); map = NULL; } FskDebugStr("add %s", toPath); FskTextAddFontFile(fte, toPath); FskMemPtrDisposeAt(&toPath); } else #endif FskTextAddFontFile(fte, fromPath); FskMemPtrDisposeAt(&fromPath); } FskMemPtrDisposeAt(&name); } #if TARGET_OS_ANDROID if (gAndroidCallbacks->getModelInfoCB) { char* osVersion; gAndroidCallbacks->getModelInfoCB(NULL, &osVersion, NULL, NULL, NULL); if ((FskStrStr(osVersion, "android.5") == osVersion) // for KPR applications || (FskStrStr(osVersion, "5.") == osVersion)) { // for tests BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/fonts.xml")); } if ((FskStrStr(osVersion, "android.4") == osVersion) // for KPR applications || (FskStrStr(osVersion, "4.") == osVersion)) { // for tests BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/system_fonts.xml")); err = FskFTAddMapping("/vendor/etc/fallback_fonts.xml"); if (err != kFskErrFileNotFound) BAIL(err); BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/fallback_fonts.xml")); } else { defaultFont = "Droid Sans"; BAIL_IF_ERR(err = FskFTAddMapping(NULL)); } } #endif if (defaultFont) FskTextDefaultFontSet(fte, defaultFont); bail: #if TARGET_OS_ANDROID if (file) FskFileClose(file); if (map) FskFileDisposeMap(map); FskMemPtrDispose(toPath); FskMemPtrDispose(toDirectory); #endif FskMemPtrDispose(name); FskDirectoryIteratorDispose(iterator); FskMemPtrDispose(fromPath); FskMemPtrDispose(fromDirectory); FskTextEngineDispose(fte); return err; }
static FskErr makeSSLRootVM(const char *calistpath) { #ifdef KPR_CONFIG FskErr err = kFskErrNone; xsBeginHost(gShell->root); xsTry { xsCall1_noResult(xsGet(xsGlobal, xsID("FskSSL")), xsID("loadRootCerts"), xsString((xsStringValue)calistpath)); } xsCatch { err = kFskErrOperationFailed; } xsEndHost(gShell->root); return err; #else char *rootPath, *xsbPath, *xsbName; xsGrammar *grammar; FskErr err; if ((err = FskMemPtrNewClear(sizeof(FskECMAScriptRecord), &gSSLVM)) != kFskErrNone) return err; #if FSK_EMBED FskExtensionsEmbedLoad(SSL_VMNAME); FskExtensionsEmbedGrammar(SSL_VMNAME, &xsbName, &grammar); #else xsbName = "FskCore.xsb"; grammar = &FskCoreGrammar; #endif rootPath = FskEnvironmentDoApply(FskStrDoCopy("[applicationPath]")); xsbPath = FskStrDoCat(rootPath, xsbName); FskMemPtrDispose(rootPath); grammar->name = (xsStringValue)SSL_VMNAME; if ((err = loadGrammar(xsbPath, grammar)) == kFskErrNone) { if ((gSSLVM->the = xsNewMachine(&anAllocation, grammar, gSSLVM)) == NULL) err = kFskErrMemFull; FskMemPtrDispose(grammar->symbols); FskMemPtrDispose(grammar->code); } FskMemPtrDispose(xsbPath); BAIL_IF_ERR(err); xsBeginHost(gSSLVM->the); xsTry { #if !FSK_EMBED /* load Crypt and FskSSL extensions which are only needed for Fsk SSL */ xsCall3_noResult(xsGet(xsGlobal, xsID("System")), xsID("loadExtension"), xsString("Crypt"), xsString("[applicationPath]"), xsInteger(0)); xsCall3_noResult(xsGet(xsGlobal, xsID("System")), xsID("loadExtension"), xsString("FskSSL"), xsString("[applicationPath]"), xsInteger(1)); #endif xsCall1_noResult(xsGet(xsGlobal, xsID("FskSSL")), xsID("loadRootCerts"), xsString((xsStringValue)calistpath)); } xsCatch { err = kFskErrOperationFailed; } xsEndHost(gSSLVM->the); if (err == kFskErrNone) xsShareMachine(gSSLVM->the); bail: if (err != kFskErrNone) disposeSSLRootVM(); return err; #endif }
Boolean FskSSLCheckServerCert(SSL *ssl, char *hostname) { long err; X509 *peer; char peer_CN[256]; err = SSL_get_verify_result(ssl); #if 0 if ((err != X509_V_OK) && (err != X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) && (err != X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)) { ERR_print_errors_fp(stderr); fprintf(stderr, "[%s] cert for %s didn't verify %d %s\n", threadTag(FskThreadGetCurrent()), hostname, err, X509_verify_cert_error_string(err)); #else if (err != X509_V_OK) { if ((NULL != FskStrStr(hostname, "google.com")) || (NULL != FskStrStr(hostname, "googleapis.com")) || (NULL != FskStrStr(hostname, "twitter.com")) || (NULL != FskStrStr(hostname, "yammer.com")) || (NULL != FskStrStr(hostname, "facebook.com")) || (NULL != FskStrStr(hostname, "foursquare.com")) || (NULL != FskStrStr(hostname, "akamaihd.net")) || (NULL != FskStrStr(hostname, "fbcdn.net")) || (NULL != FskStrStr(hostname, "radiotime.com")) || (NULL != FskStrStr(hostname, "s3.amazonaws.com")) || (NULL != FskStrStr(hostname, "orb.com"))) { if ((err != X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) && (err != X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)) { return false; } myprintf((stderr, "b) cert didn't verify because %d %s\n", err, X509_verify_cert_error_string(err))); myprintf((stderr, " but since it's %s we'll let it through\n", hostname)); } else { #endif return false; } } peer = SSL_get_peer_certificate(ssl); X509_NAME_get_text_by_NID(X509_get_subject_name(peer), NID_commonName, peer_CN, 256); //fprintf(stderr, "comparing peer_CN %s with hostname %s\n", peer_CN, hostname); if (FskStrCompareCaseInsensitive(peer_CN, hostname)) { int pos, L, subL; char *match = peer_CN + 1; subL = FskStrLen(match); L = FskStrLen(hostname); if (peer_CN[0] == '*') { pos = L - subL; if (0 == FskStrCompareCaseInsensitive(match, hostname + pos)) { //fprintf(stderr, "Matched wildcard %s and %s\n", match, hostname + pos); return true; } } if ( (FskStrEndsWith(match, "akamaihd.net") && FskStrEndsWith(hostname, "akamai.net")) || (FskStrEndsWith(match, "akamai.net") && FskStrEndsWith(hostname, "akamaihd.net")) ) { return true; } myprintf((stderr, "cert common name %s and host %s don't match\n", peer_CN, hostname)); return false; } return true; } //SSL_CTX *FskSSLInitialize(char *keyfile, char *password) static SSL_CTX *FskOpenSSLInitialize(const char *calistpath) { SSL_METHOD *method; SSL_CTX *context; if (gSSLContext) { return gSSLContext; } else { SSL_library_init(); SSL_load_error_strings(); // not necessary, but useful } method = SSLv23_method(); context = SSL_CTX_new(method); #if 0 if (FskStrLen(keyfile) > 0) { keyfile = FskEnvironmentDoApply(FskStrDoCopy(keyfile)); if (!SSL_CTX_use_certificate_chain_file(context, keyfile)) doSSLError("Can't read certificate file"); fprintf(stderr, "keyfile is %s\n", keyfile); if (FskStrLen(password) > 0) { gSSLPassword = FskStrDoCopy(password); SSL_CTX_set_default_passwd_cb(context, passwordCallback); if (!SSL_CTX_use_PrivateKey_file(context, keyfile, SSL_FILETYPE_PEM)) doSSLError( "Can't read private keyfile"); } FskMemPtrDispose(keyfile); } #endif #if TARGET_OS_WIN32 { // try to make the path 8.3 safe to avoid nightmares with multibyte character paths, etc. UInt16 *nativePath; if (kFskErrNone == FskFilePathToNative(calistpath, (char **)&nativePath)) { DWORD shortLen; shortLen = GetShortPathNameW(nativePath, NULL, 0); if (0 != shortLen) { UInt16 *eightDotThree; if (kFskErrNone == FskMemPtrNewClear(shortLen * 2, (FskMemPtr *)&eightDotThree)) { if (0 != GetShortPathNameW(nativePath, eightDotThree, shortLen)) { char *utf8; UInt32 utf8Len; if (kFskErrNone == FskTextUnicode16LEToUTF8(eightDotThree, shortLen * 2, &utf8, &utf8Len)) { char *enc; if (kFskErrNone == FskTextToPlatform(utf8, utf8Len, &enc, NULL)) { FskMemPtrDispose(calistpath); calistpath = enc; } FskMemPtrDispose(utf8); } } FskMemPtrDispose(eightDotThree); } } FskMemPtrDispose(nativePath); } } #endif if (!(SSL_CTX_load_verify_locations(context, calistpath, 0))) { doSSLError("Can't read default CA list"); } SSL_CTX_set_verify_depth(context, 0); // SSL_CTX_set_verify(context, SSL_VERIFY_PEER, 0); gSSLContext = context; return context; }