/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ export interface AsyncCallback { (err: BusinessError, data: T): void; } export interface BusinessError extends Error { code: number; data?: T; } declare namespace CertManagerFunc { function getSystemTrustedCertificateList(callback: AsyncCallback) : void; function getSystemTrustedCertificateList() : Promise; function getSystemTrustedCertificate(certUri: string, callback: AsyncCallback) : void; function getSystemTrustedCertificate(certUri: string) : Promise; function setCertificateStatus(certUri: string, store: number, status: boolean, callback: AsyncCallback) : void; function setCertificateStatus(certUri: string, store: number, status: boolean) : Promise; function installUserTrustedCertificate(certificate: CertBlob, callback: AsyncCallback) : void; function installUserTrustedCertificate(certificate: CertBlob,) : Promise; function uninstallAllUserTrustedCertificate(callback: AsyncCallback) : void; function uninstallAllUserTrustedCertificate() : Promise; function uninstallUserTrustedCertificate(certUri: string, callback: AsyncCallback) : void; function uninstallUserTrustedCertificate(certUri: string) : Promise; function getAllUserTrustedCertificates(callback: AsyncCallback) : void; function getAllUserTrustedCertificates() : Promise; function getUserTrustedCertificate(certUri: string, callback: AsyncCallback) : void; function getUserTrustedCertificate(certUri: string) : Promise; function installPublicCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback) : void; function installPublicCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string) : Promise; function installPrivateCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback) : void; function installPrivateCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string) : Promise; function generatePrivateCertificate(keyAlias: string, keyProperties: CMKeyProperties, callback: AsyncCallback) : void; function generatePrivateCertificate(keyAlias: string, keyProperties: CMKeyProperties) : Promise; function updatePrivateCertificate(type: string, keyUri: string, certificate: CertBlob, callback: AsyncCallback) : void; function updatePrivateCertificate(type: string, keyUri: string, certificate: CertBlob) : Promise; function uninstallAllAppCertificate(callback: AsyncCallback) : void; function uninstallAllAppCertificate() : Promise; function uninstallPublicCertificate(keyUri: string, callback: AsyncCallback) : void; function uninstallPublicCertificate(keyUri: string) : Promise; function uninstallPrivateCertificate(keyUri: string, callback: AsyncCallback) : void; function uninstallPrivateCertificate(keyUri: string) : Promise; function getAllPublicCertificates(callback: AsyncCallback) : void; function getAllPublicCertificates() : Promise; function getAllAppPrivateCertificates(callback: AsyncCallback) : void; function getAllAppPrivateCertificates() : Promise; function getPublicCertificate(keyUri: string, callback: AsyncCallback) : void; function getPublicCertificate(keyUri: string, ) : Promise; function getPrivateCertificate(keyUri: string, callback: AsyncCallback) : void; function getPrivateCertificate(keyUri: string) : Promise; function grantPublicCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback) : void; function grantPublicCertificate(keyUri: string, clientAppUid: string) : Promise; function isAuthorizedApp(keyUri: string, callback: AsyncCallback) : void; function isAuthorizedApp(keyUri: string) : Promise; function getAuthorizedAppList(keyUri: string, callback: AsyncCallback) : void; function getAuthorizedAppList(keyUri: string) : Promise; function removeGrantedPublicCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback) : void; function removeGrantedPublicCertificate(keyUri: string, clientAppUid: string) : Promise; function init(authUri: string, spec: CMSignatureSpec, callback: AsyncCallback) : void; function init(authUri: string, spec: CMSignatureSpec) : Promise; function update(handle: Uint8Array, data: Uint8Array, callback: AsyncCallback) : void; function update(handle: Uint8Array, data: Uint8Array) : Promise; function finish(handle: Uint8Array, callback: AsyncCallback) : void; function finish(handle: Uint8Array, signature: Uint8Array, callback: AsyncCallback) : void; function finish(handle: Uint8Array, signature?: Uint8Array) : Promise; function abort(handle: Uint8Array, callback: AsyncCallback) : void; function abort(handle: Uint8Array) : Promise; function installSystemAppCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string): Promise; function getAllSystemAppCertificates(): Promise; function getSystemAppCertificate(keyUri: string) : Promise; function uninstallSystemAppCertificate(keyUri: string) : Promise; export interface CertInfo { uri: string; certAlias: string; status: boolean; issuerName: string; subjectName: string; serial: string; notBefore: string; notAfter: string; fingerprintSha256: string; cert: Uint8Array; } export interface CertAbstract { uri: string; certAlias: string; status: boolean; subjectName: string; } export interface Credential { type: string; alias: string; keyUri: string; certNum: number; keyNum: number; credData:Uint8Array; } export interface CredentialAbstract { type: string; alias: string; keyUri: string; } export interface CertBlob { inData: Uint8Array; alias: string; } export interface CMResult { certList?: Array; certInfo?: CertInfo; credentialList?: Array; credential?: Credential; appUidList?: Array; uri?: string; outData?: Uint8Array; isAuth?: boolean; } export interface CMKeyProperties { type: string; alg: string; size: number; padding: string; purpose: string; digest: string; authType: string; authTimeout: string; } export enum CmKeyPurpose { CM_KEY_PURPOSE_SIGN = 4, CM_KEY_PURPOSE_VERIFY = 8, } export interface CMSignatureSpec { purpose: CmKeyPurpose; } export interface CMHandle { handle: Uint8Array; } export enum CMErrorCode { CM_SUCCESS = 0, CM_ERROR_GENERIC = 17500001, CM_ERROR_NO_FOUND = 17500002, CM_ERROR_INCORRECT_FORMAT = 17500003, CM_ERROR_MAX_CERT_COUNT_REACHED = 17500004, CM_ERROR_NO_AUTHORIZATION = 17500005, CM_ERROR_ALIAS_LENGTH_REACHED_LIMIT = 17500006, CM_ERROR_PASSWORD_IS_ERR = 17500008 } } export default CertManagerFunc;