2005-10-01 14:20:13 +04:00
|
|
|
/*
|
|
|
|
* WPA Supplicant - ASCII passphrase to WPA PSK tool
|
2006-04-12 19:07:34 +04:00
|
|
|
* Copyright (c) 2003-2005, Jouni Malinen <jkmaline@cc.hut.fi>
|
2005-10-01 14:20:13 +04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed under the terms of BSD
|
|
|
|
* license.
|
|
|
|
*
|
|
|
|
* See README and COPYING for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "sha1.h"
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
unsigned char psk[32];
|
|
|
|
int i;
|
2006-04-12 19:07:34 +04:00
|
|
|
char *ssid, *passphrase, buf[64], *pos;
|
2005-10-01 14:20:13 +04:00
|
|
|
|
2006-04-12 19:07:34 +04:00
|
|
|
if (argc < 2) {
|
|
|
|
printf("usage: wpa_passphrase <ssid> [passphrase]\n"
|
|
|
|
"\nIf passphrase is left out, it will be read from "
|
|
|
|
"stdin\n");
|
2005-10-01 14:20:13 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssid = argv[1];
|
2006-04-12 19:07:34 +04:00
|
|
|
|
|
|
|
if (argc > 2) {
|
|
|
|
passphrase = argv[2];
|
|
|
|
} else {
|
|
|
|
printf("# reading passphrase from stdin\n");
|
|
|
|
if (fgets(buf, sizeof(buf), stdin) == NULL) {
|
|
|
|
printf("Failed to read passphrase\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
|
|
pos = buf;
|
|
|
|
while (*pos != '\0') {
|
|
|
|
if (*pos == '\r' || *pos == '\n') {
|
|
|
|
*pos = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
passphrase = buf;
|
|
|
|
}
|
2005-10-01 14:20:13 +04:00
|
|
|
|
|
|
|
if (strlen(passphrase) < 8 || strlen(passphrase) > 63) {
|
|
|
|
printf("Passphrase must be 8..63 characters\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pbkdf2_sha1(passphrase, ssid, strlen(ssid), 4096, psk, 32);
|
|
|
|
|
|
|
|
printf("network={\n");
|
|
|
|
printf("\tssid=\"%s\"\n", ssid);
|
|
|
|
printf("\t#psk=\"%s\"\n", passphrase);
|
|
|
|
printf("\tpsk=");
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
printf("%02x", psk[i]);
|
|
|
|
printf("\n");
|
|
|
|
printf("}\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|