r = dir.Construct(dirName);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to construct directory.", GetErrorMessage(r));
- std::unique_ptr<DirEnumerator> pDirEnum(dir.ReadN());
+ std::unique_ptr< DirEnumerator > pDirEnum(dir.ReadN());
SysTryReturn(NID_SEC_CERT, pDirEnum != null, GetLastResult(), GetLastResult(), "[%s] Failed to read directory.", GetErrorMessage(GetLastResult()));
while (pDirEnum->MoveNext() == E_SUCCESS)
SysTryReturnResult(NID_SEC_CERT, pCert != null, E_INVALID_ARG, "Initial parameters are invalid.");
certFormat = _CertManager::GetEncodedCertBuffer(pCert, certLen, &pDerCert, &derCertBufferLength, &encodingType);
- std::unique_ptr<byte[]> pDerCertBuffer(pDerCert);
+ std::unique_ptr< byte[] > pDerCertBuffer(pDerCert);
pDerCert = null;
SysTryReturnResult(NID_SEC_CERT, certFormat == _CERT_X509, E_INVALID_ARG, "Unsupported certificate format.");
pCert->GetCertBuffer(pX509Buff, x509BuffSize);
SysTryReturnResult(NID_SEC_CERT, pX509Buff != null, E_SYSTEM, "Failed to get certificate buffer.");
- std::unique_ptr<byte[]> pFingerPrint(new (std::nothrow) byte[SHA_DIGEST_LENGTH + 1]);
+ std::unique_ptr< byte[] > pFingerPrint(new (std::nothrow) byte[SHA_DIGEST_LENGTH + 1]);
SysTryReturnResult(NID_SEC_CERT, pFingerPrint != null, E_OUT_OF_MEMORY, "Failed to allocate memory. ");
memset(pFingerPrint.get(), 0, SHA_DIGEST_LENGTH + 1);
pTbsCert->GetPublicKeyInfoN(publicKeyLen, &pPublicKeyBuffer);
if (pPublicKeyBuffer != null)
{
- std::unique_ptr<byte[]> pPublicKeyAuto(pPublicKeyBuffer);
+ std::unique_ptr< byte[] > pPublicKeyAuto(pPublicKeyBuffer);
int iterVal = publicKeyLen;
int index = 0;
SysTryReturn(NID_SEC_CERT, pCertBuffer != null, _CERT_UNKNOWN, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument passed.");
SysTryReturn(NID_SEC_CERT, certBufferLen > 0, _CERT_UNKNOWN, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument passed.");
- std::unique_ptr<_X509Certificate> pX509Cert(new (std::nothrow) _X509Certificate());
+ std::unique_ptr< _X509Certificate > pX509Cert(new (std::nothrow) _X509Certificate());
SysTryReturn(NID_SEC_CERT, pX509Cert != null, _CERT_UNKNOWN, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
pBase64Header = strstr(reinterpret_cast< char* >(pCertBuffer), _CERT_BASE64_HEADER);
SysTryReturn(NID_SEC_CERT, pBio != null, _CERT_UNKNOWN, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
pemCertSize = (int(pBase64Trailer - pBase64Header) + strlen(_CERT_BASE64_TRAILER));
- readCount = BIO_write(pBio, (const void*) pBase64Header, pemCertSize);
+ readCount = BIO_write(pBio, (const void*) pBase64Header, pemCertSize);
SysTryCatch(NID_SEC_CERT, readCount > 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Certificate conversion failed");
pOpensslX509Cert = PEM_read_bio_X509(pBio, NULL, 0, NULL);
}
else if (pX509Cert->Parse(pCertBuffer, certBufferLen) == E_SUCCESS)
{
- std::unique_ptr<byte[]> pCertBuf(new (std::nothrow) byte[certBufferLen]);
+ std::unique_ptr< byte[] > pCertBuf(new (std::nothrow) 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);
certBufLen = _Base64::GetDecodedSize(certBufferLen);
SysTryReturn(NID_SEC_CERT, certBufLen > 0, _CERT_UNKNOWN, E_SYSTEM, "[E_SYSTEM] Invalid certificate length.");
- std::unique_ptr<byte[]> pCertBuf(new (std::nothrow) byte[certBufLen]);
+ std::unique_ptr< byte[] > pCertBuf(new (std::nothrow) 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);
pTbsCert->GetPublicKeyInfoN(pubKeyLen, &pPuKey);
SysTryReturnResult(NID_SEC_CERT, pPuKey != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
- std::unique_ptr<byte[]> pPubKeyAuto(pPuKey);
+ std::unique_ptr< byte[] > pPubKeyAuto(pPuKey);
memcpy(pBuffer, pPubKeyAuto.get(), pubKeyLen);
ClearLastResult();
SysTryReturn(NID_SEC_CERT, subject[0] != '\0', E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid input parameter.");
-
- SysAssertf(strlen(subject) <= _MAX_ISSUER_SUBJECT_NAME_SIZE, "The buffer size of source is too big.");
+
+ SysAssertf(strlen(subject) <= (size_t) _MAX_ISSUER_SUBJECT_NAME_SIZE, "The buffer size of source is too big.");
bool done = false;
- char* pPivotPtr = null;
- char* pSavePtr = null;
- char* pSubStr = null;
- char tempSubject[_MAX_ISSUER_SUBJECT_NAME_SIZE + 1] = {0, };
+ char* pPivotPtr = null;
+ char* pSavePtr = null;
+ char* pSubStr = null;
+ char tempSubject[_MAX_ISSUER_SUBJECT_NAME_SIZE + 1] = {0, };
strncpy(tempSubject, subject, strlen(subject));
pPivotPtr = tempSubject;
- for (int count = 0; ; pSubStr = null)
- {
- pSubStr = strtok_r(pPivotPtr, "/", &pSavePtr);
+ for (;; pSubStr = null)
+ {
+ pSubStr = strtok_r(pPivotPtr, "/", &pSavePtr);
if (strncmp(pSubStr, _CERT_COMMON_NAME, strlen(_CERT_COMMON_NAME)) == 0)
{
// copy title into out param
strncpy(title, pSubStr, strlen(pSubStr));
-
+
return E_SUCCESS;
}
byte* pCertBuf = null;
byte* pCurrCertBuf = null;
_X509Certificate* pUserCert = null;
- std::unique_ptr<_CertPrivateKeyInfo> pPKeyInfo(null);
+ std::unique_ptr< _CertPrivateKeyInfo > pPKeyInfo(null);
pCertBuf = pCertChainBuffer;
bufSize = certChainLength;
// Process Private Key
if (pUserPrivateKeyBuffer != null && userPrivateKeyLength > 0)
{
- pPKeyInfo = std::unique_ptr<_CertPrivateKeyInfo> (new (std::nothrow) _CertPrivateKeyInfo(pUserPrivateKeyBuffer, userPrivateKeyLength));
+ pPKeyInfo = std::unique_ptr< _CertPrivateKeyInfo >(new (std::nothrow) _CertPrivateKeyInfo(pUserPrivateKeyBuffer, userPrivateKeyLength));
SysTryReturnResult(NID_SEC_CERT, pPKeyInfo != null, E_OUT_OF_MEMORY, "Failed allocate memory.");
}
dataOffset = 0;
- 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 parse and verify certificate chain.");
if (pPKeyInfo != null)
pCurrCertBuf = pCertBuf + dataOffset;
currCertBufLen = _CertManager::GetBlockSize(pCurrCertBuf);
- std::unique_ptr<_X509Certificate> pTmpCert(new (std::nothrow) _X509Certificate());
+ std::unique_ptr< _X509Certificate > pTmpCert(new (std::nothrow) _X509Certificate());
SysTryReturnResult(NID_SEC_CERT, pTmpCert != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
r = pTmpCert->Parse(pCurrCertBuf, currCertBufLen);
pCurrCertBuf = pCertBuf + dataOffset;
currCertBufLen = _CertManager::GetBlockSize(pCurrCertBuf);
- std::unique_ptr<_X509Certificate> pUserCertAuto(new (std::nothrow) _X509Certificate());
+ std::unique_ptr< _X509Certificate > pUserCertAuto(new (std::nothrow) _X509Certificate());
SysTryReturnResult(NID_SEC_CERT, pUserCertAuto != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
r = pUserCertAuto->Parse(pCurrCertBuf, currCertBufLen);
while (dataOffset < bufSize)
{
- std::unique_ptr<_X509Certificate> pCurrentCert(new (std::nothrow) _X509Certificate());
+ std::unique_ptr< _X509Certificate > pCurrentCert(new (std::nothrow) _X509Certificate());
SysTryReturnResult(NID_SEC_CERT, pCurrentCert != null, E_OUT_OF_MEMORY, "Failed to allocate memory. ");
pCurrCertBuf = pCertBuf + dataOffset;
pX509CertificatePrivateKey->GetPrivateKeyN(privateKeyLength, &pPriKey);
SysTryReturnResult(NID_SEC_CERT, pPriKey != null, E_SYSTEM, "Unable to get certificate private key.");
- std::unique_ptr<byte[]> pPriKeyBuf(pPriKey);
+ std::unique_ptr< byte[] > pPriKeyBuf(pPriKey);
pPrivateKey = d2i_PrivateKey(EVP_PKEY_RSA, null, const_cast< const unsigned char** >(static_cast< unsigned char** >(&pPriKey)), privateKeyLength);
if (pPrivateKey != null)
sprintf(condition, "installed = '%s'", installedRecord);
- std::unique_ptr<_UserCertDbStore> pUserCertDbStore(new (std::nothrow) _UserCertDbStore());
+ 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.");
r = pUserCertDbStore->GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), certificateStoreCtx, r, "[%s] Failed to get first certificate record.", GetErrorMessage(r));
- std::unique_ptr<_CertRootList> pCertListFirstNode(new (std::nothrow) _CertRootList());
+ std::unique_ptr< _CertRootList > pCertListFirstNode(new (std::nothrow) _CertRootList());
SysTryReturn(NID_SEC_CERT, pCertListFirstNode != null, certificateStoreCtx, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
- std::unique_ptr<_CertRootCaInfo> pRootCa(new (std::nothrow) _CertRootCaInfo());
+ std::unique_ptr< _CertRootCaInfo > pRootCa(new (std::nothrow) _CertRootCaInfo());
SysTryReturn(NID_SEC_CERT, pRootCa != null, certificateStoreCtx, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
memset(pRootCa.get(), 0, sizeof(*pRootCa.get()));
while ((pUserCertDbStore->GetNextRecordByCondition(reinterpret_cast< byte* >(condition), &certRecord, certRecord.certId)) == E_SUCCESS)
{
- std::unique_ptr<_CertRootList> pCertList(new (std::nothrow) _CertRootList());
+ std::unique_ptr< _CertRootList > pCertList(new (std::nothrow) _CertRootList());
SysTryReturn(NID_SEC_CERT, pCertList != null, certificateStoreCtx, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
r = fileStore.SetFileHandle(certRecord.certId, _CERT_PATH_USER_CERT);
sprintf(condition, "certType = %d and installed = '%s'", static_cast< int >(type), installedRecord);
- std::unique_ptr<_CaCertDbStore> pCaCertDbStore(new (std::nothrow) _CaCertDbStore());
+ 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.");
r = pCaCertDbStore->GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), certificateStoreCtx, r, "[%s] Failed to get first certificate record.", GetErrorMessage(r));
- std::unique_ptr<_CertRootList> pCertListFirstNode(new (std::nothrow) _CertRootList());
+ std::unique_ptr< _CertRootList > pCertListFirstNode(new (std::nothrow) _CertRootList());
SysTryReturn(NID_SEC_CERT, pCertListFirstNode != null, certificateStoreCtx, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
- std::unique_ptr<_CertRootCaInfo> pRootCa(new (std::nothrow) _CertRootCaInfo());
+ std::unique_ptr< _CertRootCaInfo > pRootCa(new (std::nothrow) _CertRootCaInfo());
SysTryReturn(NID_SEC_CERT, pRootCa != null, certificateStoreCtx, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
memset(pRootCa.get(), 0, sizeof(*pRootCa.get()));
while ((pCaCertDbStore->GetNextRecordByCondition(reinterpret_cast< byte* >(condition), &certRecord, certRecord.certId)) == E_SUCCESS)
{
- std::unique_ptr<_CertRootList> pCertList(new (std::nothrow) _CertRootList());
+ std::unique_ptr< _CertRootList > pCertList(new (std::nothrow) _CertRootList());
SysTryReturn(NID_SEC_CERT, pCertList != null, certificateStoreCtx, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
r = fileStore.SetFileHandle(certRecord.certId, _CERT_PATH_CA_CERT);