Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "includes.h"
00016
00017 #include "common.h"
00018 #include "crypto/sha1.h"
00019
00020
00021 int main(int argc, char *argv[])
00022 {
00023 unsigned char psk[32];
00024 int i;
00025 char *ssid, *passphrase, buf[64], *pos;
00026
00027 if (argc < 2) {
00028 printf("usage: wpa_passphrase <ssid> [passphrase]\n"
00029 "\nIf passphrase is left out, it will be read from "
00030 "stdin\n");
00031 return 1;
00032 }
00033
00034 ssid = argv[1];
00035
00036 if (argc > 2) {
00037 passphrase = argv[2];
00038 } else {
00039 printf("# reading passphrase from stdin\n");
00040 if (fgets(buf, sizeof(buf), stdin) == NULL) {
00041 printf("Failed to read passphrase\n");
00042 return 1;
00043 }
00044 buf[sizeof(buf) - 1] = '\0';
00045 pos = buf;
00046 while (*pos != '\0') {
00047 if (*pos == '\r' || *pos == '\n') {
00048 *pos = '\0';
00049 break;
00050 }
00051 pos++;
00052 }
00053 passphrase = buf;
00054 }
00055
00056 if (os_strlen(passphrase) < 8 || os_strlen(passphrase) > 63) {
00057 printf("Passphrase must be 8..63 characters\n");
00058 return 1;
00059 }
00060
00061 pbkdf2_sha1(passphrase, ssid, os_strlen(ssid), 4096, psk, 32);
00062
00063 printf("network={\n");
00064 printf("\tssid=\"%s\"\n", ssid);
00065 printf("\t#psk=\"%s\"\n", passphrase);
00066 printf("\tpsk=");
00067 for (i = 0; i < 32; i++)
00068 printf("%02x", psk[i]);
00069 printf("\n");
00070 printf("}\n");
00071
00072 return 0;
00073 }