Skip to content

Commit b02cc07

Browse files
authored
Merge pull request #248 from microsoft/authdatacli
Accept PSK and SAE authentication data in CLI
2 parents 2b8d4b7 + 3e4cc90 commit b02cc07

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/common/tools/cli/NetRemoteCli.cxx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,35 @@ NetRemoteCli::AddSubcommandWifiAccessPointsEnumerate(CLI::App* parent)
116116
return cliAppWifiAccessPointsEnumerate;
117117
}
118118

119+
namespace detail
120+
{
121+
Ieee80211RsnaPassword
122+
ParseSaePasswordCliArgument(const std::string& saePasswordArg)
123+
{
124+
Ieee80211RsnaPassword saePassword{};
125+
// TODO: parse optional password id and peer mac address fields.
126+
saePassword.Credential = saePasswordArg;
127+
128+
return saePassword;
129+
}
130+
} // namespace detail
131+
119132
void
120133
NetRemoteCli::WifiAccessPointEnableCallback()
121134
{
122135
Ieee80211AccessPointConfiguration ieee80211AccessPointConfiguration{};
123136

137+
if (!std::empty(m_cliData->WifiAccessPointPskPassphrase)) {
138+
auto& psk = ieee80211AccessPointConfiguration.AuthenticationData.Psk.emplace();
139+
psk.Psk = m_cliData->WifiAccessPointPskPassphrase;
140+
}
141+
142+
if (!std::empty(m_cliData->WifiAccessPointSaePasswords)) {
143+
auto& sae = ieee80211AccessPointConfiguration.AuthenticationData.Sae.emplace();
144+
sae.Passwords.resize(std::size(m_cliData->WifiAccessPointSaePasswords));
145+
std::ranges::transform(m_cliData->WifiAccessPointSaePasswords, std::begin(sae.Passwords), detail::ParseSaePasswordCliArgument);
146+
}
147+
124148
if (!std::empty(m_cliData->WifiAccessPointSsid)) {
125149
ieee80211AccessPointConfiguration.Ssid = m_cliData->WifiAccessPointSsid;
126150
}
@@ -250,6 +274,8 @@ NetRemoteCli::AddSubcommandWifiAccessPointEnable(CLI::App* parent)
250274
->transform(CLI::CheckedTransformer(detail::Ieee80211AuthenticationAlgorithmNames(), CLI::ignore_case));
251275
cliAppWifiAccessPointEnable->add_option("--akm,--akms,--akmSuite,--akmSuites,--keyManagement,--keyManagements", m_cliData->WifiAccessPointAkmSuites, "The AKM suites of the access point to enable")
252276
->transform(CLI::CheckedTransformer(detail::Ieee80211AkmSuiteNames(), CLI::ignore_case));
277+
cliAppWifiAccessPointEnable->add_option("--passphrase,--pskPassphrase", m_cliData->WifiAccessPointPskPassphrase, "The PSK passphrase of the access point to enable");
278+
cliAppWifiAccessPointEnable->add_option("--sae,--password,--passwords,--saePassword,--saePasswords", m_cliData->WifiAccessPointSaePasswords, "The SAE passwords of the access point to enable");
253279
cliAppWifiAccessPointEnable->callback([this] {
254280
WifiAccessPointEnableCallback();
255281
});

src/common/tools/cli/NetRemoteCliHandlerOperations.cxx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,22 @@ NetRemoteCliHandlerOperations::WifiAccessPointEnable(std::string_view accessPoin
345345
std::make_move_iterator(std::end(dot11FrequencyBands))
346346
};
347347
}
348+
349+
// Populate PSK authentication data if present.
350+
if (ieee80211AccessPointConfiguration->AuthenticationData.Psk.has_value()) {
351+
const auto& authenticationDataPsk = ieee80211AccessPointConfiguration->AuthenticationData.Psk.value();
352+
auto dot11AuthenticationDataPsk = ToDot11AuthenticationDataPsk(authenticationDataPsk);
353+
354+
*dot11AccessPointConfiguration.mutable_authenticationdata()->mutable_psk() = std::move(dot11AuthenticationDataPsk);
355+
}
356+
357+
// Populate SAE authentication data if present.
358+
if (ieee80211AccessPointConfiguration->AuthenticationData.Sae.has_value()) {
359+
const auto& authenticationDataSae = ieee80211AccessPointConfiguration->AuthenticationData.Sae.value();
360+
auto dot11AuthenticationDataSae = ToDot11AuthenticationDataSae(authenticationDataSae);
361+
362+
*dot11AccessPointConfiguration.mutable_authenticationdata()->mutable_sae() = std::move(dot11AuthenticationDataSae);
363+
}
348364
}
349365

350366
auto status = m_connection->Client->WifiAccessPointEnable(&clientContext, request, &result);

src/common/tools/cli/include/microsoft/net/remote/NetRemoteCliData.hxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <microsoft/net/remote/protocol/NetRemoteProtocol.hxx>
1010
#include <microsoft/net/wifi/Ieee80211.hxx>
11+
#include <microsoft/net/wifi/Ieee80211Authentication.hxx>
1112

1213
namespace Microsoft::Net::Remote
1314
{
@@ -24,10 +25,12 @@ struct NetRemoteCliData
2425

2526
std::string WifiAccessPointId{};
2627
std::string WifiAccessPointSsid{};
27-
Microsoft::Net::Wifi::Ieee80211PhyType WifiAccessPointPhyType{ Microsoft::Net::Wifi::Ieee80211PhyType::Unknown };
28+
std::string WifiAccessPointPskPassphrase;
29+
std::vector<std::string> WifiAccessPointSaePasswords{};
2830
std::vector<Microsoft::Net::Wifi::Ieee80211FrequencyBand> WifiAccessPointFrequencyBands{};
2931
std::vector<Microsoft::Net::Wifi::Ieee80211AuthenticationAlgorithm> WifiAccessPointAuthenticationAlgorithms{};
3032
std::vector<Microsoft::Net::Wifi::Ieee80211AkmSuite> WifiAccessPointAkmSuites{};
33+
Microsoft::Net::Wifi::Ieee80211PhyType WifiAccessPointPhyType{ Microsoft::Net::Wifi::Ieee80211PhyType::Unknown };
3134
};
3235
} // namespace Microsoft::Net::Remote
3336

0 commit comments

Comments
 (0)