sepolicy: Make wpa_supplicant a HIDL service

Note: The existing rules allowing socket communication will be removed
once we  migrate over to HIDL completely.

(cherry-pick of 2a9595ede2c9a224686e619c2ee5c976dd324ac0) 
Bug: 34603782
Test: Able to connect to wifi networks.
Test: Will be sending for full wifi integration tests
(go/wifi-test-request)
Change-Id: I9ee238fd0017ec330f6eb67ef9049211f7bd4615
diff --git a/public/attributes b/public/attributes
index 0fd9444..171ebd8 100644
--- a/public/attributes
+++ b/public/attributes
@@ -168,3 +168,6 @@
 attribute hal_wifi;
 attribute hal_wifi_client;
 attribute hal_wifi_server;
+attribute hal_wifi_supplicant;
+attribute hal_wifi_supplicant_client;
+attribute hal_wifi_supplicant_server;
diff --git a/public/domain_deprecated.te b/public/domain_deprecated.te
index 66acfd6..aa6ec4e 100644
--- a/public/domain_deprecated.te
+++ b/public/domain_deprecated.te
@@ -228,7 +228,6 @@
   -tee
   -ueventd
   -vold
-  -wpa
 } sysfs:dir { open getattr read ioctl lock }; # search granted in domain
 auditallow {
   domain_deprecated
@@ -243,7 +242,6 @@
   -tee
   -ueventd
   -vold
-  -wpa
 } sysfs:file r_file_perms;
 auditallow {
   domain_deprecated
@@ -258,7 +256,6 @@
   -tee
   -ueventd
   -vold
-  -wpa
 } sysfs:lnk_file { getattr open ioctl lock }; # read granted in domain
 auditallow {
   domain_deprecated
diff --git a/public/hal_wifi_supplicant.te b/public/hal_wifi_supplicant.te
new file mode 100644
index 0000000..8d2c0ea
--- /dev/null
+++ b/public/hal_wifi_supplicant.te
@@ -0,0 +1,55 @@
+# HwBinder IPC from client to server
+binder_call(hal_wifi_supplicant_client, hal_wifi_supplicant_server)
+binder_call(hal_wifi_supplicant_server, hal_wifi_supplicant_client)
+
+# in addition to ioctls whitelisted for all domains, grant hal_wifi_supplicant priv_sock_ioctls.
+allowxperm hal_wifi_supplicant self:udp_socket ioctl priv_sock_ioctls;
+
+r_dir_file(hal_wifi_supplicant, sysfs_type)
+r_dir_file(hal_wifi_supplicant, proc_net)
+
+allow hal_wifi_supplicant kernel:system module_request;
+allow hal_wifi_supplicant self:capability { setuid net_admin setgid net_raw };
+allow hal_wifi_supplicant cgroup:dir create_dir_perms;
+allow hal_wifi_supplicant self:netlink_route_socket nlmsg_write;
+allow hal_wifi_supplicant self:netlink_socket create_socket_perms_no_ioctl;
+allow hal_wifi_supplicant self:netlink_generic_socket create_socket_perms_no_ioctl;
+allow hal_wifi_supplicant self:packet_socket create_socket_perms;
+allowxperm hal_wifi_supplicant self:packet_socket ioctl { unpriv_sock_ioctls priv_sock_ioctls unpriv_tty_ioctls };
+allow hal_wifi_supplicant wifi_data_file:dir create_dir_perms;
+allow hal_wifi_supplicant wifi_data_file:file create_file_perms;
+# TODO(b/35707797): Remove this socket access.
+unix_socket_send(hal_wifi_supplicant, system_wpa, system_server)
+
+# HIDL interface exposed by WPA.
+hwbinder_use(hal_wifi_supplicant)
+binder_call(hal_wifi_supplicant, system_server)
+
+# Create a socket for receiving info from wpa
+allow hal_wifi_supplicant wpa_socket:dir create_dir_perms;
+allow hal_wifi_supplicant wpa_socket:sock_file create_file_perms;
+
+# TODO(b/34131400): Use hwbinder to access keystore.
+use_keystore(hal_wifi_supplicant)
+binder_use(hal_wifi_supplicant)
+
+# WPA (wifi) has a restricted set of permissions from the default.
+allow hal_wifi_supplicant keystore:keystore_key {
+    get
+    sign
+    verify
+};
+
+# Allow wpa_cli to work. wpa_cli creates a socket in
+# /data/misc/wifi/sockets which hal_wifi_supplicant supplicant communicates with.
+userdebug_or_eng(`
+  unix_socket_send(hal_wifi_supplicant, wpa, su)
+')
+
+###
+### neverallow rules
+###
+
+# wpa_supplicant should not trust any data from sdcards
+neverallow hal_wifi_supplicant_server sdcard_type:dir ~getattr;
+neverallow hal_wifi_supplicant_server sdcard_type:file *;
diff --git a/public/service.te b/public/service.te
index a6e36ba..478b00e 100644
--- a/public/service.te
+++ b/public/service.te
@@ -142,4 +142,3 @@
 type wificond_service, service_manager_type;
 type wifiaware_service, app_api_service, system_server_service, service_manager_type;
 type window_service, system_api_service, system_server_service, service_manager_type;
-type wpa_supplicant_service, system_server_service, service_manager_type;
diff --git a/public/wpa.te b/public/wpa.te
deleted file mode 100644
index 20fcd53..0000000
--- a/public/wpa.te
+++ /dev/null
@@ -1,56 +0,0 @@
-# wpa - wpa supplicant or equivalent
-type wpa, domain, domain_deprecated;
-type wpa_exec, exec_type, file_type;
-
-net_domain(wpa)
-# in addition to ioctls whitelisted for all domains, grant wpa priv_sock_ioctls.
-allowxperm wpa self:udp_socket ioctl priv_sock_ioctls;
-
-r_dir_file(wpa, sysfs_type)
-r_dir_file(wpa, proc_net)
-
-allow wpa kernel:system module_request;
-allow wpa self:capability { setuid net_admin setgid net_raw };
-allow wpa cgroup:dir create_dir_perms;
-allow wpa self:netlink_route_socket nlmsg_write;
-allow wpa self:netlink_socket create_socket_perms_no_ioctl;
-allow wpa self:netlink_generic_socket create_socket_perms_no_ioctl;
-allow wpa self:packet_socket create_socket_perms;
-allowxperm wpa self:packet_socket ioctl { unpriv_sock_ioctls priv_sock_ioctls unpriv_tty_ioctls };
-allow wpa wifi_data_file:dir create_dir_perms;
-allow wpa wifi_data_file:file create_file_perms;
-unix_socket_send(wpa, system_wpa, system_server)
-
-# Keystore access via binder.
-binder_use(wpa)
-
-# HIDL interface exposed by WPA.
-hwbinder_use(wpa)
-binder_call(wpa, system_server)
-
-# Create a socket for receiving info from wpa
-allow wpa wpa_socket:dir create_dir_perms;
-allow wpa wpa_socket:sock_file create_file_perms;
-
-use_keystore(wpa)
-
-# WPA (wifi) has a restricted set of permissions from the default.
-allow wpa keystore:keystore_key {
-	get
-	sign
-	verify
-};
-
-# Allow wpa_cli to work. wpa_cli creates a socket in
-# /data/misc/wifi/sockets which wpa supplicant communicates with.
-userdebug_or_eng(`
-  unix_socket_send(wpa, wpa, su)
-')
-
-###
-### neverallow rules
-###
-
-# wpa_supplicant should not trust any data from sdcards
-neverallow wpa sdcard_type:dir ~getattr;
-neverallow wpa sdcard_type:file *;