| 96 | } |
| 97 | |
| 98 | BOOL SavedPasswords::SavePassword(LPCWSTR path, LPCWSTR password) |
| 99 | { |
| 100 | wstring hash; |
| 101 | |
| 102 | if (!GetPathHash(path, hash)) { |
| 103 | return FALSE; |
| 104 | } |
| 105 | |
| 106 | LockZeroBuffer<WCHAR> *pBuf = NULL; |
| 107 | |
| 108 | |
| 109 | DWORD len = (DWORD)wcslen(password); |
| 110 | |
| 111 | if (len < 1) |
| 112 | return FALSE; |
| 113 | |
| 114 | if (len < MIN_SAVED_PASSWORD_LEN) { |
| 115 | pBuf = new LockZeroBuffer<WCHAR>(MIN_SAVED_PASSWORD_LEN, true); |
| 116 | wcscpy_s(pBuf->m_buf, MIN_SAVED_PASSWORD_LEN, password); |
| 117 | password = pBuf->m_buf; |
| 118 | len = MIN_SAVED_PASSWORD_LEN; |
| 119 | } else { |
| 120 | len += 1; |
| 121 | } |
| 122 | |
| 123 | DATA_BLOB pw_blob; |
| 124 | DATA_BLOB enc_pw_blob; |
| 125 | DATA_BLOB optional_entropy; |
| 126 | |
| 127 | const char *entropy = OPTIONAL_ENTROPY; |
| 128 | optional_entropy.cbData = (DWORD)strlen(entropy); |
| 129 | optional_entropy.pbData = (BYTE*)entropy; |
| 130 | |
| 131 | pw_blob.cbData = len*sizeof(WCHAR); |
| 132 | pw_blob.pbData = (BYTE*)password; |
| 133 | |
| 134 | bool bResult = CryptProtectData(&pw_blob, NULL, &optional_entropy, NULL, NULL, 0, &enc_pw_blob); |
| 135 | |
| 136 | if (pBuf) |
| 137 | delete pBuf; |
| 138 | |
| 139 | |
| 140 | if (!bResult) |
| 141 | return FALSE; |
| 142 | |
| 143 | BOOL bRet = theApp.WriteProfileBinary(SAVED_PASSWORDS_SECTION, hash.c_str(), enc_pw_blob.pbData, enc_pw_blob.cbData); |
| 144 | |
| 145 | LocalFree(enc_pw_blob.pbData); |
| 146 | |
| 147 | return bRet; |
| 148 | } |
| 149 | |
| 150 | BOOL SavedPasswords::RetrievePassword(LPCWSTR path, LPWSTR password_buf, DWORD password_buf_len) |
| 151 | { |
nothing calls this directly
no test coverage detected