From patchwork Thu Jul 21 02:13:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 12924682 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E9841FA5 for ; Thu, 21 Jul 2022 02:15:17 +0000 (UTC) Received: by mail-ot1-f46.google.com with SMTP id w6-20020a056830410600b0061c99652493so173582ott.8 for ; Wed, 20 Jul 2022 19:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7W9vQDbjB1NxCd28MDgNH6QLWOgBBnRi7TVfoKS+/QQ=; b=SsrXfoJ660zLv203sAWrseJQ0BI8VWgMA8IHj+Px2+5cmh6V8V81Wt9L/RnLGnf4TW Vppek0MwHDnUd5Vn5vjyRgV2HzbDbrZbHFATswCeCia1olmo9sBytpvijc78fjN8S8VM euZPxDtxwQFdjvTJejJRkv2TgDSuvw5kzuANOTseyCf5fCsPs99tZYvnc3iKO6VxExA1 aI6g6hYJLDAHjCzGml5GMRSsZxMWo8RiOvf2c48aGKogo0QHsYkK96IwM3PWzLRjPxsw fAUfesdeSG7RoOCwgHsCu0Gyx9Si1DP36bgdfDfdmLnvgAHuTY7wVqgsz9GLly3XLqpD X4uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7W9vQDbjB1NxCd28MDgNH6QLWOgBBnRi7TVfoKS+/QQ=; b=QQpSHdDHB2/osce56jPLQ93v2pwuzktMl0kp8lQ9ldpDuKs3TbeXckQItcfrCuPXNl uMdXwZjFY1bwD0XTOB0u7NbhT3La+gihnTVEOacKBTJgW2tPJwO/RGbn030AUKl7uCvV xcY42GCnj4X+42vrZhF0k84IPefZIn1AYNJ0ZwpX5aOyDm97elHP7bfsnhSXVzT62++v R+BOcLhcyyaHVtnPyAbb/Mldp35wlU4zcPCT1QhfceApSWaYH/vGb5NKQnTJaFOvVed+ Ie/wiOoO8Fr9WSvRLb85ZYu8+hKCYlqbvmueFa2NP+uaouAXZdIuXVHVPmJDiqr5AoW3 Pvlg== X-Gm-Message-State: AJIora/wySLHOVxBiWlhb7z0yy0DCO+Yr8qUTajiCB00MUPwMYg4UbWy wXEprpU7bobE4kK+MaA9gaw= X-Google-Smtp-Source: AGRyM1tKyVrw1eVwsSJKJ/uSufzc1Pg6TWp9JuO7F94WQdjI5XBigagbYl+di6LttejUijoJPl81Nw== X-Received: by 2002:a9d:ba6:0:b0:61c:309d:d487 with SMTP id 35-20020a9d0ba6000000b0061c309dd487mr16128751oth.183.1658369716205; Wed, 20 Jul 2022 19:15:16 -0700 (PDT) Received: from localhost.localdomain (216.106.68.145.reverse.socket.net. [216.106.68.145]) by smtp.gmail.com with ESMTPSA id w22-20020a056870e2d600b0010cb6fa9166sm297581oad.0.2022.07.20.19.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 19:15:15 -0700 (PDT) From: Denis Kenzior To: jtavares@kvh.com, iwd@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH] tools: Add simple utility to generate the PSK Date: Wed, 20 Jul 2022 21:13:14 -0500 Message-Id: <20220721021314.14066-1-denkenz@gmail.com> X-Mailer: git-send-email 2.35.1 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This utility is the equivalent to wpa_passphrase and produces a PSK as would be generated by iwd. --- .gitignore | 1 + Makefile.am | 5 +++- tools/iwd-psk.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tools/iwd-psk.c diff --git a/.gitignore b/.gitignore index 0886643b8b99..3bd270c070fe 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ tools/hwsim tools/hwsim.1 tools/probe-req tools/iwd-decrypt-profile +tools/iwd-psk unit/test-cmac-aes unit/test-arc4 unit/test-hmac-md5 diff --git a/Makefile.am b/Makefile.am index cffb0738fc55..148ffba0bb67 100644 --- a/Makefile.am +++ b/Makefile.am @@ -363,7 +363,7 @@ man_MANS += wired/ead.8 endif endif -noinst_PROGRAMS += tools/probe-req tools/iwd-decrypt-profile +noinst_PROGRAMS += tools/probe-req tools/iwd-decrypt-profile tools/iwd-psk tools_probe_req_SOURCES = tools/probe-req.c src/mpdu.h src/mpdu.c \ src/ie.h src/ie.c \ @@ -379,6 +379,9 @@ tools_iwd_decrypt_profile_SOURCES = tools/iwd-decrypt-profile.c \ src/storage.h src/storage.c tools_iwd_decrypt_profile_LDADD = ${ell_ldadd} +tools_iwd_psk_SOURCES = tools/iwd-psk.c src/crypto.h src/crypto.c +tools_iwd_psk_LDADD = ${ell_ldadd} + if HWSIM bin_PROGRAMS += tools/hwsim diff --git a/tools/iwd-psk.c b/tools/iwd-psk.c new file mode 100644 index 000000000000..0a0625c3be8a --- /dev/null +++ b/tools/iwd-psk.c @@ -0,0 +1,70 @@ +/* + * + * Wireless daemon for Linux + * + * Copyright (C) 2022 Intel Corporation. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include + +#include "ell/useful.h" +#include "src/crypto.h" + +static void usage(const char *exec_name) +{ + printf("%s - Generate a psk from passphrase\n" + "Usage:\n", exec_name); + printf("\%s \n", exec_name); + printf("\n"); +} + +int main(int argc, char *argv[]) +{ + int ret = EXIT_FAILURE; + unsigned char *ssid; + size_t ssid_len; + const char *passphrase; + uint8_t psk[32]; + char *hexpsk; + int err; + + if (argc != 3) { + usage(argv[0]); + goto done; + } + + ssid = (unsigned char *) argv[1]; + ssid_len = strlen(argv[1]); + passphrase = argv[2]; + + err = crypto_psk_from_passphrase(passphrase, ssid, ssid_len, psk); + if (err < 0) { + printf("Unable to generate passphrase: %s\n", strerror(-err)); + goto done; + } + + hexpsk = l_util_hexstring(psk, sizeof(psk)); + printf("PreSharedKey=%s\n", hexpsk); + l_free(hexpsk); + + ret = EXIT_SUCCESS; + +done: + return ret; +}