13e0f1854Sopenharmony_ci/* 23e0f1854Sopenharmony_ci* Copyright (c) 2022 Huawei Device Co., Ltd. 33e0f1854Sopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License"); 43e0f1854Sopenharmony_ci* you may not use this file except in compliance with the License. 53e0f1854Sopenharmony_ci* You may obtain a copy of the License at 63e0f1854Sopenharmony_ci* 73e0f1854Sopenharmony_ci* http://www.apache.org/licenses/LICENSE-2.0 83e0f1854Sopenharmony_ci* 93e0f1854Sopenharmony_ci* Unless required by applicable law or agreed to in writing, software 103e0f1854Sopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS, 113e0f1854Sopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123e0f1854Sopenharmony_ci* See the License for the specific language governing permissions and 133e0f1854Sopenharmony_ci* limitations under the License. 143e0f1854Sopenharmony_ci*/ 153e0f1854Sopenharmony_ci 163e0f1854Sopenharmony_ciexport interface AsyncCallback<T, E = void> { 173e0f1854Sopenharmony_ci (err: BusinessError<E>, data: T): void; 183e0f1854Sopenharmony_ci} 193e0f1854Sopenharmony_ci 203e0f1854Sopenharmony_ciexport interface BusinessError<T = void> extends Error { 213e0f1854Sopenharmony_ci code: number; 223e0f1854Sopenharmony_ci data?: T; 233e0f1854Sopenharmony_ci} 243e0f1854Sopenharmony_ci 253e0f1854Sopenharmony_cideclare namespace CertManagerFunc { 263e0f1854Sopenharmony_ci function getSystemTrustedCertificateList(callback: AsyncCallback<CMResult>) : void; 273e0f1854Sopenharmony_ci function getSystemTrustedCertificateList() : Promise<CMResult>; 283e0f1854Sopenharmony_ci 293e0f1854Sopenharmony_ci function getSystemTrustedCertificate(certUri: string, callback: AsyncCallback<CMResult>) : void; 303e0f1854Sopenharmony_ci function getSystemTrustedCertificate(certUri: string) : Promise<CMResult>; 313e0f1854Sopenharmony_ci 323e0f1854Sopenharmony_ci function setCertificateStatus(certUri: string, store: number, status: boolean, callback: AsyncCallback<boolean>) : void; 333e0f1854Sopenharmony_ci function setCertificateStatus(certUri: string, store: number, status: boolean) : Promise<boolean>; 343e0f1854Sopenharmony_ci 353e0f1854Sopenharmony_ci function installUserTrustedCertificate(certificate: CertBlob, callback: AsyncCallback<CMResult>) : void; 363e0f1854Sopenharmony_ci function installUserTrustedCertificate(certificate: CertBlob,) : Promise<CMResult>; 373e0f1854Sopenharmony_ci 383e0f1854Sopenharmony_ci function uninstallAllUserTrustedCertificate(callback: AsyncCallback<boolean>) : void; 393e0f1854Sopenharmony_ci function uninstallAllUserTrustedCertificate() : Promise<boolean>; 403e0f1854Sopenharmony_ci 413e0f1854Sopenharmony_ci function uninstallUserTrustedCertificate(certUri: string, callback: AsyncCallback<boolean>) : void; 423e0f1854Sopenharmony_ci function uninstallUserTrustedCertificate(certUri: string) : Promise<boolean>; 433e0f1854Sopenharmony_ci 443e0f1854Sopenharmony_ci function getAllUserTrustedCertificates(callback: AsyncCallback<CMResult>) : void; 453e0f1854Sopenharmony_ci function getAllUserTrustedCertificates() : Promise<CMResult>; 463e0f1854Sopenharmony_ci 473e0f1854Sopenharmony_ci function getUserTrustedCertificate(certUri: string, callback: AsyncCallback<CMResult>) : void; 483e0f1854Sopenharmony_ci function getUserTrustedCertificate(certUri: string) : Promise<CMResult>; 493e0f1854Sopenharmony_ci 503e0f1854Sopenharmony_ci function installPublicCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback<CMResult>) : void; 513e0f1854Sopenharmony_ci function installPublicCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string) : Promise<CMResult>; 523e0f1854Sopenharmony_ci 533e0f1854Sopenharmony_ci function installPrivateCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback<CMResult>) : void; 543e0f1854Sopenharmony_ci function installPrivateCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string) : Promise<CMResult>; 553e0f1854Sopenharmony_ci 563e0f1854Sopenharmony_ci function generatePrivateCertificate(keyAlias: string, keyProperties: CMKeyProperties, callback: AsyncCallback<CMResult>) : void; 573e0f1854Sopenharmony_ci function generatePrivateCertificate(keyAlias: string, keyProperties: CMKeyProperties) : Promise<CMResult>; 583e0f1854Sopenharmony_ci 593e0f1854Sopenharmony_ci function updatePrivateCertificate(type: string, keyUri: string, certificate: CertBlob, callback: AsyncCallback<boolean>) : void; 603e0f1854Sopenharmony_ci function updatePrivateCertificate(type: string, keyUri: string, certificate: CertBlob) : Promise<boolean>; 613e0f1854Sopenharmony_ci 623e0f1854Sopenharmony_ci function uninstallAllAppCertificate(callback: AsyncCallback<boolean>) : void; 633e0f1854Sopenharmony_ci function uninstallAllAppCertificate() : Promise<boolean>; 643e0f1854Sopenharmony_ci 653e0f1854Sopenharmony_ci function uninstallPublicCertificate(keyUri: string, callback: AsyncCallback<boolean>) : void; 663e0f1854Sopenharmony_ci function uninstallPublicCertificate(keyUri: string) : Promise<boolean>; 673e0f1854Sopenharmony_ci 683e0f1854Sopenharmony_ci function uninstallPrivateCertificate(keyUri: string, callback: AsyncCallback<boolean>) : void; 693e0f1854Sopenharmony_ci function uninstallPrivateCertificate(keyUri: string) : Promise<boolean>; 703e0f1854Sopenharmony_ci 713e0f1854Sopenharmony_ci function getAllPublicCertificates(callback: AsyncCallback<CMResult>) : void; 723e0f1854Sopenharmony_ci function getAllPublicCertificates() : Promise<CMResult>; 733e0f1854Sopenharmony_ci 743e0f1854Sopenharmony_ci function getAllAppPrivateCertificates(callback: AsyncCallback<CMResult>) : void; 753e0f1854Sopenharmony_ci function getAllAppPrivateCertificates() : Promise<CMResult>; 763e0f1854Sopenharmony_ci 773e0f1854Sopenharmony_ci function getPublicCertificate(keyUri: string, callback: AsyncCallback<CMResult>) : void; 783e0f1854Sopenharmony_ci function getPublicCertificate(keyUri: string, ) : Promise<CMResult>; 793e0f1854Sopenharmony_ci 803e0f1854Sopenharmony_ci function getPrivateCertificate(keyUri: string, callback: AsyncCallback<CMResult>) : void; 813e0f1854Sopenharmony_ci function getPrivateCertificate(keyUri: string) : Promise<CMResult>; 823e0f1854Sopenharmony_ci 833e0f1854Sopenharmony_ci function grantPublicCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<CMResult>) : void; 843e0f1854Sopenharmony_ci function grantPublicCertificate(keyUri: string, clientAppUid: string) : Promise<CMResult>; 853e0f1854Sopenharmony_ci 863e0f1854Sopenharmony_ci function isAuthorizedApp(keyUri: string, callback: AsyncCallback<boolean>) : void; 873e0f1854Sopenharmony_ci function isAuthorizedApp(keyUri: string) : Promise<boolean>; 883e0f1854Sopenharmony_ci 893e0f1854Sopenharmony_ci function getAuthorizedAppList(keyUri: string, callback: AsyncCallback<CMResult>) : void; 903e0f1854Sopenharmony_ci function getAuthorizedAppList(keyUri: string) : Promise<CMResult>; 913e0f1854Sopenharmony_ci 923e0f1854Sopenharmony_ci function removeGrantedPublicCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<boolean>) : void; 933e0f1854Sopenharmony_ci function removeGrantedPublicCertificate(keyUri: string, clientAppUid: string) : Promise<boolean>; 943e0f1854Sopenharmony_ci 953e0f1854Sopenharmony_ci function init(authUri: string, spec: CMSignatureSpec, callback: AsyncCallback<CMHandle>) : void; 963e0f1854Sopenharmony_ci function init(authUri: string, spec: CMSignatureSpec) : Promise<CMHandle>; 973e0f1854Sopenharmony_ci 983e0f1854Sopenharmony_ci function update(handle: Uint8Array, data: Uint8Array, callback: AsyncCallback<boolean>) : void; 993e0f1854Sopenharmony_ci function update(handle: Uint8Array, data: Uint8Array) : Promise<boolean>; 1003e0f1854Sopenharmony_ci 1013e0f1854Sopenharmony_ci function finish(handle: Uint8Array, callback: AsyncCallback<CMResult>) : void; 1023e0f1854Sopenharmony_ci function finish(handle: Uint8Array, signature: Uint8Array, callback: AsyncCallback<CMResult>) : void; 1033e0f1854Sopenharmony_ci function finish(handle: Uint8Array, signature?: Uint8Array) : Promise<CMResult>; 1043e0f1854Sopenharmony_ci 1053e0f1854Sopenharmony_ci function abort(handle: Uint8Array, callback: AsyncCallback<boolean>) : void; 1063e0f1854Sopenharmony_ci function abort(handle: Uint8Array) : Promise<boolean>; 1073e0f1854Sopenharmony_ci 1083e0f1854Sopenharmony_ci function installSystemAppCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string): Promise<CMResult>; 1093e0f1854Sopenharmony_ci 1103e0f1854Sopenharmony_ci function getAllSystemAppCertificates(): Promise<CMResult>; 1113e0f1854Sopenharmony_ci 1123e0f1854Sopenharmony_ci function getSystemAppCertificate(keyUri: string) : Promise<CMResult>; 1133e0f1854Sopenharmony_ci 1143e0f1854Sopenharmony_ci function uninstallSystemAppCertificate(keyUri: string) : Promise<void>; 1153e0f1854Sopenharmony_ci 1163e0f1854Sopenharmony_ci export interface CertInfo { 1173e0f1854Sopenharmony_ci uri: string; 1183e0f1854Sopenharmony_ci certAlias: string; 1193e0f1854Sopenharmony_ci status: boolean; 1203e0f1854Sopenharmony_ci issuerName: string; 1213e0f1854Sopenharmony_ci subjectName: string; 1223e0f1854Sopenharmony_ci serial: string; 1233e0f1854Sopenharmony_ci notBefore: string; 1243e0f1854Sopenharmony_ci notAfter: string; 1253e0f1854Sopenharmony_ci fingerprintSha256: string; 1263e0f1854Sopenharmony_ci cert: Uint8Array; 1273e0f1854Sopenharmony_ci } 1283e0f1854Sopenharmony_ci 1293e0f1854Sopenharmony_ci export interface CertAbstract { 1303e0f1854Sopenharmony_ci uri: string; 1313e0f1854Sopenharmony_ci certAlias: string; 1323e0f1854Sopenharmony_ci status: boolean; 1333e0f1854Sopenharmony_ci subjectName: string; 1343e0f1854Sopenharmony_ci } 1353e0f1854Sopenharmony_ci 1363e0f1854Sopenharmony_ci export interface Credential { 1373e0f1854Sopenharmony_ci type: string; 1383e0f1854Sopenharmony_ci alias: string; 1393e0f1854Sopenharmony_ci keyUri: string; 1403e0f1854Sopenharmony_ci certNum: number; 1413e0f1854Sopenharmony_ci keyNum: number; 1423e0f1854Sopenharmony_ci credData:Uint8Array; 1433e0f1854Sopenharmony_ci } 1443e0f1854Sopenharmony_ci 1453e0f1854Sopenharmony_ci export interface CredentialAbstract { 1463e0f1854Sopenharmony_ci type: string; 1473e0f1854Sopenharmony_ci alias: string; 1483e0f1854Sopenharmony_ci keyUri: string; 1493e0f1854Sopenharmony_ci } 1503e0f1854Sopenharmony_ci 1513e0f1854Sopenharmony_ci export interface CertBlob { 1523e0f1854Sopenharmony_ci inData: Uint8Array; 1533e0f1854Sopenharmony_ci alias: string; 1543e0f1854Sopenharmony_ci } 1553e0f1854Sopenharmony_ci 1563e0f1854Sopenharmony_ci export interface CMResult { 1573e0f1854Sopenharmony_ci certList?: Array<CertAbstract>; 1583e0f1854Sopenharmony_ci certInfo?: CertInfo; 1593e0f1854Sopenharmony_ci credentialList?: Array<CredentialAbstract>; 1603e0f1854Sopenharmony_ci credential?: Credential; 1613e0f1854Sopenharmony_ci appUidList?: Array<string>; 1623e0f1854Sopenharmony_ci uri?: string; 1633e0f1854Sopenharmony_ci outData?: Uint8Array; 1643e0f1854Sopenharmony_ci isAuth?: boolean; 1653e0f1854Sopenharmony_ci } 1663e0f1854Sopenharmony_ci 1673e0f1854Sopenharmony_ci export interface CMKeyProperties { 1683e0f1854Sopenharmony_ci type: string; 1693e0f1854Sopenharmony_ci alg: string; 1703e0f1854Sopenharmony_ci size: number; 1713e0f1854Sopenharmony_ci padding: string; 1723e0f1854Sopenharmony_ci purpose: string; 1733e0f1854Sopenharmony_ci digest: string; 1743e0f1854Sopenharmony_ci authType: string; 1753e0f1854Sopenharmony_ci authTimeout: string; 1763e0f1854Sopenharmony_ci } 1773e0f1854Sopenharmony_ci 1783e0f1854Sopenharmony_ci export enum CmKeyPurpose { 1793e0f1854Sopenharmony_ci CM_KEY_PURPOSE_SIGN = 4, 1803e0f1854Sopenharmony_ci CM_KEY_PURPOSE_VERIFY = 8, 1813e0f1854Sopenharmony_ci } 1823e0f1854Sopenharmony_ci 1833e0f1854Sopenharmony_ci export interface CMSignatureSpec { 1843e0f1854Sopenharmony_ci purpose: CmKeyPurpose; 1853e0f1854Sopenharmony_ci } 1863e0f1854Sopenharmony_ci 1873e0f1854Sopenharmony_ci export interface CMHandle { 1883e0f1854Sopenharmony_ci handle: Uint8Array; 1893e0f1854Sopenharmony_ci } 1903e0f1854Sopenharmony_ci 1913e0f1854Sopenharmony_ci export enum CMErrorCode { 1923e0f1854Sopenharmony_ci CM_SUCCESS = 0, 1933e0f1854Sopenharmony_ci CM_ERROR_GENERIC = 17500001, 1943e0f1854Sopenharmony_ci CM_ERROR_NO_FOUND = 17500002, 1953e0f1854Sopenharmony_ci CM_ERROR_INCORRECT_FORMAT = 17500003, 1963e0f1854Sopenharmony_ci CM_ERROR_MAX_CERT_COUNT_REACHED = 17500004, 1973e0f1854Sopenharmony_ci CM_ERROR_NO_AUTHORIZATION = 17500005, 1983e0f1854Sopenharmony_ci CM_ERROR_ALIAS_LENGTH_REACHED_LIMIT = 17500006, 1993e0f1854Sopenharmony_ci CM_ERROR_PASSWORD_IS_ERR = 17500008 2003e0f1854Sopenharmony_ci } 2013e0f1854Sopenharmony_ci} 2023e0f1854Sopenharmony_ci 2033e0f1854Sopenharmony_ciexport default CertManagerFunc; 204