1 /* 2 * Copyright (c) 2023 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 NAPI_CERT_DEFINES_H 17 #define NAPI_CERT_DEFINES_H 18 19 #include <cstdint> 20 #include <string> 21 22 namespace OHOS { 23 namespace CertFramework { 24 constexpr size_t ARGS_SIZE_ONE = 1; 25 constexpr size_t ARGS_SIZE_TWO = 2; 26 constexpr size_t ARGS_SIZE_THREE = 3; 27 constexpr size_t ARGS_SIZE_FOUR = 4; 28 constexpr int32_t PARAM0 = 0; 29 constexpr int32_t PARAM1 = 1; 30 constexpr int32_t PARAM2 = 2; 31 constexpr uint32_t BYTE_TO_BIT_CNT = 8; 32 constexpr uint32_t QUAD_WORD_ALIGN_UP = 3; 33 constexpr uint32_t MAX_LEN_OF_ARRAY = 1024; 34 35 const std::string CERT_TAG_DATA = "data"; 36 const std::string CERT_TAG_ERR_CODE = "code"; 37 const std::string CERT_TAG_COUNT = "count"; 38 const std::string CERT_TAG_ENCODING_FORMAT = "encodingFormat"; 39 const std::string CERT_TAG_ALGORITHM = "algorithm"; 40 const std::string CRYPTO_TAG_ALG_NAME = "algName"; 41 const std::string CRYPTO_TAG_FORMAT = "format"; 42 43 enum ResultCode { 44 JS_SUCCESS = 0, 45 JS_ERR_CERT_INVALID_PARAMS = 401, 46 JS_ERR_CERT_NOT_SUPPORT = 801, 47 JS_ERR_CERT_OUT_OF_MEMORY = 19020001, 48 JS_ERR_CERT_RUNTIME_ERROR = 19020002, 49 JS_ERR_CERT_CRYPTO_OPERATION = 19030001, 50 JS_ERR_CERT_SIGNATURE_FAILURE = 19030002, 51 JS_ERR_CERT_NOT_YET_VALID = 19030003, 52 JS_ERR_CERT_HAS_EXPIRED = 19030004, 53 JS_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY = 19030005, 54 JS_ERR_KEYUSAGE_NO_CERTSIGN = 19030006, 55 JS_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE = 19030007 56 }; 57 58 enum AsyncType { 59 ASYNC_TYPE_CALLBACK = 1, 60 ASYNC_TYPE_PROMISE = 2 61 }; 62 // X509 CERT MATCH PARAMETERS 63 const std::string CERT_MATCH_TAG_SUBJECT_ALT_NAMES_TYPE = "type"; 64 const std::string CERT_MATCH_TAG_SUBJECT_ALT_NAMES_DATA = "name"; 65 const std::string CERT_MATCH_TAG_SUBJECT_ALT_NAMES = "subjectAlternativeNames"; 66 const std::string CERT_MATCH_TAG_MATCH_ALL_SUBJECT = "matchAllSubjectAltNames"; 67 const std::string CERT_MATCH_TAG_AUTH_KEY_ID = "authorityKeyIdentifier"; 68 const std::string CERT_MATCH_TAG_MIN_PATH_LEN = "minPathLenConstraint"; 69 const std::string CERT_MATCH_TAG_X509CERT = "x509Cert"; 70 const std::string CERT_MATCH_TAG_VALID_DATE = "validDate"; 71 const std::string CERT_MATCH_TAG_ISSUER = "issuer"; 72 const std::string CERT_MATCH_TAG_EXTENDED_KEY_USAGE = "extendedKeyUsage"; 73 const std::string CERT_MATCH_TAG_KEY_USAGE = "keyUsage"; 74 const std::string CERT_MATCH_TAG_NAME_CONSTRAINT = "nameConstraint"; 75 const std::string CERT_MATCH_TAG_CERT_POLICY = "certPolicy"; 76 const std::string CERT_MATCH_TAG_PRIVATE_KEY_VALID = "privateKeyValid"; 77 const std::string CERT_MATCH_TAG_SERIAL_NUMBER = "serialNumber"; 78 const std::string CERT_MATCH_TAG_SUBJECT = "subject"; 79 const std::string CERT_MATCH_TAG_SUBJECT_KEY_IDENTIFIER = "subjectKeyIdentifier"; 80 const std::string CERT_MATCH_TAG_PUBLIC_KEY = "publicKey"; 81 const std::string CERT_MATCH_TAG_PUBLIC_KEY_ALGID = "publicKeyAlgID"; 82 83 // X509 CRL MATCH PARAMETERS 84 const std::string CRL_MATCH_TAG_PRIVATE_KEY_VALID = "issuer"; 85 const std::string CRL_MATCH_TAG_X509CERT = "x509Cert"; 86 const std::string CRL_MATCH_TAG_UPDATE_DATE_TIME = "updateDateTime"; 87 const std::string CRL_MATCH_TAG_MAXCRL = "maxCRL"; 88 const std::string CRL_MATCH_TAG_MINCRL = "minCRL"; 89 90 // X509 CERT CHAIN VALIDATE 91 // X509TrustAnchor 92 const std::string CERT_CHAIN_TRUSTANCHOR_TAG_CACERT = "CACert"; 93 const std::string CERT_CHAIN_TRUSTANCHOR_TAG_CAPUBKEY = "CAPubKey"; 94 // const std::string CERT_CHAIN_TRUSTANCHOR_TAG_NAMECSTRAINTS = "nameConstraints"; 95 const std::string CERT_CHAIN_TRUSTANCHOR_TAG_CASUBJECT = "CASubject"; 96 // CertChainValidateParameters 97 const std::string CERT_CHAIN_VALIDATE_TAG_DATE = "date"; 98 const std::string CERT_CHAIN_VALIDATE_TAG_TRUSTANCHORS = "trustAnchors"; 99 const std::string CERT_CHAIN_VALIDATE_TAG_CERTCRLS = "certCRLs"; 100 // CertChainValidateResult 101 const std::string CERT_CHAIN_VALIDATE_RESULLT_TAG_TRUSTANCHOR = "trustAnchor"; 102 const std::string CERT_CHAIN_VALIDATE_RESULLT_TAG_X509CERT = "entityCert"; 103 104 } // namespace CertFramework 105 } // namespace OHOS 106 107 #endif // NAPI_CERT_DEFINES_H 108