161847f8eSopenharmony_ci/* 261847f8eSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 461847f8eSopenharmony_ci * you may not use this file except in compliance with the License. 561847f8eSopenharmony_ci * You may obtain a copy of the License at 661847f8eSopenharmony_ci * 761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 861847f8eSopenharmony_ci * 961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and 1361847f8eSopenharmony_ci * limitations under the License. 1461847f8eSopenharmony_ci */ 1561847f8eSopenharmony_ci 1661847f8eSopenharmony_ci/** 1761847f8eSopenharmony_ci * @file 1861847f8eSopenharmony_ci * @kit NetworkKit 1961847f8eSopenharmony_ci */ 2061847f8eSopenharmony_ci 2161847f8eSopenharmony_ciimport type { AsyncCallback } from './@ohos.base'; 2261847f8eSopenharmony_ci 2361847f8eSopenharmony_ci/** 2461847f8eSopenharmony_ci * Provides networkSecurity related APIs. 2561847f8eSopenharmony_ci * @namespace networkSecurity 2661847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetStack 2761847f8eSopenharmony_ci * @since 11 2861847f8eSopenharmony_ci */ 2961847f8eSopenharmony_cideclare namespace networkSecurity { 3061847f8eSopenharmony_ci /** 3161847f8eSopenharmony_ci * Defines the certificate type. 3261847f8eSopenharmony_ci * @enum {number} 3361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetStack 3461847f8eSopenharmony_ci * @since 11 3561847f8eSopenharmony_ci */ 3661847f8eSopenharmony_ci export enum CertType { 3761847f8eSopenharmony_ci /** 3861847f8eSopenharmony_ci * PEM type certificate. 3961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetStack 4061847f8eSopenharmony_ci * @since 11 4161847f8eSopenharmony_ci */ 4261847f8eSopenharmony_ci CERT_TYPE_PEM = 0, 4361847f8eSopenharmony_ci 4461847f8eSopenharmony_ci /** 4561847f8eSopenharmony_ci * DER type certificate. 4661847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetStack 4761847f8eSopenharmony_ci * @since 11 4861847f8eSopenharmony_ci */ 4961847f8eSopenharmony_ci CERT_TYPE_DER = 1 5061847f8eSopenharmony_ci } 5161847f8eSopenharmony_ci 5261847f8eSopenharmony_ci /** 5361847f8eSopenharmony_ci * Define the certificate content. 5461847f8eSopenharmony_ci * @interface CertBlob 5561847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetStack 5661847f8eSopenharmony_ci * @since 11 5761847f8eSopenharmony_ci */ 5861847f8eSopenharmony_ci export interface CertBlob { 5961847f8eSopenharmony_ci /** 6061847f8eSopenharmony_ci * Certificate type. 6161847f8eSopenharmony_ci * @type { CertType } 6261847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetStack 6361847f8eSopenharmony_ci * @since 11 6461847f8eSopenharmony_ci */ 6561847f8eSopenharmony_ci type: CertType; 6661847f8eSopenharmony_ci 6761847f8eSopenharmony_ci /** 6861847f8eSopenharmony_ci * Certificate data. 6961847f8eSopenharmony_ci * @type {string | ArrayBuffer} 7061847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetStack 7161847f8eSopenharmony_ci * @since 11 7261847f8eSopenharmony_ci */ 7361847f8eSopenharmony_ci data: string | ArrayBuffer; 7461847f8eSopenharmony_ci } 7561847f8eSopenharmony_ci 7661847f8eSopenharmony_ci /** 7761847f8eSopenharmony_ci * Certificate verification to the server. 7861847f8eSopenharmony_ci * @param { CertBlob } cert - Certificates to be verified. 7961847f8eSopenharmony_ci * @param { CertBlob } [caCert] - Incoming custom CA cert. 8061847f8eSopenharmony_ci * @returns { Promise<number> } The promise returned by the function. 8161847f8eSopenharmony_ci * Number equals 0 if verify of certification from server succeed, else verify failed. 8261847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 8361847f8eSopenharmony_ci * @throws { BusinessError } 2305001 - Unspecified error. 8461847f8eSopenharmony_ci * @throws { BusinessError } 2305002 - Unable to get issuer certificate. 8561847f8eSopenharmony_ci * @throws { BusinessError } 2305003 - Unable to get certificate revocation list (CRL). 8661847f8eSopenharmony_ci * @throws { BusinessError } 2305004 - Unable to decrypt certificate signature. 8761847f8eSopenharmony_ci * @throws { BusinessError } 2305005 - Unable to decrypt CRL signature. 8861847f8eSopenharmony_ci * @throws { BusinessError } 2305006 - Unable to decode issuer public key. 8961847f8eSopenharmony_ci * @throws { BusinessError } 2305007 - Certificate signature failure. 9061847f8eSopenharmony_ci * @throws { BusinessError } 2305008 - CRL signature failure. 9161847f8eSopenharmony_ci * @throws { BusinessError } 2305009 - Certificate is not yet valid. 9261847f8eSopenharmony_ci * @throws { BusinessError } 2305010 - Certificate has expired. 9361847f8eSopenharmony_ci * @throws { BusinessError } 2305011 - CRL is not yet valid. 9461847f8eSopenharmony_ci * @throws { BusinessError } 2305012 - CRL has expired. 9561847f8eSopenharmony_ci * @throws { BusinessError } 2305023 - Certificate has been revoked. 9661847f8eSopenharmony_ci * @throws { BusinessError } 2305024 - Invalid certificate authority (CA). 9761847f8eSopenharmony_ci * @throws { BusinessError } 2305027 - Certificate is untrusted. 9861847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetStack 9961847f8eSopenharmony_ci * @since 11 10061847f8eSopenharmony_ci */ 10161847f8eSopenharmony_ci /** 10261847f8eSopenharmony_ci * Certificate verification to the server. 10361847f8eSopenharmony_ci * @param { CertBlob } cert - Certificates to be verified. 10461847f8eSopenharmony_ci * @param { CertBlob } [caCert] - Incoming custom CA cert. 10561847f8eSopenharmony_ci * @returns { Promise<number> } The promise returned by the function. 10661847f8eSopenharmony_ci * Number equals 0 if verify of certification from server succeed, else verify failed. 10761847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 10861847f8eSopenharmony_ci * @throws { BusinessError } 2305001 - Unspecified error. 10961847f8eSopenharmony_ci * @throws { BusinessError } 2305002 - Unable to get issuer certificate. 11061847f8eSopenharmony_ci * @throws { BusinessError } 2305003 - Unable to get certificate revocation list (CRL). 11161847f8eSopenharmony_ci * @throws { BusinessError } 2305004 - Unable to decrypt certificate signature. 11261847f8eSopenharmony_ci * @throws { BusinessError } 2305005 - Unable to decrypt CRL signature. 11361847f8eSopenharmony_ci * @throws { BusinessError } 2305006 - Unable to decode issuer public key. 11461847f8eSopenharmony_ci * @throws { BusinessError } 2305007 - Certificate signature failure. 11561847f8eSopenharmony_ci * @throws { BusinessError } 2305008 - CRL signature failure. 11661847f8eSopenharmony_ci * @throws { BusinessError } 2305009 - Certificate is not yet valid. 11761847f8eSopenharmony_ci * @throws { BusinessError } 2305010 - Certificate has expired. 11861847f8eSopenharmony_ci * @throws { BusinessError } 2305011 - CRL is not yet valid. 11961847f8eSopenharmony_ci * @throws { BusinessError } 2305012 - CRL has expired. 12061847f8eSopenharmony_ci * @throws { BusinessError } 2305018 - Self-signed certificate. 12161847f8eSopenharmony_ci * @throws { BusinessError } 2305023 - Certificate has been revoked. 12261847f8eSopenharmony_ci * @throws { BusinessError } 2305024 - Invalid certificate authority (CA). 12361847f8eSopenharmony_ci * @throws { BusinessError } 2305027 - Certificate is untrusted. 12461847f8eSopenharmony_ci * @throws { BusinessError } 2305069 - Invalid certificate verification context. 12561847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetStack 12661847f8eSopenharmony_ci * @since 12 12761847f8eSopenharmony_ci */ 12861847f8eSopenharmony_ci export function certVerification(cert: CertBlob, caCert?: CertBlob): Promise<number>; 12961847f8eSopenharmony_ci 13061847f8eSopenharmony_ci /** 13161847f8eSopenharmony_ci * Certificate verification to the server. 13261847f8eSopenharmony_ci * @param { CertBlob } cert - Certificates to be verified. 13361847f8eSopenharmony_ci * @param { CertBlob } [caCert] - Incoming custom CA cert. 13461847f8eSopenharmony_ci * @returns { number } Returns 0 if verify of certification from server succeed, else verify failed. 13561847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 13661847f8eSopenharmony_ci * @throws { BusinessError } 2305001 - Unspecified error. 13761847f8eSopenharmony_ci * @throws { BusinessError } 2305002 - Unable to get issuer certificate. 13861847f8eSopenharmony_ci * @throws { BusinessError } 2305003 - Unable to get certificate revocation list (CRL). 13961847f8eSopenharmony_ci * @throws { BusinessError } 2305004 - Unable to decrypt certificate signature. 14061847f8eSopenharmony_ci * @throws { BusinessError } 2305005 - Unable to decrypt CRL signature. 14161847f8eSopenharmony_ci * @throws { BusinessError } 2305006 - Unable to decode issuer public key. 14261847f8eSopenharmony_ci * @throws { BusinessError } 2305007 - Certificate signature failure. 14361847f8eSopenharmony_ci * @throws { BusinessError } 2305008 - CRL signature failure. 14461847f8eSopenharmony_ci * @throws { BusinessError } 2305009 - Certificate is not yet valid. 14561847f8eSopenharmony_ci * @throws { BusinessError } 2305010 - Certificate has expired. 14661847f8eSopenharmony_ci * @throws { BusinessError } 2305011 - CRL is not yet valid. 14761847f8eSopenharmony_ci * @throws { BusinessError } 2305012 - CRL has expired. 14861847f8eSopenharmony_ci * @throws { BusinessError } 2305023 - Certificate has been revoked. 14961847f8eSopenharmony_ci * @throws { BusinessError } 2305024 - Invalid certificate authority (CA). 15061847f8eSopenharmony_ci * @throws { BusinessError } 2305027 - Certificate is untrusted. 15161847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetStack 15261847f8eSopenharmony_ci * @since 11 15361847f8eSopenharmony_ci */ 15461847f8eSopenharmony_ci /** 15561847f8eSopenharmony_ci * Certificate verification to the server. 15661847f8eSopenharmony_ci * @param { CertBlob } cert - Certificates to be verified. 15761847f8eSopenharmony_ci * @param { CertBlob } [caCert] - Incoming custom CA cert. 15861847f8eSopenharmony_ci * @returns { number } Returns 0 if verify of certification from server succeed, else verify failed. 15961847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 16061847f8eSopenharmony_ci * @throws { BusinessError } 2305001 - Unspecified error. 16161847f8eSopenharmony_ci * @throws { BusinessError } 2305002 - Unable to get issuer certificate. 16261847f8eSopenharmony_ci * @throws { BusinessError } 2305003 - Unable to get certificate revocation list (CRL). 16361847f8eSopenharmony_ci * @throws { BusinessError } 2305004 - Unable to decrypt certificate signature. 16461847f8eSopenharmony_ci * @throws { BusinessError } 2305005 - Unable to decrypt CRL signature. 16561847f8eSopenharmony_ci * @throws { BusinessError } 2305006 - Unable to decode issuer public key. 16661847f8eSopenharmony_ci * @throws { BusinessError } 2305007 - Certificate signature failure. 16761847f8eSopenharmony_ci * @throws { BusinessError } 2305008 - CRL signature failure. 16861847f8eSopenharmony_ci * @throws { BusinessError } 2305009 - Certificate is not yet valid. 16961847f8eSopenharmony_ci * @throws { BusinessError } 2305010 - Certificate has expired. 17061847f8eSopenharmony_ci * @throws { BusinessError } 2305011 - CRL is not yet valid. 17161847f8eSopenharmony_ci * @throws { BusinessError } 2305012 - CRL has expired. 17261847f8eSopenharmony_ci * @throws { BusinessError } 2305018 - Self-signed certificate. 17361847f8eSopenharmony_ci * @throws { BusinessError } 2305023 - Certificate has been revoked. 17461847f8eSopenharmony_ci * @throws { BusinessError } 2305024 - Invalid certificate authority (CA). 17561847f8eSopenharmony_ci * @throws { BusinessError } 2305027 - Certificate is untrusted. 17661847f8eSopenharmony_ci * @throws { BusinessError } 2305069 - Invalid certificate verification context. 17761847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetStack 17861847f8eSopenharmony_ci * @since 12 17961847f8eSopenharmony_ci */ 18061847f8eSopenharmony_ci export function certVerificationSync(cert: CertBlob, caCert?: CertBlob): number; 18161847f8eSopenharmony_ci} 18261847f8eSopenharmony_ci 18361847f8eSopenharmony_ciexport default networkSecurity; 184