Change-Id: I34afc9172800c80849623cdd8d6d09f59afdfe9f
Signed-off-by: ashish.shri <ashish.shri@samsung.com>
char condition[_MAX_TYPE_CONST_SIZE] = {0, };
char installed[_MAX_TYPE_RECORD_SIZE] = "T\0";
char condition[_MAX_TYPE_CONST_SIZE] = {0, };
char installed[_MAX_TYPE_RECORD_SIZE] = "T\0";
- snprintf(condition, _MAX_TYPE_CONST_SIZE, "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.");
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";
char condition[_MAX_TYPE_CONST_SIZE] = {0, };
char installed[_MAX_TYPE_RECORD_SIZE] = "T\0";
- snprintf(condition, _MAX_TYPE_CONST_SIZE, "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.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.");
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.");
- strncpy(subjectName, reinterpret_cast< const char* >(pTbsCert->GetSubjectName()),lenSubjectName);
- strncpy(issuerName, reinterpret_cast< const char* >(pTbsCert->GetIssuerName()),lenIssuerName);
+ 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))
pTbsCert->GetSerialNumber(pSerial, reinterpret_cast< int& >(lenSerialNo));
if ((lenSerialNo <= 0) || (lenSerialNo > _MAX_SERIAL_NUMBER_SIZE))
SysTryReturnResult(NID_SEC_CERT, pFileName != null, E_SYSTEM, "Failed to get file attributes.");
int len = strlen(pFileName.get());
SysTryReturnResult(NID_SEC_CERT, pFileName != null, E_SYSTEM, "Failed to get file attributes.");
int len = strlen(pFileName.get());
- strncpy(certRecord.fileName, pFileName.get(), len);
+ snprintf(certRecord.fileName, sizeof(certRecord.fileName), "%s", pFileName.get());
certRecord.subjectNameLen = lenSubjectName;
memcpy(certRecord.subjectName, subjectName, lenSubjectName);
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.");
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.");
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "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));
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.");
pNewTbsCert = pNewCert->GetTbsCertInstance();
SysTryReturnResult(NID_SEC_CERT, pNewTbsCert != null, E_SYSTEM, "Failed to get certificate to be signed instance.");
- lenSubjectName = strlen(reinterpret_cast< char* >(pNewTbsCert->GetSubjectName()));
- lenIssuerName = strlen(reinterpret_cast< char* >(pNewTbsCert->GetIssuerName()));
-
- strncpy(newSubjectName, reinterpret_cast< const char* >(pNewTbsCert->GetSubjectName()),lenSubjectName);
- strncpy(newIssuerName, reinterpret_cast< const char* >(pNewTbsCert->GetIssuerName()),lenIssuerName);
+ 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);
lenNewSubjectName = strlen(newSubjectName);
lenNewIssuerName = strlen(newIssuerName);
SysTryReturnResult(NID_SEC_CERT, pFileName != null, E_OPERATION_FAILED, "Failed to get file name.");
int len = strlen(pFileName.get());
SysTryReturnResult(NID_SEC_CERT, pFileName != null, E_OPERATION_FAILED, "Failed to get file name.");
int len = strlen(pFileName.get());
- strncpy(certRecord1.fileName, pFileName.get(), len);
+ snprintf(certRecord1.fileName, sizeof(certRecord1.fileName), "%s", pFileName.get());
certRecord1.subjectNameLen = lenNewSubjectName;
memcpy(certRecord1.subjectName, newSubjectName, lenNewSubjectName);
certRecord1.subjectNameLen = lenNewSubjectName;
memcpy(certRecord1.subjectName, newSubjectName, lenNewSubjectName);
memset(&userCertRecord, 0, sizeof(userCertRecord));
memset(condition, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
memset(&userCertRecord, 0, sizeof(userCertRecord));
memset(condition, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "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.");
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)
{
if (certType == _CERT_TYPE_NOT_BOUNDED)
{
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "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);
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "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)
{
}
}
else
{
if (certType == _CERT_TYPE_NOT_BOUNDED)
{
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "subjectName = '%s' and installed = '%s'", subjectNameBase64, installed);
+ snprintf(condition, sizeof(condition), "subjectName = '%s' and installed = '%s'", subjectNameBase64, installed);
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "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.");
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.");
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_ISSUER_SUBJECT_NAME_SIZE), "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);
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_ISSUER_SUBJECT_NAME_SIZE), "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);
}
r = __userCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &userCertRecord);
memset(condition, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
memset(condition, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "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);
//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);
}
caCertId = caParentCa; // Now look for next certificate in chain
memset(condition, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "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.");
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, };
char installed[_MAX_TYPE_RECORD_SIZE] = "T\0";
char condition[_MAX_TYPE_CONST_SIZE] = {0, };
- snprintf(condition, _MAX_TYPE_CONST_SIZE, "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.");
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.");
- snprintf(condition, _MAX_TYPE_CONST_SIZE, "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.");
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;
char condition[_MAX_TYPE_CONST_SIZE] = {0, };
*ppCertList = null;
- snprintf(condition, _MAX_TYPE_CONST_SIZE, "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));
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.");
SysTryReturnResult(NID_SEC_CERT, ppCertList != null, E_INVALID_ARG, "Invalid input arguments.");
SysTryReturnResult(NID_SEC_CERT, certId > 0, E_INVALID_ARG, "Invalid input arguments.");
- snprintf(condition, _MAX_TYPE_CONST_SIZE, "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 = __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.");
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.");
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_OFFSET_CONST_SIZE), "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 = __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.");
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.");
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_ISSUER_CONDITION_SIZE), "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 = __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.");
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.");
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_CONDITION_CONST_SIZE), "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 = __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, 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.");
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.");
- strncpy(subjectNameBuffer, reinterpret_cast< char* >(pTbsCert->GetSubjectName()),lenSubjectName);
- strncpy(szIssuerName, reinterpret_cast< char* >(pTbsCert->GetIssuerName()),lenIssuerName);
+ 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))
pTbsCert->GetSerialNumber(pSerial, static_cast< int& >(lenSerialNo));
if ((lenSerialNo <= 0) || (lenSerialNo > _MAX_SERIAL_NUMBER_SIZE))
SysTryReturnResult(NID_SEC_CERT, pFileName != null, E_SYSTEM, "Failed to get attributes.");
int len = strlen(pFileName.get());
SysTryReturnResult(NID_SEC_CERT, pFileName != null, E_SYSTEM, "Failed to get attributes.");
int len = strlen(pFileName.get());
- strncpy(certRecord.fileName, pFileName.get(), len);
+ snprintf(certRecord.fileName, sizeof(certRecord.fileName), "%s", pFileName.get());
+
certRecord.subjectNameLen = lenSubjectName;
memcpy(certRecord.subjectName, subjectNameBuffer, lenSubjectName);
certRecord.subjectNameLen = lenSubjectName;
memcpy(certRecord.subjectName, subjectNameBuffer, lenSubjectName);
SysTryReturnResult(NID_SEC_CERT, pPriKeyFileName != null, E_SYSTEM, "Failed to get attributes.");
len = strlen(pPriKeyFileName.get());
SysTryReturnResult(NID_SEC_CERT, pPriKeyFileName != null, E_SYSTEM, "Failed to get attributes.");
len = strlen(pPriKeyFileName.get());
- strncpy(certRecord.prvKeyPath, pPriKeyFileName.get(), len);
+ snprintf(certRecord.prvKeyPath, sizeof(certRecord.prvKeyPath), "%s", pPriKeyFileName.get());
certRecord.prvKeyLen = privateKeyLen;
certRecord.parentCa = certId;
strcpy(certRecord.installed, installedRecord);
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.");
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.");
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "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.");
}
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.");
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "installed = '%s'", installedRecord);
+ snprintf(condition, sizeof(condition), "installed = '%s'", installedRecord);
}
memset(&userCertRecord, 0, sizeof(userCertRecord));
}
memset(&userCertRecord, 0, sizeof(userCertRecord));
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));
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));
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "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(reinterpret_cast< char* >(issuerNameBase64), reinterpret_cast< char* >(subjectNameBase64)) == 0)
{
}
memset(condition, 0, sizeof(condition));
}
memset(condition, 0, sizeof(condition));
- snprintf(condition, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "installed = '%s'", installedRecord);
+ snprintf(condition, sizeof(condition), "installed = '%s'", installedRecord);
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.");
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.");
- snprintf(conditonRecord, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "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));
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);
{
memset(&caCertRecord, 0, sizeof(caCertRecord));
memset(conditonRecord, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE);
- snprintf(conditonRecord, (_MAX_ISSUER_SUBJECT_NAME_SIZE + _MAX_SUBJECT_OFFSET_SIZE), "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));
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, };
char installedRecord[_MAX_TYPE_RECORD_SIZE] = "T\0";
char condition[_MAX_TYPE_CONST_SIZE] = {0, };
- snprintf(condition, _MAX_TYPE_CONST_SIZE, "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));
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.");
*ppUserCertInfo = null;
SysTryReturnResult(NID_SEC_CERT, certId > 0, E_INVALID_ARG, "Invalid input parameter.");
- snprintf(condition, _MAX_TYPE_CONST_SIZE, "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));
r = __userCertDbStore.GetFirstRecordByConditions(reinterpret_cast< byte* >(condition), &certRecord);
SysTryReturn(NID_SEC_CERT, !IsFailed(r), r, r, "[%s] Failed to get certificates record.", GetErrorMessage(r));
SysTryReturnResult(NID_SEC_CERT, hCert != null, E_INVALID_ARG, "Invalid input parameter.");
SysTryReturnResult(NID_SEC_CERT, hCert != null, E_INVALID_ARG, "Invalid input parameter.");
- snprintf(temp, _MAX_CERT_EXT_PATH_SIZE, "%03d", hCert);
+ snprintf(temp, sizeof(temp), "%03d", hCert);
tempStr.Append(temp);
switch (pathType)
tempStr.Append(temp);
switch (pathType)
int len = strlen(pSigAlg);
if (len <= _MAX_CERT_ALGORITHM_SIZE)
{
int len = strlen(pSigAlg);
if (len <= _MAX_CERT_ALGORITHM_SIZE)
{
- strncpy(pCertInfo->sigAlgorithm, pSigAlg, len);
+ snprintf(pCertInfo->sigAlgorithm, sizeof(pCertInfo->sigAlgorithm), "%s", pSigAlg);
memset(pCertInfo->subjectName, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
if (subLen <= _MAX_ISSUER_SUBJECT_NAME_SIZE + 1)
{
memset(pCertInfo->subjectName, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
if (subLen <= _MAX_ISSUER_SUBJECT_NAME_SIZE + 1)
{
- strncpy(pCertInfo->subjectName, reinterpret_cast< const char* >(pSubjectName), subLen);
+ snprintf(pCertInfo->subjectName, sizeof(pCertInfo->subjectName), "%s", reinterpret_cast< const char* >(pSubjectName));
}
ParseCertTitle(reinterpret_cast< char* >(pSubjectName), pCertInfo->certTitle);
ClearLastResult();
}
ParseCertTitle(reinterpret_cast< char* >(pSubjectName), pCertInfo->certTitle);
ClearLastResult();
memset(pCertInfo->issuerName, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
if (issuerLen <= _MAX_ISSUER_SUBJECT_NAME_SIZE + 1)
{
memset(pCertInfo->issuerName, 0, _MAX_ISSUER_SUBJECT_NAME_SIZE + 1);
if (issuerLen <= _MAX_ISSUER_SUBJECT_NAME_SIZE + 1)
{
- strncpy(pCertInfo->issuerName, reinterpret_cast< const char* >(pIssuerName), issuerLen);
+ snprintf(pCertInfo->issuerName, sizeof(pCertInfo->issuerName), "%s", reinterpret_cast< const char* >(pIssuerName));
}
ParseCertTitle(reinterpret_cast< char* >(pIssuerName), pCertInfo->certSubTitle);
ClearLastResult();
}
ParseCertTitle(reinterpret_cast< char* >(pIssuerName), pCertInfo->certSubTitle);
ClearLastResult();
SysTryReturnResult(NID_SEC_CERT, lenSubjectName > 0, E_SYSTEM, "Subject length is not valid.");
SysTryReturnResult(NID_SEC_CERT, lenIssuerName > 0, E_SYSTEM, "Issuer length is not valid.");
SysTryReturnResult(NID_SEC_CERT, lenSubjectName > 0, E_SYSTEM, "Subject length is not valid.");
SysTryReturnResult(NID_SEC_CERT, lenIssuerName > 0, E_SYSTEM, "Issuer length is not valid.");
- strncpy(subjectName, reinterpret_cast< const char* >(pTbsCert->GetSubjectName()), lenSubjectName);
- strncpy(issuerName, reinterpret_cast< const char* >(pTbsCert->GetIssuerName()), lenIssuerName);
+ snprintf(subjectName, sizeof(subjectName), "%s", reinterpret_cast< const char* >(pTbsCert->GetSubjectName()));
+ snprintf(issuerName, sizeof(issuerName), "%s", reinterpret_cast< const char* >(pTbsCert->GetIssuerName()));
pCertDb = _CertDbManager::GetInstance();
SysTryReturnResult(NID_SEC_CERT, pCertDb != null, E_SYSTEM, "Failed to get instance of certificate database manager.");
pCertDb = _CertDbManager::GetInstance();
SysTryReturnResult(NID_SEC_CERT, pCertDb != null, E_SYSTEM, "Failed to get instance of certificate database manager.");
char* pSubStr = null;
char tempSubject[_MAX_ISSUER_SUBJECT_NAME_SIZE + 1] = {0, };
char* pSubStr = null;
char tempSubject[_MAX_ISSUER_SUBJECT_NAME_SIZE + 1] = {0, };
- strncpy(tempSubject, subject, strlen(subject + 1));
+ snprintf(tempSubject, sizeof(tempSubject), "%s", subject);
pPivotPtr = tempSubject;
for (;; pSubStr = null)
{
pPivotPtr = tempSubject;
for (;; pSubStr = null)
{
- snprintf(condition, _MAX_TYPE_CONST_SIZE, "installed = '%s'", installedRecord);
+ snprintf(condition, sizeof(condition), "installed = '%s'", installedRecord);
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.");
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.");
SysTryReturn(NID_SEC_CERT, type > _CERT_TYPE_NOT_BOUNDED, certificateStoreCtx, E_INVALID_ARG, "[E_INVALID_ARG] Invalid certificate type.");
SysTryReturn(NID_SEC_CERT, type < _CERT_TYPE_MAX, certificateStoreCtx, E_INVALID_ARG, "[E_INVALID_ARG] Invalid certificate type.");
SysTryReturn(NID_SEC_CERT, type > _CERT_TYPE_NOT_BOUNDED, certificateStoreCtx, E_INVALID_ARG, "[E_INVALID_ARG] Invalid certificate type.");
SysTryReturn(NID_SEC_CERT, type < _CERT_TYPE_MAX, certificateStoreCtx, E_INVALID_ARG, "[E_INVALID_ARG] Invalid certificate type.");
- snprintf(condition, _MAX_TYPE_CONST_SIZE, "certType = %d and installed = '%s'", static_cast< int >(type), installedRecord);
+ snprintf(condition, sizeof(condition), "certType = %d and installed = '%s'", static_cast< int >(type), installedRecord);
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.");
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.");
- snprintf(condition, _MAX_TYPE_CONST_SIZE, "certType = %d and installed = '%s'", _CERT_TYPE_ROOT_CA, installedRecord);
+ snprintf(condition, sizeof(condition), "certType = %d and installed = '%s'", _CERT_TYPE_ROOT_CA, installedRecord);
std::unique_ptr< _CaCertDbStore > pCaCertDbStore(new (std::nothrow) _CaCertDbStore());
SysTryReturnResult(NID_SEC_CERT, pCaCertDbStore != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");
std::unique_ptr< _CaCertDbStore > pCaCertDbStore(new (std::nothrow) _CaCertDbStore());
SysTryReturnResult(NID_SEC_CERT, pCaCertDbStore != null, E_OUT_OF_MEMORY, "Failed to allocate memory.");