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 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 CertInfo { 109 uri: string; 110 certAlias: string; 111 status: boolean; 112 issuerName: string; 113 subjectName: string; 114 serial: string; 115 notBefore: string; 116 notAfter: string; 117 fingerprintSha256: string; 118 cert: Uint8Array; 119 } 120 121 export interface CertAbstract { 122 uri: string; 123 certAlias: string; 124 status: boolean; 125 subjectName: string; 126 } 127 128 export interface Credential { 129 type: string; 130 alias: string; 131 keyUri: string; 132 certNum: number; 133 keyNum: number; 134 credData:Uint8Array; 135 } 136 137 export interface CredentialAbstract { 138 type: string; 139 alias: string; 140 keyUri: string; 141 } 142 143 export interface CertBlob { 144 inData: Uint8Array; 145 alias: string; 146 } 147 148 export interface CMResult { 149 certList?: Array<CertAbstract>; 150 certInfo?: CertInfo; 151 credentialList?: Array<CredentialAbstract>; 152 credential?: Credential; 153 appUidList?: Array<string>; 154 uri?: string; 155 outData?: Uint8Array; 156 isAuth?: boolean; 157 } 158 159 export interface CMKeyProperties { 160 type: string; 161 alg: string; 162 size: number; 163 padding: string; 164 purpose: string; 165 digest: string; 166 authType: string; 167 authTimeout: string; 168 } 169 170 export enum CmKeyPurpose { 171 CM_KEY_PURPOSE_SIGN = 4, 172 CM_KEY_PURPOSE_VERIFY = 8, 173 } 174 175 export interface CMSignatureSpec { 176 purpose: CmKeyPurpose; 177 } 178 179 export interface CMHandle { 180 handle: Uint8Array; 181 } 182 183 export enum CMErrorCode { 184 CM_SUCCESS = 0, 185 CM_ERROR_INNER_ERROR = 17500001, 186 CM_ERROR_NO_PERMISSION = 17500002, 187 CM_ERROR_NO_FOUND = 17500003, 188 CM_ERROR_X509_FORMATE = 17500004, 189 } 190} 191 192export default CertManagerFunc; 193