//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
using namespace Tizen::Base;
using namespace Tizen::Io;
+namespace
+{
+struct ByteDeleter
+{
+ void operator ()(byte* c)
+ {
+ free(c);
+ }
+};
+}
+
namespace Tizen { namespace Security { namespace Cert
{
_CertDbManager* _CertDbManager::__pCertDb = null;
result r = E_SUCCESS;
r = __caCertDbStore.CreateCertificateTables();
- SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_SYSTEM, "Failed to create certificate tables in database.");
+ SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_SYSTEM, "Failed to create certificate tables in database.");
return E_SUCCESS;
}
result r = E_SUCCESS;
r = __caCertDbStore.IsRootCaCertTableCreated();
- if( r != E_SUCCESS )
+ if (r != E_SUCCESS)
{
SetLastResult(E_SYSTEM);
return false;
}
r = __userCertDbStore.IsUserCertTableCreated();
- if( r != E_SUCCESS )
+ if (r != E_SUCCESS)
{
SetLastResult(E_SYSTEM);
return false;
{
result r = E_SUCCESS;
r = __caCertDbStore.DropCertificateTables();
- SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_SYSTEM, "Failed to delete all the certificate tables in database.");
+ SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_SYSTEM, "Failed to delete all the certificate tables in database.");
return E_SUCCESS;
}
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, sizeof(condition), "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.");
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, sizeof(condition), "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.");
r = __caCertDbStore.IsRootCaCertTableCreated();
SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_SYSTEM, "Root certificate tables are not created in database.");
- std::unique_ptr <_X509Certificate> pCert (new (std::nothrow) _X509Certificate());
+ std::unique_ptr< _X509Certificate > pCert(new (std::nothrow) _X509Certificate());
SysTryReturnResult(NID_SEC_CERT, pCert != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
certBufFormat = _CertManager::GetEncodedCertBuffer(pCertBuf, certLen, &pDerCert, &derCertBufferLength, &encodingType);
- std::unique_ptr <byte[]> pDerCertBuffer(pDerCert);
+ std::unique_ptr< byte, ByteDeleter > pDerCertBuffer(pDerCert);
pDerCert = null;
SysTryReturnResult(NID_SEC_CERT, pDerCertBuffer != null, E_INVALID_CONDITION, "Input certificate buffer.");
SysTryReturnResult(NID_SEC_CERT, certBufFormat == _CERT_X509, E_INVALID_CONDITION, "Unsupported certificate format.");
SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_DECODING_FAILED, "Decoding failed.");
pTbsCert = pCert->GetTbsCertInstance();
- SysTryReturnResult(NID_SEC_CERT, pTbsCert != null,E_SYSTEM, "Failed to get certificate to be signed instance.");
+ SysTryReturnResult(NID_SEC_CERT, pTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
lenSubjectName = strlen(reinterpret_cast< const char* >(pTbsCert->GetSubjectName()));
lenIssuerName = strlen(reinterpret_cast< const char* >(pTbsCert->GetIssuerName()));
- SysTryReturnResult(NID_SEC_CERT, lenSubjectName < _MAX_ISSUER_SUBJECT_NAME_SIZE,E_SYSTEM, "Subject name is more then maximum specified length.");
+ SysTryReturnResult(NID_SEC_CERT, lenSubjectName < _MAX_ISSUER_SUBJECT_NAME_SIZE, E_SYSTEM, "Subject name is more then maximum specified length.");
SysTryReturnResult(NID_SEC_CERT, lenIssuerName < _MAX_ISSUER_SUBJECT_NAME_SIZE, E_SYSTEM, "Subject name is more then maximum specified length.");
- strcpy(subjectName, reinterpret_cast< const char* >(pTbsCert->GetSubjectName()));
- strcpy(issuerName, reinterpret_cast< const char* >(pTbsCert->GetIssuerName()));
+ snprintf(subjectName, sizeof(subjectName), "%s", reinterpret_cast< const char* >(pTbsCert->GetSubjectName()));
+ snprintf(issuerName, sizeof(issuerName), "%s", reinterpret_cast< const char* >(pTbsCert->GetIssuerName()));
pTbsCert->GetSerialNumber(pSerial, reinterpret_cast< int& >(lenSerialNo));
if ((lenSerialNo <= 0) || (lenSerialNo > _MAX_SERIAL_NUMBER_SIZE))
//Open this code - if u want to support installation of Intermediate CA Certificate with verification using this API.(ideally it should check if installing intermediate CA) (09082011)
else if (pCert->IsCaCertificate())
{
- std::unique_ptr <_CertChain> pCertChain (new (std::nothrow) _CertChain());
+ std::unique_ptr< _CertChain > pCertChain(new (std::nothrow) _CertChain());
SysTryReturnResult(NID_SEC_CERT, pCertChain != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
r = pCertChain->AddCertificate(certFormat, pDerCertBuffer.get(), derCertBufferLength);
}
r = __caCertDbStore.CheckDuplicateCertificate(certType, reinterpret_cast< byte* >(subjectName), lenSubjectName);
- if(r == E_SUCCESS)
+ if (!IsFailed(r))
{
return E_FILE_ALREADY_EXIST;
}
+
+ SysTryReturnResult(NID_SEC_CERT, r == E_DATA_NOT_FOUND, r, "Failed to check duplicate");
+
+
//Get the last installed certificate id from db table
__caCertDbStore.GetCurrentCertId(certId);
//Calculate the new (std::nothrow) certificate id for installation
certRecord.certType = static_cast< int >(certType);
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 file attributes.");
- strcpy(certRecord.fileName, pFileName.get());
+ int len = strlen(pFileName.get());
+ snprintf(certRecord.fileName, sizeof(certRecord.fileName), "%s", pFileName.get());
certRecord.subjectNameLen = lenSubjectName;
memcpy(certRecord.subjectName, subjectName, lenSubjectName);
r = __caCertDbStore.IsRootCaCertTableCreated();
SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_SYSTEM, "Root certificate tables are not created in database.");
- std::unique_ptr<_X509Certificate> pCert (new (std::nothrow) _X509Certificate());
+ std::unique_ptr< _X509Certificate > pCert(new (std::nothrow) _X509Certificate());
SysTryReturnResult(NID_SEC_CERT, pCert != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
r = pCert->Parse(pCurCertBuf, curCertLen);
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, sizeof(condition), "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));
if (certFormat == _CERT_X509)
{
- std::unique_ptr <_X509Certificate> pNewCert(new (std::nothrow) _X509Certificate());
+ std::unique_ptr< _X509Certificate > pNewCert(new (std::nothrow) _X509Certificate());
SysTryReturnResult(NID_SEC_CERT, pNewCert != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
r = pNewCert->Parse(pNewCertBuf, newCertLen);
pNewTbsCert = pNewCert->GetTbsCertInstance();
SysTryReturnResult(NID_SEC_CERT, pNewTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
- strcpy(newSubjectName, reinterpret_cast< const char* >(pNewTbsCert->GetSubjectName()));
- strcpy(newIssuerName, reinterpret_cast< const char* >((pNewTbsCert->GetIssuerName())));
+ snprintf(newSubjectName, sizeof(newSubjectName), "%s", reinterpret_cast< const char* >(pNewTbsCert->GetSubjectName()));
+ snprintf(newIssuerName, sizeof(newIssuerName), "%s", reinterpret_cast< const char* >(pNewTbsCert->GetIssuerName()));
lenNewSubjectName = strlen(newSubjectName);
lenNewIssuerName = strlen(newIssuerName);
certRecord1.certType = static_cast< int >(certType);
certRecord1.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_OPERATION_FAILED, "Failed to get file name.");
- strcpy(certRecord1.fileName, pFileName.get());
+ int len = strlen(pFileName.get());
+ snprintf(certRecord1.fileName, sizeof(certRecord1.fileName), "%s", pFileName.get());
certRecord1.subjectNameLen = lenNewSubjectName;
memcpy(certRecord1.subjectName, newSubjectName, lenNewSubjectName);
//No need to update record as only file data changed.
return E_SUCCESS;
}
- else
- {
- return E_FILE_ALREADY_EXIST;
- }
return r;
}
r = __caCertDbStore.IsRootCaCertTableCreated();
SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_OBJ_NOT_FOUND, "No root certificate tables are create in databased.");
- std::unique_ptr <_X509Certificate> pCert (new (std::nothrow) _X509Certificate());
+ std::unique_ptr< _X509Certificate > pCert(new (std::nothrow) _X509Certificate());
SysTryReturnResult(NID_SEC_CERT, pCert != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
r = pCert->Parse(pCertBuf, certLen);
SysTryReturnResult(NID_SEC_CERT, pTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
r = __caCertDbStore.CheckDuplicateCertificate(certType, pTbsCert->GetSubjectName(), strlen(reinterpret_cast< char* >(pTbsCert->GetSubjectName())));
- SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_OBJ_NOT_FOUND, "Certificate not found in db.");
+ SysTryReturnResult(NID_SEC_CERT, r != E_DATA_NOT_FOUND, E_OBJ_NOT_FOUND, "Certificate not found in db.");
+ SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), r, "Propagated.");
r = GetCaCertificateId(pTbsCert->GetSubjectName(), strlen(reinterpret_cast< char* >(pTbsCert->GetSubjectName())),
- pTbsCert->GetIssuerName(), strlen(reinterpret_cast< char* >(pTbsCert->GetIssuerName())),
- certId, certType);
+ pTbsCert->GetIssuerName(), strlen(reinterpret_cast< char* >(pTbsCert->GetIssuerName())),
+ certId, certType);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed get ca certificate id.", GetErrorMessage(r));
memset(&userCertRecord, 0, sizeof(userCertRecord));
memset(condition, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
- sprintf(condition, "certId = %d", certId);
+ snprintf(condition, sizeof(condition), "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.");
if (certType == _CERT_TYPE_NOT_BOUNDED)
{
- sprintf(condition, "subjectName = '%s' and issuerName = '%s' and installed = '%s'", subjectNameBase64, issuerNameBase64, installed);
+ snprintf(condition, sizeof(condition), "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, sizeof(condition), "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, sizeof(condition), "subjectName = '%s' and installed = '%s'", subjectNameBase64, installed);
}
else
{
- sprintf(condition, "subjectName = '%s' and certType = %d and installed = '%s'", subjectNameBase64, certType, installed);
+ snprintf(condition, sizeof(condition), "subjectName = '%s' and certType = %d and installed = '%s'", subjectNameBase64, certType, installed);
}
}
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, sizeof(condition), "subjectName = '%s' and issuerName = '%s' and installed = '%s'", subjectNameBase64, issuerNameBase64, installed);
}
else
{
- sprintf(condition, "subjectName = '%s' and installed = '%s'", subjectNameBase64, installed);
+ snprintf(condition, sizeof(condition), "subjectName = '%s' and installed = '%s'", subjectNameBase64, installed);
}
r = __userCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &userCertRecord);
memset(condition, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
- sprintf(condition, "parentCa = %d and installed = '%s'", devParentCA, installed);
+ snprintf(condition, sizeof(condition), "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);
}
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, sizeof(condition), "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.");
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, sizeof(condition), "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.");
SysTryReturnResult(NID_SEC_CERT, r != E_DATA_NOT_FOUND, E_SUCCESS, "No such record found.");
- std::unique_ptr <_CertificateListInfo> pCertList (new (std::nothrow) _CertificateListInfo);
+ std::unique_ptr< _CertificateListInfo > pCertList(new (std::nothrow) _CertificateListInfo);
SysTryReturnResult(NID_SEC_CERT, pCertList != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pCertList.get(), 0, sizeof(*pCertList.get()));
while (__caCertDbStore.GetNextRecordByCondition(reinterpret_cast< byte* >(condition), &certRecord, certRecord.certId) == E_SUCCESS)
{
- std::unique_ptr <_CertificateListInfo> pCertList (new (std::nothrow) _CertificateListInfo);
+ std::unique_ptr< _CertificateListInfo > pCertList(new (std::nothrow) _CertificateListInfo);
SysTryReturnResult(NID_SEC_CERT, pCertList != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pCertList.get(), 0, sizeof(*pCertList.get()));
*ppCertList = null;
- sprintf(condition, "certFormat = %d and installed = '%s'", certFormat, installed);
+ snprintf(condition, sizeof(condition), "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.");
SysTryReturnResult(NID_SEC_CERT, r != E_DATA_NOT_FOUND, E_SUCCESS, "No such record found.");
- std::unique_ptr<_CertificateListInfo> pCertList (new (std::nothrow) _CertificateListInfo);
+ std::unique_ptr< _CertificateListInfo > pCertList(new (std::nothrow) _CertificateListInfo);
SysTryReturnResult(NID_SEC_CERT, pCertList != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pCertList.get(), 0, sizeof(*pCertList.get()));
while (__userCertDbStore.GetNextRecordByCondition(reinterpret_cast< byte* >(condition), &certRecord, certRecord.certId) == E_SUCCESS)
{
- std::unique_ptr<_CertificateListInfo> pCertList (new (std::nothrow) _CertificateListInfo);
+ std::unique_ptr< _CertificateListInfo > pCertList(new (std::nothrow) _CertificateListInfo);
SysTryReturnResult(NID_SEC_CERT, pCertList != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pCertList.get(), 0, sizeof(*pCertList.get()));
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, sizeof(condition), "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));
- std::unique_ptr <_CertificateListInfo> pCertList (new (std::nothrow) _CertificateListInfo);
+ std::unique_ptr< _CertificateListInfo > pCertList(new (std::nothrow) _CertificateListInfo);
SysTryReturnResult(NID_SEC_CERT, pCertList != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pCertList.get(), 0, sizeof(*pCertList.get()));
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, sizeof(condition), "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));
- std::unique_ptr <_CertificateListInfo> pCertList (new (std::nothrow) _CertificateListInfo);
+ std::unique_ptr< _CertificateListInfo > pCertList(new (std::nothrow) _CertificateListInfo);
SysTryReturnResult(NID_SEC_CERT, pCertList != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pCertList.get(), 0, sizeof(*pCertList.get()));
pCertList->format = static_cast< _CertFormat >(certRecord.certFormat);
pCertList->certType = _CERT_TYPE_USER_CERT;
- std::unique_ptr <_CertPrivateKeyInfo> pPriKey (new (std::nothrow) _CertPrivateKeyInfo());
+ std::unique_ptr< _CertPrivateKeyInfo > pPriKey(new (std::nothrow) _CertPrivateKeyInfo());
SysTryReturnResult(NID_SEC_CERT, pPriKey != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
- std::unique_ptr <byte[]> pPrivateKey (new (std::nothrow) byte[_MAX_CERT_PRIVATE_KEY_SIZE]);
+ std::unique_ptr< byte[] > pPrivateKey(new (std::nothrow) byte[_MAX_CERT_PRIVATE_KEY_SIZE]);
SysTryReturnResult(NID_SEC_CERT, pPrivateKey != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pPrivateKey.get(), 0, _MAX_CERT_PRIVATE_KEY_SIZE);
pPriKey->GetPkcs8EncDecKeyN(priKeyLen, &pPrivateTempKey, 0);
SysTryReturnResult(NID_SEC_CERT, pPrivateTempKey != null, E_SYSTEM, "Failed to get private key buffer.");
- std::unique_ptr<byte[]> pPrivateKeyAuto(pPrivateTempKey);
+ std::unique_ptr< byte[] > pPrivateKeyAuto(pPrivateTempKey);
memcpy(pCertList->privatekey, pPrivateTempKey, priKeyLen);
}
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, sizeof(condition), "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));
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, sizeof(condition), "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));
filePath = static_cast< char* >(certRecord.fileName);
fileStore.SetFilePath(filePath);
- std::unique_ptr <byte[]> pCert (new (std::nothrow) byte[_MAX_CERTIFICATE_SIZE]);
+ std::unique_ptr< byte[] > pCert(new (std::nothrow) byte[_MAX_CERTIFICATE_SIZE]);
SysTryReturnResult(NID_SEC_CERT, pCert != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
r = fileStore.ReadFromFile(pCert.get(), certLen);
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, sizeof(condition), "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));
r = file.Construct(fileName, L"r");
SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_SYSTEM, "Failed to construct file.");
- std::unique_ptr <byte[]> pCertBuf (new (std::nothrow) byte[fileSize + 1]);
+ std::unique_ptr< byte[] > pCertBuf(new (std::nothrow) byte[fileSize + 1]);
SysTryReturnResult(NID_SEC_CERT, pCertBuf != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pCertBuf.get(), 0, fileSize + 1);
SysTryReturn(NID_SEC_CERT, (readCnt == fileSize) || (!IsFailed(r)), r, r, "[%s] Failed to read file.", GetErrorMessage(r));
certLen = readCnt;
- std::unique_ptr <byte[]> pOutBuf (new (std::nothrow) byte[outLen]);
+ std::unique_ptr< byte[] > pOutBuf(new (std::nothrow) byte[outLen]);
SysTryReturnResult(NID_SEC_CERT, pOutBuf != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pOutBuf.get(), 0, outLen);
pTbsCert = pCurCert->GetTbsCertInstance();
SysTryReturnResult(NID_SEC_CERT, pTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
- if (E_SUCCESS != __caCertDbStore.CheckDuplicateCertificate(certType, reinterpret_cast< byte* >(pTbsCert->GetSubjectName()), strlen(reinterpret_cast< char* >(pTbsCert->GetSubjectName()))))
+ 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));
+
pX509Buff = null;
x509BuffSize = 0;
r = InsertCaCertificateFromBuffer(certType, certFormat, pX509Buff, x509BuffSize);
SysTryReturn(NID_SEC_CERT, !(IsFailed(r) && r != E_FILE_ALREADY_EXIST), r, r, "[E_SYSTEM] Failed to insert ca certificate.");
}
+
// CA certificate already present or properly installed in CA certificate store,
// get the certificate id of certificate
r = GetCaCertificateId(pTbsCert->GetSubjectName(), strlen(reinterpret_cast< char* >(pTbsCert->GetSubjectName())),
- pTbsCert->GetIssuerName(), strlen(reinterpret_cast< char* >(pTbsCert->GetIssuerName())),
- curCACertId, certType);
+ pTbsCert->GetIssuerName(), strlen(reinterpret_cast< char* >(pTbsCert->GetIssuerName())),
+ curCACertId, certType);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed get Ca certificate id.", GetErrorMessage(r));
if (updateUserParentCa)
SysTryReturnResult(NID_SEC_CERT, pTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
r = GetCaCertificateId(pTbsCert->GetIssuerName(), strlen(reinterpret_cast< char* >(pTbsCert->GetIssuerName())),
- null, 0, curCACertId);
+ null, 0, curCACertId);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed get Ca certificate id.", GetErrorMessage(r));
__userCertDbStore.UpdateParentCa(curDevCertId, curCACertId);
SysTryReturnResult(NID_SEC_CERT, pTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
r = GetCaCertificateId(pTbsCert->GetIssuerName(), strlen(reinterpret_cast< char* >(pTbsCert->GetIssuerName())),
- null, 0, curCACertId);
+ null, 0, curCACertId);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed get Ca certificate id.", GetErrorMessage(r));
__caCertDbStore.UpdateParentCa(lastCACertId, curCACertId);
bool updateUserParentCa = false;
byte* pPrvKey = null;
- std::unique_ptr <byte[]> pPrvKeyBuffer;
+ std::unique_ptr< byte[] > pPrvKeyBuffer;
SysTryReturnResult(NID_SEC_CERT, pCertChain != null, E_INVALID_ARG, "Invalid input parameter.");
SysTryReturnResult(NID_SEC_CERT, certFormat == _CERT_X509, E_INVALID_ARG, "Invalid certificate format.");
int subjectNameLen = strlen(reinterpret_cast< char* >(pTbsCert->GetSubjectName()));
r = __userCertDbStore.CheckDuplicateCertificate(pSubjectName, subjectNameLen);
- if (IsFailed(r))
+ if (r == E_DATA_NOT_FOUND)
{
if (pPrivateKeyInfo != null)
{
pPrivateKeyInfo->GetPkcs8EncDecKeyN(prvKeyLen, &pPrvKey, 1);
SysTryReturnResult(NID_SEC_CERT, prvKeyLen > 0, E_INVALID_KEY, "Invalid key length .");
- pPrvKeyBuffer = std::unique_ptr <byte[]> (pPrvKey);
+ pPrvKeyBuffer = std::unique_ptr< byte[] >(pPrvKey);
pPrvKey = null;
}
SysTryReturnResult(NID_SEC_CERT, pTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
r = __caCertDbStore.CheckDuplicateCertificate(certType, pTbsCert->GetSubjectName(), strlen(reinterpret_cast< char* >(pTbsCert->GetSubjectName())));
- if (IsFailed(r))
+ if (r != E_SUCCESS)
{
+ SysTryReturnResult(NID_SEC_CERT, r == E_DATA_NOT_FOUND, r, "Failed to check duplicate.");
+
pX509Buff = null;
x509BuffSize = 0;
// get the certificate id of certificate
r = GetCaCertificateId(pTbsCert->GetSubjectName(), strlen(reinterpret_cast< char* >(pTbsCert->GetSubjectName())),
- pTbsCert->GetIssuerName(), strlen(reinterpret_cast< char* >(pTbsCert->GetIssuerName())),
- curCACertId, certType);
+ pTbsCert->GetIssuerName(), strlen(reinterpret_cast< char* >(pTbsCert->GetIssuerName())),
+ curCACertId, certType);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed get Ca certificate id.", GetErrorMessage(r));
if (updateUserParentCa)
SysTryReturnResult(NID_SEC_CERT, pTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
r = GetCaCertificateId(pTbsCert->GetIssuerName(), strlen(reinterpret_cast< char* >(pTbsCert->GetIssuerName())),
- null, 0, curCACertId);
+ null, 0, curCACertId);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed get Ca certificate id.", GetErrorMessage(r));
__userCertDbStore.UpdateParentCa(curDevCertId, curCACertId);
SysTryReturnResult(NID_SEC_CERT, pTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
r = GetCaCertificateId(pTbsCert->GetIssuerName(), strlen(reinterpret_cast< char* >(pTbsCert->GetIssuerName())),
- null, 0, curCACertId);
+ null, 0, curCACertId);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed get Ca certificate id.", GetErrorMessage(r));
__caCertDbStore.UpdateParentCa(lastCACertId, curCACertId);
int lenSerialNo = 0;
int certId = 0;
int keyIdB64Length = 0;
- char* pFileName = null;
- char* pPriKeyFileName = null;
char subjectNameBuffer[_MAX_ISSUER_SUBJECT_NAME_SIZE] = {0, };
char szIssuerName[_MAX_ISSUER_SUBJECT_NAME_SIZE] = {0, };
char serialName[_MAX_SERIAL_NUMBER_SIZE] = {0, };
r = __userCertDbStore.IsUserCertTableCreated();
SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_SYSTEM, "Failed to create user certificate.");
- std::unique_ptr <_X509Certificate> pCert (new (std::nothrow) _X509Certificate());
+ std::unique_ptr< _X509Certificate > pCert(new (std::nothrow) _X509Certificate());
SysTryReturnResult(NID_SEC_CERT, pCert != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
r = pCert->Parse(pCertBuffer, certLength);
SysTryReturnResult(NID_SEC_CERT, lenSubjectName < _MAX_ISSUER_SUBJECT_NAME_SIZE, E_DATABASE, "Length is greater than maximum allowed length.");
SysTryReturnResult(NID_SEC_CERT, lenIssuerName < _MAX_ISSUER_SUBJECT_NAME_SIZE, E_DATABASE, "Length is greater than maximum allowed length.");
- strcpy(subjectNameBuffer, reinterpret_cast< char* >(pTbsCert->GetSubjectName()));
- strcpy(szIssuerName, reinterpret_cast< char* >(pTbsCert->GetIssuerName()));
+ snprintf(subjectNameBuffer, sizeof(subjectNameBuffer), "%s", reinterpret_cast< char* >(pTbsCert->GetSubjectName()));
+ snprintf(szIssuerName, sizeof(szIssuerName), "%s", reinterpret_cast< char* >(pTbsCert->GetIssuerName()));
pTbsCert->GetSerialNumber(pSerial, static_cast< int& >(lenSerialNo));
if ((lenSerialNo <= 0) || (lenSerialNo > _MAX_SERIAL_NUMBER_SIZE))
r = pCert->GetKeyIdN(&pKeyId);
SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_DECODING_FAILED, "Failed to get key Id.");
- std::unique_ptr <byte[]> pKeyIdBuffer (pKeyId);
+ std::unique_ptr< byte[] > pKeyIdBuffer(pKeyId);
keyIdB64Length = _Base64::GetEncodedSize(_MAX_CERT_SHA1_DIGEST_SIZE);
SysTryReturnResult(NID_SEC_CERT, keyIdB64Length >= 0, E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
- std::unique_ptr <char[]> pId64 (new (std::nothrow) char[keyIdB64Length]);
+ std::unique_ptr< char[] > pId64(new (std::nothrow) char[keyIdB64Length]);
SysTryReturnResult(NID_SEC_CERT, pId64 != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pId64.get(), 0, keyIdB64Length);
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");
//Get the last installed certificate id from db table
__userCertDbStore.GetCurrentCertId(certId);
}
else
{
- pPriKeyFileName = null;
privateKeyLen = 0;
}
memcpy(certRecord.certPubKeyHash, pId64.get(), keyIdB64Length); //Base64 encoded device id
certRecord.certFormat = static_cast< int >(certFormat);
- 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);
+ int len = strlen(pFileName.get());
+ snprintf(certRecord.fileName, sizeof(certRecord.fileName), "%s", pFileName.get());
+
certRecord.subjectNameLen = lenSubjectName;
memcpy(certRecord.subjectName, subjectNameBuffer, lenSubjectName);
certRecord.issuerNameLen = lenIssuerName;
memcpy(certRecord.issuerName, szIssuerName, lenIssuerName);
- 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);
+ len = strlen(pPriKeyFileName.get());
+ snprintf(certRecord.prvKeyPath, sizeof(certRecord.prvKeyPath), "%s", pPriKeyFileName.get());
certRecord.prvKeyLen = privateKeyLen;
certRecord.parentCa = certId;
strcpy(certRecord.installed, installedRecord);
subjectNameBase64Len = _Base64::GetEncodedSize(issuerNameLen);
memset(issuerNameBase64, 0, sizeof(issuerNameBase64));
r = _Base64::Encode(reinterpret_cast< byte* >(pIssuerName), issuerNameLen, reinterpret_cast< char* >(issuerNameBase64), subjectNameBase64Len);
- SysTryReturnResult(NID_SEC_CERT, !IsFailed(r),E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
+ SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
if ((pSubjectName != null) && (subjectNameLen > 0))
{
subjectNameBase64Len = _Base64::GetEncodedSize(subjectNameLen);
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);
+ SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
+ snprintf(condition, sizeof(condition), "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, sizeof(condition), "installed = '%s'", installedRecord);
}
memset(&userCertRecord, 0, sizeof(userCertRecord));
r = __userCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &userCertRecord);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificates record.", GetErrorMessage(r));
- std::unique_ptr <_CertPrivateKeyInfo> pPriKey (new (std::nothrow) _CertPrivateKeyInfo());
+ std::unique_ptr< _CertPrivateKeyInfo > pPriKey(new (std::nothrow) _CertPrivateKeyInfo());
SysTryReturnResult(NID_SEC_CERT, pPriKey != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
do
{
- std::unique_ptr <_CertFileStore> pFileStore (new (std::nothrow) _CertFileStore());
+ std::unique_ptr< _CertFileStore > pFileStore(new (std::nothrow) _CertFileStore());
SysTryReturnResult(NID_SEC_CERT, pFileStore != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
- std::unique_ptr<_CertificateListInfo> pCertList(new (std::nothrow) _CertificateListInfo);
+ std::unique_ptr< _CertificateListInfo > pCertList(new (std::nothrow) _CertificateListInfo);
SysTryReturnResult(NID_SEC_CERT, pCertList != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pCertList.get(), 0, sizeof(*pCertList.get()));
if (encodingType == _CERT_ENC_TYPE_PEM)
{
const byte* pCertBuffer = pCertList->certificate;
-
+
pBio = BIO_new(BIO_s_mem());
SysTryReturnResult(NID_SEC_CERT, pBio != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
-
+
pCert = d2i_X509(null, &pCertBuffer, pCertList->length);
SysTryCatch(NID_SEC_CERT, pCert != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Certificate convertion failed.");
BIO_free(pBio);
pBio = null;
-
+
X509_free(pCert);
pCert = null;
else if (encodingType == _CERT_ENC_TYPE_BASE64)
{
int certLen = _Base64::GetEncodedSize(pCertList->length);
+ SysTryReturnResult(NID_SEC_CERT, certLen > 0, E_SYSTEM, "Certificate length is invalid.");
memset(pCertList->certificate + pCertList->length, 0, sizeof(pCertList->certificate) - pCertList->length);
r = _Base64::Encode(reinterpret_cast< byte* >(pCertList->certificate), pCertList->length, reinterpret_cast< char* >(pCertList->certificate), certLen);
SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
pCertList->length = certLen;
}
- std::unique_ptr <byte[]> pPrivateKey (new (std::nothrow) byte[_MAX_CERT_PRIVATE_KEY_SIZE]);
+ std::unique_ptr< byte[] > pPrivateKey(new (std::nothrow) byte[_MAX_CERT_PRIVATE_KEY_SIZE]);
SysTryReturnResult(NID_SEC_CERT, pPrivateKey != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pPrivateKey.get(), 0, _MAX_CERT_PRIVATE_KEY_SIZE);
pPriKey->GetPkcs8EncDecKeyN(priKeyLen, &pPrivateTempKey, 0);
SysTryReturnResult(NID_SEC_CERT, pPrivateTempKey != null, E_SYSTEM, "Failed to get private key buffer.");
-
- pPrivateKey = std::unique_ptr<byte[]>(pPrivateTempKey);
+
+ pPrivateKey = std::unique_ptr< byte[] >(pPrivateTempKey);
if (encodingType == _CERT_ENC_TYPE_PEM)
{
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, sizeof(condition), "subjectName = '%s' and installed = '%s'", subjectNameBase64, installedRecord);
if (strcmp(reinterpret_cast< char* >(issuerNameBase64), reinterpret_cast< char* >(subjectNameBase64)) == 0)
{
if (strcmp(certRecord.issuerName, certRecord.subjectName) != 0)
{
- std::unique_ptr<_CertificateListInfo> pCertList(new (std::nothrow) _CertificateListInfo());
+ std::unique_ptr< _CertificateListInfo > pCertList(new (std::nothrow) _CertificateListInfo());
SysTryReturnResult(NID_SEC_CERT, pCertList != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pCertList.get(), 0, sizeof(*pCertList.get()));
int certLen = _Base64::GetEncodedSize(pCertList->length);
memset(pCertList->certificate + pCertList->length, 0, sizeof(pCertList->certificate) - pCertList->length);
r = _Base64::Encode(reinterpret_cast< byte* >(pCertList->certificate), pCertList->length, reinterpret_cast< char* >(pCertList->certificate), certLen);
- SysTryReturnResult(NID_SEC_CERT, !IsFailed(r),E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
+ SysTryReturnResult(NID_SEC_CERT, !IsFailed(r), E_ENCODING_FAILED, "Failed to encode data in base 64 encoding.");
pCertList->length = certLen;
}
pCertList->format = (_CertFormat) certRecord.certFormat;
}
memset(condition, 0, sizeof(condition));
- sprintf(condition, "installed = '%s'", installedRecord);
+ snprintf(condition, sizeof(condition), "installed = '%s'", installedRecord);
count++;
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, sizeof(conditonRecord), "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));
{
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, sizeof(conditonRecord), "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));
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, sizeof(condition), "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));
byte* pPrivateTempKey = null;
UserCertRecord certRecord = {0, };
_CertFileStore fileStore;
- std::unique_ptr <_CertPrivateKeyInfo> pPriKey;
+ std::unique_ptr< _CertPrivateKeyInfo > pPriKey;
BIO* pBio = null;
X509* pCert = null;
EVP_PKEY* pKey = null;
*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, sizeof(condition), "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));
- std::unique_ptr <_CertInfo> pCertInfo (new (std::nothrow) _CertInfo);
+ std::unique_ptr< _CertInfo > pCertInfo(new (std::nothrow) _CertInfo);
SysTryCatch(NID_SEC_CERT, pCertInfo != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
memset(pCertInfo.get(), 0, sizeof(*pCertInfo.get()));
if (certRecord.prvKeyLen > 0)
{
- pPriKey = std::unique_ptr <_CertPrivateKeyInfo> (new (std::nothrow) _CertPrivateKeyInfo());
+ pPriKey = std::unique_ptr< _CertPrivateKeyInfo >(new (std::nothrow) _CertPrivateKeyInfo());
SysTryReturnResult(NID_SEC_CERT, pPriKey != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
- std::unique_ptr <byte[]> pPrivateKey (new (std::nothrow) byte[_MAX_CERT_PRIVATE_KEY_SIZE]);
+ std::unique_ptr< byte[] > pPrivateKey(new (std::nothrow) byte[_MAX_CERT_PRIVATE_KEY_SIZE]);
SysTryReturnResult(NID_SEC_CERT, pPrivateKey != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
memset(pPrivateKey.get(), 0, _MAX_CERT_PRIVATE_KEY_SIZE);
pPriKey->GetPkcs8EncDecKeyN(priKeyLen, &pPrivateTempKey, 0);
SysTryReturnResult(NID_SEC_CERT, pPrivateTempKey != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
- pPrivateKey = std::unique_ptr<byte[]>(pPrivateTempKey);
+ pPrivateKey = std::unique_ptr< byte[] >(pPrivateTempKey);
if (encodingType == _CERT_ENC_TYPE_PEM)
{
EVP_PKEY_free(pKey);
}
- {
- }
return r;
}