Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

wpa_passphrase.c 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * WPA Supplicant - ASCII passphrase to WPA PSK tool
  3. * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #include "common.h"
  16. #include "crypto/sha1.h"
  17. int main(int argc, char *argv[])
  18. {
  19. unsigned char psk[32];
  20. int i;
  21. char *ssid, *passphrase, buf[64], *pos;
  22. if (argc < 2) {
  23. printf("usage: wpa_passphrase <ssid> [passphrase]\n"
  24. "\nIf passphrase is left out, it will be read from "
  25. "stdin\n");
  26. return 1;
  27. }
  28. ssid = argv[1];
  29. if (argc > 2) {
  30. passphrase = argv[2];
  31. } else {
  32. printf("# reading passphrase from stdin\n");
  33. if (fgets(buf, sizeof(buf), stdin) == NULL) {
  34. printf("Failed to read passphrase\n");
  35. return 1;
  36. }
  37. buf[sizeof(buf) - 1] = '\0';
  38. pos = buf;
  39. while (*pos != '\0') {
  40. if (*pos == '\r' || *pos == '\n') {
  41. *pos = '\0';
  42. break;
  43. }
  44. pos++;
  45. }
  46. passphrase = buf;
  47. }
  48. if (os_strlen(passphrase) < 8 || os_strlen(passphrase) > 63) {
  49. printf("Passphrase must be 8..63 characters\n");
  50. return 1;
  51. }
  52. pbkdf2_sha1(passphrase, ssid, os_strlen(ssid), 4096, psk, 32);
  53. printf("network={\n");
  54. printf("\tssid=\"%s\"\n", ssid);
  55. printf("\t#psk=\"%s\"\n", passphrase);
  56. printf("\tpsk=");
  57. for (i = 0; i < 32; i++)
  58. printf("%02x", psk[i]);
  59. printf("\n");
  60. printf("}\n");
  61. return 0;
  62. }