0to100All

Signed-off-by: ivans <shangguanjingwei@huawei.com>
This commit is contained in:
ivans 2024-08-29 20:24:38 +08:00 committed by 上官景威
parent 7413e0382f
commit a5d53125a2
6 changed files with 195 additions and 15 deletions

View File

@ -46,6 +46,8 @@ int32_t CmServiceInstallUserCertCheck(struct CmContext *cmContext, const struct
int32_t CmServiceUninstallUserCertCheck(struct CmContext *cmContext, const struct CmBlob *certUri);
int32_t CmServiceGetUserCertInfoCheck(struct CmContext *cmContext, const struct CmBlob *uri,
const uint32_t type, bool isCheckUid);
#ifdef __cplusplus
}
#endif

View File

@ -53,7 +53,7 @@ int32_t CmServiceAbort(const struct CmContext *context, const struct CmBlob *han
int32_t CmServiceGetCertList(const struct CmContext *context, uint32_t store, struct CmMutableBlob *certFileList);
int32_t CmServiceGetCertInfo(const struct CmContext *context, const struct CmBlob *certUri,
int32_t CmServiceGetCertInfo(struct CmContext *context, const struct CmBlob *certUri,
uint32_t store, struct CmBlob *certificateData, uint32_t *status);
int32_t CmX509ToPEM(const X509 *x509, struct CmBlob *userCertPem);

View File

@ -252,7 +252,7 @@ int32_t CmServiceInstallAppCertCheck(const struct CmAppCertParam *certParam, str
return CM_SUCCESS;
}
static int32_t checkCallerAndUri(struct CmContext *cmContext, const struct CmBlob *uri,
static int32_t CheckAndUpdateCallerAndUri(struct CmContext *cmContext, const struct CmBlob *uri,
const uint32_t type, bool isCheckUid)
{
struct CMUri uriObj;
@ -286,6 +286,23 @@ static int32_t checkCallerAndUri(struct CmContext *cmContext, const struct CmBlo
return CM_SUCCESS;
}
/* check context and uri and update it */
int32_t CmServiceGetUserCertInfoCheck(struct CmContext *cmContext, const struct CmBlob *uri,
const uint32_t type, bool isCheckUid)
{
if (cmContext == NULL) {
CM_LOG_E("CmServiceGetCertInfoCheck: Context is NULL");
return CMR_ERROR_INVALID_ARGUMENT;
}
if (CheckUri(uri) != CM_SUCCESS) {
CM_LOG_E("invalid input arguments");
return CMR_ERROR_INVALID_ARGUMENT;
}
return CheckAndUpdateCallerAndUri(cmContext, uri, type, isCheckUid);
}
int32_t CmServiceUninstallAppCertCheck(struct CmContext *cmContext,
const uint32_t store, const struct CmBlob *keyUri)
{
@ -310,7 +327,7 @@ int32_t CmServiceUninstallAppCertCheck(struct CmContext *cmContext,
}
if (store == CM_SYS_CREDENTIAL_STORE) {
return checkCallerAndUri(cmContext, keyUri, CM_URI_TYPE_SYS_KEY, true);
return CheckAndUpdateCallerAndUri(cmContext, keyUri, CM_URI_TYPE_SYS_KEY, true);
}
return CM_SUCCESS;
@ -410,7 +427,7 @@ int32_t CmServiceGetAppCertCheck(struct CmContext *cmContext, const uint32_t sto
}
if (store == CM_SYS_CREDENTIAL_STORE) {
int32_t ret = checkCallerAndUri(cmContext, keyUri, CM_URI_TYPE_SYS_KEY, false);
int32_t ret = CheckAndUpdateCallerAndUri(cmContext, keyUri, CM_URI_TYPE_SYS_KEY, false);
if (ret != CM_SUCCESS) {
CM_LOG_E("get type and userid from uri error");
return ret;
@ -506,7 +523,7 @@ int32_t CmServiceUninstallUserCertCheck(struct CmContext *cmContext, const struc
return CMR_ERROR_NOT_SYSTEMP_APP;
}
int32_t ret = checkCallerAndUri(cmContext, certUri, CM_URI_TYPE_CERTIFICATE, true);
int32_t ret = CheckAndUpdateCallerAndUri(cmContext, certUri, CM_URI_TYPE_CERTIFICATE, true);
if (ret != CM_SUCCESS) {
CM_LOG_E("uninstall user cert: caller and uri check fail");
return ret;

View File

@ -41,6 +41,7 @@
#include "cert_manager_file_operator.h"
#include "cert_manager_updateflag.h"
#define MAX_PATH_LEN 256
static int32_t CheckPermission(bool needPriPermission, bool needCommonPermission)
{
@ -462,14 +463,9 @@ int32_t CmServiceGetCertList(const struct CmContext *context, uint32_t store, st
return ret;
}
int32_t CmServiceGetCertInfo(const struct CmContext *context, const struct CmBlob *certUri,
static int32_t CmServiceGetSysCertInfo(const struct CmContext *context, const struct CmBlob *certUri,
uint32_t store, struct CmBlob *certificateData, uint32_t *status)
{
if (CmCheckBlob(certUri) != CM_SUCCESS || CheckUri(certUri) != CM_SUCCESS) {
CM_LOG_E("input params invalid");
return CMR_ERROR_INVALID_ARGUMENT;
}
int32_t ret = CM_SUCCESS;
struct CmMutableBlob certFileList = { 0, NULL };
do {
@ -490,15 +486,13 @@ int32_t CmServiceGetCertInfo(const struct CmContext *context, const struct CmBlo
ret = CmGetCertStatus(context, &cFileList[matchIndex], store, status); /* status */
if (ret != CM_SUCCESS) {
CM_LOG_E("Failed to get cert status");
ret = CM_FAILURE;
break;
}
ret = CmStorageGetBuf((char *)cFileList[matchIndex].path.data,
(char *)cFileList[matchIndex].fileName.data, certificateData); /* cert data */
(char *)cFileList[matchIndex].fileName.data, certificateData); /* cert data */
if (ret != CM_SUCCESS) {
CM_LOG_E("Failed to get cert data");
ret = CM_FAILURE;
break;
}
} while (0);
@ -509,6 +503,67 @@ int32_t CmServiceGetCertInfo(const struct CmContext *context, const struct CmBlo
return ret;
}
static int32_t CmServiceGetUserCertInfo(struct CmContext *context, const struct CmBlob *certUri,
uint32_t store, struct CmBlob *certificateData, uint32_t *status)
{
int32_t ret = CM_SUCCESS;
char uidPath[MAX_PATH_LEN] = { 0 };
ret = CmServiceGetUserCertInfoCheck(context, certUri, CM_URI_TYPE_CERTIFICATE, false);
if (ret != CM_SUCCESS) {
CM_LOG_E("Failed to check caller and uri");
return ret;
}
ret = ConstructUidPath(context, store, uidPath, MAX_PATH_LEN);
if (ret != CM_SUCCESS) {
CM_LOG_E("Failed to construct uidpath");
return ret;
}
struct CmBlob path = {MAX_PATH_LEN, (uint8_t *)uidPath};
struct CertFileInfo cFile = {*certUri, path};
ret = CmGetCertStatus(context, &cFile, store, status); /* status */
if (ret != CM_SUCCESS) {
CM_LOG_E("Failed to get cert status");
return ret;
}
ret = CmStorageGetBuf(uidPath, (char *)cFile.fileName.data, certificateData); /* cert data */
if (ret != CM_SUCCESS) {
CM_LOG_E("Failed to get cert data");
return ret;
}
return ret;
}
int32_t CmServiceGetCertInfo(struct CmContext *context, const struct CmBlob *certUri,
uint32_t store, struct CmBlob *certificateData, uint32_t *status)
{
if (CmCheckBlob(certUri) != CM_SUCCESS || CheckUri(certUri) != CM_SUCCESS) {
CM_LOG_E("input params invalid");
return CMR_ERROR_INVALID_ARGUMENT;
}
int32_t ret = CM_SUCCESS;
if (store == CM_SYSTEM_TRUSTED_STORE) {
ret = CmServiceGetSysCertInfo(context, certUri, store, certificateData, status);
if (ret != CM_SUCCESS) {
CM_LOG_E("Failed to get system cert info");
return ret;
}
} else if (store == CM_USER_TRUSTED_STORE) {
ret = CmServiceGetUserCertInfo(context, certUri, store, certificateData, status);
if (ret != CM_SUCCESS) {
CM_LOG_E("Failed to get user cert info");
return ret;
}
} else {
CM_LOG_E("Invalid store");
ret = CM_FAILURE;
}
return ret;
}
int32_t CmX509ToPEM(const X509 *x509, struct CmBlob *userCertPem)
{
int32_t ret = CM_SUCCESS;

View File

@ -306,6 +306,61 @@ static const uint8_t g_certData05[] = { /* 2e0g9ue5 */
0x59, 0xae, 0x6b, 0x04, 0x1b
};
static const uint8_t g_certData07[] { /*882de061*/
0x30, 0x82, 0x03, 0x38, 0x30, 0x82, 0x02, 0x20, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x06, 0x20,
0x06, 0x05, 0x16, 0x70, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
0x02, 0x52, 0x4f, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x63, 0x65,
0x72, 0x74, 0x53, 0x49, 0x47, 0x4e, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13,
0x10, 0x63, 0x65, 0x72, 0x74, 0x53, 0x49, 0x47, 0x4e, 0x20, 0x52, 0x4f, 0x4f, 0x54, 0x20, 0x43,
0x41, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x36, 0x30, 0x37, 0x30, 0x34, 0x31, 0x37, 0x32, 0x30, 0x30,
0x34, 0x5a, 0x17, 0x0d, 0x33, 0x31, 0x30, 0x37, 0x30, 0x34, 0x31, 0x37, 0x32, 0x30, 0x30, 0x34,
0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x52, 0x4f,
0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x63, 0x65, 0x72, 0x74, 0x53,
0x49, 0x47, 0x4e, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x10, 0x63, 0x65,
0x72, 0x74, 0x53, 0x49, 0x47, 0x4e, 0x20, 0x52, 0x4f, 0x4f, 0x54, 0x20, 0x43, 0x41, 0x30, 0x82,
0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,
0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb7,
0x33, 0xb9, 0x7e, 0xc8, 0x25, 0x4a, 0x8e, 0xb5, 0xdb, 0xb4, 0x28, 0x1b, 0xaa, 0x57, 0x90, 0xe8,
0xd1, 0x22, 0xd3, 0x64, 0xba, 0xd3, 0x93, 0xe8, 0xd4, 0xac, 0x86, 0x61, 0x40, 0x6a, 0x60, 0x57,
0x68, 0x54, 0x84, 0x4d, 0xbc, 0x6a, 0x54, 0x02, 0x05, 0xff, 0xdf, 0x9b, 0x9a, 0x2a, 0xae, 0x5d,
0x07, 0x8f, 0x4a, 0xc3, 0x28, 0x7f, 0xef, 0xfb, 0x2b, 0xfa, 0x79, 0xf1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98, 0xa1, 0xc9, 0x51, 0x2f, 0xd7, 0xde, 0xac, 0x33, 0xb3, 0x4f, 0x02,
0x03, 0x01, 0x00, 0x01, 0xa3, 0x42, 0x30, 0x40, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01,
0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f,
0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0xc6, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e,
0x04, 0x16, 0x04, 0x14, 0xe0, 0x8c, 0x9b, 0xdb, 0x25, 0x49, 0xb3, 0xf1, 0x7c, 0x86, 0xd6, 0xb2,
0x42, 0x87, 0x0b, 0xd0, 0x6b, 0xa0, 0xd9, 0xe4, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x3e, 0xd2, 0x1c, 0x89,
0x2e, 0x35, 0xfc, 0xf8, 0x75, 0xdd, 0xe6, 0x7f, 0x65, 0x88, 0xf4, 0x72, 0x4c, 0xc9, 0x2c, 0xd7,
0x32, 0x4e, 0xf3, 0xdd, 0x19, 0x79, 0x47, 0xbd, 0x8e, 0x3b, 0x5b, 0x93, 0x0f, 0x50, 0x49, 0x24,
0x13, 0x6b, 0x14, 0x06, 0x72, 0xef, 0x09, 0xd3, 0xa1, 0xa1, 0xe3, 0x40, 0x84, 0xc9, 0xe7, 0x18,
0x32, 0x74, 0x3c, 0x48, 0x6e, 0x0f, 0x9f, 0x4b, 0xd4, 0xf7, 0x1e, 0xd3, 0x93, 0x86, 0x64, 0x54,
0x97, 0x63, 0x72, 0x50, 0xd5, 0x55, 0xcf, 0xfa, 0x20, 0x93, 0x02, 0xa2, 0x9b, 0xc3, 0x23, 0x93,
0x4e, 0x16, 0x55, 0x76, 0xa0, 0x70, 0x79, 0x6d, 0xcd, 0x21, 0x1f, 0xcf, 0x2f, 0x2d, 0xbc, 0x19,
0xe3, 0x88, 0x31, 0xf8, 0x59, 0x1a, 0x81, 0x09, 0xc8, 0x97, 0xa6, 0x74, 0xc7, 0x60, 0xc4, 0x5b,
0xcc, 0x57, 0x8e, 0xb2, 0x75, 0xfd, 0x1b, 0x02, 0x09, 0xdb, 0x59, 0x6f, 0x72, 0x93, 0x69, 0xf7,
0x31, 0x41, 0xd6, 0x88, 0x38, 0xbf, 0x87, 0xb2, 0xbd, 0x16, 0x79, 0xf9, 0xaa, 0xe4, 0xbe, 0x88,
0x25, 0xdd, 0x61, 0x27, 0x23, 0x1c, 0xb5, 0x31, 0x07, 0x04, 0x36, 0xb4, 0x1a, 0x90, 0xbd, 0xa0,
0x74, 0x71, 0x50, 0x89, 0x6d, 0xbc, 0x14, 0xe3, 0x0f, 0x86, 0xae, 0xf1, 0xab, 0x3e, 0xc7, 0xa0,
0x09, 0xcc, 0xa3, 0x48, 0xd1, 0xe0, 0xdb, 0x64, 0xe7, 0x92, 0xb5, 0xcf, 0xaf, 0x72, 0x43, 0x70,
0x8b, 0xf9, 0xc3, 0x84, 0x3c, 0x13, 0xaa, 0x7e, 0x92, 0x9b, 0x57, 0x53, 0x93, 0xfa, 0x70, 0xc2,
0x91, 0x0e, 0x31, 0xf9, 0x9b, 0x67, 0x5d, 0xe9, 0x96, 0x38, 0x5e, 0x5f, 0xb3, 0x73, 0x4e, 0x88,
0x15, 0x67, 0xde, 0x9e, 0x76, 0x10, 0x62, 0x20, 0xbe, 0x55, 0x69, 0x95, 0x43, 0x00, 0x39, 0x4d,
0xf6, 0xee, 0xb0, 0x5a, 0x4e, 0x49, 0x44, 0x54, 0x58, 0x5f, 0x42, 0x83
};
static char g_certData06[] =
"-----BEGIN CERTIFICATE-----\r\n"
"MIID6jCCAtKgAwIBAgIIIM2q/TmRoLcwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UE\r\n"
@ -330,5 +385,5 @@ static char g_certData06[] =
"DnYaJOgPt0B/5izhoWNK7GhJDy9KEuLURcTSWFysbbnljwO9INPT9MmlS83PdAgN\r\n"
"iS8VXF4pce1W9U5jH7d7k0JDVSXybebe1iPFphsZpYM/NE+jap+mPy1nTCbf9g==\r\n"
"-----END CERTIFICATE-----\r\n";
#endif /* CM_CERT_DATA_USER_H */

View File

@ -141,6 +141,24 @@ struct UserCertInfoResult g_certInfoExpectResult[] = {
}
};
struct UserCertInfoResult g_userCertInfoExpectResult[] = {
{
{
"oh:t=c;o=882de061;u=100;a=0",
"882de061",
true,
"CN=,OU=certSIGN ROOT CA,O=certSIGN",
"CN=,OU=certSIGN ROOT CA,O=certSIGN",
"200605167002",
"2006-7-5",
"2031-7-5",
"EA:A9:62:C4:FA:4A:6B:AF:EB:E4:15:19:6D:35:1C:CD:88:8D:4F:53:F3:FA:8A:E6:D7:C4:66:A9:4E:60:42:BB",
{ sizeof(g_certData07), const_cast<uint8_t *>(g_certData07) }
},
true
}
};
struct UserCertStatusExpectResult {
char uri[MAX_URI_LEN];
bool inparamStatus;
@ -1222,6 +1240,39 @@ HWTEST_F(CmUserCertTest, GetUserCertInfoTest006, TestSize.Level0)
}
}
/**
* @tc.name: GetUserCertInfoTest007
* @tc.desc: Test SA Get user cert info interface performance
* @tc.type: FUNC
* @tc.require: AR000H0MJ8 /SR000H09N7
*/
HWTEST_F(CmUserCertTest, GetUserCertInfoTest007, TestSize.Level0)
{
int32_t ret;
uint8_t aliasBuf013[] = "882de061";
uint8_t uriBuf027[MAX_URI_LEN] = {0};
struct CmBlob testUserCert = { sizeof(g_certData07), const_cast<uint8_t *>(g_certData07) };
struct CmBlob testCertAlias = { sizeof(aliasBuf013), aliasBuf013 };
struct CmBlob testCertUri = { sizeof(uriBuf027), uriBuf027};
ret = CmInstallUserCACert(&testUserCert, &testCertAlias, TEST_USERID, true, &testCertUri);
EXPECT_EQ(ret, CM_SUCCESS) << "normal install user ca cert test failed, recode:" << ret;
struct CertInfo *certInfo008 = nullptr;
InitUserCertInfo(&certInfo008);
ret = CmGetUserCertInfo(&testCertUri, CM_USER_TRUSTED_STORE, certInfo008);
EXPECT_EQ(CompareCertInfo(certInfo008, &(g_userCertInfoExpectResult[0].certInfo)), true) <<
DumpCertInfo(certInfo008);
EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user cert info test failed, recode:" << ret;
EXPECT_EQ(CompareCertData(&(certInfo008->certInfo), &(g_userCertInfoExpectResult[0].certInfo.certInfo)), true);
FreeCertInfo(certInfo008);
ret = CmUninstallUserTrustedCert(&testCertUri);
EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall test failed, recode:" << ret;
}
/**
* @tc.name: SetUserCertStatusTest001
* @tc.desc: Test CertManager Set user cert status interface base function