diff --git a/frameworks/js/napi/websocket/websocket_module/src/net_ssl_c.cpp b/frameworks/js/napi/websocket/websocket_module/src/net_ssl_c.cpp index 8ddbe0575181bb935368345cc8dc882d4a541890..a791a33f52768e6e29f2b36e0d8aaf613c371b52 100644 --- a/frameworks/js/napi/websocket/websocket_module/src/net_ssl_c.cpp +++ b/frameworks/js/napi/websocket/websocket_module/src/net_ssl_c.cpp @@ -28,6 +28,7 @@ #include "net_ssl_verify_cert.h" #include "net_manager_constants.h" #include "network_security_config.h" +#include "netmanager_base_permission.h" struct OHOS::NetStack::Ssl::CertBlob SwitchToCertBlob(const struct NetStack_CertBlob cert) { @@ -206,4 +207,18 @@ int32_t OH_Netstack_IsCleartextPermittedByHostName(const char *hostname, bool *i } return OHOS::NetManagerStandard::NetworkSecurityConfig::GetInstance() .IsCleartextPermitted(std::string(hostname), *isCleartextPermitted); +} + +int32_t OH_Netstack_IsCleartextCfgByComponent(const char *component, bool *componentCfg) +{ + if (!OHOS::NetManagerStandard::NetManagerPermission::IsSystemCaller()) { + NETSTACK_LOGE("Caller not have sys permission"); + return OHOS::NetManagerStandard::NETMANAGER_ERR_NOT_SYSTEM_CALL; + } + if (component == nullptr || componentCfg == nullptr) { + NETSTACK_LOGE("OH_Netstack_IsCleartextCfgByComponent received invalid parameters"); + return OHOS::NetManagerStandard::NETMANAGER_ERR_INVALID_PARAMETER; + } + return OHOS::NetManagerStandard::NetworkSecurityConfig::GetInstance() + .IsCleartextCfgByComponent(std::string(component), *componentCfg); } \ No newline at end of file diff --git a/interfaces/kits/c/net_ssl/BUILD.gn b/interfaces/kits/c/net_ssl/BUILD.gn index 9c3dd374e09e02fdee9a5300cb2d5e4095f5a9fb..a49001ded6a1aedf281193983909a8b1dd516261 100644 --- a/interfaces/kits/c/net_ssl/BUILD.gn +++ b/interfaces/kits/c/net_ssl/BUILD.gn @@ -45,6 +45,7 @@ ohos_shared_library("net_ssl_ndk") { "openssl:libcrypto_shared", "openssl:libssl_shared", "samgr:samgr_proxy", + "netmanager_base:net_manager_common", ] cflags_cc = [ diff --git a/interfaces/kits/c/net_ssl/include/net_ssl_c.h b/interfaces/kits/c/net_ssl/include/net_ssl_c.h index bb94978cb1e33ceb50b88c44e03ae56914d0c118..676ccc4c0c87796962990c44b695fc94c70faebe 100644 --- a/interfaces/kits/c/net_ssl/include/net_ssl_c.h +++ b/interfaces/kits/c/net_ssl/include/net_ssl_c.h @@ -80,6 +80,7 @@ int32_t OH_Netstack_IsCleartextPermitted(bool *isCleartextPermitted); int32_t OH_Netstack_IsCleartextPermittedByHostName(const char *hostname, bool *isCleartextPermitted); +int32_t OH_Netstack_IsCleartextCfgByComponent(const char *component, bool *componentCfg); #ifdef __cplusplus } #endif diff --git a/interfaces/kits/c/net_ssl/libnet_ssl_c.json b/interfaces/kits/c/net_ssl/libnet_ssl_c.json index 30cbe090110ff6054be0161f77e70f93fae62298..f98946f7b9bf4b28c0d780fd798bfaa0565b8af5 100644 --- a/interfaces/kits/c/net_ssl/libnet_ssl_c.json +++ b/interfaces/kits/c/net_ssl/libnet_ssl_c.json @@ -22,5 +22,9 @@ { "first_introduced":"16", "name": "OH_Netstack_IsCleartextPermittedByHostName" + }, + { + "first_introduced": "20", + "name": "OH_Netstack_IsCleartextCfgByComponent" } ] diff --git a/test/fuzztest/netsslinner_fuzzer/BUILD.gn b/test/fuzztest/netsslinner_fuzzer/BUILD.gn index 4adf9dba987b4bc18ef175d5eebb24214b54322f..68c1a1ef918da995bb06295074d6bbdd6c2afb08 100644 --- a/test/fuzztest/netsslinner_fuzzer/BUILD.gn +++ b/test/fuzztest/netsslinner_fuzzer/BUILD.gn @@ -35,6 +35,7 @@ common_external_deps = [ "openssl:libcrypto_shared", "openssl:libssl_shared", "samgr:samgr_proxy", + "netmanager_base:net_manager_common", ] ohos_fuzztest("NetsslInnerFuzzTest") { diff --git a/test/unittest/utils/common_utils/NetStackCommonUtilsTest.cpp b/test/unittest/utils/common_utils/NetStackCommonUtilsTest.cpp index 054ea1a872b8b7ba939f654c7f744d3d2099caae..44124217e35a639cb8efe74d69bb946b41a51088 100644 --- a/test/unittest/utils/common_utils/NetStackCommonUtilsTest.cpp +++ b/test/unittest/utils/common_utils/NetStackCommonUtilsTest.cpp @@ -832,6 +832,13 @@ HWTEST_F(NetStackCommonUtilsTest, IsCertPubKeyInPinned09, TestSize.Level2) "oChTociMee9wno="); EXPECT_TRUE(IsCertPubKeyInPinned(pubkey, pinnedPubkey)); } + +HWTEST_F(NetStackCommonUtilsTest, IsCleartextPermitted01, TestSize.Level2) +{ + std::string url("http://text.com"); + std::string protocol("http://"); + EXPECT_TRUE(IsCleartextPermitted(url, protocol)); +} } // namespace CommonUtils } // namespace NetStack } // namespace OHOS \ No newline at end of file diff --git a/utils/common_utils/src/netstack_common_utils.cpp b/utils/common_utils/src/netstack_common_utils.cpp index 69018132a2958ee3d9d2f18357d6b25618cd7294..c77883b89fb70354e75c531008f500d9de1a900e 100644 --- a/utils/common_utils/src/netstack_common_utils.cpp +++ b/utils/common_utils/src/netstack_common_utils.cpp @@ -597,6 +597,12 @@ bool IsCleartextPermitted(const std::string &url, const std::string &protocol) bool isCleartextPermitted = true; #if HAS_NETMANAGER_BASE using namespace OHOS::NetManagerStandard; + bool isComponetCfg = true; + int32_t ret = NetworkSecurityConfig::GetInstance().IsCleartextCfgByComponent("Network Kit", isComponetCfg); + if (ret || !isComponetCfg) { + NETSTACK_LOGD("Network Kit Component Not Cfg or Cfg False"); + return isCleartextPermitted; + } if (url.find(protocol) != std::string::npos) { std::string hostName = GetHostnameFromURL(url); NetworkSecurityConfig::GetInstance().IsCleartextPermitted(hostName, isCleartextPermitted);