Fixed Klocworks issues
authorBhanu Singh Rao <bhanu.singh@samsung.com>
Mon, 30 Sep 2013 15:11:32 +0000 (20:41 +0530)
committerBhanu Singh Rao <bhanu.singh@samsung.com>
Mon, 30 Sep 2013 15:11:32 +0000 (20:41 +0530)
Change-Id: I44a974726218f4eee622e53d27beb5321d5828c3

inc/FSecPkcsTypes.h
src/security/FSecRsaKeyConverter.cpp
src/security/cert/FSecCert_Base64.h
src/security/cert/FSecCert_CertDbManager.cpp
src/security/cert/FSecCert_CertFileStore.cpp
src/security/cert/FSecCert_CertManager.cpp
src/security/cert/FSecCert_CertOidDef.h
src/security/cert/FSecCert_CertService.cpp
src/security/inc/FSecCert_CertTypes.h
src/security/pkcs/FSecPkcsAlgorithmIdentifier.cpp

index defdf3e..c9cd4fd 100755 (executable)
@@ -91,7 +91,6 @@ enum Pkcs08TagValue
 -- Basic object identifiers in Pkcs05 and Pkcs08
 */
 
-_OSP_EXPORT_ extern const wchar_t OID_PKCS_05[];    /**< An object identifier for pkcs05 */
 _OSP_EXPORT_ extern const wchar_t OID_PBKDF2[];  /**< An object identifier for password based key derivation function scheme2 */
 _OSP_EXPORT_ extern const wchar_t OID_PBES2[];   /**< An object identifier for password based encryption scheme2 */
 _OSP_EXPORT_ extern const wchar_t OID_PBMAC1[];  /**< An object identifier for password based message authentication scheme1 */
@@ -106,7 +105,6 @@ _OSP_EXPORT_ extern const wchar_t OID_AES_128_CBC[];    /**< An object identifie
 _OSP_EXPORT_ extern const wchar_t OID_AES_192_CBC[];   /**< An object identifier for aes-192-cbc mode */
 _OSP_EXPORT_ extern const wchar_t OID_AES_256_CBC[];   /**< An object identifier for aes-256-cbc mode */
 _OSP_EXPORT_ extern const wchar_t OID_RC2_CBC[];    /**< An object identifier for rc2-cbc mode */
-_OSP_EXPORT_ extern const wchar_t OID_PKCS_08[];    /**< An object identifier for pkcs08 */
 _OSP_EXPORT_ extern const wchar_t OID_RSA_ENCRYPTION[];   /**< An object identifier for RSA encryption scheme */
 
 
index 4302318..b8f9bff 100644 (file)
@@ -140,10 +140,10 @@ RsaKeyConverter::ConvertPrivateKeyFormatN(RsaKeyFormat format, const IPrivateKey
 
        if (isPemFormat == true)
        {
-               PrivateKey key;
-               r = key.SetKey(*pOutBuffer.get());
+               PrivateKey nKey;
+               r = nKey.SetKey(*pOutBuffer.get());
                SysTryCatch(NID_SEC, !IsFailed(r), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid.");
-               pOutBuffer = std::unique_ptr< ByteBuffer >(ConvertDerToPemN(format, key));
+               pOutBuffer = std::unique_ptr< ByteBuffer >(ConvertDerToPemN(format, nKey));
                SysTryCatch(NID_SEC, pOutBuffer != null, r = GetLastResult(), GetLastResult(), "[%s] Failed to convert der to pem encoded byte buffer");
        }
 
@@ -247,11 +247,11 @@ RsaKeyConverter::ConvertPublicKeyFormatN(RsaKeyFormat format, const IPublicKey&
 
        if (isPemFormat == true)
        {
-               PublicKey key;
-               r = key.SetKey(*pOutBuffer);
+               PublicKey nKey;
+               r = nKey.SetKey(*pOutBuffer);
                SysTryCatch(NID_SEC, !IsFailed(r), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid.");
-               pOutBuffer.reset(ConvertDerToPemN(format, key));
-               //pOutBuffer = std::unique_ptr< ByteBuffer >(ConvertDerToPemN(format, key));
+               pOutBuffer.reset(ConvertDerToPemN(format, nKey));
+               //pOutBuffer = std::unique_ptr< ByteBuffer >(ConvertDerToPemN(format, nKey));
                SysTryCatch(NID_SEC, pOutBuffer != null, r = GetLastResult(), GetLastResult(), "[%s] Failed to convert der to pem encoded byte buffer");
        }
 
index 9cad6c8..3ca27c9 100644 (file)
@@ -30,9 +30,6 @@
 namespace Tizen { namespace Security { namespace Cert
 {
 
-const int _MAX_BASE64_CODE_SIZE = 64;
-const int _MAX_BASE64_MAP_SIZE = 128;
-
 class _Base64
 {
 
index ff06400..4c4e61d 100644 (file)
@@ -152,7 +152,7 @@ _CertDbManager::RemoveCaCertificateByType(_CaCertType certType)
        char condition[_MAX_TYPE_CONST_SIZE] = {0, };
        char installed[_MAX_TYPE_RECORD_SIZE] = "T\0";
 
-       sprintf(condition, "certType = %d and installed = '%s'", certType, installed);
+       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certType = %d and installed = '%s'", certType, installed);
 
        r = __caCertDbStore.RemoveAllCertificateByCondition(reinterpret_cast< byte* >(condition));
        SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_SYSTEM, "Failed to delete all the certificate tables in database.");
@@ -167,7 +167,7 @@ _CertDbManager::RemoveUserCaCertificateByCertId(int certId)
        char condition[_MAX_TYPE_CONST_SIZE] = {0, };
        char installed[_MAX_TYPE_RECORD_SIZE] = "T\0";
 
-       sprintf(condition, "certId = %d and certType = %d and installed = '%s'", certId, _CERT_TYPE_ROOT_CA_BY_USER, installed);
+       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certId = %d and certType = %d and installed = '%s'", certId, _CERT_TYPE_ROOT_CA_BY_USER, installed);
        r = __caCertDbStore.RemoveAllCertificateByCondition(reinterpret_cast< byte* >(condition));
        SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_SYSTEM, "Failed to delete all the certificate tables in database.");
 
@@ -378,7 +378,7 @@ _CertDbManager::UpdateCaCertificateFromBuffer(_CaCertType certType, _CertFormat
                r = _Base64::Encode(pTbsCert->GetSubjectName(), lenSubjectName, subjectNameBase64, subjNameB64len);
                SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
 
-               sprintf(condition, "subjectName = '%s' and certType = %d and installed = '%s'", subjectNameBase64, certType, installed);
+               snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "subjectName = '%s' and certType = %d and installed = '%s'", subjectNameBase64, certType, installed);
                r = __caCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
                SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificates record.", GetErrorMessage(r));
 
@@ -504,7 +504,7 @@ _CertDbManager::RemoveCertificateChainByCertId(int certId)
        memset(&userCertRecord, 0, sizeof(userCertRecord));
        memset(condition, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
 
-       sprintf(condition, "certId = %d", certId);
+       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "certId = %d", certId);
        r = __userCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &userCertRecord);
        SysTryReturnResult(NID_SEC_CERT, !IsFailed(r) || r == E_DATA_NOT_FOUND, E_SYSTEM, "Failed to get certificate record.");
        SysTryReturnResult(NID_SEC_CERT, r != E_DATA_NOT_FOUND, E_SUCCESS, "No such record found.");
@@ -549,22 +549,22 @@ _CertDbManager::GetCaCertificateId(byte* pSubjectName, int subjectNameSize, byte
 
                if (certType == _CERT_TYPE_NOT_BOUNDED)
                {
-                       sprintf(condition, "subjectName = '%s' and issuerName = '%s' and installed = '%s'", subjectNameBase64, issuerNameBase64, installed);
+                       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "subjectName = '%s' and issuerName = '%s' and installed = '%s'", subjectNameBase64, issuerNameBase64, installed);
                }
                else
                {
-                       sprintf(condition, "subjectName = '%s' and issuerName = '%s' and certType = %d and installed = '%s'", subjectNameBase64, issuerNameBase64, certType, installed);
+                       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "subjectName = '%s' and issuerName = '%s' and certType = %d and installed = '%s'", subjectNameBase64, issuerNameBase64, certType, installed);
                }
        }
        else
        {
                if (certType == _CERT_TYPE_NOT_BOUNDED)
                {
-                       sprintf(condition, "subjectName = '%s' and installed = '%s'", subjectNameBase64, installed);
+                       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "subjectName = '%s' and installed = '%s'", subjectNameBase64, installed);
                }
                else
                {
-                       sprintf(condition, "subjectName = '%s' and certType = %d and installed = '%s'", subjectNameBase64, certType, installed);
+                       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "subjectName = '%s' and certType = %d and installed = '%s'", subjectNameBase64, certType, installed);
                }
        }
 
@@ -607,11 +607,11 @@ _CertDbManager::GetUserCertificateId(byte* pSubjectName, int subjectNameSize, by
                r = _Base64::Encode(reinterpret_cast< byte* >(pIssuerName), issuerNameSize, issuerNameBase64, issuerB64len);
                SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
 
-               sprintf(condition, "subjectName = '%s' and issuerName = '%s' and installed = '%s'", subjectNameBase64, issuerNameBase64, installed);
+               snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_ISSUER_SUBJECT_NAME_SIZE), "subjectName = '%s' and issuerName = '%s' and installed = '%s'", subjectNameBase64, issuerNameBase64, installed);
        }
        else
        {
-               sprintf(condition, "subjectName = '%s' and installed = '%s'", subjectNameBase64, installed);
+               snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_ISSUER_SUBJECT_NAME_SIZE), "subjectName = '%s' and installed = '%s'", subjectNameBase64, installed);
        }
 
        r = __userCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &userCertRecord);
@@ -647,7 +647,7 @@ _CertDbManager::DeleteCertificateChain(int devCertId, int devParentCA)
 
        memset(condition, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
 
-       sprintf(condition, "parentCa = %d and installed = '%s'", devParentCA, installed);
+       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "parentCa = %d and installed = '%s'", devParentCA, installed);
        //Check if any other device certificate has same parent as of referred device certificare. If it is yes then we
        //delete only device certificate and return. We cannot disturb another chain.
        __userCertDbStore.GetCountByCondition(reinterpret_cast< byte* >(&condition), recCount);
@@ -703,7 +703,7 @@ _CertDbManager::DeleteCertificateChain(int devCertId, int devParentCA)
                        }
                        caCertId = caParentCa; // Now look for next certificate in chain
                        memset(condition, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
-                       sprintf(condition, "certId = %d and installed = '%s'", devParentCA, installed);
+                       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "certId = %d and installed = '%s'", devParentCA, installed);
                        memset(&certRecord, 0, sizeof(certRecord));
                        r = __caCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
                        SysTryReturnResult(NID_SEC_CERT, !IsFailed(r) || r == E_DATA_NOT_FOUND, E_SYSTEM, "Failed to get certificate record.");
@@ -729,7 +729,7 @@ _CertDbManager::GetCertificateListByFormat(_CertFormat certFormat, _CertificateL
        char installed[_MAX_TYPE_RECORD_SIZE] = "T\0";
        char condition[_MAX_TYPE_CONST_SIZE] = {0, };
 
-       sprintf(condition, "certFormat = %d and certType != %d and installed = '%s'", certFormat, _CERT_TYPE_INTERMIDIATE_CA, installed);
+       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certFormat = %d and certType != %d and installed = '%s'", certFormat, _CERT_TYPE_INTERMIDIATE_CA, installed);
 
        r = __caCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
        SysTryReturnResult(NID_SEC_CERT, !IsFailed(r) || r == E_DATA_NOT_FOUND, E_SYSTEM, "Failed to get certificate record.");
@@ -800,7 +800,7 @@ _CertDbManager::GetUserCertificateListByFormat(_CertFormat certFormat, _Certific
 
        *ppCertList = null;
 
-       sprintf(condition, "certFormat = %d and installed = '%s'", certFormat, installed);
+       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certFormat = %d and installed = '%s'", certFormat, installed);
 
        r = __userCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
        SysTryReturnResult(NID_SEC_CERT, !IsFailed(r) || r == E_DATA_NOT_FOUND, E_SYSTEM, "Failed to get certificate record.");
@@ -868,7 +868,7 @@ _CertDbManager::GetCaCertificateListByCertId(int certId, _CertificateListInfo**
        char condition[_MAX_TYPE_CONST_SIZE] = {0, };
 
        *ppCertList = null;
-       sprintf(condition, "certId = %d and certType != %d and installed = '%s'", certId, _CERT_TYPE_INTERMIDIATE_CA, installed);
+       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certId = %d and certType != %d and installed = '%s'", certId, _CERT_TYPE_INTERMIDIATE_CA, installed);
 
        r = __caCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
        SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificate record.", GetErrorMessage(r));
@@ -911,7 +911,7 @@ _CertDbManager::GetUserCertificateListByCertId(int certId, _CertificateListInfo*
        SysTryReturnResult(NID_SEC_CERT, ppCertList != null, E_INVALID_ARG, "Invalid input arguments.");
        SysTryReturnResult(NID_SEC_CERT, certId > 0, E_INVALID_ARG, "Invalid input arguments.");
 
-       sprintf(condition, "certId = %d and installed = '%s'", certId, installed);
+       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certId = %d and installed = '%s'", certId, installed);
        r = __userCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
        SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificate record.", GetErrorMessage(r));
 
@@ -990,7 +990,7 @@ _CertDbManager::FindIssuerCertificateAndTypeN(_CertFormat certFormat, char* pIss
        r = _Base64::Encode(reinterpret_cast< byte* >(pIssuerName), strlen(pIssuerName), issuerNameBase64, issuerNameB64len);
        SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
 
-       sprintf(condition, "subjectName = '%s' and certFormat = %d and installed = '%s'", issuerNameBase64, certFormat, installed);
+       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_OFFSET_CONST_SIZE), "subjectName = '%s' and certFormat = %d and installed = '%s'", issuerNameBase64, certFormat, installed);
 
        r = __caCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
        SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificate record.", GetErrorMessage(r));
@@ -1036,7 +1036,7 @@ _CertDbManager::FindIssuerCertificateByTypeN(_CertFormat certFormat, _CaCertType
        r = _Base64::Encode(reinterpret_cast< byte* >(pIssuerName), strlen(pIssuerName), issuerNameBase64, issuerNameB64len);
        SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
 
-       sprintf(condition, "subjectName = '%s' and certFormat = %d and certType = %d and installed = '%s'", issuerNameBase64, certFormat, certType, installed);
+       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_ISSUER_CONDITION_SIZE), "subjectName = '%s' and certFormat = %d and certType = %d and installed = '%s'", issuerNameBase64, certFormat, certType, installed);
        r = __caCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
        SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificate record.", GetErrorMessage(r));
 
@@ -1094,7 +1094,7 @@ _CertDbManager::FindCertType(_CertFormat certFormat, char* pIssuerName, char* pS
        r = _Base64::Encode(reinterpret_cast< byte* >(pSubjectName), strlen(pSubjectName), subjectNameBase64, subjectNameB64len);
        SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
 
-       sprintf(condition, "certFormat = %d and issuerName = '%s' and subjectName = '%s' and installed = '%s'", certFormat, issuerNameBase64, subjectNameBase64, installed);
+       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_CONDITION_CONST_SIZE), "certFormat = %d and issuerName = '%s' and subjectName = '%s' and installed = '%s'", certFormat, issuerNameBase64, subjectNameBase64, installed);
        r = __caCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
        SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificate record.", GetErrorMessage(r));
 
@@ -1732,14 +1732,14 @@ _CertDbManager::GetUserCertificateChain(char* pIssuerName, int issuerNameLen, ch
                memset(subjectNameBase64, 0, sizeof(subjectNameBase64));
                r = _Base64::Encode(reinterpret_cast< byte* >(pSubjectName), subjectNameLen, reinterpret_cast< char* >(subjectNameBase64), subjectNameBase64Len);
                SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
-               sprintf(condition, "subjectName = '%s' and installed = '%s'", subjectNameBase64, installedRecord);
+               snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "subjectName = '%s' and installed = '%s'", subjectNameBase64, installedRecord);
        }
        else
        {
                r = __userCertDbStore.GetNumberOfCertificates(recordCount);
                SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificates.", GetErrorMessage(r));
                SysTryReturnResult(NID_SEC_CERT, recordCount > 0, E_OBJ_NOT_FOUND, "Failed to get certificate records.");
-               sprintf(condition, "installed = '%s'", installedRecord);
+               snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "installed = '%s'", installedRecord);
        }
 
        memset(&userCertRecord, 0, sizeof(userCertRecord));
@@ -1888,7 +1888,7 @@ _CertDbManager::GetUserCertificateChain(char* pIssuerName, int issuerNameLen, ch
                        memset(subjectNameBase64, 0, sizeof(subjectNameBase64));
                        r = _Base64::Encode(reinterpret_cast< byte* >(subName), subNameLen, reinterpret_cast< char* >(subjectNameBase64), subjectNameBase64Len);
                        SysTryCatch(NID_SEC_CERT, !IsFailed(r), , r, "[%s] Failed to encode data in base 64 encoding.", GetErrorMessage(r));
-                       sprintf(condition, "subjectName = '%s' and installed = '%s'", subjectNameBase64, installedRecord);
+                       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "subjectName = '%s' and installed = '%s'", subjectNameBase64, installedRecord);
 
                        if (strcmp(reinterpret_cast< char* >(issuerNameBase64), reinterpret_cast< char* >(subjectNameBase64)) == 0)
                        {
@@ -1974,7 +1974,7 @@ _CertDbManager::GetUserCertificateChain(char* pIssuerName, int issuerNameLen, ch
                        }
 
                        memset(condition, 0, sizeof(condition));
-                       sprintf(condition, "installed = '%s'", installedRecord);
+                       snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "installed = '%s'", installedRecord);
 
                        count++;
 
@@ -2030,7 +2030,7 @@ _CertDbManager::GetUserCertificateChain(_CertFormat certFormat, _CertChain* pCer
        memset(subjectNameBase64, 0, sizeof(subjectNameBase64));
        r = _Base64::Encode(reinterpret_cast< byte* >(pSubjectName), strlen(pSubjectName), subjectNameBase64, subjNameB64len);
        SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
-       sprintf(conditonRecord, "subjectName = '%s' and installed = '%s'", subjectNameBase64, installedRecord);
+       snprintf(conditonRecord, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "subjectName = '%s' and installed = '%s'", subjectNameBase64, installedRecord);
 
        r = __userCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(conditonRecord), &userCertRecord);
        SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificates record.", GetErrorMessage(r));
@@ -2049,7 +2049,7 @@ _CertDbManager::GetUserCertificateChain(_CertFormat certFormat, _CertChain* pCer
        {
                memset(&caCertRecord, 0, sizeof(caCertRecord));
                memset(conditonRecord, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
-               sprintf(conditonRecord, "certId = %d and installed = '%s'", parentCa, installedRecord);
+               snprintf(conditonRecord, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "certId = %d and installed = '%s'", parentCa, installedRecord);
 
                r = __caCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(conditonRecord), &caCertRecord);
                SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificates record.", GetErrorMessage(r));
@@ -2075,7 +2075,7 @@ _CertDbManager::GetUserCertificateInfoByCertId(int certId, int* pSubjectLength,
        char installedRecord[_MAX_TYPE_RECORD_SIZE] = "T\0";
        char condition[_MAX_TYPE_CONST_SIZE] = {0, };
 
-       sprintf(condition, "certId = %d and installed = '%s'", certId, installedRecord);
+       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certId = %d and installed = '%s'", certId, installedRecord);
 
        r = __userCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &userCertRecord);
        SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificates record.", GetErrorMessage(r));
@@ -2113,7 +2113,7 @@ _CertDbManager::GetUserCertificateInfoByCertId(int certId, _CertEncodingType enc
        *ppUserCertInfo = null;
 
        SysTryReturnResult(NID_SEC_CERT, certId > 0, E_INVALID_ARG, "Invalid input parameter.");
-       sprintf(condition, "certId = %d and installed = '%s'", certId, installedRecord);
+       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certId = %d and installed = '%s'", certId, installedRecord);
 
        r = __userCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
        SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificates record.", GetErrorMessage(r));
index 9ff66dd..1bfe0c0 100644 (file)
@@ -191,7 +191,7 @@ _CertFileStore::GetFileNameFromHandle(CertIdNo hCert, _CertPathType pathType, St
 
        SysTryReturnResult(NID_SEC_CERT, hCert != null, E_INVALID_ARG, "Invalid input parameter.");
 
-       sprintf(temp, "%03d", hCert);
+       snprintf(temp, _MAX_CERT_EXT_PATH_SIZE, "%03d", hCert);
        tempStr.Append(temp);
 
        switch (pathType)
index 4d718de..eb0e3d1 100644 (file)
@@ -371,7 +371,7 @@ _CertManager::GetCertInfo(CertificateHandle certHandle, _CertFieldType field, _C
                        memset(pCertInfo->serialNo, 0, _MAX_SERIAL_NUMBER_SIZE + 1);
                        for (index = 0; index < iterVal; index++)
                        {
-                               sprintf(&pCertInfo->serialNo[index * 2], "%02X", pSerialNumber[index]);
+                               snprintf(&pCertInfo->serialNo[index * 2], (_MAX_SERIAL_NUMBER_SIZE + 1), "%02X", pSerialNumber[index]);
                        }
                }
        }
@@ -383,7 +383,7 @@ _CertManager::GetCertInfo(CertificateHandle certHandle, _CertFieldType field, _C
                        int len = strlen(pSigAlg);
                        if (len <= _MAX_CERT_ALGORITHM_SIZE)
                        {
-                               strcpy(pCertInfo->sigAlgorithm, pSigAlg);
+                               strncpy(pCertInfo->sigAlgorithm, pSigAlg, len);
                        }
                        else
                        {
@@ -421,7 +421,7 @@ _CertManager::GetCertInfo(CertificateHandle certHandle, _CertFieldType field, _C
                memset(pCertInfo->subjectName, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
                if (subLen <= _MAX_ISSUER_SUBJECT_NAME_SIZE + 1)
                {
-                       strcpy(pCertInfo->subjectName, reinterpret_cast< const char* >(pSubjectName));
+                       strncpy(pCertInfo->subjectName, reinterpret_cast< const char* >(pSubjectName), subLen);
                }
                ParseCertTitle(reinterpret_cast< char* >(pSubjectName), pCertInfo->certTitle);
                ClearLastResult();
@@ -433,7 +433,7 @@ _CertManager::GetCertInfo(CertificateHandle certHandle, _CertFieldType field, _C
                memset(pCertInfo->issuerName, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
                if (issuerLen <= _MAX_ISSUER_SUBJECT_NAME_SIZE + 1)
                {
-                       strcpy(pCertInfo->issuerName, reinterpret_cast< const char* >(pIssuerName));
+                       strncpy(pCertInfo->issuerName, reinterpret_cast< const char* >(pIssuerName), issuerLen);
                }
                ParseCertTitle(reinterpret_cast< char* >(pIssuerName), pCertInfo->certSubTitle);
                ClearLastResult();
@@ -461,7 +461,7 @@ _CertManager::GetCertInfo(CertificateHandle certHandle, _CertFieldType field, _C
                int maxValue = SHA_DIGEST_LENGTH;
                for (index = 0; index < maxValue; index++)
                {
-                       sprintf(&pCertInfo->fingerPrint[index * 2], "%02X", pFingerPrint[index]);
+                       snprintf(&pCertInfo->fingerPrint[index * 2], (_MAX_CERT_FINGERPRINT_SIZE + 1), "%02X", pFingerPrint[index]);
                }
                pCertInfo->fingerPrintLen = fingerPrintLen;
 
@@ -479,7 +479,7 @@ _CertManager::GetCertInfo(CertificateHandle certHandle, _CertFieldType field, _C
                        memset(pCertInfo->publicKey, 0, _MAX_CERT_PUBLIC_KEY_SIZE + 1);
                        for (index = 0; index < iterVal; index++)
                        {
-                               sprintf(&pCertInfo->publicKey[index * 2], "%02X", pPublicKeyBuffer[index]);
+                               snprintf(&pCertInfo->publicKey[index * 2], (_MAX_CERT_PUBLIC_KEY_SIZE + 1), "%02X", pPublicKeyBuffer[index]);
                        }
 
                }
@@ -762,8 +762,8 @@ _CertManager::GetCertificateType(CertificateHandle certHandle, _CaCertType* pCer
        SysTryReturnResult(NID_SEC_CERT, lenSubjectName > 0, E_SYSTEM, "Subject length is not valid.");
        SysTryReturnResult(NID_SEC_CERT, lenIssuerName > 0, E_SYSTEM, "Issuer length is not valid.");
 
-       strcpy(subjectName, reinterpret_cast< const char* >(pTbsCert->GetSubjectName()));
-       strcpy(issuerName, reinterpret_cast< const char* >(pTbsCert->GetIssuerName()));
+       strncpy(subjectName, reinterpret_cast< const char* >(pTbsCert->GetSubjectName()), lenSubjectName);
+       strncpy(issuerName, reinterpret_cast< const char* >(pTbsCert->GetIssuerName()), lenIssuerName);
 
        pCertDb = _CertDbManager::GetInstance();
        SysTryReturnResult(NID_SEC_CERT, pCertDb != null, E_SYSTEM, "Failed to get instance of certificate database manager.");
@@ -794,7 +794,7 @@ _CertManager::ParseCertTitle(char subject[_MAX_ISSUER_SUBJECT_NAME_SIZE + 1], ch
        char* pSubStr = null;
        char tempSubject[_MAX_ISSUER_SUBJECT_NAME_SIZE + 1] = {0, };
 
-       strncpy(tempSubject, subject, strlen(subject));
+       strncpy(tempSubject, subject, strlen(subject + 1));
        pPivotPtr = tempSubject;
        for (;; pSubStr = null)
        {
@@ -1107,7 +1107,7 @@ _CertManager::OpenUserCertificateStore(int& totalCount)
 
        totalCount = 0;
 
-       sprintf(condition, "installed = '%s'", installedRecord);
+       snprintf(condition, _MAX_TYPE_CONST_SIZE, "installed = '%s'", installedRecord);
 
        std::unique_ptr< _UserCertDbStore > pUserCertDbStore(new (std::nothrow) _UserCertDbStore());
        SysTryReturn(NID_SEC_CERT, pUserCertDbStore != null, certificateStoreCtx, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
@@ -1185,7 +1185,7 @@ _CertManager::OpenRootCaStore(_CaCertType type, int& totalCount) // _CERT_TYPE_T
        SysTryReturn(NID_SEC_CERT, type > _CERT_TYPE_NOT_BOUNDED, certificateStoreCtx, E_INVALID_ARG, "[E_INVALID_ARG] Invalid certificate type.");
        SysTryReturn(NID_SEC_CERT, type < _CERT_TYPE_MAX, certificateStoreCtx, E_INVALID_ARG, "[E_INVALID_ARG] Invalid certificate type.");
 
-       sprintf(condition, "certType = %d and installed = '%s'", static_cast< int >(type), installedRecord);
+       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certType = %d and installed = '%s'", static_cast< int >(type), installedRecord);
 
        std::unique_ptr< _CaCertDbStore > pCaCertDbStore(new (std::nothrow) _CaCertDbStore());
        SysTryReturn(NID_SEC_CERT, pCaCertDbStore != null, certificateStoreCtx, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
@@ -1256,7 +1256,7 @@ _CertManager::CheckRootCaIntegrity(void)
 
        ClearLastResult();
 
-       sprintf(condition, "certType = %d and installed = '%s'", _CERT_TYPE_ROOT_CA, installedRecord);
+       snprintf(condition, _MAX_TYPE_CONST_SIZE, "certType = %d and installed = '%s'", _CERT_TYPE_ROOT_CA, installedRecord);
 
        std::unique_ptr< _CaCertDbStore > pCaCertDbStore(new (std::nothrow) _CaCertDbStore());
        SysTryReturnResult(NID_SEC_CERT, pCaCertDbStore != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
index aef257f..137f060 100644 (file)
 namespace Tizen { namespace Security { namespace Cert
 {
 
-const char* const _OID_AES_128_CBC = "2.16.840.1.101.3.4.1.2";
-const char* const _OID_AES_192_CBC = "2.16.840.1.101.3.4.1.22";
-const char* const _OID_AES_256_CBC = "2.16.840.1.101.3.4.1.42";
-const char* const _OID_DES_CBC = "1.3.14.3.2.7";
-const char* const _OID_RC2_CBC = "1.2.840.113549.3.2";
-const char* const _OID_RC5_CBC = "1.2.840.113549.3.8";
-const char* const _OID_IDEA_CBC = "1.3.6.1.4.1.188.7.1.1.2";
-const char* const _OID_ECC = "1.2.840.10045.2.1";
-const char* const _OID_DES_CBC_EDE3 = "1.2.840.113549.3.7";
 const char* const _OID_SIG_SHA1_RSA = "1.2.840.113549.1.1.5";
 const char* const _OID_SIG_MD5_RSA = "1.2.840.113549.1.1.4";
 const char* const _OID_SIG_MD2_RSA = "1.2.840.113549.1.1.2";
@@ -43,17 +34,6 @@ const char* const _OID_SIG_SHA_224_RSA = "1.2.840.113549.1.1.14";
 const char* const _OID_SIG_SHA_256_RSA = "1.2.840.113549.1.1.11";
 const char* const _OID_SIG_SHA_384_RSA = "1.2.840.113549.1.1.12";
 const char* const _OID_SIG_SHA_512_RSA = "1.2.840.113549.1.1.13";
-const char* const _OID_HASH_SHA1 = "1.3.14.3.2.26";
-const char* const _OID_CERT_COMMON_NAME = "2.5.4.3";
-const char* const _OID_CERT_ORG_UNIT_NAME = "2.5.4.11";
-const char* const _OID_CERT_ORG_NAME = "2.5.4.10";
-const char* const _OID_CERT_LOCALITY_NAME = "2.5.4.7";
-const char* const _OID_CERT_STATE_OR_PROVINCE_NAME = "2.5.4.8";
-const char* const _OID_CERT_COUNTRY_NAME = "2.5.4.6";
-const char* const _OID_CERT_EMAIL_ADDRESS = "1.2.840.113549.1.9.1";
-const char* const _OID_CERT_SERIAL_NUM = "2.5.4.5";
-const char* const _OID_CERT_GIVEN_NAME = "2.5.4.42";
-const char* const _OID_CERT_SUR_NAME = "2.5.4.4";
 const char* const _OID_SUBJECT_DIRECTORY_ATTRIBUTES = "2.5.29.9";
 const char* const _OID_SUBJECT_KEY_IDENTIFIER = "2.5.29.14";
 const char* const _OID_KEY_USAGE = "2.5.29.15";
index 42a3b57..cd2171f 100644 (file)
@@ -87,15 +87,7 @@ const String _CERT_SVC_DEFAULT_CERT_DIRECTORY = L"/opt/share/cert-svc/certs/ssl/
 const char* _CERT_COMMON_NAME = "CN=";
 const char* _CERT_ORG_UNIT_NAME = "OU=";
 const char* _CERT_ORG_NAME = "O=";
-const char* _CERT_LOCALITY_NAME = "L=";
-const char* _CERT_STATE_OR_PROVINCE_NAME = "S=";
-const char* _CERT_COUNTRY_NAME = "C=";
 const char* _CERT_EMAIL_ADDRESS = "emailAddress=";
-const char* _CERT_SERIAL_NUM = "SN=";
-const char* _CERT_GIVEN_NAME = "GN=";
-const char* _CERT_SUR_NAME = "SUN=";
-const char* _CERT_STATE_OF_PROVINCE = "ST=";
-const char* _CERT_DC = "_CERT_DC=";
 const char* _CERT_TK_ISSUER_NAME = "Test";
 
 result
index 598721c..9d405e0 100644 (file)
@@ -40,32 +40,21 @@ const int _MAX_ISSUER_SUBJECT_NAME_SIZE = 512;
 const int _MAX_SERIAL_NUMBER_SIZE = 40;
 const int _MAX_FILENAME_SIZE = 256;
 const int _MAX_CERT_SHA1_DIGEST_SIZE = 20;
-const int _MAX_BASE64_CERT_SIZE = 2000 * (4 / 3);
 const int _MAX_TYPE_CONST_SIZE = 100;
 const int _MAX_TYPE_RECORD_SIZE = 3;
 const int _MAX_CERT_PUB_KEY_HASH_SIZE = 256;
 const int _MAX_QUERY_LEN = 2000;
 const int _MAX_CERT_TYPE = 32;
 const int _MIN_CERT_TYPE = 0;
-const int _MAX_HASH_SIZE = 256;
 const int _MAX_CERT_VALIDITY_SIZE = 64;
 const int _MAX_CERT_ALGORITHM_SIZE = 64;
 const int _MAX_CERT_FINGERPRINT_SIZE = 40;
 const int _MAX_CERT_TYPE_SIZE = 32;
 const int _MAX_CERT_TIME_LEN = 15;
-const int _MAX_CERT_OSP_CRITICAL1_COUNT = 1;
-const int _MAX_CERT_OSP_CRITICAL2_COUNT = 2;
-const int _MAX_CERT_OSP_CRITICAL3_COUNT = 0;
-const int _MAX_CERT_OSP_CRITICAL4_COUNT = 1;
-const int _MAX_CERT_OSP_CRITICAL5_COUNT = 0;
-const int _MAX_CERT_OSP_PRELOAD_APP_COUNT = 1;
-const int _MAX_OID_SIZE = 250;
-const int _MAX_GAP = 1;
 const int _MAX_EXT_TABLESIZE = 31;
 const int _MAX_SUBJECT_OFFSET_SIZE = 50;
 const int _MAX_ISSUER_OFFSET_SIZE = 30;
 const int _MAX_OFFSET_CONST_SIZE = 90;
-const int _MAX_CA_CONDITION_SIZE = 610;
 const int _MAX_ISSUER_CONDITION_SIZE = 150;
 const int _MAX_ISSUER_NAME_OFFSET = 70;
 const int _MAX_CONDITION_CONST_SIZE = 700;
@@ -93,15 +82,7 @@ extern const Tizen::Base::String _TEMP_CERT_MGR_CRT_FILE_PATH;
 extern const char* _CERT_COMMON_NAME;
 extern const char* _CERT_ORG_UNIT_NAME;
 extern const char* _CERT_ORG_NAME;
-extern const char* _CERT_LOCALITY_NAME;
-extern const char* _CERT_STATE_OR_PROVINCE_NAME;
-extern const char* _CERT_COUNTRY_NAME;
 extern const char* _CERT_EMAIL_ADDRESS;
-extern const char* _CERT_SERIAL_NUM;
-extern const char* _CERT_GIVEN_NAME;
-extern const char* _CERT_SUR_NAME;
-extern const char* _CERT_STATE_OF_PROVINCE;
-extern const char* _CERT_DC;
 extern const char* _CERT_TK_ISSUER_NAME;
 
 //Typedef for readability of code and distinguish between different types of handles and context
index 42e38c0..5af58c0 100644 (file)
@@ -36,7 +36,6 @@ using namespace Tizen::Base;
 namespace Tizen { namespace Security { namespace Pkcs
 {
 
-const wchar_t OID_PKCS_05[] = L"1.2.840.113549.1.5";
 const wchar_t OID_PBKDF2[] = L"1.2.840.113549.1.5.12";
 const wchar_t OID_PBES2[] = L"1.2.840.113549.1.5.13";
 const wchar_t OID_PBMAC1[] = L"1.2.840.113549.1.5.14";
@@ -51,7 +50,6 @@ const wchar_t OID_AES_128_CBC[] = L"2.16.840.1.101.3.4.1.2";
 const wchar_t OID_AES_192_CBC[] = L"2.16.840.1.101.3.4.1.22";
 const wchar_t OID_AES_256_CBC[] = L"2.16.840.1.101.3.4.1.42";
 const wchar_t OID_RC2_CBC[] = L"1.2.840.113549.3.2";
-const wchar_t OID_PKCS_08[] = L"1.2.840.113549.1.8";
 const wchar_t OID_RSA_ENCRYPTION[] = L"1.2.804.113549.1.1.1";
 const wchar_t OID_ATTR_NAME[] = L"2.5.4.41";
 const wchar_t OID_ATTR_SURNAME[] = L"2.5.4.4";