class CryptoImplementationNSS : public ICryptoImplementation
{
PK11SlotInfo* mSlot;
PK11Context* mContext;
SECItem* mSecParam;
PK11SymKey* mSymKey;
PK11Context* mWrapKeyContext;
PK11SymKey* mWrapKey;
public:
CryptoImplementationNSS()
: mSlot(nullptr)
, mContext(nullptr)
, mSecParam(nullptr)
, mSymKey(nullptr)
, mWrapKeyContext(nullptr)
, mWrapKey(nullptr)
{ // Initialize NSS, database functions are not needed if (!NSS_IsInitialized())
{ autoconst e = NSS_NoDB_Init(nullptr); if (e != SECSuccess)
{
PRErrorCode error = PR_GetError(); constchar* errorText = PR_ErrorToName(error); throw css::uno::RuntimeException( "NSS_NoDB_Init failed with "
+ OUString(errorText, strlen(errorText), RTL_TEXTENCODING_UTF8) + " ("
+ OUString::number(static_cast<int>(error)) + ")");
}
}
}
virtual ~CryptoImplementationNSS()
{ if (mContext)
PK11_DestroyContext(mContext, PR_TRUE); if (mSecParam)
SECITEM_FreeItem(mSecParam, PR_TRUE); if (mSymKey)
PK11_FreeSymKey(mSymKey); if (mWrapKeyContext)
PK11_DestroyContext(mWrapKeyContext, PR_TRUE); if (mWrapKey)
PK11_FreeSymKey(mWrapKey); if (mSlot)
PK11_FreeSlot(mSlot);
}
PK11SymKey* ImportSymKey(CK_MECHANISM_TYPE mechanism, CK_ATTRIBUTE_TYPE operation, SECItem* key)
{
mSymKey = PK11_ImportSymKey(mSlot, mechanism, PK11_OriginUnwrap, operation, key, nullptr); if (!mSymKey) //rhbz#1614419 maybe failed due to FIPS, use rhbz#1461450 style workaround
{ /* *WithoutFIPSitwouldbepossibletojustuse *mSymKey=PK11_ImportSymKey(mSlot,mechanism,PK11_OriginUnwrap,CKA_ENCRYPT,&keyItem,nullptr); *withFIPSNSSLevel2certificationhastobe"workarounded"(soitbecomesLevel1)byusing *followingmethod: *1.Generatewrapkey *2.Encryptauthkeywithwrapkey *3.Unwrapencryptedauthkeyusingwrapkey
*/
switch (type)
{ case CryptoType::AES_128_ECB: case CryptoType::AES_192_ECB: case CryptoType::AES_256_ECB:
mechanism = CKM_AES_ECB; break; case CryptoType::AES_128_CBC: case CryptoType::AES_192_CBC: case CryptoType::AES_256_CBC:
mechanism = CKM_AES_CBC;
pIvItem = &ivItem; break; default: break;
}
mSlot = PK11_GetBestSlot(mechanism, nullptr);
if (!mSlot) throw css::uno::RuntimeException(u"NSS Slot failure"_ustr,
css::uno::Reference<css::uno::XInterface>());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.