MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / EnterInternal

Method EnterInternal

libcppcryptfs/util/KeybufManager.cpp:122–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120
121
122bool KeybufManager::EnterInternal()
123{
124
125 lock_guard<mutex> lock(m_mutex);
126
127 assert(m_refcount >= 0);
128
129 m_refcount++;
130
131 if (m_refcount > 1) {
132 return true;
133 }
134
135 if (m_key_cache_id) {
136 bool result = KeyCache::GetInstance()->Retrieve(m_key_cache_id, m_bufs);
137 if (result) {
138 return true;
139 }
140 }
141
142 DATA_BLOB key_blob;
143 DATA_BLOB enc_key_blob;
144
145 DATA_BLOB optional_entropy;
146 optional_entropy.cbData = static_cast<DWORD>(sizeof(m_optional_entropy));
147 optional_entropy.pbData = m_optional_entropy;
148
149 enc_key_blob.cbData = static_cast<DWORD>(m_encryptedBuf.size());
150 enc_key_blob.pbData = &m_encryptedBuf[0];
151
152 BOOL bResult = CryptUnprotectData(&enc_key_blob, NULL, &optional_entropy, NULL, NULL, 0, &key_blob);
153
154 if (!bResult)
155 throw std::exception("KeybufManager unable to decrypt keys");
156
157 if (key_blob.cbData != m_total_len) {
158 SecureZeroMemory(key_blob.pbData, key_blob.cbData);
159 LocalFree(key_blob.pbData);
160 throw std::exception("KeybufManager decrypted wrong number of bytes");
161 }
162
163 KeyBuf::CopyBuffers(m_bufs, key_blob.pbData, key_blob.cbData);
164
165 if (m_key_cache_id) {
166 KeyCache::GetInstance()->Store(m_key_cache_id, key_blob.pbData, key_blob.cbData);
167 }
168
169 SecureZeroMemory(key_blob.pbData, key_blob.cbData);
170 LocalFree(key_blob.pbData);
171
172 return bResult;
173}
174
175void KeybufManager::LeaveInternal()
176{

Callers

nothing calls this directly

Calls 3

RetrieveMethod · 0.80
sizeMethod · 0.80
StoreMethod · 0.80

Tested by

no test coverage detected