• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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/**
17 * @file
18 * @kit DeviceCertificateKit
19 */
20
21import type common from '@ohos.app.ability.common';
22
23/**
24 * OpenHarmony Universal CertificateManager
25 *
26 * @namespace certificateManagerDialog
27 * @syscap SystemCapability.Security.CertificateManagerDialog
28 * @stagemodelonly
29 * @since 13
30 */
31declare namespace certificateManagerDialog {
32  /**
33   * Enum for result code
34   *
35   * @enum { number }
36   * @syscap SystemCapability.Security.CertificateManagerDialog
37   * @stagemodelonly
38   * @since 13
39   */
40  export enum CertificateDialogErrorCode {
41
42    /**
43     * Indicates that internal error.
44     *
45     * @syscap SystemCapability.Security.CertificateManagerDialog
46     * @stagemodelonly
47     * @since 13
48     */
49    ERROR_GENERIC = 29700001,
50
51    /**
52     * Indicates the user cancels the operation.
53     *
54     * @syscap SystemCapability.Security.CertificateManagerDialog
55     * @stagemodelonly
56     * @since 14
57     */
58    ERROR_OPERATION_CANCELED = 29700002,
59
60    /**
61     * Indicates that the user operation failed in the certificate manager dialog, such as install certificate failed.
62     *
63     * @syscap SystemCapability.Security.CertificateManagerDialog
64     * @stagemodelonly
65     * @since 14
66     */
67    ERROR_OPERATION_FAILED = 29700003,
68
69    /**
70     * Indicates that the API is not supported on this device.
71     *
72     * @syscap SystemCapability.Security.CertificateManagerDialog
73     * @stagemodelonly
74     * @since 14
75     */
76    ERROR_DEVICE_NOT_SUPPORTED = 29700004,
77
78    /**
79     * Indicates that the operation does not comply with the device security policy, such as the device does not allow users to manage the ca certificate of the global user..
80     *
81     * @syscap SystemCapability.Security.CertificateManagerDialog
82     * @stagemodelonly
83     * @since 18
84     */
85    ERROR_NOT_COMPLY_SECURITY_POLICY = 29700005,
86  }
87
88
89  /**
90   * Enum for page type of certificate manager dialog
91   *
92   * @enum { number }
93   * @syscap SystemCapability.Security.CertificateManagerDialog
94   * @stagemodelonly
95   * @since 13
96   */
97  export enum CertificateDialogPageType {
98    /**
99     * Indicates the main entrance page.
100     *
101     * @syscap SystemCapability.Security.CertificateManagerDialog
102     * @stagemodelonly
103     * @since 13
104     */
105    PAGE_MAIN = 1,
106
107    /**
108     * Indicates the CA certificate list page.
109     *
110     * @syscap SystemCapability.Security.CertificateManagerDialog
111     * @stagemodelonly
112     * @since 13
113     */
114    PAGE_CA_CERTIFICATE = 2,
115
116    /**
117     * Indicates the Credential list page.
118     *
119     * @syscap SystemCapability.Security.CertificateManagerDialog
120     * @stagemodelonly
121     * @since 13
122     */
123    PAGE_CREDENTIAL = 3,
124
125    /**
126     * Indicates the install certificate page.
127     *
128     * @syscap SystemCapability.Security.CertificateManagerDialog
129     * @stagemodelonly
130     * @since 13
131     */
132    PAGE_INSTALL_CERTIFICATE = 4
133  }
134
135  /**
136   * open certificate manager dialog and show the specified page.
137   *
138   * @permission ohos.permission.ACCESS_CERT_MANAGER
139   * @param { common.Context } context - Hap context information.
140   * @param { CertificateDialogPageType } pageType - Indicates page type.
141   * @returns { Promise<void> } The promise returned by the function.
142   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
143   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
144   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
145   * @throws { BusinessError } 29700001 - Internal error.
146   * @syscap SystemCapability.Security.CertificateManagerDialog
147   * @stagemodelonly
148   * @since 13
149   */
150  function openCertificateManagerDialog(context: common.Context, pageType: CertificateDialogPageType): Promise<void>;
151
152
153
154  /**
155   * Enum for certificate type
156   *
157   * @enum { number }
158   * @syscap SystemCapability.Security.CertificateManagerDialog
159   * @stagemodelonly
160   * @since 14
161   */
162  export enum CertificateType {
163    /**
164     * Indicates CA certificate.
165     *
166     * @syscap SystemCapability.Security.CertificateManagerDialog
167     * @stagemodelonly
168     * @since 14
169     */
170    CA_CERT = 1
171  }
172
173  /**
174   * Enum for certificate scope
175   *
176   * @enum { number }
177   * @syscap SystemCapability.Security.CertificateManagerDialog
178   * @stagemodelonly
179   * @since 14
180   */
181  export enum CertificateScope {
182    /**
183     * Indicates the certificate scope is not specified and user can select the scope in the certificate install dialog.
184     *
185     * @syscap SystemCapability.Security.CertificateManagerDialog
186     * @stagemodelonly
187     * @since 18
188     */
189    NOT_SPECIFIED = 0,
190
191    /**
192     * Indicates the certificate is for current user.
193     *
194     * @syscap SystemCapability.Security.CertificateManagerDialog
195     * @stagemodelonly
196     * @since 14
197     */
198    CURRENT_USER = 1,
199
200    /**
201     * Indicates the certificate is for all users.
202     *
203     * @syscap SystemCapability.Security.CertificateManagerDialog
204     * @stagemodelonly
205     * @since 18
206     */
207    GLOBAL_USER = 2,
208  }
209
210  /**
211   * open install certificate dialog.
212   *
213   * @permission ohos.permission.ACCESS_CERT_MANAGER
214   * @param { common.Context } context - Hap context information
215   * @param { CertificateType } certType - Indicates the type of certificate to be installed.
216   * @param { CertificateScope } certScope - Indicates the user scope of certificate to be installed.
217   * @param { Uint8Array } cert - Indicates the contents of the certificate file to be installed.
218   * @returns { Promise<string> } The uri of installed certificate.
219   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
220   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
221   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
222   * @throws { BusinessError } 29700001 - Internal error.
223   * @throws { BusinessError } 29700002 - The user cancels the installation operation.
224   * @throws { BusinessError } 29700003 - The user install certificate failed in the certificate manager dialog.
225   * @throws { BusinessError } 29700004 - The API is not supported on this device.
226   * @syscap SystemCapability.Security.CertificateManagerDialog
227   * @stagemodelonly
228   * @since 14
229   */
230  /**
231   * open install certificate dialog.
232   *
233   * @permission ohos.permission.ACCESS_CERT_MANAGER
234   * @param { common.Context } context - Hap context information
235   * @param { CertificateType } certType - Indicates the type of certificate to be installed.
236   * @param { CertificateScope } certScope - Indicates the user scope of certificate to be installed.
237   * @param { Uint8Array } cert - Indicates the contents of the certificate file to be installed.
238   * @returns { Promise<string> } The uri of installed certificate.
239   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
240   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
241   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
242   * @throws { BusinessError } 29700001 - Internal error.
243   * @throws { BusinessError } 29700002 - The user cancels the installation operation.
244   * @throws { BusinessError } 29700003 - The user install certificate failed in the certificate manager dialog, such as the certificate is in an invalid format.
245   * @throws { BusinessError } 29700004 - The API is not supported on this device.
246   * @throws { BusinessError } 29700005 - The operation does not comply with the device security policy, such as the device does not allow users to manage the ca certificate of the global user.
247   * @syscap SystemCapability.Security.CertificateManagerDialog
248   * @stagemodelonly
249   * @since 18
250   */
251  function openInstallCertificateDialog(context: common.Context, certType: CertificateType, certScope: CertificateScope, cert: Uint8Array): Promise<string>;
252
253  /**
254   * open uninstall certificate dialog.
255   *
256   * @permission ohos.permission.ACCESS_CERT_MANAGER
257   * @param { common.Context } context - Hap context information
258   * @param { CertificateType } certType - Indicates the type of certificate to be uninstalled.
259   * @param { string } certUri - Indicates the certificate uri to be uninstalled.
260   * @returns { Promise<void> } The promise returned by the function.
261   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
262   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
263   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
264   * @throws { BusinessError } 29700001 - Internal error.
265   * @throws { BusinessError } 29700002 - The user cancels the uninstallation operation.
266   * @throws { BusinessError } 29700003 - The user uninstall certificate failed in the certificate manager dialog, such as the certificate uri is not exist.
267   * @throws { BusinessError } 29700004 - The API is not supported on this device.
268   * @throws { BusinessError } 29700005 - The operation does not comply with the device security policy, such as the device does not allow users to manage the ca certificate of the global user.
269   * @syscap SystemCapability.Security.CertificateManagerDialog
270   * @stagemodelonly
271   * @since 18
272   */
273  function openUninstallCertificateDialog(context: common.Context, certType: CertificateType, certUri: string): Promise<void>;
274
275  /**
276   * Provides the certificate dialog property.
277   *
278   * @typedef CertificateDialogProperty
279   * @syscap SystemCapability.Security.CertificateManagerDialog
280   * @stagemodelonly
281   * @since 18
282   */
283  export interface CertificateDialogProperty {
284    /**
285     * Indicates if the certificate dialog show install button.
286     *
287     * @type { boolean }
288     * @syscap SystemCapability.Security.CertificateManagerDialog
289     * @stagemodelonly
290     * @since 18
291     */
292    showInstallButton: boolean;
293  }
294
295  /**
296   * open certificate manager dialog and show the certificate detail page.
297   *
298   * @permission ohos.permission.ACCESS_CERT_MANAGER
299   * @param { common.Context } context - Hap context information
300   * @param { Uint8Array } cert - Indicates the contents of the certificate file.
301   * @param { CertificateDialogProperty } property - the certificate dialog property.
302   * @returns { Promise<void> } The promise returned by the function.
303   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
304   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
305   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
306   * @throws { BusinessError } 29700001 - Internal error.
307   * @throws { BusinessError } 29700003 - Show the certificate detail dialog fail, such as the certificate is in an invalid format.
308   * @throws { BusinessError } 29700004 - The API is not supported on this device.
309   * @syscap SystemCapability.Security.CertificateManagerDialog
310   * @stagemodelonly
311   * @since 18
312   */
313  function openCertificateDetailDialog(context: common.Context, cert: Uint8Array, property: CertificateDialogProperty): Promise<void>;
314}
315
316export default certificateManagerDialog;
317