1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CERT_MANAGER_STATUS_H 17 #define CERT_MANAGER_STATUS_H 18 19 #include "cert_manager_mem.h" 20 21 #include "rbtree.h" 22 23 #include "cm_type.h" 24 25 #define CERT_STATUS_ENANLED ((uint32_t) 0) 26 #define CERT_STATUS_DISABLED ((uint32_t) 1) 27 #define CERT_STATUS_MAX CERT_STATUS_DISABLED 28 #define CERT_STATUS_INVALID ((uint32_t)(CERT_STATUS_MAX + 1)) 29 30 // integrity protection key for internal use only. 31 #define CM_INTEGRITY_KEY_URI "oh:o=ik;t=mk;a=cm" 32 #define CM_INTEGRITY_TAG_LEN ((uint32_t) 32) 33 #define CM_INTEGRITY_SALT_LEN ((uint32_t) 32) 34 #define VERSION_1 ((uint32_t) 0) 35 #define VERSION_1 ((uint32_t) 0) 36 37 #define CERT_STATUS_ENABLED ((uint32_t) 0) 38 #define CERT_STATUS_DISABLED ((uint32_t) 1) 39 40 #define DECODE_UINT32(_b) (uint32_t)(((_b)[0] << 24) | ((_b)[1] << 16) | ((_b)[2] << 8) | (_b)[3]) 41 #define ENCODE_UINT32(_b, _i) do { (_b)[0] = ((_i) >> 24) & 0xff; (_b)[1] = ((_i) >> 16) & 0xff; \ 42 (_b)[2] = ((_i) >> 8) & 0xff; (_b)[3] = (_i) & 0xff; } while (0) 43 44 #define CERT_STATUS_DIR "/data/service/el1/public/cert_manager_service/status" 45 #define CERT_STATUS_SYSTEM_STORE "system" 46 #define CERT_STATUS_USER_STORE "user" 47 #define CERT_STATUS_APPLICATION_STORE "app" 48 49 #define CM_ERROR(rc) (int32_t) (rc) 50 51 #define ASSERT_ARGS(c) if (!(c)) { CM_LOG_W("Invalid args: %s\n", #c); return CMR_ERROR_INVALID_ARGUMENT; } 52 #define ASSERT_FUNC(f) if (CMR_OK != (f)) { CM_LOG_W("Failed: %s\n", #f); return CMR_ERROR; } 53 54 #define ASSERT_CM_CALL(f) do {int32_t _rc = (f); if ((_rc) != CM_SUCCESS) { return CM_ERROR((_rc)); }} while (0) 55 56 #define TRY_FUNC(f, rc) do { \ 57 (rc) = (f); if ((rc)) { CM_LOG_W("Failed: %s, %d\n", #f, (rc)); goto finally; }} while (0) 58 59 #define FREE_PTR(p) if ((p) != NULL) { CMFree((p)); (p) = NULL; } 60 61 #define CM_BLOB(b) (struct CmBlob) { .size = (b)->size, .data = (uint8_t *) (b)->data } 62 63 #define HKS_BLOB(b) (struct HksBlob) { .size = (b)->size, .data = (uint8_t *) (b)->data } 64 65 #define TRY_HKS_CALL(f, rc) do {int32_t _rc = (f); if ((_rc) != HKS_SUCCESS) { \ 66 CM_LOG_W("Failed: %s, %d\n", #f, (_rc)); (rc) = CM_ERROR((_rc)); goto finally; }} while (0) 67 68 typedef int (*RbTreeValueEncoder)(RbTreeValue value, uint8_t *buf, uint32_t *size); 69 70 #ifdef __cplusplus 71 extern "C" { 72 #endif 73 74 struct CertStatus { 75 uint32_t userId; 76 uint32_t uid; 77 uint32_t status; 78 char *fileName; 79 }; 80 81 int32_t CertManagerStatusInit(void); 82 83 int32_t SetcertStatus(const struct CmContext *context, const struct CmBlob *certUri, 84 uint32_t store, uint32_t status, uint32_t *stp); 85 86 int32_t CmSetStatusEnable(const struct CmContext *context, struct CmMutableBlob *pathBlob, 87 const struct CmBlob *certUri, uint32_t store); 88 89 int32_t CmGetCertStatus(const struct CmContext *context, struct CertFileInfo *cFile, 90 uint32_t store, uint32_t *status); 91 92 #ifdef __cplusplus 93 } 94 #endif 95 96 #endif // CERT_MANAGER_STATUS_H