Check the minimun length of PSK
authorCheoleun Moon <chleun.moon@samsung.com>
Tue, 3 Mar 2020 11:11:43 +0000 (20:11 +0900)
committerCheoleun Moon <chleun.moon@samsung.com>
Tue, 3 Mar 2020 11:11:43 +0000 (20:11 +0900)
include/wifi-aware.h
src/include/wifi-aware-data-path.h
src/wifi-aware-data-path.c
src/wifi-aware.c

index 9e3eccf..645e6c2 100644 (file)
@@ -632,10 +632,9 @@ int wifi_aware_data_path_set_psk(wifi_aware_data_path_h data_path, char *key);
  * @brief Set a PMK for Wi-Fi Aware Data Path. It can be used only when secury_type is WIFI_AWARE_SECURITY_TYPE_PMK.
  * @since_tizen 6.0
  * @param[in] data_path
- * @param[in] key
- * @param[in] key_len
+ * @param[in] key Pairwise Master Key. Its length should be 32
  */
-int wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, unsigned char *key, size_t key_len);
+int wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, unsigned char *key);
 
 // only for responder
 /**
@@ -643,10 +642,14 @@ int wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, unsigned char
  * @remarks The service specific information can be set only when the role is WIFI_AWARE_DATA_PATH_RESPONDER.
  * @since_tizen 6.0
  * @param[in] data_path
- * @param[in] key
- * @param[in] key_len
+ * @param[in] service_specific_info
+ * @param[in] service_specific_info_len
  */
 int wifi_aware_data_path_set_service_specific_info(wifi_aware_data_path_h data_path, unsigned char *service_specific_info, size_t service_specific_info_len);
+// TODO:
+// We are considering
+// removing wifi_aware_data_path_set_service_specific_info() and
+// adding wifi_aware_data_path_set_port() and wifi_aware_data_path_set_ip_address().
 
 /**
  * @brief Destroy a handle for Wi-Fi Aware Data Path
index c2dff6f..b22d772 100644 (file)
@@ -27,8 +27,9 @@
 extern "C" {
 #endif
 
+#define WIFI_AWARE_MIN_PSK_LEN 8
 #define WIFI_AWARE_MAX_PSK_LEN 63
-#define WIFI_AWARE_MAX_PMK_LEN 32
+#define WIFI_AWARE_PMK_LEN 32
 
 int _wifi_aware_data_path_handle_create(wifi_aware_session_h session, wifi_aware_peer_h peer,
                wifi_aware_data_path_role_e role, wifi_aware_data_path_h *data_path);
@@ -36,7 +37,7 @@ int _wifi_aware_data_path_set_security(wifi_aware_data_path_h data_path,
                wifi_aware_security_type_e security_type);
 int _wifi_aware_data_path_set_psk(wifi_aware_data_path_h data_path, const char *key);
 int _wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path,
-               unsigned char *key, size_t key_len);
+               unsigned char *key);
 int _wifi_aware_data_path_set_service_specific_info(wifi_aware_data_path_h data_path,
                unsigned char *service_specific_info, size_t service_specific_info_len);
 int _wifi_aware_data_path_destroy(wifi_aware_data_path_h data_path);
index cd51fee..f3bf9cf 100644 (file)
@@ -43,7 +43,7 @@ typedef struct {
        wifi_aware_data_path_role_e role;
        wifi_aware_security_type_e security_type;
        char psk[WIFI_AWARE_MAX_PSK_LEN + 1];
-       unsigned char pmk[WIFI_AWARE_MAX_PMK_LEN];
+       unsigned char pmk[WIFI_AWARE_PMK_LEN];
        size_t pmk_len;
 
        unsigned char specific_info[WIFI_AWARE_MAX_SERVICE_SPECIFIC_INFO_LEN];
@@ -131,6 +131,14 @@ int _wifi_aware_data_path_set_security(wifi_aware_data_path_h data_path,
        return WIFI_AWARE_ERROR_NONE;
 }
 
+static bool __is_valid_psk_len(const char *key)
+{
+       size_t len = strlen(key);
+       WIFI_AWARE_LOGD("PSK len: %d", len);
+
+       return len >= WIFI_AWARE_MIN_PSK_LEN && len <= WIFI_AWARE_MAX_PSK_LEN;
+}
+
 int _wifi_aware_data_path_set_psk(wifi_aware_data_path_h data_path, const char *key)
 {
        __WIFI_AWARE_FUNC_ENTER__;
@@ -141,20 +149,16 @@ int _wifi_aware_data_path_set_psk(wifi_aware_data_path_h data_path, const char *
        RET_VAL_IF(ndp->security_type != WIFI_AWARE_SECURITY_TYPE_PSK,
                WIFI_AWARE_ERROR_INVALID_OPERATION, "security type is not WIFI_AWARE_SECURITY_TYPE_PSK");
 
-       size_t len = strlen(key);
-       if (len > WIFI_AWARE_MAX_PSK_LEN) {
-               WIFI_AWARE_LOGE("Password is too long");
+       if (!__is_valid_psk_len(key)) {
+               WIFI_AWARE_LOGE("The length of the password should be equal to or greater than 8 and less than 64");
                return WIFI_AWARE_ERROR_INVALID_PARAMETER;
        }
 
-       if (len == 0)
-               return WIFI_AWARE_ERROR_NONE;
-
        strncpy(ndp->psk, key, WIFI_AWARE_MAX_PSK_LEN);
        return WIFI_AWARE_ERROR_NONE;
 }
 
-int _wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, unsigned char *key, size_t key_len)
+int _wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, unsigned char *key)
 {
        __WIFI_AWARE_FUNC_ENTER__;
 
@@ -163,15 +167,7 @@ int _wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, unsigned cha
        RET_VAL_IF(ndp->security_type != WIFI_AWARE_SECURITY_TYPE_PMK,
                WIFI_AWARE_ERROR_INVALID_OPERATION, "security type is not WIFI_AWARE_SECURITY_TYPE_PMK");
 
-       if (key_len > WIFI_AWARE_MAX_PMK_LEN) {
-               WIFI_AWARE_LOGE("PMK is too long");
-               return WIFI_AWARE_ERROR_INVALID_PARAMETER;
-       }
-
-       if (key_len == 0)
-               return WIFI_AWARE_ERROR_NONE;
-
-       memcpy(ndp->pmk, key, key_len);
+       memcpy(ndp->pmk, key, WIFI_AWARE_PMK_LEN);
        return WIFI_AWARE_ERROR_NONE;
 }
 
@@ -183,7 +179,7 @@ int _wifi_aware_data_path_set_service_specific_info(wifi_aware_data_path_h data_
        RET_VAL_IF(data_path== NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "data_path is NULL");
        wifi_aware_data_path_s *ndp = (wifi_aware_data_path_s *)data_path;
 
-       if (service_specific_info_len > WIFI_AWARE_MAX_PMK_LEN) {
+       if (service_specific_info_len > WIFI_AWARE_MAX_SERVICE_SPECIFIC_INFO_LEN) {
                WIFI_AWARE_LOGE("service_specific_info is too long");
                return WIFI_AWARE_ERROR_INVALID_PARAMETER;
        }
@@ -243,9 +239,8 @@ static void __data_path_open_reply(GObject *src, GAsyncResult *res, gpointer use
                // TODO: Parameter parsing
        }
        
-       if (error == WIFI_AWARE_ERROR_NONE) {
+       if (error == WIFI_AWARE_ERROR_NONE)
                __data_path_open(data_path);
-       }
        __data_path_invoke_callback(data_path, error, NULL, NULL, 0);
 }
 
@@ -284,7 +279,7 @@ int _wifi_aware_data_path_open(wifi_aware_data_path_h data_path,
                                ndp->specific_info,
                                ndp->specific_info_len,
                                ndp->pmk,
-                               ndp->pmk_len,
+                               WIFI_AWARE_PMK_LEN,
                                __data_path_open_reply);
        }
 
index 695d104..65f071e 100644 (file)
@@ -612,7 +612,7 @@ API int wifi_aware_data_path_set_psk(wifi_aware_data_path_h data_path, char *key
        return ret;
 }
 
-API int wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, unsigned char *key, size_t key_len)
+API int wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, unsigned char *key)
 {
        int ret = WIFI_AWARE_ERROR_NONE;
 
@@ -621,7 +621,7 @@ API int wifi_aware_data_path_set_pmk(wifi_aware_data_path_h data_path, unsigned
        RET_VAL_IF(!_wifi_aware_is_initialized(), WIFI_AWARE_ERROR_NOT_INITIALIZED, "Not initialized");
        RET_VAL_IF(data_path == NULL, WIFI_AWARE_ERROR_INVALID_PARAMETER, "Data path is NULL");
 
-       ret = _wifi_aware_data_path_set_pmk(data_path, key, key_len);
+       ret = _wifi_aware_data_path_set_pmk(data_path, key);
 
        __WIFI_AWARE_FUNC_EXIT__;
        return ret;