Kaydet (Commit) 91f645f5 authored tarafından Caolán McNamara's avatar Caolán McNamara

ofz: handle bad key len and subsequent PK11_ImportSymKey failure

Change-Id: Ied93745f924cbcbc674b5c9a78545aa1f79fc61e
Reviewed-on: https://gerrit.libreoffice.org/45513Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst ba4a124b
...@@ -34,9 +34,12 @@ Crypto::~Crypto() ...@@ -34,9 +34,12 @@ Crypto::~Crypto()
EVP_CIPHER_CTX_cleanup( &mContext ); EVP_CIPHER_CTX_cleanup( &mContext );
#endif #endif
#if USE_TLS_NSS #if USE_TLS_NSS
PK11_DestroyContext( mContext, PR_TRUE ); if (mContext)
PK11_FreeSymKey( mSymKey ); PK11_DestroyContext(mContext, PR_TRUE);
SECITEM_FreeItem( mSecParam, PR_TRUE ); if (mSymKey)
PK11_FreeSymKey(mSymKey);
if (mSecParam)
SECITEM_FreeItem(mSecParam, PR_TRUE);
#endif #endif
} }
...@@ -101,6 +104,9 @@ void Crypto::setupContext(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& i ...@@ -101,6 +104,9 @@ void Crypto::setupContext(std::vector<sal_uInt8>& key, std::vector<sal_uInt8>& i
keyItem.len = key.size(); keyItem.len = key.size();
mSymKey = PK11_ImportSymKey(pSlot, mechanism, PK11_OriginUnwrap, CKA_ENCRYPT, &keyItem, nullptr); mSymKey = PK11_ImportSymKey(pSlot, mechanism, PK11_OriginUnwrap, CKA_ENCRYPT, &keyItem, nullptr);
if (!mSymKey)
throw css::uno::RuntimeException("NSS SymKey failure", css::uno::Reference<css::uno::XInterface>());
mSecParam = PK11_ParamFromIV(mechanism, pIvItem); mSecParam = PK11_ParamFromIV(mechanism, pIvItem);
mContext = PK11_CreateContextBySymKey(mechanism, operation, mSymKey, mSecParam); mContext = PK11_CreateContextBySymKey(mechanism, operation, mSymKey, mSecParam);
} }
......
...@@ -113,6 +113,8 @@ bool Standard2007Engine::calculateEncryptionKey(const OUString& rPassword) ...@@ -113,6 +113,8 @@ bool Standard2007Engine::calculateEncryptionKey(const OUString& rPassword)
buffer[i] ^= hash[i]; buffer[i] ^= hash[i];
hash = comphelper::Hash::calculateHash(buffer.data(), buffer.size(), comphelper::HashType::SHA1); hash = comphelper::Hash::calculateHash(buffer.data(), buffer.size(), comphelper::HashType::SHA1);
if (mKey.size() > hash.size())
return false;
std::copy(hash.begin(), hash.begin() + mKey.size(), mKey.begin()); std::copy(hash.begin(), hash.begin() + mKey.size(), mKey.begin());
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment