P2P: Allow passphrase length to be configured
authorJouni Malinen <j@w1.fi>
Sat, 21 Jun 2014 21:15:53 +0000 (00:15 +0300)
committerJouni Malinen <j@w1.fi>
Sat, 21 Jun 2014 21:15:53 +0000 (00:15 +0300)
Previously, eight character random passphrase was generated
automatically for P2P GO. The new p2p_passphrase_len parameter can be
used to increase this length to generate a stronger passphrase for cases
where practicality of manual configuration of legacy devices is not a
concern.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/p2p/p2p.c
src/p2p/p2p.h
wpa_supplicant/config.c
wpa_supplicant/config.h
wpa_supplicant/config_file.c
wpa_supplicant/p2p_supplicant.c
wpa_supplicant/wpa_supplicant.conf

index 104f77b..d0191e7 100644 (file)
@@ -1561,7 +1561,7 @@ void p2p_build_ssid(struct p2p_data *p2p, u8 *ssid, size_t *ssid_len)
 int p2p_go_params(struct p2p_data *p2p, struct p2p_go_neg_results *params)
 {
        p2p_build_ssid(p2p, params->ssid, &params->ssid_len);
-       p2p_random(params->passphrase, 8);
+       p2p_random(params->passphrase, p2p->cfg->passphrase_len);
        return 0;
 }
 
@@ -1595,7 +1595,7 @@ void p2p_go_complete(struct p2p_data *p2p, struct p2p_device *peer)
                                               p2p->op_channel);
                os_memcpy(res.ssid, p2p->ssid, p2p->ssid_len);
                res.ssid_len = p2p->ssid_len;
-               p2p_random(res.passphrase, 8);
+               p2p_random(res.passphrase, p2p->cfg->passphrase_len);
        } else {
                res.freq = peer->oper_freq;
                if (p2p->ssid_len) {
@@ -2388,7 +2388,8 @@ struct p2p_data * p2p_init(const struct p2p_config *cfg)
 {
        struct p2p_data *p2p;
 
-       if (cfg->max_peers < 1)
+       if (cfg->max_peers < 1 ||
+           cfg->passphrase_len < 8 || cfg->passphrase_len > 63)
                return NULL;
 
        p2p = os_zalloc(sizeof(*p2p) + sizeof(*cfg));
@@ -4719,3 +4720,12 @@ void p2p_set_authorized_oob_dev_pw_id(struct p2p_data *p2p, u16 dev_pw_id,
 }
 
 #endif /* CONFIG_WPS_NFC */
+
+
+int p2p_set_passphrase_len(struct p2p_data *p2p, unsigned int len)
+{
+       if (len < 8 || len > 63)
+               return -1;
+       p2p->cfg->passphrase_len = len;
+       return 0;
+}
index 9cf100f..5938aa7 100644 (file)
@@ -395,6 +395,14 @@ struct p2p_config {
        unsigned int max_listen;
 
        /**
+        * passphrase_len - Passphrase length (8..63)
+        *
+        * This parameter controls the length of the random passphrase that is
+        * generated at the GO.
+        */
+       unsigned int passphrase_len;
+
+       /**
         * cb_ctx - Context to use with callback functions
         */
        void *cb_ctx;
@@ -1960,4 +1968,6 @@ void p2p_set_authorized_oob_dev_pw_id(struct p2p_data *p2p, u16 dev_pw_id,
                                      int go_intent,
                                      const u8 *own_interface_addr);
 
+int p2p_set_passphrase_len(struct p2p_data *p2p, unsigned int len);
+
 #endif /* P2P_H */
index 4cea2ef..86d6d72 100644 (file)
@@ -3836,6 +3836,8 @@ static const struct global_parse_data global_fields[] = {
        { INT_RANGE(persistent_reconnect, 0, 1), 0 },
        { INT_RANGE(p2p_intra_bss, 0, 1), CFG_CHANGED_P2P_INTRA_BSS },
        { INT(p2p_group_idle), 0 },
+       { INT_RANGE(p2p_passphrase_len, 8, 63),
+         CFG_CHANGED_P2P_PASSPHRASE_LEN },
        { FUNC(p2p_pref_chan), CFG_CHANGED_P2P_PREF_CHAN },
        { FUNC(p2p_no_go_freq), CFG_CHANGED_P2P_PREF_CHAN },
        { INT_RANGE(p2p_add_cli_chan, 0, 1), 0 },
index 3c2fc4a..52add9d 100644 (file)
@@ -317,6 +317,7 @@ struct wpa_cred {
 #define CFG_CHANGED_P2P_PREF_CHAN BIT(13)
 #define CFG_CHANGED_EXT_PW_BACKEND BIT(14)
 #define CFG_CHANGED_NFC_PASSWORD_TOKEN BIT(15)
+#define CFG_CHANGED_P2P_PASSPHRASE_LEN BIT(16)
 
 /**
  * struct wpa_config - wpa_supplicant configuration data
@@ -716,6 +717,14 @@ struct wpa_config {
        int p2p_group_idle;
 
        /**
+        * p2p_passphrase_len - Passphrase length (8..63) for P2P GO
+        *
+        * This parameter controls the length of the random passphrase that is
+        * generated at the GO.
+        */
+       unsigned int p2p_passphrase_len;
+
+       /**
         * bss_max_count - Maximum number of BSS entries to keep in memory
         */
        unsigned int bss_max_count;
index 58e7111..fd99218 100644 (file)
@@ -1016,6 +1016,9 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
                fprintf(f, "p2p_intra_bss=%u\n", config->p2p_intra_bss);
        if (config->p2p_group_idle)
                fprintf(f, "p2p_group_idle=%u\n", config->p2p_group_idle);
+       if (config->p2p_passphrase_len)
+               fprintf(f, "p2p_passphrase_len=%u\n",
+                       config->p2p_passphrase_len);
        if (config->p2p_pref_chan) {
                unsigned int i;
                fprintf(f, "p2p_pref_chan=");
index 6b85efe..afa8121 100644 (file)
@@ -3949,6 +3949,12 @@ int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
 
        p2p.max_listen = wpa_s->max_remain_on_chan;
 
+       if (wpa_s->conf->p2p_passphrase_len >= 8 &&
+           wpa_s->conf->p2p_passphrase_len <= 63)
+               p2p.passphrase_len = wpa_s->conf->p2p_passphrase_len;
+       else
+               p2p.passphrase_len = 8;
+
        global->p2p = p2p_init(&p2p);
        if (global->p2p == NULL)
                return -1;
@@ -6334,6 +6340,9 @@ void wpas_p2p_update_config(struct wpa_supplicant *wpa_s)
                                   "update failed");
                }
        }
+
+       if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PASSPHRASE_LEN)
+               p2p_set_passphrase_len(p2p, wpa_s->conf->p2p_passphrase_len);
 }
 
 
index 191f206..2a0dc20 100644 (file)
@@ -269,6 +269,12 @@ fast_reauth=1
 # inactive stations.
 #p2p_go_max_inactivity=300
 
+# Passphrase length (8..63) for P2P GO
+#
+# This parameter controls the length of the random passphrase that is
+# generated at the GO. Default: 8.
+#p2p_passphrase_len=8
+
 # Extra delay between concurrent P2P search iterations
 #
 # This value adds extra delay in milliseconds between concurrent search