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 16export interface AsyncCallback<T, E = void> { 17 (err: BusinessError<E>, data: T): void; 18} 19 20export interface BusinessError<T = void> extends Error { 21 code: number; 22 data?: T; 23} 24 25declare namespace CertManagerFunc { 26 function getSystemTrustedCertificateList(callback: AsyncCallback<CMResult>) : void; 27 function getSystemTrustedCertificateList() : Promise<CMResult>; 28 29 function getSystemTrustedCertificate(certUri: string, callback: AsyncCallback<CMResult>) : void; 30 function getSystemTrustedCertificate(certUri: string) : Promise<CMResult>; 31 32 function setCertificateStatus(certUri: string, store: number, status: boolean, callback: AsyncCallback<boolean>) : void; 33 function setCertificateStatus(certUri: string, store: number, status: boolean) : Promise<boolean>; 34 35 function installUserTrustedCertificate(certificate: CertBlob, callback: AsyncCallback<CMResult>) : void; 36 function installUserTrustedCertificate(certificate: CertBlob,) : Promise<CMResult>; 37 38 function uninstallAllUserTrustedCertificate(callback: AsyncCallback<boolean>) : void; 39 function uninstallAllUserTrustedCertificate() : Promise<boolean>; 40 41 function uninstallUserTrustedCertificate(certUri: string, callback: AsyncCallback<boolean>) : void; 42 function uninstallUserTrustedCertificate(certUri: string) : Promise<boolean>; 43 44 function getAllUserTrustedCertificates(callback: AsyncCallback<CMResult>) : void; 45 function getAllUserTrustedCertificates() : Promise<CMResult>; 46 47 function getUserTrustedCertificate(certUri: string, callback: AsyncCallback<CMResult>) : void; 48 function getUserTrustedCertificate(certUri: string) : Promise<CMResult>; 49 50 function installPublicCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback<CMResult>) : void; 51 function installPublicCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string) : Promise<CMResult>; 52 53 function installPrivateCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback<CMResult>) : void; 54 function installPrivateCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string) : Promise<CMResult>; 55 56 function generatePrivateCertificate(keyAlias: string, keyProperties: CMKeyProperties, callback: AsyncCallback<CMResult>) : void; 57 function generatePrivateCertificate(keyAlias: string, keyProperties: CMKeyProperties) : Promise<CMResult>; 58 59 function updatePrivateCertificate(type: string, keyUri: string, certificate: CertBlob, callback: AsyncCallback<boolean>) : void; 60 function updatePrivateCertificate(type: string, keyUri: string, certificate: CertBlob) : Promise<boolean>; 61 62 function uninstallAllAppCertificate(callback: AsyncCallback<boolean>) : void; 63 function uninstallAllAppCertificate() : Promise<boolean>; 64 65 function uninstallPublicCertificate(keyUri: string, callback: AsyncCallback<boolean>) : void; 66 function uninstallPublicCertificate(keyUri: string) : Promise<boolean>; 67 68 function uninstallPrivateCertificate(keyUri: string, callback: AsyncCallback<boolean>) : void; 69 function uninstallPrivateCertificate(keyUri: string) : Promise<boolean>; 70 71 function getAllPublicCertificates(callback: AsyncCallback<CMResult>) : void; 72 function getAllPublicCertificates() : Promise<CMResult>; 73 74 function getAllAppPrivateCertificates(callback: AsyncCallback<CMResult>) : void; 75 function getAllAppPrivateCertificates() : Promise<CMResult>; 76 77 function getPublicCertificate(keyUri: string, callback: AsyncCallback<CMResult>) : void; 78 function getPublicCertificate(keyUri: string, ) : Promise<CMResult>; 79 80 function getPrivateCertificate(keyUri: string, callback: AsyncCallback<CMResult>) : void; 81 function getPrivateCertificate(keyUri: string) : Promise<CMResult>; 82 83 function grantPublicCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<CMResult>) : void; 84 function grantPublicCertificate(keyUri: string, clientAppUid: string) : Promise<CMResult>; 85 86 function isAuthorizedApp(keyUri: string, callback: AsyncCallback<boolean>) : void; 87 function isAuthorizedApp(keyUri: string) : Promise<boolean>; 88 89 function getAuthorizedAppList(keyUri: string, callback: AsyncCallback<CMResult>) : void; 90 function getAuthorizedAppList(keyUri: string) : Promise<CMResult>; 91 92 function removeGrantedPublicCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<boolean>) : void; 93 function removeGrantedPublicCertificate(keyUri: string, clientAppUid: string) : Promise<boolean>; 94 95 function init(authUri: string, spec: CMSignatureSpec, callback: AsyncCallback<CMHandle>) : void; 96 function init(authUri: string, spec: CMSignatureSpec) : Promise<CMHandle>; 97 98 function update(handle: Uint8Array, data: Uint8Array, callback: AsyncCallback<boolean>) : void; 99 function update(handle: Uint8Array, data: Uint8Array) : Promise<boolean>; 100 101 function finish(handle: Uint8Array, callback: AsyncCallback<CMResult>) : void; 102 function finish(handle: Uint8Array, signature: Uint8Array, callback: AsyncCallback<CMResult>) : void; 103 function finish(handle: Uint8Array, signature?: Uint8Array) : Promise<CMResult>; 104 105 function abort(handle: Uint8Array, callback: AsyncCallback<boolean>) : void; 106 function abort(handle: Uint8Array) : Promise<boolean>; 107 108 function installSystemAppCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string): Promise<CMResult>; 109 110 function getAllSystemAppCertificates(): Promise<CMResult>; 111 112 function getSystemAppCertificate(keyUri: string) : Promise<CMResult>; 113 114 function uninstallSystemAppCertificate(keyUri: string) : Promise<void>; 115 116 export interface CertInfo { 117 uri: string; 118 certAlias: string; 119 status: boolean; 120 issuerName: string; 121 subjectName: string; 122 serial: string; 123 notBefore: string; 124 notAfter: string; 125 fingerprintSha256: string; 126 cert: Uint8Array; 127 } 128 129 export interface CertAbstract { 130 uri: string; 131 certAlias: string; 132 status: boolean; 133 subjectName: string; 134 } 135 136 export interface Credential { 137 type: string; 138 alias: string; 139 keyUri: string; 140 certNum: number; 141 keyNum: number; 142 credData:Uint8Array; 143 } 144 145 export interface CredentialAbstract { 146 type: string; 147 alias: string; 148 keyUri: string; 149 } 150 151 export enum CertFileFormat { 152 PEM_DER = 0, 153 P7B = 1, 154 } 155 156 export enum CertScope { 157 CURRENT_USER = 1, 158 GLOBAL_USER = 2 159 } 160 161 export interface CertBlob { 162 inData: Uint8Array; 163 alias: string; 164 certFormat? : CertFileFormat; 165 certScope? : CertScope; 166 } 167 168 export interface CMResult { 169 certList?: Array<CertAbstract>; 170 certInfo?: CertInfo; 171 credentialList?: Array<CredentialAbstract>; 172 credential?: Credential; 173 appUidList?: Array<string>; 174 uri?: string; 175 outData?: Uint8Array; 176 isAuth?: boolean; 177 } 178 179 export interface CMKeyProperties { 180 type: string; 181 alg: string; 182 size: number; 183 padding: string; 184 purpose: string; 185 digest: string; 186 authType: string; 187 authTimeout: string; 188 } 189 190 export enum CmKeyPurpose { 191 CM_KEY_PURPOSE_SIGN = 4, 192 CM_KEY_PURPOSE_VERIFY = 8, 193 } 194 195 export interface CMSignatureSpec { 196 purpose: CmKeyPurpose; 197 } 198 199 export interface CMHandle { 200 handle: Uint8Array; 201 } 202 203 export enum CMErrorCode { 204 CM_SUCCESS = 0, 205 CM_ERROR_GENERIC = 17500001, 206 CM_ERROR_NO_FOUND = 17500002, 207 CM_ERROR_INCORRECT_FORMAT = 17500003, 208 CM_ERROR_MAX_CERT_COUNT_REACHED = 17500004, 209 CM_ERROR_NO_AUTHORIZATION = 17500005, 210 CM_ERROR_ALIAS_LENGTH_REACHED_LIMIT = 17500006, 211 CM_ERROR_PASSWORD_IS_ERR = 17500008 212 } 213} 214 215export default CertManagerFunc; 216