void RTPSessionInterface::CreateDigestAuthenticationNonce() { // Calculate nonce: MD5 of sessionid:timestamp SInt64 curTime = OS::Milliseconds(); char* curTimeStr = new char[128]; qtss_sprintf(curTimeStr, "%" _64BITARG_ "d", curTime); // Delete old nonce before creating a new one if (fAuthNonce.Ptr != NULL) delete[] fAuthNonce.Ptr; MD5_CTX ctxt; unsigned char nonceStr[16]; unsigned char colon[] = ":"; MD5_Init(&ctxt); StrPtrLen* sesID = this->GetValue(qtssCliSesRTSPSessionID); MD5_Update(&ctxt, (unsigned char *)sesID->Ptr, sesID->Len); MD5_Update(&ctxt, (unsigned char *)colon, 1); MD5_Update(&ctxt, (unsigned char *)curTimeStr, ::strlen(curTimeStr)); MD5_Final(nonceStr, &ctxt); HashToString(nonceStr, &fAuthNonce); delete[] curTimeStr; // No longer required once nonce is created // Set the nonce count value to zero // as a new nonce has been created fAuthNonceCount = 0; }
BOOL FetchUpdaterModule() { int responseCode; TCHAR updateFilePath[MAX_PATH]; BYTE updateFileHash[20]; TCHAR extraHeaders[256]; tsprintf_s (updateFilePath, _countof(updateFilePath)-1, TEXT("%s\\updates\\updater.exe"), lpAppDataPath); if (CalculateFileHash(updateFilePath, updateFileHash)) { TCHAR hashString[41]; HashToString(updateFileHash, hashString); tsprintf_s (extraHeaders, _countof(extraHeaders)-1, TEXT("If-None-Match: %s"), hashString); } else extraHeaders[0] = 0; if (HTTPGetFile(TEXT("https://obsproject.com/update/updater.exe"), updateFilePath, extraHeaders, &responseCode)) { if (responseCode != 200 && responseCode != 304) return FALSE; } return TRUE; }
/* * Digest: Returns the MD5 hash of user:realm:password */ static char* Digest(char *user, char *passwd, char *realm) { StrPtrLen userSPL(user), passwdSPL(passwd), realmSPL(realm), hashHex16Bit, hashSPL; CalcMD5HA1(&userSPL, &realmSPL, &passwdSPL, &hashHex16Bit); // memory allocated for hashHex16Bit.Ptr HashToString((unsigned char *)hashHex16Bit.Ptr, &hashSPL); // memory allocated for hashSPL.Ptr char* digestStr = hashSPL.GetAsCString(); delete [] hashSPL.Ptr; // freeing memory allocated in above calls delete [] hashHex16Bit.Ptr; return digestStr; }
VOID GenerateGUID(String &strGUID) { BYTE junk[20]; if (!CryptGenRandom(hProvider, sizeof(junk), junk)) return; strGUID.SetLength(41); HashToString(junk, strGUID.Array()); }
void RTConnectionManager::GenericSessionId(std::string& strId) { SInt64 curTime = OS::Microseconds(); MD5_CTX context; StrPtrLen hashStr; OSMutexLocker locker(&s_mutex); memset(s_curMicroSecStr, 0, 128); memset(s_digest, 0, 16); qtss_sprintf(s_curMicroSecStr, "%lld", curTime); MD5_Init(&context); MD5_Update(&context, (unsigned char*)s_curMicroSecStr, (unsigned int)strlen((const char*)s_curMicroSecStr)); MD5_Update(&context, (unsigned char*)m_lastUpdateTime.c_str(), (unsigned int)m_lastUpdateTime.length()); MD5_Final(s_digest, &context); HashToString(s_digest, &hashStr); strId = hashStr.GetAsCString(); m_lastUpdateTime = s_curMicroSecStr; }
std::string NotaryPage::hashFile(std::string fileName) { unsigned char hashSha[SHA256_DIGEST_LENGTH]; FILE* file = fopen(fileName.c_str(), "rb"); if (file == NULL) { return ""; } SHA256_CTX sha256; SHA256_Init(&sha256); char buffer[4096]; int bytesRead = 0; while ((bytesRead = fread(buffer, 1, 4096, file)) != 0) { SHA256_Update(&sha256, buffer, bytesRead); } SHA256_Final(hashSha, &sha256); std::string notaryID = HashToString(hashSha, SHA256_DIGEST_LENGTH); LogPrintf("NotaryPage::hashFile: hash of file: %s\n", notaryID); fclose(file); return notaryID; }
int vsinterpreter_execute (vs_cursor *cursor,vs_cursor *thesaurus,interpreter_session *session, char command, t_uuid elementid,float value, vs_queue *output_buffer ){ vs_value val; vs_cursor *cluster; vector *temp; char *did,*cCX,*cCY,*cCZ,*cCA; int result,min, CX,CY, CZ; result = 0; time(&session->touched); if (command=='M'){ did = HashToString(elementid); min = atoi(did); free(did); session->mode = (int)min; session->thesaurus = value; } if (command=='Q'){ session->current_vector = vs_createvector (elementid,(int) value); // printf ("Q%d\n",(int) value); session->vectorcount=0; session->command=command; result = 1; } if (command=='V'){ // printf ("V%d\n",(int) value); session->current_vector = vs_createvector (elementid,(int) value); session->vectorcount=0; session->command=command; result = 1; } if (command=='T'){ // printf ("V%d\n",(int) value); session->current_vector = vs_createvector (elementid,(int) value); session->vectorcount=0; session->command=command; result = 1; } if (command=='D'){ if (session->current_vector!=NULL){ val.floatvalue= value; vs_setvalue(session->current_vector,elementid,val); session->vectorcount+=1; if (session->vectorcount==session->current_vector->dimensioncount){ if (session->command=='V'){ if (session->mode==CLASSIFIED_VECTOR_MODE){ vst_classify_vector(session->current_vector,thesaurus,session->thesaurus); } if (session->mode==META_VECTOR_MODE){ temp = vst_metavector(session->current_vector,thesaurus,session->thesaurus); vs_destroyvector(&session->current_vector); session->current_vector = temp; } vsc_replacevector(cursor,session->current_vector); vs_destroyvector(&session->current_vector); session->current_vector=NULL; } if (session->command=='T'){ vsc_replacevector(thesaurus,session->current_vector); vs_destroyvector(&session->current_vector); } } result = 1; } } if (command=='-'){ vsc_deletevector(cursor,elementid); result = 1; } if (command=='E'){ if (session->mode==CLASSIFIED_VECTOR_MODE){ vst_classify_vector(session->current_vector,thesaurus,session->thesaurus); } if (session->mode==META_VECTOR_MODE){ temp = vst_metavector(session->current_vector,thesaurus,session->thesaurus); vs_destroyvector(&session->current_vector); session->current_vector = temp; } vsdb_query(session->id,cursor,session->current_vector,value,output_buffer); vs_destroyvector(&session->current_vector); session->current_vector=NULL; result = 1; } if (command=='X'){ if (session->mode==CLASSIFIED_VECTOR_MODE){ vst_classify_vector(session->current_vector,thesaurus,session->thesaurus); } if (session->mode==META_VECTOR_MODE){ temp = vst_metavector(session->current_vector,thesaurus,session->thesaurus); vs_destroyvector(&session->current_vector); session->current_vector = temp; } vsdb_query(session->id,cursor,session->current_vector,value,output_buffer); vs_destroyvector(&session->current_vector); result = 2; } if (command=='C'){ did = HashToString(elementid); // XXXXXXXXXXYYYYYYYYYYZZZZZZZZZZAA //min = atoi(did); cCX = malloc(10); cCY = malloc(10); cCZ = malloc(10); cCA = malloc(2); sscanf(did,"%10s%10s%10s%2s",cCX,cCY,cCZ,cCA); CX = atoi(cCX); CY = atoi(cCY); CZ = atoi(cCZ); free(did); //X Y Z // cluster = vsc_vector_cluster(cursor,CX,CY,value,CZ); // vsdb_outputcursor(session->id,cluster,output_buffer); // vsc_destroycursor(&cluster); // result = 1; // cluster = vsc_vector_metacluster(cursor,CX,CY,value,CZ); cluster = vsc_vector_cluster(cursor,CX,CY,value,CZ); vsdb_outputcursor(session->id,cluster,output_buffer); vsc_destroycursor(&cluster); result=1; } if (command=='K'){ did = HashToString(elementid); min = atoi(did); free(did); cluster = vsc_vector_metacluster(cursor,0,cursor->count,value,min); vsdb_outputcursor(session->id,cluster,output_buffer); vsc_destroycursor(&cluster); result = 1; } if (command=='S'){ //used by the persistor to dump the contents of the cursor //persistor then reloads everything using standard V commands. vsdb_outputcursor(session->id,cursor,output_buffer); result = 1; } return(result); }
DWORD WINAPI CheckUpdateThread (VOID *arg) { int responseCode; TCHAR extraHeaders[256]; BYTE manifestHash[20]; TCHAR manifestPath[MAX_PATH]; tsprintf_s (manifestPath, _countof(manifestPath)-1, TEXT("%s\\updates\\packages.xconfig"), lpAppDataPath); if (!CryptAcquireContext(&hProvider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { Log (TEXT("Updater: CryptAcquireContext failed: %08x"), GetLastError()); return 1; } extraHeaders[0] = 0; if (CalculateFileHash(manifestPath, manifestHash)) { TCHAR hashString[41]; HashToString(manifestHash, hashString); tsprintf_s (extraHeaders, _countof(extraHeaders)-1, TEXT("If-None-Match: %s"), hashString); } //this is an arbitrary random number that we use to count the number of unique OBS installations //and is not associated with any kind of identifiable information String strGUID = GlobalConfig->GetString(TEXT("General"), TEXT("InstallGUID")); if (strGUID.IsEmpty()) { GenerateGUID(strGUID); if (strGUID.IsValid()) GlobalConfig->SetString(TEXT("General"), TEXT("InstallGUID"), strGUID); } if (strGUID.IsValid()) { if (extraHeaders[0]) scat(extraHeaders, TEXT("\n")); scat(extraHeaders, TEXT("X-OBS-GUID: ")); scat(extraHeaders, strGUID); } if (HTTPGetFile(TEXT("https://obsproject.com/update/packages.xconfig"), manifestPath, extraHeaders, &responseCode)) { if (responseCode == 200 || responseCode == 304) { String updateInfo; BOOL updatesAvailable; updateInfo = Str("Updater.NewUpdates"); if (ParseUpdateManifest(manifestPath, &updatesAvailable, updateInfo)) { if (updatesAvailable) { updateInfo << TEXT("\r\n") << Str("Updater.DownloadNow"); if (MessageBox (NULL, updateInfo.Array(), Str("Updater.UpdatesAvailable"), MB_ICONQUESTION|MB_YESNO) == IDYES) { if (App->IsRunning()) { if (MessageBox (NULL, Str("Updater.RunningWarning"), NULL, MB_ICONEXCLAMATION|MB_YESNO) == IDNO) goto abortUpdate; } TCHAR updateFilePath[MAX_PATH]; TCHAR cwd[MAX_PATH]; GetModuleFileName(NULL, cwd, _countof(cwd)-1); TCHAR *p = srchr(cwd, '\\'); if (p) *p = 0; tsprintf_s (updateFilePath, _countof(updateFilePath)-1, TEXT("%s\\updates\\updater.exe"), lpAppDataPath); //note, can't use CreateProcess to launch as admin. SHELLEXECUTEINFO execInfo; zero(&execInfo, sizeof(execInfo)); execInfo.cbSize = sizeof(execInfo); execInfo.lpFile = updateFilePath; #ifndef _WIN64 execInfo.lpParameters = TEXT("Win32"); #else execInfo.lpParameters = TEXT("Win64"); #endif execInfo.lpDirectory = cwd; execInfo.nShow = SW_SHOWNORMAL; if (!ShellExecuteEx (&execInfo)) { AppWarning(TEXT("Can't launch updater '%s': %d"), updateFilePath, GetLastError()); goto abortUpdate; } //force OBS to perform another update check immediately after updating in case of issues //with the new version GlobalConfig->SetInt(TEXT("General"), TEXT("LastUpdateCheck"), 0); //since we're in a separate thread we can't just PostQuitMessage ourselves SendMessage(hwndMain, WM_CLOSE, 0, 0); } } } } } abortUpdate: CryptReleaseContext(hProvider, 0); return 0; }
BOOL ParseUpdateManifest (TCHAR *path, BOOL *updatesAvailable, String &description) { XConfig manifest; XElement *root; if (!manifest.Open(path)) return FALSE; root = manifest.GetRootElement(); DWORD numPackages = root->NumElements(); DWORD totalUpdatableFiles = 0; int priority, bestPriority = 999; for (DWORD i = 0; i < numPackages; i++) { XElement *package; package = root->GetElementByID(i); CTSTR packageName = package->GetName(); //find out if this package is relevant to us String platform = package->GetString(TEXT("platform")); if (!platform) continue; if (scmp(platform, TEXT("all"))) { #ifndef _WIN64 if (scmp(platform, TEXT("Win32"))) continue; #else if (scmp(platform, TEXT("Win64"))) continue; #endif } //what is it? String name = package->GetString(TEXT("name")); String version = package->GetString(TEXT("version")); //figure out where the files belong XDataItem *pathElement = package->GetDataItem(TEXT("path")); if (!pathElement) continue; CTSTR path = pathElement->GetData(); if (path == NULL) path = TEXT(""); if (!IsSafePath(path)) continue; priority = package->GetInt(TEXT("priority"), 999); //get the file list for this package XElement *files = package->GetElement(TEXT("files")); if (!files) continue; DWORD numFiles = files->NumElements(); DWORD numUpdatableFiles = 0; for (DWORD j = 0; j < numFiles; j++) { XElement *file = files->GetElementByID(j); String hash = file->GetString(TEXT("hash")); if (!hash || hash.Length() != 40) continue; String fileName = file->GetName(); if (!fileName) continue; if (!IsSafeFilename(fileName)) continue; String filePath; filePath << path; filePath << fileName; BYTE fileHash[20]; TCHAR fileHashString[41]; if (OSFileExists(filePath)) { if (!CalculateFileHash(filePath, fileHash)) continue; HashToString(fileHash, fileHashString); if (!scmp(fileHashString, hash)) continue; } numUpdatableFiles++; } if (numUpdatableFiles) { if (version.Length()) description << name << TEXT(" (") << version << TEXT(")\r\n"); else description << name << TEXT("\r\n"); if (priority < bestPriority) bestPriority = priority; } totalUpdatableFiles += numUpdatableFiles; numUpdatableFiles = 0; } manifest.Close(); if (totalUpdatableFiles) { if (!FetchUpdaterModule()) return FALSE; } if (bestPriority <= 5) *updatesAvailable = TRUE; else *updatesAvailable = FALSE; return TRUE; }
int vsd_interpreter_execute ( __vdi_interface *intf,char *thesaurus_directory,vs_cursor *cursor,vs_cursor *thesaurus,interpreter_session *session, char command, t_uuid elementid,float value, vs_queue *output_buffer ){ vs_value val; vector *temp; char *did; int result,min; result = 0; time(&session->touched); if (command=='M'){ did = HashToString(elementid); min = atoi(did); free(did); session->mode = (int)min; session->thesaurus = value; } if (command=='Q'){ session->current_vector = vs_createvector (elementid,(int) value); // printf ("Q%d\n",(int) value); session->vectorcount=0; session->command=command; result = 1; } if (command=='V'){ // printf ("V%d\n",(int) value); session->current_vector = vs_createvector (elementid,(int) value); session->vectorcount=0; session->command=command; result = 1; } if (command=='T'){ // printf ("V%d\n",(int) value); session->current_vector = vs_createvector (elementid,(int) value); session->vectorcount=0; session->command=command; result = 1; } if (command=='D'){ if (session->current_vector!=NULL){ val.floatvalue= value; vs_setvalue(session->current_vector,elementid,val); session->vectorcount+=1; if (session->vectorcount==session->current_vector->dimensioncount){ if (session->command=='V'){ if (session->mode==CLASSIFIED_VECTOR_MODE){ vst_classify_vector(session->current_vector,thesaurus,session->thesaurus); } if (session->mode==META_VECTOR_MODE){ temp = vst_metavector(session->current_vector,thesaurus,session->thesaurus); vs_destroyvector(&session->current_vector); session->current_vector = temp; } //DISK REPLACE VECTOR vsd_replacevector(intf,session->current_vector); vs_destroyvector(&session->current_vector); session->current_vector=NULL; } if (session->command=='T'){ //DISK REPLACE THESAURUS vsd_replacevector(intf,session->current_vector); vs_destroyvector(&session->current_vector); } } result = 1; } } if (command=='-'){ //DISK DELETE VECTOR vsd_deletevector(intf,elementid); result = 1; } if (command=='E'){ if (session->mode==CLASSIFIED_VECTOR_MODE){ vst_classify_vector(session->current_vector,thesaurus,session->thesaurus); } if (session->mode==META_VECTOR_MODE){ temp = vst_metavector(session->current_vector,thesaurus,session->thesaurus); vs_destroyvector(&session->current_vector); session->current_vector = temp; } //DISK QUERY vsd_query(intf,session->id,session->current_vector,value,output_buffer); vs_destroyvector(&session->current_vector); session->current_vector=NULL; result = 1; } if (command=='X'){ if (session->mode==CLASSIFIED_VECTOR_MODE){ vst_classify_vector(session->current_vector,thesaurus,session->thesaurus); } if (session->mode==META_VECTOR_MODE){ temp = vst_metavector(session->current_vector,thesaurus,session->thesaurus); vs_destroyvector(&session->current_vector); session->current_vector = temp; } //DISK QUERY vsd_query(intf,session->id,session->current_vector,value,output_buffer); vs_destroyvector(&session->current_vector); result = 2; } return(result); }