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(context: CMContext, callback: AsyncCallback<CMResult>) : void; 27 function getSystemTrustedCertificateList(context: CMContext) : Promise<CMResult>; 28 29 function getSystemTrustedCertificate(context: CMContext, certUri: string, callback: AsyncCallback<CMResult>) : void; 30 function getSystemTrustedCertificate(context: CMContext, certUri: string) : Promise<CMResult>; 31 32 function setCertificateStatus(context: CMContext, certUri: string, store: number, status: boolean, callback: AsyncCallback<boolean>) : void; 33 function setCertificateStatus(context: CMContext, 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 getUserTrustedCertificateList(callback: AsyncCallback<CMResult>) : void; 45 function getUserTrustedCertificateList() : Promise<CMResult>; 46 47 function getUserTrustedCertificate(certUri: string, callback: AsyncCallback<CMResult>) : void; 48 function getUserTrustedCertificate(certUri: string) : Promise<CMResult>; 49 50 function installAppCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback<CMResult>) : void; 51 function installAppCertificate(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 uninstallAppCertificate(keyUri: string, callback: AsyncCallback<boolean>) : void; 66 function uninstallAppCertificate(keyUri: string) : Promise<boolean>; 67 68 function uninstallPrivateCertificate(keyUri: string, callback: AsyncCallback<boolean>) : void; 69 function uninstallPrivateCertificate(keyUri: string) : Promise<boolean>; 70 71 function getAppCertificateList(callback: AsyncCallback<CMResult>) : void; 72 function getAppCertificateList() : Promise<CMResult>; 73 74 function getPrivateCertificateList(callback: AsyncCallback<CMResult>) : void; 75 function getPrivateCertificateList() : Promise<CMResult>; 76 77 function getAppCertificate(keyUri: string, callback: AsyncCallback<CMResult>) : void; 78 function getAppCertificate(keyUri: string, ) : Promise<CMResult>; 79 80 function getPrivateCertificate(keyUri: string, callback: AsyncCallback<CMResult>) : void; 81 function getPrivateCertificate(keyUri: string) : Promise<CMResult>; 82 83 function grantAppCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<CMResult>) : void; 84 function grantAppCertificate(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 removeGrantedAppCertificate(keyUri: string, clientAppUid: string, callback: AsyncCallback<boolean>) : void; 93 function removeGrantedAppCertificate(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 export interface CMContext { 109 userId: string; 110 uid: string; 111 packageName: string; 112 } 113 114 export interface CertInfo { 115 uri: string; 116 certAlias: string; 117 status: boolean; 118 issuerName: string; 119 subjectName: string; 120 serial: string; 121 notBefore: string; 122 notAfter: string; 123 fingerprintSha256: string; 124 cert: Uint8Array; 125 } 126 127 export interface CertAbstract { 128 uri: string; 129 certAlias: string; 130 status: boolean; 131 subjectName: string; 132 } 133 134 export interface Credential { 135 type: string; 136 alias: string; 137 keyUri: string; 138 certNum: number; 139 keyNum: number; 140 credData:Uint8Array; 141 } 142 143 export interface CredentialAbstract { 144 type: string; 145 alias: string; 146 keyUri: string; 147 } 148 149 export interface CertBlob { 150 inData: Uint8Array; 151 alias: string; 152 } 153 154 export interface CMResult { 155 certList?: Array<CertAbstract>; 156 certInfo?: CertInfo; 157 credentialList?: Array<CredentialAbstract>; 158 credential?: Credential; 159 appUidList?: Array<string>; 160 uri?: string; 161 outData?: Uint8Array; 162 isAuth?: boolean; 163 } 164 165 export interface CMKeyProperties { 166 type: string; 167 alg: string; 168 size: number; 169 padding: string; 170 purpose: string; 171 digest: string; 172 authType: string; 173 authTimeout: string; 174 } 175 176 export enum CmKeyPurpose { 177 CM_KEY_PURPOSE_SIGN = 4, 178 CM_KEY_PURPOSE_VERIFY = 8, 179 } 180 181 export interface CMSignatureSpec { 182 purpose: CmKeyPurpose; 183 } 184 185 export interface CMHandle { 186 handle: Uint8Array; 187 } 188 189 export enum CMErrorCode { 190 CM_SUCCESS = 0, 191 CM_ERROR_INNER_ERROR = 17500001, 192 CM_ERROR_NO_PERMISSION = 17500002, 193 CM_ERROR_NO_FOUND = 17500003, 194 CM_ERROR_X509_FORMATE = 17500004, 195 } 196} 197 198export default CertManagerFunc; 199