1e41f4b71Sopenharmony_ci# Network Subsystem Changelog
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Error Code Change for the certVerification and certVerificationSync APIs
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci**Access Level**
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciPublic API
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci**Reason for Change**
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ciThe error code of the **certVerification** and **certVerificationSync** APIs needs to be refined.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci**Change Impact**
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ciThis change is a non-compatible change.
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciBefore change: If a certificate with an invalid context or a self-signed certificate is specified, **2305001 Unspecified error** is displayed.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciAfter 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.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Start API Level**
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ciAPI 11
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**Change Since**
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ciOpenHarmony SDK 5.0.0.38
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**Adaptation Guide**
30e41f4b71Sopenharmony_ciThe 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.
31e41f4b71Sopenharmony_ci```
32e41f4b71Sopenharmony_ciimport { describe, it, expect } from '@ohos/hypium';
33e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
34e41f4b71Sopenharmony_ciimport { networkSecurity } from '@kit.NetworkKit';
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ciconst expectFalse: (n: boolean, name: string) => void = (n: boolean, name: string) => {
37e41f4b71Sopenharmony_ci  try {
38e41f4b71Sopenharmony_ci    expect(n).assertFalse();
39e41f4b71Sopenharmony_ci  }
40e41f4b71Sopenharmony_ci  catch (err) {
41e41f4b71Sopenharmony_ci    console.info(`${name}, test failed`);
42e41f4b71Sopenharmony_ci  }
43e41f4b71Sopenharmony_ci}
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ciconst expectTrue: (n: boolean, name: string) => void = (n: boolean, name: string) => {
46e41f4b71Sopenharmony_ci  try {
47e41f4b71Sopenharmony_ci    expect(n).assertTrue();
48e41f4b71Sopenharmony_ci  } catch (err) {
49e41f4b71Sopenharmony_ci    console.info(`${name}, test failed`);
50e41f4b71Sopenharmony_ci  }
51e41f4b71Sopenharmony_ci}
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ciexport default function netWorkSecurityTest() {
54e41f4b71Sopenharmony_ci  describe('netWorkSecurityTest', () => {
55e41f4b71Sopenharmony_ci    /**
56e41f4b71Sopenharmony_ci     * @tc.name      : Verifying the 2305069 Error Code of the CertVerification Interface
57e41f4b71Sopenharmony_ci     * @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.
58e41f4b71Sopenharmony_ci     */
59e41f4b71Sopenharmony_ci    it('Verifying the 2305069 Error Code of the CertVerification Interface', 0, async (done: Function) => {
60e41f4b71Sopenharmony_ci      let caseName: string = 'Verifying the 2305069 Error Code of the CertVerification Interface';
61e41f4b71Sopenharmony_ci      console.info(`${caseName} test start`);
62e41f4b71Sopenharmony_ci      try {
63e41f4b71Sopenharmony_ci        const cert: networkSecurity.CertBlob = {
64e41f4b71Sopenharmony_ci          type: networkSecurity.CertType.CERT_TYPE_PEM,
65e41f4b71Sopenharmony_ci          data: '-----BEGIN CERTIFICATE-----\n... (xxxx certificate data) ...\n-----END CERTIFICATE-----',
66e41f4b71Sopenharmony_ci        };
67e41f4b71Sopenharmony_ci        networkSecurity.certVerification(cert).then((result) => {
68e41f4b71Sopenharmony_ci          console.info(`${caseName} Certificate verification result:, ${JSON.stringify(result)}`);
69e41f4b71Sopenharmony_ci          expectFalse(true, caseName);
70e41f4b71Sopenharmony_ci          done();
71e41f4b71Sopenharmony_ci        }).catch((error: BusinessError) => {
72e41f4b71Sopenharmony_ci          console.error(`${caseName} Certificate verification failed:', ${JSON.stringify(error)}`);
73e41f4b71Sopenharmony_ci          expectTrue(error.code == 2305069, caseName);
74e41f4b71Sopenharmony_ci          done();
75e41f4b71Sopenharmony_ci        });
76e41f4b71Sopenharmony_ci      } catch (err) {
77e41f4b71Sopenharmony_ci        console.info(`${caseName}  err:${err}`);
78e41f4b71Sopenharmony_ci        expectFalse(true, caseName);
79e41f4b71Sopenharmony_ci        done();
80e41f4b71Sopenharmony_ci      }
81e41f4b71Sopenharmony_ci      console.info(`${caseName} test end`);
82e41f4b71Sopenharmony_ci    });
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci    /**
85e41f4b71Sopenharmony_ci     * @tc.name      : Verifying the 2305018 Error Code of the CertVerification Interface
86e41f4b71Sopenharmony_ci     * @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.
87e41f4b71Sopenharmony_ci     */
88e41f4b71Sopenharmony_ci    it('Verifying the 2305018 Error Code of the CertVerification Interface', 0, async (done: Function) => {
89e41f4b71Sopenharmony_ci      let caseName: string = 'Verifying the 2305018 Error Code of the CertVerification Interface';
90e41f4b71Sopenharmony_ci      console.info(`${caseName} test start`);
91e41f4b71Sopenharmony_ci      try {
92e41f4b71Sopenharmony_ci        const cert: networkSecurity.CertBlob = {
93e41f4b71Sopenharmony_ci          type: networkSecurity.CertType.CERT_TYPE_PEM,
94e41f4b71Sopenharmony_ci          data: 'your Self-signed certificate data',
95e41f4b71Sopenharmony_ci        };
96e41f4b71Sopenharmony_ci        networkSecurity.certVerification(cert).then((result) => {
97e41f4b71Sopenharmony_ci          console.info(`${caseName} Certificate verification result:, ${JSON.stringify(result)}`);
98e41f4b71Sopenharmony_ci          expectFalse(true, caseName);
99e41f4b71Sopenharmony_ci          done();
100e41f4b71Sopenharmony_ci        }).catch((error: BusinessError) => {
101e41f4b71Sopenharmony_ci          console.error(`${caseName} Certificate verification failed:', ${JSON.stringify(error)}`);
102e41f4b71Sopenharmony_ci          expectTrue(error.code == 2305018, caseName);
103e41f4b71Sopenharmony_ci          done();
104e41f4b71Sopenharmony_ci        });
105e41f4b71Sopenharmony_ci      } catch (err) {
106e41f4b71Sopenharmony_ci        console.info(`${caseName}  err:${err}`);
107e41f4b71Sopenharmony_ci        expectFalse(true, caseName);
108e41f4b71Sopenharmony_ci        done();
109e41f4b71Sopenharmony_ci      }
110e41f4b71Sopenharmony_ci      console.info(`${caseName} test end`);
111e41f4b71Sopenharmony_ci    });
112e41f4b71Sopenharmony_ci  })
113e41f4b71Sopenharmony_ci}
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci```
116