Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

64 Character WPA2 passwords do not work #1921

Closed
MB3hel opened this issue Apr 16, 2016 · 3 comments
Closed

64 Character WPA2 passwords do not work #1921

MB3hel opened this issue Apr 16, 2016 · 3 comments

Comments

@MB3hel
Copy link

MB3hel commented Apr 16, 2016

Basic Info

64 Character WPA2 passwords do not work.

Hardware

Hardware: ESP-12 (NodeMCU 1.0 V3)
Core Version: 2.1.0

Description

64 byte(character) WPA2 passwords do not work. The library will return WL_CONNECT_FAILED then WL_IDLE_STATUS. In ESP8266WiFiSTA.cpp in the begin function there is a condition stating that if the password is longer than 63 characters return WL_CONNECT_FAILED. This needs to be 64 characters because strlen is 1 indexed not 0 indexed. When I made that change it worked correctly.

if(passphrase && strlen(passphrase) > 63) {  //This needs to be 64
        // fail passphrase too long!
        return WL_CONNECT_FAILED;
}

Settings in IDE

Module: NodeMCU 1.0(ESP-12E Module)
Flash Size: 4M
CPU Frequency: 80Mhz
Flash Mode: qio
Flash Frequency: 40Mhz
Upload Using: SERIAL
Reset Method: nodemcu

Sketch

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <IPAddress.h>

const char* ssid = "SSID";
const char* password = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl";

void setup(void)
{
  Serial.begin(115200);
  Serial.println("Connecting...");

  WiFi.begin(ssid, password);

  int s = -999;

  // Wait for connection
  while ((s = WiFi.status()) != WL_CONNECTED) {
    delay(500);
    Serial.println(s);
  }

  Serial.println(WiFi.localIP());

}

void loop(){}

Debug Messages(Serial Monitor)

Connecting...
4
0
0
0
0

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@igrr
Copy link
Member

igrr commented Apr 16, 2016

Please check 2.2.0-rc1 or git version, this has been fixed in 1b8f6d2:

if(passphrase && strlen(passphrase) > 64) {
// fail passphrase too long!
return WL_CONNECT_FAILED;
}
struct station_config conf;
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
if(passphrase) {
if (strlen(passphrase) == 64) // it's not a passphrase, is the PSK
memcpy(reinterpret_cast<char*>(conf.password), passphrase, 64);
else
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
} else {
*conf.password = 0;
}

@zgoda
Copy link

zgoda commented Jun 13, 2017

According to 802.11 spec, WPA passphrases are 8-63 ASCII chars so this is not a bug and I guess it should stay as it was. See https://stackoverflow.com/a/21554182/12138

@percz
Copy link

percz commented Dec 5, 2017

This bug of sorts seems to be in ESP8266WiFiMulti.cpp as well, around line 174...

  if(passphrase && strlen(passphrase) > 63) {
        // fail passphrase to long!
        DEBUG_WIFI_MULTI("[WIFI][APlistAdd] passphrase to long\n");
        return false;
    }

While it's right that the passphrase can't be more than 63 chars it should be possible to specify a 64 hex character PSK, as mentioned in zgoda's link, for a non-ASCII based PSK.
In fact just changing that 63 to a 64 seems to work perfectly, although the ESP8266WiFiSTA.cpp error-handling code added by igrr would be proper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants