1 /* 2 * Copyright (c) 2023-2024 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 const std::string CERT_TAG_CERT_MATCH_PARAMS = "certMatchParameters"; 43 const std::string CERT_TAG_MAX_LENGTH = "maxLength"; 44 const std::string CERT_TAG_VALIDATE_PARAMS = "validationParameters"; 45 const std::string CERT_TAG_KEYSTORE = "keystore"; 46 47 enum ResultCode { 48 JS_SUCCESS = 0, 49 JS_ERR_CERT_INVALID_PARAMS = 401, 50 JS_ERR_CERT_NOT_SUPPORT = 801, 51 JS_ERR_CERT_OUT_OF_MEMORY = 19020001, 52 JS_ERR_CERT_RUNTIME_ERROR = 19020002, 53 JS_ERR_CERT_CRYPTO_OPERATION = 19030001, 54 JS_ERR_CERT_SIGNATURE_FAILURE = 19030002, 55 JS_ERR_CERT_NOT_YET_VALID = 19030003, 56 JS_ERR_CERT_HAS_EXPIRED = 19030004, 57 JS_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY = 19030005, 58 JS_ERR_KEYUSAGE_NO_CERTSIGN = 19030006, 59 JS_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE = 19030007 60 }; 61 62 enum AsyncType { ASYNC_TYPE_CALLBACK = 1, ASYNC_TYPE_PROMISE = 2 }; 63 // X509 CERT MATCH PARAMETERS 64 const std::string CERT_MATCH_TAG_SUBJECT_ALT_NAMES_TYPE = "type"; 65 const std::string CERT_MATCH_TAG_SUBJECT_ALT_NAMES_DATA = "name"; 66 const std::string CERT_MATCH_TAG_SUBJECT_ALT_NAMES = "subjectAlternativeNames"; 67 const std::string CERT_MATCH_TAG_MATCH_ALL_SUBJECT = "matchAllSubjectAltNames"; 68 const std::string CERT_MATCH_TAG_AUTH_KEY_ID = "authorityKeyIdentifier"; 69 const std::string CERT_MATCH_TAG_MIN_PATH_LEN = "minPathLenConstraint"; 70 const std::string CERT_MATCH_TAG_X509CERT = "x509Cert"; 71 const std::string CERT_MATCH_TAG_VALID_DATE = "validDate"; 72 const std::string CERT_MATCH_TAG_ISSUER = "issuer"; 73 const std::string CERT_MATCH_TAG_EXTENDED_KEY_USAGE = "extendedKeyUsage"; 74 const std::string CERT_MATCH_TAG_KEY_USAGE = "keyUsage"; 75 const std::string CERT_MATCH_TAG_NAME_CONSTRAINTS = "nameConstraints"; 76 const std::string CERT_MATCH_TAG_CERT_POLICY = "certPolicy"; 77 const std::string CERT_MATCH_TAG_PRIVATE_KEY_VALID = "privateKeyValid"; 78 const std::string CERT_MATCH_TAG_SERIAL_NUMBER = "serialNumber"; 79 const std::string CERT_MATCH_TAG_SUBJECT = "subject"; 80 const std::string CERT_MATCH_TAG_SUBJECT_KEY_IDENTIFIER = "subjectKeyIdentifier"; 81 const std::string CERT_MATCH_TAG_PUBLIC_KEY = "publicKey"; 82 const std::string CERT_MATCH_TAG_PUBLIC_KEY_ALGID = "publicKeyAlgID"; 83 84 // X509 CRL MATCH PARAMETERS 85 const std::string CRL_MATCH_TAG_PRIVATE_KEY_VALID = "issuer"; 86 const std::string CRL_MATCH_TAG_X509CERT = "x509Cert"; 87 const std::string CRL_MATCH_TAG_UPDATE_DATE_TIME = "updateDateTime"; 88 const std::string CRL_MATCH_TAG_MAXCRL = "maxCRL"; 89 const std::string CRL_MATCH_TAG_MINCRL = "minCRL"; 90 91 // X509 CERT CHAIN VALIDATE 92 // X509TrustAnchor 93 const std::string CERT_CHAIN_TRUSTANCHOR_TAG_CACERT = "CACert"; 94 const std::string CERT_CHAIN_TRUSTANCHOR_TAG_CAPUBKEY = "CAPubKey"; 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 const std::string CERT_CHAIN_VALIDATE_TAG_REVOCATIONCHECKPARAM = "revocationCheckParam"; 101 const std::string CERT_CHAIN_VALIDATE_TAG_OCSP_REQ_EXTENSION = "ocspRequestExtension"; 102 const std::string CERT_CHAIN_VALIDATE_TAG_OCSP_RESP_URI = "ocspResponderURI"; 103 const std::string CERT_CHAIN_VALIDATE_TAG_OCSP_RESP_CERT = "ocspResponderCert"; 104 const std::string CERT_CHAIN_VALIDATE_TAG_OCSP_RESPS = "ocspResponses"; 105 const std::string CERT_CHAIN_VALIDATE_TAG_CRL_DOWNLOAD_URI = "crlDownloadURI"; 106 const std::string CERT_CHAIN_VALIDATE_TAG_OPTIONS = "options"; 107 const std::string CERT_CHAIN_VALIDATE_TAG_OCSP_DIGEST = "ocspDigest"; 108 const std::string CERT_CHAIN_VALIDATE_TAG_POLICY = "policy"; 109 const std::string CERT_CHAIN_VALIDATE_TAG_SSLHOSTNAME = "sslHostname"; 110 const std::string CERT_CHAIN_VALIDATE_TAG_KEYUSAGE = "keyUsage"; 111 // CertChainValidateResult 112 const std::string CERT_CHAIN_VALIDATE_RESULLT_TAG_TRUSTANCHOR = "trustAnchor"; 113 const std::string CERT_CHAIN_VALIDATE_RESULLT_TAG_X509CERT = "entityCert"; 114 115 const std::string CERT_CHAIN_BUILD_RESULLT_TAG_CERTCHAIN = "certChain"; 116 const std::string CERT_CHAIN_BUILD_RESULLT_TAG_VALIDATERESULT = "validationResult"; 117 118 } // namespace CertFramework 119 } // namespace OHOS 120 121 #endif // NAPI_CERT_DEFINES_H 122