From: Bhanu Singh Rao Date: Mon, 16 Sep 2013 16:00:13 +0000 (+0530) Subject: Fixed N_SE-51655, incorrect date display. X-Git-Tag: submit/tizen/20131210.080830^2^2~100 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ecbc860e21ec0852e491a8698678003bf96d1241;p=platform%2Fframework%2Fnative%2Fappfw.git Fixed N_SE-51655, incorrect date display. Change-Id: Ifa53c49c38be167da2db0fbae16d4c12ae42bf0c Signed-off-by: Bhanu Singh Rao --- diff --git a/src/security/cert/FSecCert_CertDbManager.cpp b/src/security/cert/FSecCert_CertDbManager.cpp old mode 100755 new mode 100644 index 08f5916..ff06400 --- a/src/security/cert/FSecCert_CertDbManager.cpp +++ b/src/security/cert/FSecCert_CertDbManager.cpp @@ -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()); diff --git a/src/security/cert/FSecCert_CertManager.cpp b/src/security/cert/FSecCert_CertManager.cpp index c75cce8..4d718de 100644 --- a/src/security/cert/FSecCert_CertManager.cpp +++ b/src/security/cert/FSecCert_CertManager.cpp @@ -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 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(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(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(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); diff --git a/src/security/cert/FSecCert_CertTime.cpp b/src/security/cert/FSecCert_CertTime.cpp index 608759b..e41f103 100644 --- a/src/security/cert/FSecCert_CertTime.cpp +++ b/src/security/cert/FSecCert_CertTime.cpp @@ -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'; + } diff --git a/src/security/inc/FSecCert_CertTypes.h b/src/security/inc/FSecCert_CertTypes.h index 5ce15e1..598721c 100644 --- a/src/security/inc/FSecCert_CertTypes.h +++ b/src/security/inc/FSecCert_CertTypes.h @@ -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;