Some changes for PSK (#228) 25/256725/1 accepted/tizen/unified/20210413.021236 submit/tizen/20210412.063618
author문선아/Tizen Platform Lab(SR)/Engineer/삼성전자 <seonah1.moon@samsung.com>
Mon, 12 Apr 2021 03:48:29 +0000 (12:48 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Mon, 12 Apr 2021 03:50:31 +0000 (12:50 +0900)
* Use calloc/free for auth frame

* Limit PSK length to 512

Change-Id: I17afa6dc51cffb463f8ef9e44e0725b8ff4dc06e

include/vine.h
src/vine-auth.cpp
src/vine-security.cpp

index 068e248..aaf2e6b 100755 (executable)
@@ -1319,7 +1319,7 @@ int vine_security_get_private_key(vine_security_h security, char **key_path);
  * @remarks The @psk is exchanged over a websocket connection.
  * @since_tizen 6.5
  * @param[in] security The security handle.
- * @param[in] psk The preshared key
+ * @param[in] psk The preshared key. This is limited to the maximum 512 characters.
  * @return 0 on success, otherwise a negative error value
  * @retval #VINE_ERROR_NONE    Successful
  * @retval #VINE_ERROR_INVALID_PARAMTER        Invalid parameter
index 10b8b4b..049d1a3 100644 (file)
@@ -25,7 +25,7 @@ unsigned char *alloc_auth_frame(unsigned char ver,
                int data_len, const unsigned char *data, int *size)
 {
        *size = 5 + data_len;
-       unsigned char *buf = new unsigned char[*size];
+       unsigned char *buf = (unsigned char *)calloc(*size, sizeof(unsigned char));
        if (buf == NULL) {
                VINE_LOGE("Out of memory");
                return NULL;
@@ -43,7 +43,7 @@ unsigned char *alloc_auth_frame(unsigned char ver,
 
 void release_auth_frame(unsigned char *buf)
 {
-       delete [] buf;
+       free(buf);
 }
 
 bool parse_auth_frame(unsigned char *buf, size_t buf_size,
index 57e9f80..2eaccd7 100755 (executable)
@@ -20,6 +20,8 @@
 #include "vine-log.h"
 #include "vine-utils.h"
 
+#define VINE_SECURITY_PSK_MAX_LEN 512
+
 typedef struct {
        vine_security_type_e type;
        int flags;
@@ -241,6 +243,8 @@ int _vine_security_set_psk(vine_security_h security, const char *psk)
 {
        RET_VAL_IF(security == NULL, VINE_ERROR_INVALID_PARAMETER, "security is NULL");
        RET_VAL_IF(psk == NULL, VINE_ERROR_INVALID_PARAMETER, "psk is NULL");
+       RET_VAL_IF(strlen(psk) > VINE_SECURITY_PSK_MAX_LEN,
+                       VINE_ERROR_INVALID_PARAMETER, "psk should be less than or equal to 512");
 
        vine_security_s *s = (vine_security_s *)security;
        if (s->psk)