void Feed::CreateEntries(const std::string& feedData) { const xercesc_2_8::MemBufInputSource input( reinterpret_cast<const XMLByte*>(feedData.c_str()), feedData.size(), ""); xercesc_2_8::XercesDOMParser parser; parser.setValidationScheme(xercesc_2_8::XercesDOMParser::Val_Never); parser.parse(input); if (!parser.getDocument()->hasChildNodes() || !parser.getDocument()->getChildNodes()->item(0)->hasChildNodes()) { return; } const xercesc_2_8::DOMNodeList* const children = parser.getDocument()->getChildNodes()->item(0)->getChildNodes(); for (XMLSize_t i = 0, listLength = children->getLength(); i < listLength; ++i) { const xercesc_2_8::DOMNode* const node = children->item(i); const std::string nodeName = XmlCharsToStdString(node->getNodeName()); if (nodeName == XERCESC_EMPTY_NODE_NAME) { continue; } if (xercesc_2_8::XMLString::equals(nodeName.c_str(), "entry")) { AddEntryToList(node); } else { const std::string textContent = XmlCharsToStdString(node->getTextContent()); m_feedElements[nodeName] = textContent; } } }
nsresult nsClientAuthRememberService::RememberDecision(const nsACString & aHostName, CERTCertificate *aServerCert, CERTCertificate *aClientCert) { // aClientCert == NULL means: remember that user does not want to use a cert NS_ENSURE_ARG_POINTER(aServerCert); if (aHostName.IsEmpty()) return NS_ERROR_INVALID_ARG; nsCAutoString fpStr; nsresult rv = GetCertFingerprintByOidTag(aServerCert, SEC_OID_SHA256, fpStr); if (NS_FAILED(rv)) return rv; { nsAutoMonitor lock(monitor); if (aClientCert) { nsNSSCertificate pipCert(aClientCert); char *dbkey = NULL; rv = pipCert.GetDbKey(&dbkey); if (NS_SUCCEEDED(rv) && dbkey) { AddEntryToList(aHostName, fpStr, nsDependentCString(dbkey)); } if (dbkey) { PORT_Free(dbkey); } } else { nsCString empty; AddEntryToList(aHostName, fpStr, empty); } } return NS_OK; }
bool ListInterface::AddNewEntry(const wxString &groupName, const DataEntry &newEntry ) { List* list = FindListByName(groupName); if( !list ) { SetErrorMessage(wxT("List Not Found")); return false; } if( !ValidEntryName( newEntry.GetName() ) ) { SetErrorMessage(wxT("Name Already Exists")); return false; } DataEntry *e = new DataEntry(newEntry); data.push_back(e); AddEntryToList(*e); SortEntriesByGroup(); return true; }
NS_IMETHODIMP nsCertOverrideService::RememberValidityOverride(const nsACString & aHostName, PRInt32 aPort, nsIX509Cert *aCert, PRUint32 aOverrideBits, PRBool aTemporary) { NS_ENSURE_ARG_POINTER(aCert); if (aHostName.IsEmpty()) return NS_ERROR_INVALID_ARG; if (aPort < -1) return NS_ERROR_INVALID_ARG; nsCOMPtr<nsIX509Cert2> cert2 = do_QueryInterface(aCert); if (!cert2) return NS_ERROR_FAILURE; CERTCertificate* nsscert = cert2->GetCert(); if (!nsscert) return NS_ERROR_FAILURE; CERTCertificateCleaner nsscertCleaner(nsscert); nsCAutoString nickname; nickname = nsNSSCertificate::defaultServerNickname(nsscert); if (!aTemporary && !nickname.IsEmpty()) { PK11SlotInfo *slot = PK11_GetInternalKeySlot(); if (!slot) return NS_ERROR_FAILURE; SECStatus srv = PK11_ImportCert(slot, nsscert, CK_INVALID_HANDLE, const_cast<char*>(nickname.get()), PR_FALSE); PK11_FreeSlot(slot); if (srv != SECSuccess) return NS_ERROR_FAILURE; } nsCAutoString fpStr; nsresult rv = GetCertFingerprintByOidTag(nsscert, mOidTagForStoringNewHashes, fpStr); if (NS_FAILED(rv)) return rv; char *dbkey = NULL; rv = aCert->GetDbKey(&dbkey); if (NS_FAILED(rv) || !dbkey) return rv; // change \n and \r to spaces in the possibly multi-line-base64-encoded key for (char *dbkey_walk = dbkey; *dbkey_walk; ++dbkey_walk) { char c = *dbkey_walk; if (c == '\r' || c == '\n') { *dbkey_walk = ' '; } } { nsAutoMonitor lock(monitor); AddEntryToList(aHostName, aPort, aTemporary ? aCert : nsnull, // keep a reference to the cert for temporary overrides aTemporary, mDottedOidForStoringNewHashes, fpStr, (nsCertOverride::OverrideBits)aOverrideBits, nsDependentCString(dbkey)); Write(); } PR_Free(dbkey); return NS_OK; }
nsresult nsCertOverrideService::Read() { nsAutoMonitor lock(monitor); nsresult rv; nsCOMPtr<nsIInputStream> fileInputStream; rv = NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream), mSettingsFile); if (NS_FAILED(rv)) { return rv; } nsCOMPtr<nsILineInputStream> lineInputStream = do_QueryInterface(fileInputStream, &rv); if (NS_FAILED(rv)) { return rv; } nsCAutoString buffer; PRBool isMore = PR_TRUE; PRInt32 hostIndex = 0, algoIndex, fingerprintIndex, overrideBitsIndex, dbKeyIndex; /* file format is: * * host:port \t fingerprint-algorithm \t fingerprint \t override-mask \t dbKey * * where override-mask is a sequence of characters, * M meaning hostname-Mismatch-override * U meaning Untrusted-override * T meaning Time-error-override (expired/not yet valid) * * if this format isn't respected we move onto the next line in the file. */ while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(buffer, &isMore))) { if (buffer.IsEmpty() || buffer.First() == '#') { continue; } // this is a cheap, cheesy way of parsing a tab-delimited line into // string indexes, which can be lopped off into substrings. just for // purposes of obfuscation, it also checks that each token was found. // todo: use iterators? if ((algoIndex = buffer.FindChar('\t', hostIndex) + 1) == 0 || (fingerprintIndex = buffer.FindChar('\t', algoIndex) + 1) == 0 || (overrideBitsIndex = buffer.FindChar('\t', fingerprintIndex) + 1) == 0 || (dbKeyIndex = buffer.FindChar('\t', overrideBitsIndex) + 1) == 0) { continue; } const nsASingleFragmentCString &tmp = Substring(buffer, hostIndex, algoIndex - hostIndex - 1); const nsASingleFragmentCString &algo_string = Substring(buffer, algoIndex, fingerprintIndex - algoIndex - 1); const nsASingleFragmentCString &fingerprint = Substring(buffer, fingerprintIndex, overrideBitsIndex - fingerprintIndex - 1); const nsASingleFragmentCString &bits_string = Substring(buffer, overrideBitsIndex, dbKeyIndex - overrideBitsIndex - 1); const nsASingleFragmentCString &db_key = Substring(buffer, dbKeyIndex, buffer.Length() - dbKeyIndex); nsCAutoString host(tmp); nsCertOverride::OverrideBits bits; nsCertOverride::convertStringToBits(bits_string, bits); PRInt32 port; PRInt32 portIndex = host.RFindChar(':'); if (portIndex == kNotFound) continue; // Ignore broken entries PRInt32 portParseError; nsCAutoString portString(Substring(host, portIndex+1)); port = portString.ToInteger(&portParseError); if (portParseError) continue; // Ignore broken entries host.Truncate(portIndex); AddEntryToList(host, port, nsnull, // don't have the cert PR_FALSE, // not temporary algo_string, fingerprint, bits, db_key); } return NS_OK; }
BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPCWSTR keyPath) { DWORD max_sub_key_len; DWORD max_val_name_len; DWORD max_val_size; DWORD val_count; HKEY hNewKey; LONG errCode; INT i, c; BOOL AddedDefault = FALSE; if (!hwndLV) return FALSE; (void)ListView_EditLabel(hwndLV, -1); SendMessageW(hwndLV, WM_SETREDRAW, FALSE, 0); DestroyListView(hwndLV); (void)ListView_DeleteAllItems(hwndLV); if(!hKey) return FALSE; errCode = RegOpenKeyExW(hKey, keyPath, 0, KEY_READ, &hNewKey); if (errCode != ERROR_SUCCESS) return FALSE; /* get size information and resize the buffers if necessary */ errCode = RegQueryInfoKeyW(hNewKey, NULL, NULL, NULL, NULL, &max_sub_key_len, NULL, &val_count, &max_val_name_len, &max_val_size, NULL, NULL); if (errCode == ERROR_SUCCESS) { WCHAR* ValName = HeapAlloc(GetProcessHeap(), 0, ++max_val_name_len * sizeof(WCHAR)); DWORD dwValNameLen = max_val_name_len; BYTE* ValBuf = HeapAlloc(GetProcessHeap(), 0, max_val_size + sizeof(WCHAR)); DWORD dwValSize = max_val_size; DWORD dwIndex = 0L; DWORD dwValType; /* if (RegQueryValueExW(hNewKey, NULL, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) { */ /* AddEntryToList(hwndLV, L"(Default)", dwValType, ValBuf, dwValSize); */ /* } */ /* dwValSize = max_val_size; */ while (RegEnumValueW(hNewKey, dwIndex, ValName, &dwValNameLen, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) { /* Add a terminating 0 character. Usually this is only necessary for strings. */ ValBuf[dwValSize] = ValBuf[dwValSize + 1] = 0; AddEntryToList(hwndLV, ValName, dwValType, ValBuf, dwValSize, -1, TRUE); dwValNameLen = max_val_name_len; dwValSize = max_val_size; dwValType = 0L; ++dwIndex; if(!wcscmp(ValName, L"")) { AddedDefault = TRUE; } } HeapFree(GetProcessHeap(), 0, ValBuf); HeapFree(GetProcessHeap(), 0, ValName); } RegCloseKey(hNewKey); if(!AddedDefault) { AddEntryToList(hwndLV, L"", REG_SZ, NULL, 0, 0, FALSE); } c = ListView_GetItemCount(hwndLV); for(i = 0; i < c; i++) { ListView_SetItemState(hwndLV, i, 0, LVIS_FOCUSED | LVIS_SELECTED); } ListView_SetItemState(hwndLV, iListViewSelect, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); (void)ListView_Sort(hwndLV, g_iSortedColumn, -1); SendMessageW(hwndLV, WM_SETREDRAW, TRUE, 0); return TRUE; }