//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
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.");
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))
}
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
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 = _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));
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);
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;
}
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())),
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.");
*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.");
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));
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));
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));
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));
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())),
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)
{
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;
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, };
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 = __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);
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);
+ 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));
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.");
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)
{
}
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));
*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));
EVP_PKEY_free(pKey);
}
- {
- }
return r;
}