{
int ca_fd = -1;
const char* permission = "http://tizen.org/privilege/tee.client";
+ struct stat sb;
- ca_fd = open_socket_for_ca(uuid, &open_sock_list);
+ char path[MAX_PATH_LENGTH] = {0};
+ sprintf(path, SOCK_PATH_PREFIX"%s", uuid);
+
+ if ((stat(path, &sb) == 0) && S_ISSOCK(sb.st_mode)) {
+ DMSG("We verified this connection already.");
+ if (get_allowed_path(path, ta_dir, &open_sock_list) < 0) {
+ EMSG("Socket existes but hasn't allowed path.");
+ return TEEC_ERROR_GENERIC;
+ }
+ return TEEC_SUCCESS;
+ }
+ ca_fd = open_socket_for_ca(path, &open_sock_list);
if (ca_fd < 0) {
EMSG("Open socket error");
return TEEC_ERROR_GENERIC;
return TEEC_ERROR_ITEM_NOT_FOUND;
}
+ if (set_allowed_path(path, *ta_dir, &open_sock_list) < 0) {
+ EMSG("Setting allowed path has failed.");
+ return TEEC_ERROR_GENERIC;
+ }
return TEEC_SUCCESS;
}
size = shm_ta.size;
ta_found = TEECI_LoadSecureModule(ta_dir, &uuid, shm_ta.buffer, &size);
- free(ta_dir);
+ //free(ta_dir);
if (ta_found != TA_BINARY_FOUND) {
EMSG(" TA not found");
return TEEC_ERROR_ITEM_NOT_FOUND;
#include <unistd.h>
#define WAIT_SEC 10
-#define SOCK_PATH_PREFIX "/tmp/"
-int open_socket_for_ca(const char *ca_id, struct sock_data* open_sockets[])
+
+int get_allowed_path(const char *path, char **allowed_path, struct sock_data* open_sockets[])
+{
+ for (int i = 0; i < MAX_TA_NUMBER; ++i) {
+ if (open_sockets[i] && strcmp(path, open_sockets[i]->addr) == 0) {
+ *allowed_path = open_sockets[i]->allowed_path;
+ return 0;
+ }
+ }
+ return -1;
+}
+
+int set_allowed_path(const char *path, const char *allowed_path, struct sock_data* open_sockets[])
+{
+ for (int i = 0; i < MAX_TA_NUMBER; ++i) {
+ if (open_sockets[i] && strcmp(path, open_sockets[i]->addr) == 0) {
+ asprintf(&(open_sockets[i]->allowed_path), "%s", allowed_path);
+ return 0;
+ }
+ }
+ return -1;
+}
+
+int open_socket_for_ca(const char *path, struct sock_data* open_sockets[])
{
int sockfd = -1;
int newsockfd = -1;
int portno = 0;
int free_index = -1;
- char path[MAX_PATH_LENGTH] = {0};
- sprintf(path, SOCK_PATH_PREFIX"%s", ca_id);
-
if (access(path, F_OK) == -1) {
DMSG("Socket file doesn't exist. Creating");
close_socket_by_addr(path, open_sockets);
#define MAX_PATH_LENGTH 100
#define N_CONNECTIONS 5
#define MAX_TA_NUMBER 10
+#define SOCK_PATH_PREFIX "/tmp/"
struct sock_data
{
int fd, parent_fd;
char* addr;
+ char* allowed_path;
};
+int get_allowed_path(const char *path, char **allowed_path, struct sock_data* open_sockets[]);
+
+int set_allowed_path(const char *path, const char *allowed_path, struct sock_data* open_sockets[]);
+
/* Open socket on adress /tmp/ca_id and add it to the list of open sockets
* Returns file descriptor of opened socket
* struct sock_data* conn_list[] - list of open sockets which add new socket to*/