Fixed N_SE-51655, incorrect date display.
authorBhanu Singh Rao <bhanu.singh@samsung.com>
Mon, 16 Sep 2013 16:00:13 +0000 (21:30 +0530)
committerBhanu Singh Rao <bhanu.singh@samsung.com>
Mon, 16 Sep 2013 16:00:13 +0000 (21:30 +0530)
Change-Id: Ifa53c49c38be167da2db0fbae16d4c12ae42bf0c
Signed-off-by: Bhanu Singh Rao <bhanu.singh@samsung.com>
src/security/cert/FSecCert_CertDbManager.cpp [changed mode: 0755->0644]
src/security/cert/FSecCert_CertManager.cpp
src/security/cert/FSecCert_CertTime.cpp
src/security/inc/FSecCert_CertTypes.h

old mode 100755 (executable)
new mode 100644 (file)
index 08f5916..ff06400
@@ -280,12 +280,12 @@ _CertDbManager::InsertCaCertificateFromBuffer(_CaCertType certType, _CertFormat
        }
 
        r = __caCertDbStore.CheckDuplicateCertificate(certType, reinterpret_cast< byte* >(subjectName), lenSubjectName);
-       if(!IsFailed(r))
+       if (!IsFailed(r))
        {
                return E_FILE_ALREADY_EXIST;
        }
 
-       SysTryReturnResult(NID_SEC_CERT, r==E_DATA_NOT_FOUND, r, "Failed to check duplicate");
+       SysTryReturnResult(NID_SEC_CERT, r == E_DATA_NOT_FOUND, r, "Failed to check duplicate");
 
 
        //Get the last installed certificate id from db table
@@ -446,7 +446,7 @@ _CertDbManager::UpdateCaCertificateFromBuffer(_CaCertType certType, _CertFormat
                //No need to update record as only file data changed.
                return E_SUCCESS;
        }
-       
+
        return r;
 }
 
@@ -1266,8 +1266,8 @@ _CertDbManager::InsertCertChain(_CertFormat certFormat, _CertChain* pCertChain)
                        pTbsCert = pCurCert->GetTbsCertInstance();
                        SysTryReturnResult(NID_SEC_CERT, pTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
 
-                       r =  __caCertDbStore.CheckDuplicateCertificate(certType, reinterpret_cast< byte* >(pTbsCert->GetSubjectName()), strlen(reinterpret_cast< char* >(pTbsCert->GetSubjectName())));
-                       if(r != E_SUCCESS)
+                       r = __caCertDbStore.CheckDuplicateCertificate(certType, reinterpret_cast< byte* >(pTbsCert->GetSubjectName()), strlen(reinterpret_cast< char* >(pTbsCert->GetSubjectName())));
+                       if (r != E_SUCCESS)
                        {
                                SysTryReturn(NID_SEC_CERT, r == E_DATA_NOT_FOUND, r, r, "[%s] Failed to check duplicate.", GetErrorMessage(r));
 
@@ -1626,7 +1626,7 @@ _CertDbManager::InsertUserCertificateFromBuffer(_CertFormat certFormat, byte* pC
 
        r = __userCertDbStore.CheckDuplicateCertificate(reinterpret_cast< byte* >(subjectNameBuffer), lenSubjectName);
        SysTryReturnResult(NID_SEC_CERT, IsFailed(r), E_FILE_ALREADY_EXIST, "File already exists.");
-       SysTryReturnResult(NID_SEC_CERT, r==E_DATA_NOT_FOUND, r, "Failed to check duplicate");
+       SysTryReturnResult(NID_SEC_CERT, r == E_DATA_NOT_FOUND, r, "Failed to check duplicate");
 
        //Get the last installed certificate id from db table
        __userCertDbStore.GetCurrentCertId(certId);
@@ -1654,7 +1654,7 @@ _CertDbManager::InsertUserCertificateFromBuffer(_CertFormat certFormat, byte* pC
        memcpy(certRecord.certPubKeyHash, pId64.get(), keyIdB64Length); //Base64 encoded device id
        certRecord.certFormat = static_cast< int >(certFormat);
 
-       std::unique_ptr< char > pFileName(Tizen::Base::_StringConverter::CopyToCharArrayN(tempFileName));
+       std::unique_ptr< char[] > pFileName(Tizen::Base::_StringConverter::CopyToCharArrayN(tempFileName));
        SysTryReturnResult(NID_SEC_CERT, pFileName != null, E_SYSTEM, "Failed to get attributes.");
 
        strcpy(certRecord.fileName, pFileName.get());
@@ -1664,7 +1664,7 @@ _CertDbManager::InsertUserCertificateFromBuffer(_CertFormat certFormat, byte* pC
        certRecord.issuerNameLen = lenIssuerName;
        memcpy(certRecord.issuerName, szIssuerName, lenIssuerName);
 
-       std::unique_ptr< char > pPriKeyFileName(Tizen::Base::_StringConverter::CopyToCharArrayN(privateKeyFile));
+       std::unique_ptr< char[] > pPriKeyFileName(Tizen::Base::_StringConverter::CopyToCharArrayN(privateKeyFile));
        SysTryReturnResult(NID_SEC_CERT, pPriKeyFileName != null, E_SYSTEM, "Failed to get attributes.");
 
        strcpy(certRecord.prvKeyPath, pPriKeyFileName.get());
index c75cce8..4d718de 100644 (file)
@@ -130,10 +130,10 @@ _CertManager::CreateCrtFile(void)
                        pBio = BIO_new(BIO_s_mem());
                        SysTryCatch(NID_SEC_CERT, pBio != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
 
-                       std::unique_ptr<unsigned char[]> pCertBuffer(new (std::nothrow) unsigned char[readCnt]);
+                       std::unique_ptr< unsigned char[] > pCertBuffer(new (std::nothrow) unsigned char[readCnt]);
                        SysTryCatch(NID_SEC_CERT, pCertBuffer != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
 
-                       memcpy(static_cast<void*>(pCertBuffer.get()), certBufData, readCnt);
+                       memcpy(static_cast< void* >(pCertBuffer.get()), certBufData, readCnt);
                        certBufferLen = readCnt;
 
                        const unsigned char* pTemp = pCertBuffer.get();
@@ -353,6 +353,8 @@ _CertManager::GetCertInfo(CertificateHandle certHandle, _CertFieldType field, _C
        SysTryReturnResult(NID_SEC_CERT, pCert != null, E_INVALID_ARG, "Initial params not set.");
        SysTryReturnResult(NID_SEC_CERT, pCertInfo != null, E_INVALID_ARG, "Initial params not set.");
 
+       memset(pCertInfo, 0, sizeof(_CertFieldInfos));
+
        pTbsCert = pCert->GetTbsCertInstance();
        SysTryReturnResult(NID_SEC_CERT, pTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
 
@@ -399,13 +401,17 @@ _CertManager::GetCertInfo(CertificateHandle certHandle, _CertFieldType field, _C
        {
                Tizen::Base::DateTime notBefore;
                Tizen::Base::DateTime notAfter;
+
                pTbsCert->GetAfterTimes(notAfter);
                pTbsCert->GetBeforeTimes(notBefore);
+
                memset(pCertInfo->validityFrom, 0, _MAX_CERT_VALIDITY_SIZE + 1);
                memset(pCertInfo->validityTo, 0, _MAX_CERT_VALIDITY_SIZE + 1);
 
                _CertTime::FormatDateTime(notBefore, pCertInfo->validityFrom);
+
                _CertTime::FormatDateTime(notAfter, pCertInfo->validityTo);
+
        }
 
        if (field & _CERT_FIELD_SUBJECT)
@@ -549,7 +555,7 @@ _CertManager::GetEncodedCertBuffer(byte* pCertBuffer, int certBufferLen, byte**
        }
        else if (pX509Cert->Parse(pCertBuffer, certBufferLen) == E_SUCCESS)
        {
-               std::unique_ptr< byte, ByteDeleter > pCertBuf(static_cast<byte*>(malloc(sizeof(byte) * certBufferLen)));
+               std::unique_ptr< byte, ByteDeleter > pCertBuf(static_cast< byte* >(malloc(sizeof(byte) * certBufferLen)));
                SysTryReturn(NID_SEC_CERT, pCertBuf != null, _CERT_UNKNOWN, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
 
                memcpy(pCertBuf.get(), pCertBuffer, certBufferLen);
@@ -566,7 +572,7 @@ _CertManager::GetEncodedCertBuffer(byte* pCertBuffer, int certBufferLen, byte**
                certBufLen = _Base64::GetDecodedSize(certBufferLen);
                SysTryReturn(NID_SEC_CERT, certBufLen > 0, _CERT_UNKNOWN, E_SYSTEM, "[E_SYSTEM] Invalid certificate length.");
 
-               std::unique_ptr< byte, ByteDeleter > pCertBuf(static_cast<byte*>(malloc(sizeof(byte) * certBufLen)));
+               std::unique_ptr< byte, ByteDeleter > pCertBuf(static_cast< byte* >(malloc(sizeof(byte) * certBufLen)));
                SysTryReturn(NID_SEC_CERT, pCertBuf != null, _CERT_UNKNOWN, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
 
                memset(pCertBuf.get(), 0, certBufLen);
@@ -1276,17 +1282,17 @@ _CertManager::CheckRootCaIntegrity(void)
                SysTryReturnResult(NID_SEC_CERT, pFile != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
                r = pFile->Construct(certPath, "r");
-               SysTryCatch(NID_SEC_CERT, !IsFailed(r),  , r, "[%s] Propagating.", GetErrorMessage(r));
+               SysTryCatch(NID_SEC_CERT, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
 
                pBuffer.reset(new (std::nothrow) ByteBuffer());
                SysTryReturnResult(NID_SEC_CERT, pBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
                r = pBuffer->Construct(_BUF_SIZE);
-               SysTryCatch(NID_SEC_CERT, !IsFailed(r),  , r, "[%s] Propagating.", GetErrorMessage(r));
+               SysTryCatch(NID_SEC_CERT, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
 
                pTempBuffer = pBuffer.get();
                r = pFile->Read(*pTempBuffer);
-               SysTryCatch(NID_SEC_CERT, !IsFailed(r),  , r, "[%s] Propagating.", GetErrorMessage(r));
+               SysTryCatch(NID_SEC_CERT, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
 
                pTempBuffer->Flip();
 
@@ -1294,11 +1300,11 @@ _CertManager::CheckRootCaIntegrity(void)
                SysTryReturnResult(NID_SEC_CERT, pBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
 
                r = pCert->Construct(*pTempBuffer);
-               SysTryCatch(NID_SEC_CERT, !IsFailed(r),  , r, "[%s] Propagating.", GetErrorMessage(r));
+               SysTryCatch(NID_SEC_CERT, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
 
                continue;
 
-       CATCH:
+CATCH:
                SysSecureLog(NID_SEC_CERT, "Remove broken certificate %d", certRecord.certId);
 
                r = pCaCertDbStore->RemoveCertificateById(certRecord.certId);
index 608759b..e41f103 100644 (file)
@@ -51,6 +51,7 @@ _CertTime::FormatDateTime(Tizen::Base::DateTime& time, char* pFormattedDatTime)
        String formattedStr;
        String cutomizedPattern = L"yyyy-MM-dd HH:mm:ss";
        LocaleManager localeManager;
+       int len = 0;
 
        ClearLastResult();
        SysTryReturnVoidResult(NID_SEC_CERT, pFormattedDatTime != null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid input argument.");
@@ -66,12 +67,15 @@ _CertTime::FormatDateTime(Tizen::Base::DateTime& time, char* pFormattedDatTime)
        pDateFormatter->ApplyPattern(cutomizedPattern);
 
        r = pDateFormatter->Format(time, formattedStr);
-       SysTryReturnVoidResult(NID_SEC_CERT, !IsFailed(r), r, "[%s] Failed to create time formet.", GetErrorMessage(r));
+       SysTryReturnVoidResult(NID_SEC_CERT, !IsFailed(r), r, "[%s] Failed to create time format.", GetErrorMessage(r));
 
-       std::unique_ptr< char > pTemp(Tizen::Base::_StringConverter::CopyToCharArrayN(formattedStr));
+       std::unique_ptr< char[] > pTemp(Tizen::Base::_StringConverter::CopyToCharArrayN(formattedStr));
        SysTryReturnVoidResult(NID_SEC_CERT, pTemp != null, GetLastResult(), "[%s] Failed to convert string array.", GetErrorMessage(GetLastResult()));
 
-       memcpy(pFormattedDatTime, pTemp.get(), strlen(pTemp.get()) + 1);
+       len = strlen(pTemp.get());
+       memcpy(pFormattedDatTime, pTemp.get(), len);
+       pFormattedDatTime[len] = '\0';
+
 }
 
 
index 5ce15e1..598721c 100644 (file)
@@ -48,7 +48,7 @@ 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 = 32;
+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;