[Pkcs] Added GetAttributeType API and also added padding check in utility class
authorAnju <anju.ramani@samsung.com>
Wed, 3 Apr 2013 09:19:37 +0000 (14:49 +0530)
committerAnju <anju.ramani@samsung.com>
Wed, 3 Apr 2013 09:19:37 +0000 (14:49 +0530)
Change-Id: Ia5c179d3a39b6c2ae9b1be33dbb86e5d569689f9
Signed-off-by: Anju <anju.ramani@samsung.com>
src/security/pkcs/FSecPkcsPkcs08Attribute.cpp
src/security/pkcs/FSecPkcs_Pkcs08AttributeImpl.cpp
src/security/pkcs/FSecPkcs_PkcsUtility.cpp

index 786622c..5f3451e 100644 (file)
@@ -98,6 +98,17 @@ Pkcs08Attribute::RemoveAttributeValue(const Pkcs08AttributeValue& value)
        return r;
 }
 
+Tizen::Base::String
+Pkcs08Attribute::GetAttributeType(void) const
+{
+       ClearLastResult();
+
+       SysAssertf(__pPkcs08AttributeImpl != null, "Not yet constructed. Reconstructor the object.");
+
+       return __pPkcs08AttributeImpl->GetAttributeType();
+
+}
+
 const Tizen::Base::Collection::ArrayList&
 Pkcs08Attribute::GetAttributeValues(void) const
 {
index f82d0ac..87e5bde 100644 (file)
@@ -156,6 +156,16 @@ _Pkcs08AttributeImpl::RemoveAttributeValue(const Pkcs08AttributeValue& value)
        return __attributeValues.Remove(value);
 }
 
+Tizen::Base::String
+_Pkcs08AttributeImpl::GetAttributeType(void) const
+{
+       SysAssertf(__attributeType.GetLength() > 0, "Not yet constructed. Construct () should be called before use.");
+
+       return __attributeType;
+
+}
+
+
 const Tizen::Base::Collection::ArrayList&
 _Pkcs08AttributeImpl::GetAttributeValues(void) const
 {
index 078eb34..05d0ad9 100644 (file)
@@ -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;
@@ -881,6 +881,13 @@ _PkcsUtility::EncryptDecryptN(const AlgorithmIdentifier& algo, const Tizen::Base
 
        memset(pOut.get(), 0, tempLen);
 
+       if (dataLen % pCipherAlgorithm->block_size != 0)
+       {
+               // set padding
+               ret = EVP_CIPHER_CTX_set_padding(&cipherCtx, static_cast< int >(true));
+               SysTryCatch(NID_SEC_CRYPTO, ret == 1, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error.");
+       }
+
        //cipher update operation
        ret = EVP_CipherUpdate(&cipherCtx, pOut.get(), static_cast< int* >(&outLen), pData, dataLen);
        SysTryCatch(NID_SEC_CRYPTO, ret == 1, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] The method cannot proceed due to a severe system error.");
@@ -904,7 +911,7 @@ _PkcsUtility::EncryptDecryptN(const AlgorithmIdentifier& algo, const Tizen::Base
 
        pOutBuffer->Flip();
 
-CATCH:
+       CATCH:
 
        if (IsFailed(r))
        {
@@ -981,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);
@@ -1022,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);
@@ -1127,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;
@@ -1270,13 +1277,13 @@ _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.");
@@ -1342,15 +1349,15 @@ _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);