//
-// 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;
}
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()));
//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 (r == E_SUCCESS)
{
return E_FILE_ALREADY_EXIST;
}
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());
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);
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);
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());
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, !IsFailed(r), E_OBJ_NOT_FOUND, "Certificate not found in db.");
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));
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()));
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()));
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()));
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);
}
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 = 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);
// 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.");
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;
}
// 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);
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);
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);
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.");
+ 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);
}
else
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)
{
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;
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;
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)
{