From: Anju Date: Fri, 5 Apr 2013 11:04:09 +0000 (+0530) Subject: [PKCS] Fix review comments, jira issue and prevent issue X-Git-Tag: accepted/tizen_2.1/20130425.034849~148 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ccc2d7bce6461b98d5cdcadf47ceaac196823b4;p=platform%2Fframework%2Fnative%2Fappfw.git [PKCS] Fix review comments, jira issue and prevent issue Change-Id: I718b817181ee102aac396e93d89941ef93b7d63a Signed-off-by: Anju --- diff --git a/src/security/pkcs/FSecPkcsAlgorithmIdentifier.cpp b/src/security/pkcs/FSecPkcsAlgorithmIdentifier.cpp index 384da84..726582f 100644 --- a/src/security/pkcs/FSecPkcsAlgorithmIdentifier.cpp +++ b/src/security/pkcs/FSecPkcsAlgorithmIdentifier.cpp @@ -76,12 +76,11 @@ const wchar_t OID_ATTR_EMAIL_ADDRESS[] = L"1.2.840.113549.1.9.1"; AlgorithmIdentifier::AlgorithmIdentifier(void) : __pAlgorithmIdentifierImpl(null) { - __pAlgorithmIdentifierImpl = new (std::nothrow) _AlgorithmIdentifierImpl(); - SysTryReturnVoidResult(NID_SEC_CERT, __pAlgorithmIdentifierImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + } AlgorithmIdentifier::~AlgorithmIdentifier(void) { - delete __pAlgorithmIdentifierImpl; + } result @@ -89,9 +88,22 @@ AlgorithmIdentifier::Construct(const Tizen::Base::String& algorithm, const IAlgo { result r = E_SUCCESS; - SysAssertf(__pAlgorithmIdentifierImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pAlgorithmIdentifierImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + + __pAlgorithmIdentifierImpl = new (std::nothrow) _AlgorithmIdentifierImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pAlgorithmIdentifierImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pAlgorithmIdentifierImpl->Construct(algorithm, pAlgoParams); - SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pAlgorithmIdentifierImpl; + __pAlgorithmIdentifierImpl = null; return r; } @@ -101,9 +113,21 @@ AlgorithmIdentifier::Construct(const Tizen::Base::ByteBuffer& encodedData) { result r = E_SUCCESS; - SysAssertf(__pAlgorithmIdentifierImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pAlgorithmIdentifierImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pAlgorithmIdentifierImpl = new (std::nothrow) _AlgorithmIdentifierImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pAlgorithmIdentifierImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pAlgorithmIdentifierImpl->Construct(encodedData); - SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pAlgorithmIdentifierImpl; + __pAlgorithmIdentifierImpl = null; return r; } @@ -149,6 +173,7 @@ AlgorithmIdentifier::GetParametersN(void) const ClearLastResult(); SysAssertf(__pAlgorithmIdentifierImpl != null, "Not yet constructed. Reconstructor the object."); + std::unique_ptr< IAlgorithmParameters > pObj(__pAlgorithmIdentifierImpl->GetParametersN()); SysTryReturn(NID_IO, pObj != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r)); @@ -164,6 +189,7 @@ AlgorithmIdentifier::GetEncodedDataN(void) const ClearLastResult(); SysAssertf(__pAlgorithmIdentifierImpl != null, "Not yet constructed. Reconstructor the object."); + std::unique_ptr< ByteBuffer > pEncAlgoIdParam(__pAlgorithmIdentifierImpl->GetEncodedDataN()); SysTryReturn(NID_IO, pEncAlgoIdParam != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r)); diff --git a/src/security/pkcs/FSecPkcsInitialVector.cpp b/src/security/pkcs/FSecPkcsInitialVector.cpp index 0b4b8fa..252e6ec 100644 --- a/src/security/pkcs/FSecPkcsInitialVector.cpp +++ b/src/security/pkcs/FSecPkcsInitialVector.cpp @@ -39,13 +39,12 @@ namespace Tizen { namespace Security { namespace Pkcs InitialVector::InitialVector(void) : __pInitialVectorImpl(null) { - __pInitialVectorImpl = new (std::nothrow) _InitialVectorImpl(); - SysTryReturnVoidResult(NID_SEC_CERT, __pInitialVectorImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + } InitialVector::~InitialVector(void) { - delete __pInitialVectorImpl; + } result @@ -53,10 +52,21 @@ InitialVector::Construct(const Tizen::Base::ByteBuffer& initialVector) { result r = E_SUCCESS; - SysAssertf(__pInitialVectorImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pInitialVectorImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pInitialVectorImpl = new (std::nothrow) _InitialVectorImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pInitialVectorImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); r = __pInitialVectorImpl->Construct(initialVector); - SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pInitialVectorImpl; + __pInitialVectorImpl = null; return r; diff --git a/src/security/pkcs/FSecPkcsPkcs05PbEs2Parameters.cpp b/src/security/pkcs/FSecPkcsPkcs05PbEs2Parameters.cpp index a644ca0..38dc41e 100644 --- a/src/security/pkcs/FSecPkcsPkcs05PbEs2Parameters.cpp +++ b/src/security/pkcs/FSecPkcsPkcs05PbEs2Parameters.cpp @@ -40,13 +40,12 @@ namespace Tizen { namespace Security { namespace Pkcs Pkcs05PbEs2Parameters::Pkcs05PbEs2Parameters(void) : __pPkcs05PbEs2ParametersImpl(null) { - __pPkcs05PbEs2ParametersImpl = new (std::nothrow) _Pkcs05PbEs2ParametersImpl(); - SysTryReturnVoidResult(NID_SEC_CRYPTO, __pPkcs05PbEs2ParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + } Pkcs05PbEs2Parameters::~Pkcs05PbEs2Parameters(void) { - delete __pPkcs05PbEs2ParametersImpl; + } result @@ -54,12 +53,23 @@ Pkcs05PbEs2Parameters::Construct(const Tizen::Base::ByteBuffer& encodedData) { result r = E_SUCCESS; - SysAssertf(__pPkcs05PbEs2ParametersImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs05PbEs2ParametersImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs05PbEs2ParametersImpl = new (std::nothrow) _Pkcs05PbEs2ParametersImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs05PbEs2ParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs05PbEs2ParametersImpl->Construct(encodedData); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); return r; +CATCH: + + delete __pPkcs05PbEs2ParametersImpl; + __pPkcs05PbEs2ParametersImpl = null; + + return r; } result @@ -67,9 +77,22 @@ Pkcs05PbEs2Parameters::Construct(const AlgorithmIdentifier& keyDerivationFunctio { result r = E_SUCCESS; - SysAssertf(__pPkcs05PbEs2ParametersImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs05PbEs2ParametersImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs05PbEs2ParametersImpl = new (std::nothrow) _Pkcs05PbEs2ParametersImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs05PbEs2ParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs05PbEs2ParametersImpl->Construct(keyDerivationFunction, encryptionScheme); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + ; + + return r; + +CATCH: + + delete __pPkcs05PbEs2ParametersImpl; + __pPkcs05PbEs2ParametersImpl = null; return r; diff --git a/src/security/pkcs/FSecPkcsPkcs05PbKdf2Parameters.cpp b/src/security/pkcs/FSecPkcsPkcs05PbKdf2Parameters.cpp index 8eab89a..5ebc1b5 100644 --- a/src/security/pkcs/FSecPkcsPkcs05PbKdf2Parameters.cpp +++ b/src/security/pkcs/FSecPkcsPkcs05PbKdf2Parameters.cpp @@ -42,13 +42,12 @@ namespace Tizen { namespace Security { namespace Pkcs Pkcs05PbKdf2Parameters::Pkcs05PbKdf2Parameters(void) : __pPkcs05PbKdf2ParametersImpl(null) { - __pPkcs05PbKdf2ParametersImpl = new (std::nothrow) _Pkcs05PbKdf2ParametersImpl(); - SysTryReturnVoidResult(NID_SEC_CRYPTO, __pPkcs05PbKdf2ParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + } Pkcs05PbKdf2Parameters::~Pkcs05PbKdf2Parameters(void) { - delete __pPkcs05PbKdf2ParametersImpl; + } result @@ -56,9 +55,21 @@ Pkcs05PbKdf2Parameters::Construct(const Tizen::Base::ByteBuffer& encodedData) { result r = E_SUCCESS; - SysAssertf(__pPkcs05PbKdf2ParametersImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs05PbKdf2ParametersImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs05PbKdf2ParametersImpl = new (std::nothrow) _Pkcs05PbKdf2ParametersImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs05PbKdf2ParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs05PbKdf2ParametersImpl->Construct(encodedData); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs05PbKdf2ParametersImpl; + __pPkcs05PbKdf2ParametersImpl = null; return r; } @@ -68,9 +79,21 @@ Pkcs05PbKdf2Parameters::Construct(const Tizen::Base::ByteBuffer& saltBuffer, int { result r = E_SUCCESS; - SysAssertf(__pPkcs05PbKdf2ParametersImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs05PbKdf2ParametersImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs05PbKdf2ParametersImpl = new (std::nothrow) _Pkcs05PbKdf2ParametersImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs05PbKdf2ParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs05PbKdf2ParametersImpl->Construct(saltBuffer, iterationCount, derivedKeyLength); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs05PbKdf2ParametersImpl; + __pPkcs05PbKdf2ParametersImpl = null; return r; } @@ -81,9 +104,21 @@ Pkcs05PbKdf2Parameters::Construct(const Tizen::Base::ByteBuffer& saltBuffer, int { result r = E_SUCCESS; - SysAssertf(__pPkcs05PbKdf2ParametersImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs05PbKdf2ParametersImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs05PbKdf2ParametersImpl = new (std::nothrow) _Pkcs05PbKdf2ParametersImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs05PbKdf2ParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs05PbKdf2ParametersImpl->Construct(saltBuffer, iterationCount, prf, derivedKeyLength); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs05PbKdf2ParametersImpl; + __pPkcs05PbKdf2ParametersImpl = null; return r; } diff --git a/src/security/pkcs/FSecPkcsPkcs05PbMacParameters.cpp b/src/security/pkcs/FSecPkcsPkcs05PbMacParameters.cpp index 8aade31..21dd29f 100644 --- a/src/security/pkcs/FSecPkcsPkcs05PbMacParameters.cpp +++ b/src/security/pkcs/FSecPkcsPkcs05PbMacParameters.cpp @@ -41,13 +41,12 @@ namespace Tizen { namespace Security { namespace Pkcs Pkcs05PbMacParameters::Pkcs05PbMacParameters(void) : __pPkcs05PbMacParametersImpl(null) { - __pPkcs05PbMacParametersImpl = new (std::nothrow) _Pkcs05PbMacParametersImpl(); - SysTryReturnVoidResult(NID_SEC_CRYPTO, __pPkcs05PbMacParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + } Pkcs05PbMacParameters::~Pkcs05PbMacParameters(void) { - delete __pPkcs05PbMacParametersImpl; + } result @@ -55,9 +54,22 @@ Pkcs05PbMacParameters::Construct(const Tizen::Base::ByteBuffer& encodedData) { result r = E_SUCCESS; - SysAssertf(__pPkcs05PbMacParametersImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs05PbMacParametersImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs05PbMacParametersImpl = new (std::nothrow) _Pkcs05PbMacParametersImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs05PbMacParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + + r = __pPkcs05PbMacParametersImpl->Construct(encodedData); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_IO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs05PbMacParametersImpl; + __pPkcs05PbMacParametersImpl = null; return r; } @@ -67,9 +79,21 @@ Pkcs05PbMacParameters::Construct(const AlgorithmIdentifier& keyDerivationFunctio { result r = E_SUCCESS; - SysAssertf(__pPkcs05PbMacParametersImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs05PbMacParametersImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs05PbMacParametersImpl = new (std::nothrow) _Pkcs05PbMacParametersImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs05PbMacParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs05PbMacParametersImpl->Construct(keyDerivationFunction, messageAuthScheme); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs05PbMacParametersImpl; + __pPkcs05PbMacParametersImpl = null; return r; } @@ -81,6 +105,7 @@ Pkcs05PbMacParameters::GetEncodedDataN(void) const result r = E_SUCCESS; SysAssertf(__pPkcs05PbMacParametersImpl != null, "Not yet constructed. Reconstructor the object."); + std::unique_ptr< ByteBuffer > pEncPbMacParam(__pPkcs05PbMacParametersImpl->GetEncodedDataN()); SysTryReturn(NID_SEC_CRYPTO, pEncPbMacParam != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(r)); @@ -160,6 +185,7 @@ Pkcs05PbMacParameters::GetHashCode(void) const ClearLastResult(); SysAssertf(__pPkcs05PbMacParametersImpl != null, "Not yet constructed. Reconstructor the object."); + return __pPkcs05PbMacParametersImpl->GetHashCode(); } diff --git a/src/security/pkcs/FSecPkcsPkcs05Schemes.cpp b/src/security/pkcs/FSecPkcsPkcs05Schemes.cpp index 0898650..8fa8c3b 100644 --- a/src/security/pkcs/FSecPkcsPkcs05Schemes.cpp +++ b/src/security/pkcs/FSecPkcsPkcs05Schemes.cpp @@ -42,13 +42,12 @@ namespace Tizen { namespace Security { namespace Pkcs Pkcs05Schemes::Pkcs05Schemes(void) : __pPkcs05SchemesImpl(null) { - __pPkcs05SchemesImpl = new (std::nothrow) _Pkcs05SchemesImpl(); - SysTryReturnVoidResult(NID_SEC_CRYPTO, __pPkcs05SchemesImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + } Pkcs05Schemes::~Pkcs05Schemes(void) { - delete __pPkcs05SchemesImpl; + } result @@ -56,9 +55,21 @@ Pkcs05Schemes::Construct(const Tizen::Base::ByteBuffer& password, int derivedKey { result r = E_SUCCESS; - SysAssertf(__pPkcs05SchemesImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs05SchemesImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs05SchemesImpl = new (std::nothrow) _Pkcs05SchemesImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs05SchemesImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs05SchemesImpl->Construct(password, derivedKeyLength); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs05SchemesImpl; + __pPkcs05SchemesImpl = null; return r; } diff --git a/src/security/pkcs/FSecPkcsPkcs08Attribute.cpp b/src/security/pkcs/FSecPkcsPkcs08Attribute.cpp index 5f3451e..afa43f7 100644 --- a/src/security/pkcs/FSecPkcsPkcs08Attribute.cpp +++ b/src/security/pkcs/FSecPkcsPkcs08Attribute.cpp @@ -39,13 +39,12 @@ namespace Tizen { namespace Security { namespace Pkcs Pkcs08Attribute::Pkcs08Attribute(void) : __pPkcs08AttributeImpl(null) { - __pPkcs08AttributeImpl = new (std::nothrow) _Pkcs08AttributeImpl(); - SysTryReturnVoidResult(NID_SEC_CERT, __pPkcs08AttributeImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + } Pkcs08Attribute::~Pkcs08Attribute(void) { - delete __pPkcs08AttributeImpl; + } result @@ -53,9 +52,21 @@ Pkcs08Attribute::Construct(const Tizen::Base::ByteBuffer& encodedData) { result r = E_SUCCESS; - SysAssertf(__pPkcs08AttributeImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs08AttributeImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs08AttributeImpl = new (std::nothrow) _Pkcs08AttributeImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08AttributeImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs08AttributeImpl->Construct(encodedData); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs08AttributeImpl; + __pPkcs08AttributeImpl = null; return r; } @@ -66,9 +77,21 @@ Pkcs08Attribute::Construct(const Tizen::Base::String& attrType) //Variables local to function result r = E_SUCCESS; - SysAssertf(__pPkcs08AttributeImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs08AttributeImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs08AttributeImpl = new (std::nothrow) _Pkcs08AttributeImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08AttributeImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs08AttributeImpl->Construct(attrType); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs08AttributeImpl; + __pPkcs08AttributeImpl = null; return r; } diff --git a/src/security/pkcs/FSecPkcsPkcs08AttributeValue.cpp b/src/security/pkcs/FSecPkcsPkcs08AttributeValue.cpp index 5006bbf..f42c894 100644 --- a/src/security/pkcs/FSecPkcsPkcs08AttributeValue.cpp +++ b/src/security/pkcs/FSecPkcsPkcs08AttributeValue.cpp @@ -41,13 +41,12 @@ namespace Tizen { namespace Security { namespace Pkcs Pkcs08AttributeValue::Pkcs08AttributeValue(void) : __pPkcs08AttributeValueImpl(null) { - __pPkcs08AttributeValueImpl = new (std::nothrow) _Pkcs08AttributeValueImpl(); - SysTryReturnVoidResult(NID_SEC_CERT, __pPkcs08AttributeValueImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + } Pkcs08AttributeValue::~Pkcs08AttributeValue(void) { - delete __pPkcs08AttributeValueImpl; + } result @@ -55,9 +54,21 @@ Pkcs08AttributeValue::Construct(const Tizen::Base::ByteBuffer& encodedData) { result r = E_SUCCESS; - SysAssertf(__pPkcs08AttributeValueImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs08AttributeValueImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs08AttributeValueImpl = new (std::nothrow) _Pkcs08AttributeValueImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08AttributeValueImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs08AttributeValueImpl->Construct(encodedData); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs08AttributeValueImpl; + __pPkcs08AttributeValueImpl = null; return r; } @@ -68,9 +79,21 @@ Pkcs08AttributeValue::Construct(const Tizen::Base::ByteBuffer& value, const Pkcs //Variables local to function result r = E_SUCCESS; - SysAssertf(__pPkcs08AttributeValueImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs08AttributeValueImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs08AttributeValueImpl = new (std::nothrow) _Pkcs08AttributeValueImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08AttributeValueImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs08AttributeValueImpl->Construct(value, tag); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs08AttributeValueImpl; + __pPkcs08AttributeValueImpl = null; return r; } diff --git a/src/security/pkcs/FSecPkcsPkcs08EncryptedPrivateKeyInfo.cpp b/src/security/pkcs/FSecPkcsPkcs08EncryptedPrivateKeyInfo.cpp index 82923af..b252241 100644 --- a/src/security/pkcs/FSecPkcsPkcs08EncryptedPrivateKeyInfo.cpp +++ b/src/security/pkcs/FSecPkcsPkcs08EncryptedPrivateKeyInfo.cpp @@ -43,14 +43,13 @@ namespace Tizen { namespace Security { namespace Pkcs Pkcs08EncryptedPrivateKeyInfo::Pkcs08EncryptedPrivateKeyInfo(void) : __pPkcs08EncryptedPrivateKeyInfoImpl(null) { - __pPkcs08EncryptedPrivateKeyInfoImpl = new (std::nothrow) _Pkcs08EncryptedPrivateKeyInfoImpl(); - SysTryReturnVoidResult(NID_SEC_CRYPTO, __pPkcs08EncryptedPrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + } //Default Destructor Pkcs08EncryptedPrivateKeyInfo::~Pkcs08EncryptedPrivateKeyInfo(void) { - delete __pPkcs08EncryptedPrivateKeyInfoImpl; + } result @@ -58,9 +57,21 @@ Pkcs08EncryptedPrivateKeyInfo::Construct(const Tizen::Base::ByteBuffer& encodedD { result r = E_SUCCESS; - SysAssertf(__pPkcs08EncryptedPrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs08EncryptedPrivateKeyInfoImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs08EncryptedPrivateKeyInfoImpl = new (std::nothrow) _Pkcs08EncryptedPrivateKeyInfoImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08EncryptedPrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs08EncryptedPrivateKeyInfoImpl->Construct(encodedData); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs08EncryptedPrivateKeyInfoImpl; + __pPkcs08EncryptedPrivateKeyInfoImpl = null; return r; } @@ -71,9 +82,21 @@ Pkcs08EncryptedPrivateKeyInfo::Construct(const AlgorithmIdentifier& algorithmId, { result r = E_SUCCESS; - SysAssertf(__pPkcs08EncryptedPrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs08EncryptedPrivateKeyInfoImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs08EncryptedPrivateKeyInfoImpl = new (std::nothrow) _Pkcs08EncryptedPrivateKeyInfoImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08EncryptedPrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs08EncryptedPrivateKeyInfoImpl->Construct(algorithmId, encryptedData); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs08EncryptedPrivateKeyInfoImpl; + __pPkcs08EncryptedPrivateKeyInfoImpl = null; return r; } @@ -84,9 +107,21 @@ Pkcs08EncryptedPrivateKeyInfo::Construct(const AlgorithmIdentifier& algorithmId, { result r = E_SUCCESS; - SysAssertf(__pPkcs08EncryptedPrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs08EncryptedPrivateKeyInfoImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs08EncryptedPrivateKeyInfoImpl = new (std::nothrow) _Pkcs08EncryptedPrivateKeyInfoImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08EncryptedPrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs08EncryptedPrivateKeyInfoImpl->Construct(algorithmId, key, encodedPrivateKeyInfoBuffer); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs08EncryptedPrivateKeyInfoImpl; + __pPkcs08EncryptedPrivateKeyInfoImpl = null; return r; } diff --git a/src/security/pkcs/FSecPkcsPkcs08PrivateKeyInfo.cpp b/src/security/pkcs/FSecPkcsPkcs08PrivateKeyInfo.cpp index 5a3d4f0..94e8e3b 100644 --- a/src/security/pkcs/FSecPkcsPkcs08PrivateKeyInfo.cpp +++ b/src/security/pkcs/FSecPkcsPkcs08PrivateKeyInfo.cpp @@ -39,14 +39,13 @@ namespace Tizen { namespace Security { namespace Pkcs Pkcs08PrivateKeyInfo::Pkcs08PrivateKeyInfo(void) : __pPkcs08PrivateKeyInfoImpl(null) { - __pPkcs08PrivateKeyInfoImpl = new (std::nothrow) _Pkcs08PrivateKeyInfoImpl(); - SysTryReturnVoidResult(NID_SEC_CRYPTO, __pPkcs08PrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + } //Default Destructor Pkcs08PrivateKeyInfo::~Pkcs08PrivateKeyInfo(void) { - delete __pPkcs08PrivateKeyInfoImpl; + } @@ -55,9 +54,21 @@ Pkcs08PrivateKeyInfo::Construct(const Tizen::Base::ByteBuffer& encodedData) { result r = E_SUCCESS; - SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs08PrivateKeyInfoImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs08PrivateKeyInfoImpl = new (std::nothrow) _Pkcs08PrivateKeyInfoImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08PrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pPkcs08PrivateKeyInfoImpl->Construct(encodedData); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs08PrivateKeyInfoImpl; + __pPkcs08PrivateKeyInfoImpl = null; return r; } @@ -67,9 +78,22 @@ Pkcs08PrivateKeyInfo::Construct(const AlgorithmIdentifier& privAlgoId, const Tiz { result r = E_SUCCESS; - SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pPkcs08PrivateKeyInfoImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pPkcs08PrivateKeyInfoImpl = new (std::nothrow) _Pkcs08PrivateKeyInfoImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08PrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + + r = __pPkcs08PrivateKeyInfoImpl->Construct(privAlgoId, privKey); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pPkcs08PrivateKeyInfoImpl; + __pPkcs08PrivateKeyInfoImpl = null; return r; } diff --git a/src/security/pkcs/FSecPkcsRc2CbcParameters.cpp b/src/security/pkcs/FSecPkcsRc2CbcParameters.cpp index ef74078..2b488ac 100644 --- a/src/security/pkcs/FSecPkcsRc2CbcParameters.cpp +++ b/src/security/pkcs/FSecPkcsRc2CbcParameters.cpp @@ -42,13 +42,12 @@ namespace Tizen { namespace Security { namespace Pkcs Rc2CbcParameters::Rc2CbcParameters(void) : __pRc2CbcParametersImpl(null) { - __pRc2CbcParametersImpl = new (std::nothrow) _Rc2CbcParametersImpl(); - SysTryReturnVoidResult(NID_SEC_CERT, __pRc2CbcParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + } Rc2CbcParameters::~Rc2CbcParameters(void) { - delete __pRc2CbcParametersImpl; + } result @@ -56,10 +55,22 @@ Rc2CbcParameters::Construct(const Tizen::Base::ByteBuffer& initialVector, int ve { result r = E_SUCCESS; - SysAssertf(__pRc2CbcParametersImpl != null, "Not yet constructed. Reconstructor the object."); + SysAssertf(__pRc2CbcParametersImpl == null, + "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class"); + + __pRc2CbcParametersImpl = new (std::nothrow) _Rc2CbcParametersImpl(); + SysTryReturnResult(NID_SEC_CRYPTO, __pRc2CbcParametersImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient."); + r = __pRc2CbcParametersImpl->Construct(initialVector, version); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r)); + SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r)); + + return r; + +CATCH: + + delete __pRc2CbcParametersImpl; + __pRc2CbcParametersImpl = null; return r; } diff --git a/src/security/pkcs/FSecPkcs_AlgorithmIdentifierImpl.cpp b/src/security/pkcs/FSecPkcs_AlgorithmIdentifierImpl.cpp index d794854..a842949 100644 --- a/src/security/pkcs/FSecPkcs_AlgorithmIdentifierImpl.cpp +++ b/src/security/pkcs/FSecPkcs_AlgorithmIdentifierImpl.cpp @@ -210,8 +210,9 @@ _AlgorithmIdentifierImpl::Equals(const Object& obj) const { Tizen::Base::String algorithm; - const _AlgorithmIdentifierImpl* pOther = dynamic_cast< const _AlgorithmIdentifierImpl* >(&obj); + SysAssertf(__algorithm.GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + const _AlgorithmIdentifierImpl* pOther = dynamic_cast< const _AlgorithmIdentifierImpl* >(&obj); SysTryReturn(NID_SEC_CRYPTO, pOther != null, false, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); if (pOther == this) @@ -294,6 +295,8 @@ _AlgorithmIdentifierImpl::Equals(const Object& obj) const SysTryReturn(NID_SEC_CRYPTO, __pAlgoParams != null, false, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryReturn(NID_SEC_CRYPTO, dynamic_cast< Pkcs05PbEs2Parameters* >(__pAlgoParams) != null, false, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + if (pEncObj->GetKeyDerivationAlgorithm().Equals(((dynamic_cast< Pkcs05PbEs2Parameters* >(__pAlgoParams))->GetKeyDerivationAlgorithm()))) { if (pEncObj->GetEncryptionScheme().Equals(((dynamic_cast< Pkcs05PbEs2Parameters* >(__pAlgoParams))->GetEncryptionScheme()))) @@ -316,6 +319,7 @@ _AlgorithmIdentifierImpl::Equals(const Object& obj) const case _OID_TYPE_PBKDF2: { + std::unique_ptr< Pkcs05PbKdf2Parameters > pKdf2Obj(dynamic_cast< Pkcs05PbKdf2Parameters* >(pOther->GetParametersN())); SysTryReturn(NID_SEC_CRYPTO, pKdf2Obj, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); @@ -352,6 +356,8 @@ _AlgorithmIdentifierImpl::GetHashCode(void) const Pkcs05PbKdf2Parameters* pKdf2Obj = null; int hashCode = 0; + SysAssertf(__algorithm.GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + switch (_PkcsUtility::ConvertOidToEnum(__algorithm)) { case _OID_TYPE_DES_CBC: @@ -365,6 +371,8 @@ _AlgorithmIdentifierImpl::GetHashCode(void) const case _OID_TYPE_AES_256_CBC: { pIvObj = dynamic_cast< InitialVector* >(__pAlgoParams); + SysTryReturn(NID_SEC_CRYPTO, pIvObj != null, 0, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + hashCode = __algorithm.GetHashCode() + pIvObj->GetHashCode(); return hashCode; @@ -372,7 +380,11 @@ _AlgorithmIdentifierImpl::GetHashCode(void) const case _OID_TYPE_RC2_CBC: { + SysTryReturn(NID_SEC_CRYPTO, __pAlgoParams != null, 0, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + pRcObj = dynamic_cast< Rc2CbcParameters* >(__pAlgoParams); + SysTryReturn(NID_SEC_CRYPTO, pRcObj != null, 0, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + hashCode = __algorithm.GetHashCode() + pRcObj->GetHashCode(); return hashCode; @@ -395,7 +407,10 @@ _AlgorithmIdentifierImpl::GetHashCode(void) const case _OID_TYPE_PBES2: { + SysTryReturn(NID_SEC_CRYPTO, __pAlgoParams != null, 0, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + pEncObj = dynamic_cast< Pkcs05PbEs2Parameters* >(__pAlgoParams); + SysTryReturn(NID_SEC_CRYPTO, pEncObj != null, 0, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); hashCode = pEncObj->GetKeyDerivationAlgorithm().GetHashCode() + pEncObj->GetEncryptionScheme().GetHashCode(); @@ -404,7 +419,10 @@ _AlgorithmIdentifierImpl::GetHashCode(void) const case _OID_TYPE_PBKDF2: { + SysTryReturn(NID_SEC_CRYPTO, __pAlgoParams != null, 0, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + pKdf2Obj = dynamic_cast< Pkcs05PbKdf2Parameters* >(__pAlgoParams); + SysTryReturn(NID_SEC_CRYPTO, pKdf2Obj != null, 0, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); hashCode = __algorithm.GetHashCode() + pKdf2Obj->GetHashCode(); return hashCode; diff --git a/src/security/pkcs/FSecPkcs_Pkcs05PbEs2ParametersImpl.cpp b/src/security/pkcs/FSecPkcs_Pkcs05PbEs2ParametersImpl.cpp index de46c9e..d16413c 100644 --- a/src/security/pkcs/FSecPkcs_Pkcs05PbEs2ParametersImpl.cpp +++ b/src/security/pkcs/FSecPkcs_Pkcs05PbEs2ParametersImpl.cpp @@ -75,9 +75,6 @@ _Pkcs05PbEs2ParametersImpl::Construct(const Tizen::Base::ByteBuffer& encodedData std::unique_ptr< IAlgorithmParameters > pEncParam; const byte* pBuffer = null; - SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); - SysAssertf(__encryptionScheme.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); - pBuffer = encodedData.GetPointer(); SysTryReturnResult(NID_SEC_CRYPTO, pBuffer != null, E_INVALID_ARG, "The specified input parameter is invalid."); @@ -122,9 +119,6 @@ _Pkcs05PbEs2ParametersImpl::Construct(const AlgorithmIdentifier& keyDerivationFu { result r = E_SUCCESS; - SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. "); - SysAssertf(__encryptionScheme.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); - std::unique_ptr< IAlgorithmParameters > pkdfParam(keyDerivationFunction.GetParametersN()); r = GetLastResult(); SysTryReturn(NID_SEC_CRYPTO, pkdfParam != null, r, r, "[%s] Failed to get the parameters.", GetErrorMessage(r)); @@ -237,6 +231,10 @@ const AlgorithmIdentifier& _Pkcs05PbEs2ParametersImpl::GetEncryptionScheme(void) const { ClearLastResult(); + + SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + SysAssertf(__encryptionScheme.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + return __encryptionScheme; } @@ -252,6 +250,9 @@ _Pkcs05PbEs2ParametersImpl::Equals(const Object& obj) const { bool value = false; + SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + SysAssertf(__encryptionScheme.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + const _Pkcs05PbEs2ParametersImpl* pOther = dynamic_cast< const _Pkcs05PbEs2ParametersImpl* >(&obj); SysTryReturn(NID_SEC_CRYPTO, pOther != null, false, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); diff --git a/src/security/pkcs/FSecPkcs_Pkcs05PbKdf2ParametersImpl.cpp b/src/security/pkcs/FSecPkcs_Pkcs05PbKdf2ParametersImpl.cpp index 474dca1..8695cbf 100644 --- a/src/security/pkcs/FSecPkcs_Pkcs05PbKdf2ParametersImpl.cpp +++ b/src/security/pkcs/FSecPkcs_Pkcs05PbKdf2ParametersImpl.cpp @@ -332,6 +332,8 @@ _Pkcs05PbKdf2ParametersImpl::Equals(const Object& obj) const bool value = false; const _Pkcs05PbKdf2ParametersImpl* pOther = dynamic_cast< const _Pkcs05PbKdf2ParametersImpl* >(&obj); + SysAssertf(__saltBuffer.GetRemaining() > 0, "Not yet constructed. Construct () should be called before use."); + SysTryReturn(NID_SEC_CRYPTO, pOther != null, false, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); if (pOther == this) diff --git a/src/security/pkcs/FSecPkcs_Pkcs05PbMacParametersImpl.cpp b/src/security/pkcs/FSecPkcs_Pkcs05PbMacParametersImpl.cpp index 6369d23..04f60e1 100644 --- a/src/security/pkcs/FSecPkcs_Pkcs05PbMacParametersImpl.cpp +++ b/src/security/pkcs/FSecPkcs_Pkcs05PbMacParametersImpl.cpp @@ -75,10 +75,6 @@ _Pkcs05PbMacParametersImpl::Construct(const Tizen::Base::ByteBuffer& encodedData ASN1_TYPE* pParam = null; std::unique_ptr< Pkcs05PbKdf2Parameters > pKdf2Parameters; - - SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. "); - SysAssertf(__messageAuthScheme.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. "); - pBuffer = encodedData.GetPointer(); SysTryReturnResult(NID_SEC_CRYPTO, pBuffer != null, E_INVALID_ARG, "The specified input parameter is invalid."); @@ -139,19 +135,14 @@ _Pkcs05PbMacParametersImpl::Construct(const AlgorithmIdentifier& keyDerivationFu { result r = E_SUCCESS; - SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. "); - SysAssertf(__messageAuthScheme.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. "); - std::unique_ptr< IAlgorithmParameters > pParam(keyDerivationFunction.GetParametersN()); - r = GetLastResult(); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to get the parameters.", GetErrorMessage(r)); + SysTryReturn(NID_SEC_CRYPTO, pParam != null, r, r, "[%s] Failed to get the parameters.", GetErrorMessage(r)); r = __keyDerivationFunction.Construct(keyDerivationFunction.GetAlgorithmObjectId(), pParam.get()); SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to construct the algorithm identifier.", GetErrorMessage(r)); std::unique_ptr< IAlgorithmParameters > pAuthParam(messageAuthScheme.GetParametersN()); - r = GetLastResult(); - SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to get the parameters.", GetErrorMessage(r)); + SysTryReturn(NID_SEC_CRYPTO, pParam != null, r, r, "[%s] Failed to get the parameters.", GetErrorMessage(r)); r = __messageAuthScheme.Construct(messageAuthScheme.GetAlgorithmObjectId(), pAuthParam.get()); SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Failed to construct the algorithm identifier.", GetErrorMessage(r)); @@ -248,6 +239,10 @@ const AlgorithmIdentifier& _Pkcs05PbMacParametersImpl::GetKeyDerivationAlgorithm(void) const { ClearLastResult(); + + SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + SysAssertf(__messageAuthScheme.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + return __keyDerivationFunction; } @@ -255,6 +250,10 @@ const AlgorithmIdentifier& _Pkcs05PbMacParametersImpl::GetMacAlgorithm(void) const { ClearLastResult(); + + SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + SysAssertf(__messageAuthScheme.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + return __messageAuthScheme; } @@ -270,6 +269,9 @@ _Pkcs05PbMacParametersImpl::Equals(const Object& obj) const { bool value = false; + SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + SysAssertf(__messageAuthScheme.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); + const _Pkcs05PbMacParametersImpl* pOther = dynamic_cast< const _Pkcs05PbMacParametersImpl* >(&obj); SysTryReturn(NID_SEC_CRYPTO, pOther != null, false, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); @@ -294,7 +296,6 @@ _Pkcs05PbMacParametersImpl::GetHashCode(void) const SysAssertf(__keyDerivationFunction.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); SysAssertf(__messageAuthScheme.GetAlgorithmObjectId().GetLength() > 0, "Not yet constructed. Construct () should be called before use."); - return __keyDerivationFunction.GetHashCode() + __messageAuthScheme.GetHashCode(); } diff --git a/src/security/pkcs/FSecPkcs_Pkcs05SchemesImpl.cpp b/src/security/pkcs/FSecPkcs_Pkcs05SchemesImpl.cpp index 247a6c3..d7e94f5 100644 --- a/src/security/pkcs/FSecPkcs_Pkcs05SchemesImpl.cpp +++ b/src/security/pkcs/FSecPkcs_Pkcs05SchemesImpl.cpp @@ -160,10 +160,6 @@ _Pkcs05SchemesImpl::GenerateKeyKdf2N(const Pkcs05PbKdf2Parameters& params) pOut->Flip(); - if (IsFailed(r)) - { - pOut.reset(null); - } return pOut.release(); } @@ -182,6 +178,9 @@ _Pkcs05SchemesImpl::EncryptionScheme2N(const Pkcs05PbEs2Parameters& params, cons ClearLastResult(); + SysAssertf(__password.GetPointer() != null, "Not yet constructed. Construct () should be called before use."); + SysAssertf(__password.GetRemaining() > 0, "Not yet constructed. Construct () should be called before use."); + SysTryReturn(NID_SEC_CRYPTO, params.GetKeyDerivationAlgorithm().GetAlgorithmObjectId().GetLength() > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); SysTryReturn(NID_SEC_CRYPTO, params.GetEncryptionScheme().GetAlgorithmObjectId().GetLength() > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); @@ -221,6 +220,9 @@ _Pkcs05SchemesImpl::DecryptionScheme2N(const Pkcs05PbEs2Parameters& params, cons ClearLastResult(); + SysAssertf(__password.GetPointer() != null, "Not yet constructed. Construct () should be called before use."); + SysAssertf(__password.GetRemaining() > 0, "Not yet constructed. Construct () should be called before use."); + SysTryReturn(NID_SEC_CRYPTO, params.GetKeyDerivationAlgorithm().GetAlgorithmObjectId().GetLength() > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); SysTryReturn(NID_SEC_CRYPTO, params.GetEncryptionScheme().GetAlgorithmObjectId().GetLength() > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); @@ -268,6 +270,9 @@ _Pkcs05SchemesImpl::GetPbHMacN(const Pkcs05PbMacParameters& params, const Tizen: ClearLastResult(); + SysAssertf(__password.GetPointer() != null, "Not yet constructed. Construct () should be called before use."); + SysAssertf(__password.GetRemaining() > 0, "Not yet constructed. Construct () should be called before use."); + SysTryReturn(NID_SEC_CRYPTO, params.GetKeyDerivationAlgorithm().GetAlgorithmObjectId().GetLength() > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); SysTryReturn(NID_SEC_CRYPTO, params.GetMacAlgorithm().GetAlgorithmObjectId().GetLength() > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); @@ -348,10 +353,6 @@ _Pkcs05SchemesImpl::GetPbHMacN(const Pkcs05PbMacParameters& params, const Tizen: pOutput->Flip(); - if (IsFailed(r)) - { - pOutput.reset(null); - } return pOutput.release(); } @@ -375,6 +376,9 @@ _Pkcs05SchemesImpl::VerifyPbMac(const Pkcs05PbMacParameters& params, const Tizen ClearLastResult(); + SysAssertf(__password.GetPointer() != null, "Not yet constructed. Construct () should be called before use."); + SysAssertf(__password.GetRemaining() > 0, "Not yet constructed. Construct () should be called before use."); + SysTryReturn(NID_SEC_CRYPTO, params.GetKeyDerivationAlgorithm().GetAlgorithmObjectId().GetLength() > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); SysTryReturn(NID_SEC_CRYPTO, params.GetMacAlgorithm().GetAlgorithmObjectId().GetLength() > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); diff --git a/src/security/pkcs/FSecPkcs_Pkcs08EncryptedPrivateKeyInfoImpl.cpp b/src/security/pkcs/FSecPkcs_Pkcs08EncryptedPrivateKeyInfoImpl.cpp index e22d2b7..3a3a5bc 100644 --- a/src/security/pkcs/FSecPkcs_Pkcs08EncryptedPrivateKeyInfoImpl.cpp +++ b/src/security/pkcs/FSecPkcs_Pkcs08EncryptedPrivateKeyInfoImpl.cpp @@ -79,7 +79,6 @@ _Pkcs08EncryptedPrivateKeyInfoImpl::Construct(const Tizen::Base::ByteBuffer& enc int prf_nid = 0; SysAssertf(__encryptedData.GetRemaining() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); - SysAssertf(__encryptionAlgorithm.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); pBuffer = encodedData.GetPointer(); SysTryReturnResult(NID_SEC_CRYPTO, pBuffer != null, E_INVALID_ARG, "The specified input parameter is invalid."); @@ -138,7 +137,6 @@ _Pkcs08EncryptedPrivateKeyInfoImpl::Construct(const AlgorithmIdentifier& algorit result r = E_SUCCESS; SysAssertf(__encryptedData.GetRemaining() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); - SysAssertf(__encryptionAlgorithm.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); SysTryReturn(NID_SEC_CRYPTO, encryptedData.GetRemaining() > 0, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); @@ -159,7 +157,6 @@ _Pkcs08EncryptedPrivateKeyInfoImpl::Construct(const AlgorithmIdentifier& algorit result r = E_SUCCESS; SysAssertf(__encryptedData.GetRemaining() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); - SysAssertf(__encryptionAlgorithm.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); SysTryReturnResult(NID_SEC_CRYPTO, key.GetRemaining() > 0, E_INVALID_ARG, "The specified input parameter is invalid."); SysTryReturnResult(NID_SEC_CRYPTO, encodedPrivateKeyInfoBuffer.GetRemaining() > 0, E_INVALID_ARG, "The specified input parameter is invalid."); diff --git a/src/security/pkcs/FSecPkcs_Pkcs08PrivateKeyInfoImpl.cpp b/src/security/pkcs/FSecPkcs_Pkcs08PrivateKeyInfoImpl.cpp index d5ab859..c2bd3b1 100644 --- a/src/security/pkcs/FSecPkcs_Pkcs08PrivateKeyInfoImpl.cpp +++ b/src/security/pkcs/FSecPkcs_Pkcs08PrivateKeyInfoImpl.cpp @@ -82,8 +82,6 @@ _Pkcs08PrivateKeyInfoImpl::Construct(const Tizen::Base::ByteBuffer& encodedData) X509_ATTRIBUTE* pAttribute = null; SysAssertf(__privateKey.GetRemaining() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. "); - SysAssertf(__algorithm.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. "); - pBuffer = encodedData.GetPointer(); SysTryReturnResult(NID_SEC_CRYPTO, pBuffer != null, E_INVALID_ARG, "The specified input parameter is invalid."); @@ -167,8 +165,6 @@ _Pkcs08PrivateKeyInfoImpl::Construct(const AlgorithmIdentifier& privAlgoId, cons result r = E_SUCCESS; SysAssertf(__privateKey.GetRemaining() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. "); - SysAssertf(__algorithm.GetAlgorithmObjectId().GetLength() <= 0, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class. "); - SysTryReturnResult(NID_SEC_CRYPTO, privKey.GetRemaining() > 0, E_INVALID_ARG, "The specified input parameter is invalid."); diff --git a/src/security/pkcs/FSecPkcs_PkcsUtility.cpp b/src/security/pkcs/FSecPkcs_PkcsUtility.cpp index 05d0ad9..f2ee5f6 100644 --- a/src/security/pkcs/FSecPkcs_PkcsUtility.cpp +++ b/src/security/pkcs/FSecPkcs_PkcsUtility.cpp @@ -58,7 +58,7 @@ bool _PkcsUtility::IsParameterSupported(Tizen::Base::String algorithm) { if (algorithm == OID_PBKDF2 || algorithm == OID_PBES2 || algorithm == OID_PBMAC1 || algorithm == OID_DES_CBC || algorithm == OID_DES_CBC_EDE3 - || algorithm == OID_AES_128_CBC || algorithm == OID_AES_192_CBC || algorithm == OID_AES_256_CBC || algorithm == OID_RC2_CBC) + || algorithm == OID_AES_128_CBC || algorithm == OID_AES_192_CBC || algorithm == OID_AES_256_CBC || algorithm == OID_RC2_CBC) { return true; } @@ -830,7 +830,7 @@ _PkcsUtility::EncryptDecryptN(const AlgorithmIdentifier& algo, const Tizen::Base } } - return pOutBuffer.release(); + return pOutBuffer.release(); case _OID_TYPE_RSA_ENCRYPTION: { @@ -855,7 +855,7 @@ _PkcsUtility::EncryptDecryptN(const AlgorithmIdentifier& algo, const Tizen::Base } } - return pOutBuffer.release(); + return pOutBuffer.release(); default: r = E_UNSUPPORTED_ALGORITHM; @@ -911,7 +911,7 @@ _PkcsUtility::EncryptDecryptN(const AlgorithmIdentifier& algo, const Tizen::Base pOutBuffer->Flip(); - CATCH: +CATCH: if (IsFailed(r)) { @@ -988,7 +988,7 @@ _PkcsUtility::GenerateKdfParametersN(int iter, unsigned char* pSaltValue, int sa PBKDF2PARAM_free(pKdf); return pKeyfunc; - CATCH: +CATCH: PBKDF2PARAM_free(pKdf); X509_ALGOR_free(pKeyfunc); @@ -1029,13 +1029,13 @@ _PkcsUtility::GernerateParametersFromOidN(Tizen::Base::String algoOid, X509_ALGO switch (oidValue) { case _OID_TYPE_DES_CBC: - // fall through + // fall through case _OID_TYPE_DES_CBC_EDE3: - // fall through + // fall through case _OID_TYPE_AES_128_CBC: - // fall through + // fall through case _OID_TYPE_AES_192_CBC: - // fall through + // fall through case _OID_TYPE_AES_256_CBC: { X509_ALGOR_get0(&pAlgoObj->algorithm, &pType, &pVal, pAlgoObj); @@ -1134,15 +1134,15 @@ _PkcsUtility::GernerateParametersFromOidN(Tizen::Base::String algoOid, X509_ALGO break; case _OID_TYPE_HMAC_SHA1: - // fall through + // fall through case _OID_TYPE_HMAC_SHA2_224: - // fall through + // fall through case _OID_TYPE_HMAC_SHA2_256: - // fall through + // fall through case _OID_TYPE_HMAC_SHA2_384: - // fall through + // fall through case _OID_TYPE_HMAC_SHA2_512: - // fall through + // fall through case _OID_TYPE_RSA_ENCRYPTION: { pAlgoParams = null; @@ -1277,71 +1277,75 @@ _PkcsUtility::GenerateAlgorithmIdentifierStructureN(Tizen::Base::String algoOid, switch (oidValue) { case _OID_TYPE_DES_CBC: - // fall through + // fall through case _OID_TYPE_DES_CBC_EDE3: - // fall through + // fall through case _OID_TYPE_AES_128_CBC: - // fall through + // fall through case _OID_TYPE_AES_192_CBC: - // fall through + // fall through case _OID_TYPE_AES_256_CBC: { - SysTryReturn(NID_SEC_CRYPTO, pAlgoParam != null, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryCatch(NID_SEC_CRYPTO, pAlgoParam != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + + SysTryCatch(NID_SEC_CRYPTO, dynamic_cast< InitialVector* >(pAlgoParam) != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); ivBuffer.Construct(((dynamic_cast< InitialVector* >(pAlgoParam))->GetInitialVector())); - SysTryReturn(NID_SEC_CRYPTO, ivBuffer.GetRemaining() > 0, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + SysTryCatch(NID_SEC_CRYPTO, ivBuffer.GetRemaining() > 0, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); pIv = ASN1_STRING_new(); - SysTryReturn(NID_SEC_CRYPTO, pIv != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + SysTryCatch(NID_SEC_CRYPTO, pIv != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); pIv->data = static_cast< unsigned char* >(OPENSSL_malloc(ivBuffer.GetRemaining())); - SysTryReturn(NID_SEC_CRYPTO, pIv->data != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + SysTryCatch(NID_SEC_CRYPTO, pIv->data != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); memcpy(pIv->data, ivBuffer.GetPointer(), ivBuffer.GetRemaining()); pIv->length = ivBuffer.GetRemaining(); ret = X509_ALGOR_set0(pAlgoObj, OBJ_nid2obj(algoNid), V_ASN1_OCTET_STRING, reinterpret_cast< void* >(pIv)); - SysTryReturn(NID_SEC_CRYPTO, ret > 0, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, ret > 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); } break; case _OID_TYPE_RC2_CBC: { - SysTryReturn(NID_SEC_CRYPTO, pAlgoParam != null, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryCatch(NID_SEC_CRYPTO, pAlgoParam != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + + SysTryCatch(NID_SEC_CRYPTO, dynamic_cast< Rc2CbcParameters* >(pAlgoParam) != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); ivBuffer.Construct(((dynamic_cast< Rc2CbcParameters* >(pAlgoParam))->GetInitialVector())); - SysTryReturn(NID_SEC_CRYPTO, ivBuffer.GetRemaining() > 0, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + SysTryCatch(NID_SEC_CRYPTO, ivBuffer.GetRemaining() > 0, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); version = (dynamic_cast< Rc2CbcParameters* >(pAlgoParam))->GetVersion(); if (version == 0) { pIv = ASN1_STRING_new(); - SysTryReturn(NID_SEC_CRYPTO, pIv != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + SysTryCatch(NID_SEC_CRYPTO, pIv != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); pIv->data = static_cast< unsigned char* >(OPENSSL_malloc(ivBuffer.GetRemaining())); - SysTryReturn(NID_SEC_CRYPTO, pIv->data != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + SysTryCatch(NID_SEC_CRYPTO, pIv->data != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); memcpy(pIv->data, ivBuffer.GetPointer(), ivBuffer.GetRemaining()); pIv->length = ivBuffer.GetRemaining(); ret = X509_ALGOR_set0(pAlgoObj, OBJ_nid2obj(algoNid), V_ASN1_OCTET_STRING, reinterpret_cast< void* >(pIv)); - SysTryReturn(NID_SEC_CRYPTO, ret > 0, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, ret > 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); } else { pAsn1Type = ASN1_TYPE_new(); - SysTryReturn(NID_SEC_CRYPTO, pAsn1Type != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + SysTryCatch(NID_SEC_CRYPTO, pAsn1Type != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); ret = ASN1_TYPE_set_int_octetstring(pAsn1Type, version, const_cast< unsigned char* >(ivBuffer.GetPointer()), ivBuffer.GetRemaining()); - SysTryReturn(NID_SEC_CRYPTO, ret > 0, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, ret > 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); ret = X509_ALGOR_set0(pAlgoObj, OBJ_nid2obj(algoNid), V_ASN1_SEQUENCE, reinterpret_cast< void* >(pAsn1Type->value.ptr)); - SysTryReturn(NID_SEC_CRYPTO, ret > 0, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, ret > 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); } @@ -1349,25 +1353,26 @@ _PkcsUtility::GenerateAlgorithmIdentifierStructureN(Tizen::Base::String algoOid, break; case _OID_TYPE_HMAC_SHA1: - // fall through + // fall through case _OID_TYPE_HMAC_SHA2_224: - // fall through + // fall through case _OID_TYPE_HMAC_SHA2_256: - // fall through + // fall through case _OID_TYPE_HMAC_SHA2_384: - // fall through + // fall through case _OID_TYPE_RSA_ENCRYPTION: - // fall through + // fall through case _OID_TYPE_HMAC_SHA2_512: { ret = X509_ALGOR_set0(pAlgoObj, OBJ_nid2obj(algoNid), V_ASN1_NULL, NULL); - SysTryReturn(NID_SEC_CRYPTO, ret > 0, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, ret > 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); } break; case _OID_TYPE_PBKDF2: { - SysTryReturn(NID_SEC_CRYPTO, pAlgoParam != null, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryCatch(NID_SEC_CRYPTO, pAlgoParam != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryCatch(NID_SEC_CRYPTO, dynamic_cast< Pkcs05PbKdf2Parameters* >(pAlgoParam) != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); std::unique_ptr< ByteBuffer > pKdfBuffer((dynamic_cast< Pkcs05PbKdf2Parameters* >(pAlgoParam))->GetEncodedDataN()); if (pKdfBuffer == null) @@ -1375,35 +1380,36 @@ _PkcsUtility::GenerateAlgorithmIdentifierStructureN(Tizen::Base::String algoOid, r = GetLastResult(); if (r == E_OUT_OF_MEMORY) { - SysTryReturn(NID_SEC_CRYPTO, pKdfBuffer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + SysTryCatch(NID_SEC_CRYPTO, pKdfBuffer, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); } else { - SysTryReturn(NID_SEC_CRYPTO, pKdfBuffer, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, pKdfBuffer, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); } } pBuf = pKdfBuffer->GetPointer(); - SysTryReturn(NID_SEC_CRYPTO, pBuf != null, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryCatch(NID_SEC_CRYPTO, pBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); pKdf = d2i_PBKDF2PARAM(null, reinterpret_cast< const unsigned char** >(&pBuf), pKdfBuffer->GetRemaining()); - SysTryReturn(NID_SEC_CRYPTO, pKdf != null, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, pKdf != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); ASN1_item_pack(pKdf, ASN1_ITEM_rptr(PBKDF2PARAM), &pbKdf2Str); - SysTryReturn(NID_SEC_CRYPTO, pbKdf2Str != null, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, pbKdf2Str != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); ret = X509_ALGOR_set0(pAlgoObj, OBJ_nid2obj(algoNid), V_ASN1_SEQUENCE, pbKdf2Str); - SysTryReturn(NID_SEC_CRYPTO, ret > 0, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, ret > 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); } break; case _OID_TYPE_PBES2: { - SysTryReturn(NID_SEC_CRYPTO, pAlgoParam != null, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryCatch(NID_SEC_CRYPTO, pAlgoParam != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryCatch(NID_SEC_CRYPTO, dynamic_cast< Pkcs05PbEs2Parameters* >(pAlgoParam) != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); std::unique_ptr< ByteBuffer > pbEs2Buffer((dynamic_cast< Pkcs05PbEs2Parameters* >(pAlgoParam))->GetEncodedDataN()); if (pbEs2Buffer == null) @@ -1411,34 +1417,35 @@ _PkcsUtility::GenerateAlgorithmIdentifierStructureN(Tizen::Base::String algoOid, r = GetLastResult(); if (r == E_OUT_OF_MEMORY) { - SysTryReturn(NID_SEC_CRYPTO, pbEs2Buffer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + SysTryCatch(NID_SEC_CRYPTO, pbEs2Buffer, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); } else { - SysTryReturn(NID_SEC_CRYPTO, pbEs2Buffer, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, pbEs2Buffer, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); } } pBuf = pbEs2Buffer->GetPointer(); - SysTryReturn(NID_SEC_CRYPTO, pBuf != null, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryCatch(NID_SEC_CRYPTO, pBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); pPbes2Obj = d2i_PBE2PARAM(null, reinterpret_cast< const unsigned char** >(&pBuf), pbEs2Buffer->GetRemaining()); - SysTryReturn(NID_SEC_CRYPTO, pPbes2Obj != null, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, pPbes2Obj != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); ASN1_item_pack(pPbes2Obj, ASN1_ITEM_rptr(PBE2PARAM), &pbE2Str); ret = X509_ALGOR_set0(pAlgoObj, OBJ_nid2obj(algoNid), V_ASN1_SEQUENCE, pbE2Str); - SysTryReturn(NID_SEC_CRYPTO, pbE2Str != null, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, pbE2Str != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); - SysTryReturn(NID_SEC_CRYPTO, ret > 0, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, ret > 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); } break; case _OID_TYPE_PBMAC1: { - SysTryReturn(NID_SEC_CRYPTO, pAlgoParam != null, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryCatch(NID_SEC_CRYPTO, pAlgoParam != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryCatch(NID_SEC_CRYPTO, dynamic_cast< Pkcs05PbMacParameters* >(pAlgoParam) != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); std::unique_ptr< ByteBuffer > pbMacBuffer((dynamic_cast< Pkcs05PbMacParameters* >(pAlgoParam))->GetEncodedDataN()); if (pbMacBuffer == null) @@ -1446,26 +1453,26 @@ _PkcsUtility::GenerateAlgorithmIdentifierStructureN(Tizen::Base::String algoOid, r = GetLastResult(); if (r == E_OUT_OF_MEMORY) { - SysTryReturn(NID_SEC_CRYPTO, pbMacBuffer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + SysTryCatch(NID_SEC_CRYPTO, pbMacBuffer, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); } else { - SysTryReturn(NID_SEC_CRYPTO, pbMacBuffer, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, pbMacBuffer, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); } } pBuf = pbMacBuffer->GetPointer(); - SysTryReturn(NID_SEC_CRYPTO, pBuf != null, null, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); + SysTryCatch(NID_SEC_CRYPTO, pBuf != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid."); pMacObj = d2i_PBE2PARAM(null, reinterpret_cast< const unsigned char** >(&pBuf), pbMacBuffer->GetRemaining()); - SysTryReturn(NID_SEC_CRYPTO, pMacObj != null, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, pMacObj != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); ASN1_item_pack(pMacObj, ASN1_ITEM_rptr(PBE2PARAM), &pbE2Str); ret = X509_ALGOR_set0(pAlgoObj, OBJ_nid2obj(algoNid), V_ASN1_SEQUENCE, pbE2Str); - SysTryReturn(NID_SEC_CRYPTO, ret > 0, null, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); + SysTryCatch(NID_SEC_CRYPTO, ret > 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error."); } break; @@ -1474,6 +1481,37 @@ _PkcsUtility::GenerateAlgorithmIdentifierStructureN(Tizen::Base::String algoOid, break; } +CATCH: + + if (IsFailed(r)) + { + X509_ALGOR_free(pAlgoObj); + if (pIv != null) + { + ASN1_STRING_free(pIv); + } + + if (pAsn1Type != null) + { + ASN1_TYPE_free(pAsn1Type); + } + if (pKdf != null) + { + PBKDF2PARAM_free(pKdf); + } + + if (pPbes2Obj != null) + { + PBE2PARAM_free(pPbes2Obj); + } + + if (pMacObj != null) + { + PBE2PARAM_free(pMacObj); + } + + return null; + } return pAlgoObj; }