1# 网络子系统Changelog
2
3## certVerification接口和certVerificationSync接口错误码2305001细化
4
5**访问级别**
6
7公开接口
8
9**变更原因**
10
11对2305001 - Unspecified error错误进行细化调整。
12
13**变更影响**
14
15该变更为不兼容变更。
16
17变更前:输入上下文非法的证书及自验证证书返回错误码:2305001,错误信息:Unspecified error。
18
19变更后:输入上下文非法的证书返回错误码:2305069,错误信息:Invalid certificate verification context;输入自验证证书返回错误码:2305018,错误信息:Self-signed certificate。
20
21**起始API Level**
22
23API 11
24
25**变更发生版本**
26
27从OpenHarmony SDK 5.0.0.38开始。
28
29**适配指导**
30以下两个用例分别为错误码2305069和2305018的测试用例,测试时请将Verifying the 2305069 Error Code of the CertVerification用例中的'your Self-signed certificate data'替换为开发者真实使用的自签名证书内容。
31```
32import { describe, it, expect } from '@ohos/hypium';
33import { BusinessError } from '@kit.BasicServicesKit';
34import { networkSecurity } from '@kit.NetworkKit';
35
36const expectFalse: (n: boolean, name: string) => void = (n: boolean, name: string) => {
37  try {
38    expect(n).assertFalse();
39  }
40  catch (err) {
41    console.info(`${name}, test failed`);
42  }
43}
44
45const expectTrue: (n: boolean, name: string) => void = (n: boolean, name: string) => {
46  try {
47    expect(n).assertTrue();
48  } catch (err) {
49    console.info(`${name}, test failed`);
50  }
51}
52
53export default function netWorkSecurityTest() {
54  describe('netWorkSecurityTest', () => {
55    /**
56     * @tc.name      : Verifying the 2305069 Error Code of the CertVerification Interface
57     * @tc.desc      : Obtain system preset CA certificates and user installed CA certificates from certificate management, and verify the certificate chain passed in by the application.
58     */
59    it('Verifying the 2305069 Error Code of the CertVerification Interface', 0, async (done: Function) => {
60      let caseName: string = 'Verifying the 2305069 Error Code of the CertVerification Interface';
61      console.info(`${caseName} test start`);
62      try {
63        const cert: networkSecurity.CertBlob = {
64          type: networkSecurity.CertType.CERT_TYPE_PEM,
65          data: '-----BEGIN CERTIFICATE-----\n... (xxxx certificate data) ...\n-----END CERTIFICATE-----',
66        };
67        networkSecurity.certVerification(cert).then((result) => {
68          console.info(`${caseName} Certificate verification result:, ${JSON.stringify(result)}`);
69          expectFalse(true, caseName);
70          done();
71        }).catch((error: BusinessError) => {
72          console.error(`${caseName} Certificate verification failed:', ${JSON.stringify(error)}`);
73          expectTrue(error.code == 2305069, caseName);
74          done();
75        });
76      } catch (err) {
77        console.info(`${caseName}  err:${err}`);
78        expectFalse(true, caseName);
79        done();
80      }
81      console.info(`${caseName} test end`);
82    });
83
84    /**
85     * @tc.name      : Verifying the 2305018 Error Code of the CertVerification Interface
86     * @tc.desc      : Obtain system preset CA certificates and user installed CA certificates from certificate management, and verify the certificate chain passed in by the application.
87     */
88    it('Verifying the 2305018 Error Code of the CertVerification Interface', 0, async (done: Function) => {
89      let caseName: string = 'Verifying the 2305018 Error Code of the CertVerification Interface';
90      console.info(`${caseName} test start`);
91      try {
92        const cert: networkSecurity.CertBlob = {
93          type: networkSecurity.CertType.CERT_TYPE_PEM,
94          data: 'your Self-signed certificate data',
95        };
96        networkSecurity.certVerification(cert).then((result) => {
97          console.info(`${caseName} Certificate verification result:, ${JSON.stringify(result)}`);
98          expectFalse(true, caseName);
99          done();
100        }).catch((error: BusinessError) => {
101          console.error(`${caseName} Certificate verification failed:', ${JSON.stringify(error)}`);
102          expectTrue(error.code == 2305018, caseName);
103          done();
104        });
105      } catch (err) {
106        console.info(`${caseName}  err:${err}`);
107        expectFalse(true, caseName);
108        done();
109      }
110      console.info(`${caseName} test end`);
111    });
112  })
113}
114
115```
116