• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     JS_ERR_CERT_INVALID_PRIVATE_KEY = 19030008
61 };
62 
63 enum AsyncType { ASYNC_TYPE_CALLBACK = 1, ASYNC_TYPE_PROMISE = 2 };
64 // X509 CERT MATCH PARAMETERS
65 const std::string CERT_MATCH_TAG_SUBJECT_ALT_NAMES_TYPE = "type";
66 const std::string CERT_MATCH_TAG_SUBJECT_ALT_NAMES_DATA = "name";
67 const std::string CERT_MATCH_TAG_SUBJECT_ALT_NAMES = "subjectAlternativeNames";
68 const std::string CERT_MATCH_TAG_MATCH_ALL_SUBJECT = "matchAllSubjectAltNames";
69 const std::string CERT_MATCH_TAG_AUTH_KEY_ID = "authorityKeyIdentifier";
70 const std::string CERT_MATCH_TAG_MIN_PATH_LEN = "minPathLenConstraint";
71 const std::string CERT_MATCH_TAG_X509CERT = "x509Cert";
72 const std::string CERT_MATCH_TAG_VALID_DATE = "validDate";
73 const std::string CERT_MATCH_TAG_ISSUER = "issuer";
74 const std::string CERT_MATCH_TAG_EXTENDED_KEY_USAGE = "extendedKeyUsage";
75 const std::string CERT_MATCH_TAG_KEY_USAGE = "keyUsage";
76 const std::string CERT_MATCH_TAG_NAME_CONSTRAINTS = "nameConstraints";
77 const std::string CERT_MATCH_TAG_CERT_POLICY = "certPolicy";
78 const std::string CERT_MATCH_TAG_PRIVATE_KEY_VALID = "privateKeyValid";
79 const std::string CERT_MATCH_TAG_SERIAL_NUMBER = "serialNumber";
80 const std::string CERT_MATCH_TAG_SUBJECT = "subject";
81 const std::string CERT_MATCH_TAG_SUBJECT_KEY_IDENTIFIER = "subjectKeyIdentifier";
82 const std::string CERT_MATCH_TAG_PUBLIC_KEY = "publicKey";
83 const std::string CERT_MATCH_TAG_PUBLIC_KEY_ALGID = "publicKeyAlgID";
84 
85 // X509 CRL MATCH PARAMETERS
86 const std::string CRL_MATCH_TAG_PRIVATE_KEY_VALID = "issuer";
87 const std::string CRL_MATCH_TAG_X509CERT = "x509Cert";
88 const std::string CRL_MATCH_TAG_UPDATE_DATE_TIME = "updateDateTime";
89 const std::string CRL_MATCH_TAG_MAXCRL = "maxCRL";
90 const std::string CRL_MATCH_TAG_MINCRL = "minCRL";
91 
92 // X509 CERT CHAIN VALIDATE
93 // X509TrustAnchor
94 const std::string CERT_CHAIN_TRUSTANCHOR_TAG_CERT = "Cert";
95 const std::string CERT_CHAIN_TRUSTANCHOR_TAG_PRIKEY = "CertPriKey";
96 const std::string CERT_CHAIN_TRUSTANCHOR_TAG_CACERT = "CACert";
97 const std::string CERT_CHAIN_TRUSTANCHOR_TAG_CAPUBKEY = "CAPubKey";
98 const std::string CERT_CHAIN_TRUSTANCHOR_TAG_CASUBJECT = "CASubject";
99 // PKCS12 conf
100 const std::string CERT_CHAIN_PKCS12_TAG_PASSWORD = "password";
101 const std::string CERT_CHAIN_PKCS12_TAG_NEEDS_PRIVATE_KEY = "needsPrivateKey";
102 const std::string CERT_CHAIN_PKCS12_TAG_PRIKEY_FORMAT = "privateKeyFormat";
103 const std::string CERT_CHAIN_PKCS12_TAG_NEEDS_CERT = "needsCert";
104 const std::string CERT_CHAIN_PKCS12_TAG_NEEDS_OTHER_CERTS = "needsOtherCerts";
105 // PKCS12 data
106 const std::string CERT_CHAIN_PKCS12_TAG_PRIKEY = "privateKey";
107 const std::string CERT_CHAIN_PKCS12_TAG_CERT = "cert";
108 const std::string CERT_CHAIN_PKCS12_TAG_OTHER_CERTS = "otherCerts";
109 // CertChainValidateParameters
110 const std::string CERT_CHAIN_VALIDATE_TAG_DATE = "date";
111 const std::string CERT_CHAIN_VALIDATE_TAG_TRUSTANCHORS = "trustAnchors";
112 const std::string CERT_CHAIN_VALIDATE_TAG_CERTCRLS = "certCRLs";
113 const std::string CERT_CHAIN_VALIDATE_TAG_REVOCATIONCHECKPARAM = "revocationCheckParam";
114 const std::string CERT_CHAIN_VALIDATE_TAG_OCSP_REQ_EXTENSION = "ocspRequestExtension";
115 const std::string CERT_CHAIN_VALIDATE_TAG_OCSP_RESP_URI = "ocspResponderURI";
116 const std::string CERT_CHAIN_VALIDATE_TAG_OCSP_RESP_CERT = "ocspResponderCert";
117 const std::string CERT_CHAIN_VALIDATE_TAG_OCSP_RESPS = "ocspResponses";
118 const std::string CERT_CHAIN_VALIDATE_TAG_CRL_DOWNLOAD_URI = "crlDownloadURI";
119 const std::string CERT_CHAIN_VALIDATE_TAG_OPTIONS = "options";
120 const std::string CERT_CHAIN_VALIDATE_TAG_OCSP_DIGEST = "ocspDigest";
121 const std::string CERT_CHAIN_VALIDATE_TAG_POLICY = "policy";
122 const std::string CERT_CHAIN_VALIDATE_TAG_SSLHOSTNAME = "sslHostname";
123 const std::string CERT_CHAIN_VALIDATE_TAG_KEYUSAGE = "keyUsage";
124 // CertChainValidateResult
125 const std::string CERT_CHAIN_VALIDATE_RESULLT_TAG_TRUSTANCHOR = "trustAnchor";
126 const std::string CERT_CHAIN_VALIDATE_RESULLT_TAG_X509CERT = "entityCert";
127 
128 const std::string CERT_CHAIN_BUILD_RESULLT_TAG_CERTCHAIN = "certChain";
129 const std::string CERT_CHAIN_BUILD_RESULLT_TAG_VALIDATERESULT = "validationResult";
130 
131 // HcfAttributes
132 const std::string CERT_ATTRIBUTE_TYPE = "type";
133 const std::string CERT_ATTRIBUTE_VALUE = "value";
134 
135 // HcfGenCsrConf
136 const std::string CERT_CSR_CONF_SUBJECT = "subject";
137 const std::string CERT_CSR_CONF_ATTRIBUTES = "attributes";
138 const std::string CERT_MDNAME = "mdName";
139 const std::string CERT_CSR_CONF_OUT_FORMAT = "outFormat";
140 
141 // Cms GENERATOR
142 const std::string CMS_GENERATOR_MDNAME = "mdName";
143 const std::string CMS_GENERATOR_ADD_ATTR = "addAttr";
144 const std::string CMS_GENERATOR_ADD_CERT = "addCert";
145 const std::string CMS_GENERATOR_ADD_SMIME_CAP_ATTR = "addSmimeCapAttr";
146 const std::string CERT_PRIVATE_KEY = "key";
147 const std::string CERT_PASSWORD = "password";
148 const std::string CMS_GENERATOR_CONTENT_DATA_FORMAT = "contentDataFormat";
149 const std::string CMS_GENERATOR_OUT_FORMAT = "outFormat";
150 const std::string CMS_GENERATOR_IS_DETACHED_CONTENT = "isDetached";
151 } // namespace CertFramework
152 } // namespace OHOS
153 
154 #endif // NAPI_CERT_DEFINES_H
155