1# Network Subsystem Changelog
2
3## Error Code Change for the certVerification and certVerificationSync APIs
4
5**Access Level**
6
7Public API
8
9**Reason for Change**
10
11The error code of the **certVerification** and **certVerificationSync** APIs needs to be refined.
12
13**Change Impact**
14
15This change is a non-compatible change.
16
17Before change: If a certificate with an invalid context or a self-signed certificate is specified, **2305001 Unspecified error** is displayed.
18
19After change: If the context of a certificate is invalid, **2305069 Invalid certificate verification context** is returned. If the context of a self-signed certificate is invalid, **2305018 Self-signed certificate** is returned.
20
21**Start API Level**
22
23API 11
24
25**Change Since**
26
27OpenHarmony SDK 5.0.0.38
28
29**Adaptation Guide**
30The following two test cases of error codes 2305069 and 2305018 are for your reference. During the test, replace **your Self-signed certificate data** in the **Verifying the 2305069 Error Code of the CertVerification** test case with the actual 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