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 16import {AsyncCallback} from './basic'; 17 18/** 19 * OpenHarmony Universal CertificateManager 20 * @since 9 21 * @syscap SystemCapability.Security.CertificateManager 22 * @permission N/A 23 */ 24declare namespace CertificateManager { 25 /** 26 * Get a list of system root certificates. 27 * @since 9 28 * @syscap SystemCapability.Security.CertificateManager 29 * @param context Indicates the context of the calling interface application. 30 * @permission ohos.permission.ACCESS_CERT_MANAGER 31 */ 32 function getSystemTrustedCertificateList(context: CMContext, callback: AsyncCallback<CMResult>) : void; 33 function getSystemTrustedCertificateList(context: CMContext) : Promise<CMResult>; 34 35 /** 36 * Get the detail of system root certificate. 37 * @since 9 38 * @syscap SystemCapability.Security.CertificateManager 39 * @param context Indicates the context of the calling interface application. 40 * @param certUri Indicates the certificate's name. 41 * @permission ohos.permission.ACCESS_CERT_MANAGER 42 */ 43 function getSystemTrustedCertificate(context: CMContext, certUri: string, callback: AsyncCallback<CMResult>) : void; 44 function getSystemTrustedCertificate(context: CMContext, certUri: string) : Promise<CMResult>; 45 46 /** 47 * Set the status of root certificates. 48 * @since 9 49 * @syscap SystemCapability.Security.CertificateManager 50 * @param context Indicates the context of the calling interface application. 51 * @param certUri Indicates the certificate's name. 52 * @param store Indicates the type of certificate. 53 * @param status Indicates the status of certificate to be set. 54 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 55 * @systemapi Hide this for inner system use 56 */ 57 function setCertificateStatus(context: CMContext, certUri: string, store: number, status: boolean, callback: AsyncCallback<boolean>) : void; 58 function setCertificateStatus(context: CMContext, certUri: string, store: number, status: boolean) : Promise<boolean>; 59 60 /** 61 * Install the user root certificate. 62 * @since 9 63 * @syscap SystemCapability.Security.CertificateManager 64 * @param certificate Indicates the certificate file. 65 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 66 * @systemapi Hide this for inner system use 67 */ 68 function installUserTrustedCertificate(certificate: CertBlob, callback: AsyncCallback<CMResult>) : void; 69 function installUserTrustedCertificate(certificate: CertBlob,) : Promise<CMResult>; 70 71 /** 72 * Uninstall all user root certificates. 73 * @since 9 74 * @syscap SystemCapability.Security.CertificateManager 75 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 76 * @systemapi Hide this for inner system use 77 */ 78 function uninstallAllUserTrustedCertificate(callback: AsyncCallback<boolean>) : void; 79 function uninstallAllUserTrustedCertificate() : Promise<boolean>; 80 81 /** 82 * Uninstall the specified user root certificate. 83 * @since 9 84 * @syscap SystemCapability.Security.CertificateManager 85 * @param certUri Indicates the certificate's name. 86 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 87 * @systemapi Hide this for inner system use 88 */ 89 function uninstallUserTrustedCertificate(certUri: string, callback: AsyncCallback<boolean>) : void; 90 function uninstallUserTrustedCertificate(certUri: string) : Promise<boolean>; 91 92 /** 93 * Get a list of user root certificates. 94 * @since 9 95 * @syscap SystemCapability.Security.CertificateManager 96 * @permission ohos.permission.ACCESS_CERT_MANAGER 97 */ 98 function getUserTrustedCertificateList(callback: AsyncCallback<CMResult>) : void; 99 function getUserTrustedCertificateList() : Promise<CMResult>; 100 101 /** 102 * Get the detail of user root certificate. 103 * @since 9 104 * @syscap SystemCapability.Security.CertificateManager 105 * @param certUri Indicates the certificate's name. 106 * @permission ohos.permission.ACCESS_CERT_MANAGER 107 */ 108 function getUserTrustedCertificate(certUri: string, callback: AsyncCallback<CMResult>) : void; 109 function getUserTrustedCertificate(certUri: string) : Promise<CMResult>; 110 111 /** 112 * Install normal application certificate. 113 * @since 9 114 * @syscap SystemCapability.Security.CertificateManager 115 * @param keystore Indicates the keystore file with key pair and certificate. 116 * @param keystorePwd Indicates the password of keystore file. 117 * @param certAlias Indicates the certificate name inputted by the user. 118 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 119 * @systemapi Hide this for inner system use 120 */ 121 function installAppCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback<CMResult>) : void; 122 function installAppCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string) : Promise<CMResult>; 123 124 /** 125 * Install private application certificate. 126 * @since 9 127 * @syscap SystemCapability.Security.CertificateManager 128 * @param keystore Indicates the keystore file with key pair and certificate. 129 * @param keystorePwd Indicates the password of keystore file. 130 * @param certAlias Indicates the certificate name inputted by the user. 131 * @permission ohos.permission.ACCESS_CERT_MANAGER 132 */ 133 function installPrivateCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback<CMResult>) : void; 134 function installPrivateCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string) : Promise<CMResult>; 135 136 /** 137 * Generate private application certificate locally. 138 * @since 9 139 * @syscap SystemCapability.Security.CertificateManager 140 * @param keyAlias Indicates the key alias inputted by the user. 141 * @param keyProperties Indicates the properties of keys in keystore file. 142 * @permission ohos.permission.ACCESS_CERT_MANAGER 143 */ 144 function generatePrivateCertificate(keyAlias: string, keyProperties: CMKeyProperties, callback: AsyncCallback<CMResult>) : void; 145 function generatePrivateCertificate(keyAlias: string, keyProperties: CMKeyProperties) : Promise<CMResult>; 146 147 /** 148 * Update private application certificate. 149 * @since 9 150 * @syscap SystemCapability.Security.CertificateManager 151 * @param type Indicates the type of the certificate used. 152 * @param keyUri Indicates key's name. 153 * @param certificate Indicates the certificate file. 154 * @permission ohos.permission.ACCESS_CERT_MANAGER 155 */ 156 function updatePrivateCertificate(type: string, keyUri: string, certificate: CertBlob, callback: AsyncCallback<boolean>) : void; 157 function updatePrivateCertificate(type: string, keyUri: string, certificate: CertBlob) : Promise<boolean>; 158 159 /** 160 * Uninstall all application certificate. 161 * @since 9 162 * @syscap SystemCapability.Security.CertificateManager 163 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 164 * @systemapi Hide this for inner system use 165 */ 166 function uninstallAllAppCertificate(callback: AsyncCallback<boolean>) : void; 167 function uninstallAllAppCertificate() : Promise<boolean>; 168 169 /** 170 * Uninstall the specified normal application certificate. 171 * @since 9 172 * @syscap SystemCapability.Security.CertificateManager 173 * @param keyUri Indicates key's name. 174 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 175 * @systemapi Hide this for inner system use 176 */ 177 function uninstallAppCertificate(keyUri: string, callback: AsyncCallback<boolean>) : void; 178 function uninstallAppCertificate(keyUri: string) : Promise<boolean>; 179 180 /** 181 * Uninstall the specified normal application certificate. 182 * @since 9 183 * @syscap SystemCapability.Security.CertificateManager 184 * @param keyUri Indicates key's name. 185 * @permission ohos.permission.ACCESS_CERT_MANAGER 186 */ 187 function uninstallPrivateCertificate(keyUri: string, callback: AsyncCallback<boolean>) : void; 188 function uninstallPrivateCertificate(keyUri: string) : Promise<boolean>; 189 190 /** 191 * Get a list of normal application certificates. 192 * @since 9 193 * @syscap SystemCapability.Security.CertificateManager 194 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 195 * @systemapi Hide this for inner system use 196 */ 197 function getAppCertificateList(callback: AsyncCallback<CMResult>) : void; 198 function getAppCertificateList() : Promise<CMResult>; 199 200 /** 201 * Get a list of private application certificates. 202 * @since 9 203 * @syscap SystemCapability.Security.CertificateManager 204 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 205 * @systemapi Hide this for inner system use 206 */ 207 function getPrivateCertificateList(callback: AsyncCallback<CMResult>) : void; 208 function getPrivateCertificateList() : Promise<CMResult>; 209 210 /** 211 * Get the detail of normal application certificate. 212 * @since 9 213 * @syscap SystemCapability.Security.CertificateManager 214 * @param keyUri Indicates key's name. 215 * @permission ohos.permission.ACCESS_CERT_MANAGER 216 */ 217 function getAppCertificate(keyUri: string, callback: AsyncCallback<CMResult>) : void; 218 function getAppCertificate(keyUri: string, ) : Promise<CMResult>; 219 220 /** 221 * Get the detail of private application certificate. 222 * @since 9 223 * @syscap SystemCapability.Security.CertificateManager 224 * @param keyUri Indicates key's name. 225 * @permission ohos.permission.ACCESS_CERT_MANAGER 226 */ 227 function getPrivateCertificate(keyUri: string, callback: AsyncCallback<CMResult>) : void; 228 function getPrivateCertificate(keyUri: string) : Promise<CMResult>; 229 230 /** 231 * Authorize the specified application certificate for the specified application. 232 * @since 9 233 * @syscap SystemCapability.Security.CertificateManager 234 * @param keyUri Indicates key's name. 235 * @param clientAppUid Indicates the uid of the authorized application. 236 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 237 * @systemapi Hide this for inner system use 238 */ 239 function grantAppCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<CMResult>) : void; 240 function grantAppCertificate(keyUri: string, clientAppUid: string) : Promise<CMResult>; 241 242 /** 243 * Whether the current application is authorized by the specified application certificate. 244 * @since 9 245 * @syscap SystemCapability.Security.CertificateManager 246 * @param keyUri Indicates key's name. 247 * @permission ohos.permission.ACCESS_CERT_MANAGER 248 */ 249 function isAuthorizedApp(keyUri: string, callback: AsyncCallback<boolean>) : void; 250 function isAuthorizedApp(keyUri: string) : Promise<boolean>; 251 252 /** 253 * Get the list of applications authorized by the specified certificate. 254 * @since 9 255 * @syscap SystemCapability.Security.CertificateManager 256 * @param keyUri Indicates key's name. 257 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 258 * @systemapi Hide this for inner system use 259 */ 260 function getAuthorizedAppList(keyUri: string, callback: AsyncCallback<CMResult>) : void; 261 function getAuthorizedAppList(keyUri: string) : Promise<CMResult>; 262 263 /** 264 * Deauthorize the specified application from the specified application certificate. 265 * @since 9 266 * @syscap SystemCapability.Security.CertificateManager 267 * @param keyUri Indicates key's name. 268 * @param clientAppUid Indicates the uid of the deauthorized application. 269 * @permission ohos.permission.ACCESS_CERT_MANAGER_INTERNAL 270 * @systemapi Hide this for inner system use 271 */ 272 function removeGrantedAppCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<boolean>) : void; 273 function removeGrantedAppCertificate(keyUri: string, clientAppUid: string) : Promise<boolean>; 274 275 /** 276 * Init operation for signing and verifying etc. 277 * @since 9 278 * @syscap SystemCapability.Security.CertificateManager 279 * @param authUri Indicates the authorization relationship between application and application certificate. 280 * @param spec Indicates the properties of the signature and verification.. 281 * @return The handle of the init Operation. 282 * @permission ohos.permission.ACCESS_CERT_MANAGER 283 */ 284 function init(authUri: string, spec: CMSignatureSpec, callback: AsyncCallback<CMHandle>) : void; 285 function init(authUri: string, spec: CMSignatureSpec) : Promise<CMHandle>; 286 287 /** 288 * Update operation for signing and verifying etc. 289 * @since 9 290 * @syscap SystemCapability.Security.CertificateManager 291 * @param handle Indicates the handle of the init operation. 292 * @param data Indicates the input value. 293 * @param token Indicates the value of token. 294 * @permission ohos.permission.ACCESS_CERT_MANAGER 295 */ 296 function update(handle: Uint8Array, data: Uint8Array, callback: AsyncCallback<boolean>) : void; 297 function update(handle: Uint8Array, data: Uint8Array) : Promise<boolean>; 298 299 /** 300 * Finish operation for signing and verifying etc. 301 * @since 9 302 * @syscap SystemCapability.Security.CertificateManager 303 * @param handle Indicates the handle of the init operation. 304 * @param signature Indicates the sign data. 305 * @permission ohos.permission.ACCESS_CERT_MANAGER 306 */ 307 function finish(handle: Uint8Array, callback: AsyncCallback<CMResult>) : void; 308 function finish(handle: Uint8Array, signature: Uint8Array, callback: AsyncCallback<CMResult>) : void; 309 function finish(handle: Uint8Array, signature?: Uint8Array) : Promise<CMResult>; 310 311 /** 312 * Abort operation for signing and verifying etc. 313 * @since 9 314 * @syscap SystemCapability.Security.CertificateManager 315 * @param handle Indicates the handle of the init operation. 316 * @permission ohos.permission.ACCESS_CERT_MANAGER 317 */ 318 function abort(handle: Uint8Array, callback: AsyncCallback<boolean>) : void; 319 function abort(handle: Uint8Array) : Promise<boolean>; 320 321 export interface CMContext { 322 userId: string; 323 uid: string; 324 packageName: string; 325 } 326 327 export interface CertInfo { 328 uri: string; 329 certAlias: string; 330 status: boolean; 331 issuerName: string; 332 subjectName: string; 333 serial: string; 334 notBefore: string; 335 notAfter: string; 336 fingerprintSha256: string; 337 cert: Uint8Array; 338 } 339 340 export interface CertAbstract { 341 uri: string; 342 certAlias: string; 343 status: boolean; 344 subjectName: string; 345 } 346 347 export interface Credential { 348 type: string; 349 alias: string; 350 keyUri: string; 351 certNum: number; 352 keyNum: number; 353 credData:Uint8Array; 354 } 355 356 export interface CredentialAbstract { 357 type: string; 358 alias: string; 359 keyUri: string; 360 } 361 362 export interface CertBlob { 363 inData: Uint8Array; 364 alias: string; 365 } 366 367 export interface CMResult { 368 certList?: Array<CertAbstract>; 369 certInfo?: CertInfo; 370 credentialList?: Array<CredentialAbstract>; 371 credential?: Credential; 372 appUidList?: Array<string>; 373 uri?: string; 374 outData?: Uint8Array; 375 isAuth?: boolean; 376 } 377 378 export interface CMKeyProperties { 379 type: string; 380 alg: string; 381 size: number; 382 padding: string; 383 purpose: string; 384 digest: string; 385 authType: string; 386 authTimeout: string; 387 } 388 389 export enum CmKeyPurpose { 390 CM_KEY_PURPOSE_SIGN = 4, 391 CM_KEY_PURPOSE_VERIFY = 8, 392 } 393 394 export interface CMSignatureSpec { 395 purpose: CmKeyPurpose; 396 } 397 398 export interface CMHandle { 399 handle: Uint8Array; 400 } 401 402 export enum CMErrorCode { 403 CM_SUCCESS = 0, 404 CM_ERROR_INNER_ERROR = 17500001, 405 CM_ERROR_NO_PERMISSION = 17500002, 406 CM_ERROR_NO_FOUND = 17500003, 407 CM_ERROR_X509_FORMATE = 17500004, 408 } 409} 410 411export default CertificateManager; 412