[meshcop] move Joiner::IsPskdValid() to MeshCoP::IsPskdValid() (#5065)

This commit is contained in:
kangping
2020-06-09 10:45:27 -07:00
committed by GitHub
parent b51d9100e6
commit 8a1339a859
5 changed files with 50 additions and 42 deletions
+1 -1
View File
@@ -280,7 +280,7 @@ otError Commissioner::AddJoiner(const Mac::ExtAddress *aEui64, const char *aPskd
VerifyOrExit(mState == OT_COMMISSIONER_STATE_ACTIVE, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(MeshCoP::Joiner::IsPskdValid(aPskd), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(IsPskdValid(aPskd), error = OT_ERROR_INVALID_ARGS);
IgnoreError(RemoveJoiner(aEui64, 0, kJoinerOpFlagNotNotifyLeader)); // remove immediately
-24
View File
@@ -87,30 +87,6 @@ exit:
return;
}
bool Joiner::IsPskdValid(const char *aPskd)
{
bool valid = false;
size_t pskdLength = StringLength(aPskd, kPskdMaxLength + 1);
OT_STATIC_ASSERT(static_cast<uint8_t>(kPskdMaxLength) <= static_cast<uint8_t>(Dtls::kPskMaxLength),
"The maximum length of DTLS PSK is smaller than joiner PSKd");
VerifyOrExit(pskdLength >= kPskdMinLength && pskdLength <= kPskdMaxLength, OT_NOOP);
for (size_t i = 0; i < pskdLength; i++)
{
char c = aPskd[i];
VerifyOrExit(isdigit(c) || isupper(c), OT_NOOP);
VerifyOrExit(c != 'I' && c != 'O' && c != 'Q' && c != 'Z', OT_NOOP);
}
valid = true;
exit:
return valid;
}
otError Joiner::Start(const char * aPskd,
const char * aProvisioningUrl,
const char * aVendorName,
-17
View File
@@ -109,29 +109,12 @@ public:
*/
void GetJoinerId(Mac::ExtAddress &aJoinerId) const;
/**
* This method validates the PSKd.
*
* Per Thread specification, a Joining Device Credential is encoded as
* uppercase alphanumeric characters (base32-thread: 0-9, A-Z excluding
* I, O, Q, and Z for readability) with a minimum length of 6 such
* characters and a maximum length of 32 such characters.
*
* param[in] aPskd The PSKd to validate.
*
* @retval A boolean indicates whether the given @p aPskd is valid.
*
*/
static bool IsPskdValid(const char *aPskd);
private:
enum
{
kJoinerUdpPort = OPENTHREAD_CONFIG_JOINER_UDP_PORT,
kConfigExtAddressDelay = 100, ///< [milliseconds]
kReponseTimeout = 4000, ///< Maximum wait time to receive response [milliseconds].
kPskdMinLength = 6, ///< Minimum PSKd length.
kPskdMaxLength = 32, ///< Maximum PSKd Length.
};
struct JoinerRouter
+32
View File
@@ -44,6 +44,12 @@
namespace ot {
namespace MeshCoP {
enum
{
kPskdMinLength = 6, ///< Minimum PSKd length.
kPskdMaxLength = 32, ///< Maximum PSKd Length.
};
void SteeringData::Init(uint8_t aLength)
{
OT_ASSERT(aLength <= kMaxLength);
@@ -181,5 +187,31 @@ exit:
}
#endif // OPENTHREAD_FTD
#if OPENTHREAD_CONFIG_JOINER_ENABLE || OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
bool IsPskdValid(const char *aPskd)
{
bool valid = false;
size_t pskdLength = StringLength(aPskd, kPskdMaxLength + 1);
OT_STATIC_ASSERT(static_cast<uint8_t>(kPskdMaxLength) <= static_cast<uint8_t>(Dtls::kPskMaxLength),
"The maximum length of DTLS PSK is smaller than joiner PSKd");
VerifyOrExit(pskdLength >= kPskdMinLength && pskdLength <= kPskdMaxLength, OT_NOOP);
for (size_t i = 0; i < pskdLength; i++)
{
char c = aPskd[i];
VerifyOrExit(isdigit(c) || isupper(c), OT_NOOP);
VerifyOrExit(c != 'I' && c != 'O' && c != 'Q' && c != 'Z', OT_NOOP);
}
valid = true;
exit:
return valid;
}
#endif // OPENTHREAD_CONFIG_JOINER_ENABLE || OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
} // namespace MeshCoP
} // namespace ot
+17
View File
@@ -255,6 +255,23 @@ void ComputeJoinerId(const Mac::ExtAddress &aEui64, Mac::ExtAddress &aJoinerId);
*/
otError GetBorderAgentRloc(ThreadNetif &aNetIf, uint16_t &aRloc);
#if OPENTHREAD_CONFIG_JOINER_ENABLE || OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
/**
* This method validates the PSKd.
*
* Per Thread specification, a Joining Device Credential is encoded as
* uppercase alphanumeric characters (base32-thread: 0-9, A-Z excluding
* I, O, Q, and Z for readability) with a minimum length of 6 such
* characters and a maximum length of 32 such characters.
*
* param[in] aPskd The PSKd to validate.
*
* @retval A boolean indicates whether the given @p aPskd is valid.
*
*/
bool IsPskdValid(const char *aPskd);
#endif // OPENTHREAD_CONFIG_JOINER_ENABLE || OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
} // namespace MeshCoP
} // namespace ot