[srp-server] use case-insensitive DNS name match (#7189)

This commit updates `Srp::Server` use case-insensitive DNS name
match for domain name, host, service, or service instance names.
This commit is contained in:
Abtin Keshavarzian
2021-11-23 16:31:18 -08:00
committed by Jonathan Hui
parent e16261aa6c
commit 9d81f99b94
2 changed files with 30 additions and 11 deletions
+26 -4
View File
@@ -713,7 +713,7 @@ Error Server::ProcessZoneSection(const Message &aMessage, MessageMetadata &aMeta
SuccessOrExit(error = Dns::Name::ReadName(aMessage, offset, name, sizeof(name)));
// TODO: return `Dns::kResponseNotAuth` for not authorized zone names.
VerifyOrExit(strcmp(name, GetDomain()) == 0, error = kErrorSecurity);
VerifyOrExit(StringMatch(name, GetDomain(), kStringCaseInsensitiveMatch), error = kErrorSecurity);
SuccessOrExit(error = aMessage.Read(offset, aMetadata.mDnsZone));
offset += sizeof(Dns::Zone);
@@ -865,7 +865,7 @@ Error Server::ProcessServiceDiscoveryInstructions(Host & aHost,
// Check if the `serviceName` is a subtype with the name
// format: "<sub-label>._sub.<service-labels>.<domain>."
subServiceName = StringFind(serviceName, kServiceSubTypeLabel);
subServiceName = StringFind(serviceName, kServiceSubTypeLabel, kStringCaseInsensitiveMatch);
isSubType = (subServiceName != nullptr);
if (isSubType)
@@ -877,7 +877,9 @@ Error Server::ProcessServiceDiscoveryInstructions(Host & aHost,
// Verify that instance name and service name are related.
VerifyOrExit(StringEndsWith(instanceName, isSubType ? subServiceName : serviceName), error = kErrorFailed);
VerifyOrExit(
StringEndsWith(instanceName, isSubType ? subServiceName : serviceName, kStringCaseInsensitiveMatch),
error = kErrorFailed);
// Ensure the same service does not exist already.
VerifyOrExit(aHost.FindService(serviceName, instanceName) == nullptr, error = kErrorFailed);
@@ -1467,7 +1469,7 @@ Error Server::Service::GetServiceSubTypeLabel(char *aLabel, uint8_t aMaxSize) co
VerifyOrExit(IsSubType(), error = kErrorInvalidArgs);
subServiceName = StringFind(serviceName, kServiceSubTypeLabel);
subServiceName = StringFind(serviceName, kServiceSubTypeLabel, kStringCaseInsensitiveMatch);
OT_ASSERT(subServiceName != nullptr);
if (subServiceName - serviceName < aMaxSize)
@@ -1499,6 +1501,16 @@ TimeMilli Server::Service::GetKeyExpireTime(void) const
return mUpdateTime + Time::SecToMsec(mDescription->mKeyLease);
}
bool Server::Service::MatchesInstanceName(const char *aInstanceName) const
{
return StringMatch(mDescription->mInstanceName.AsCString(), aInstanceName, kStringCaseInsensitiveMatch);
}
bool Server::Service::MatchesServiceName(const char *aServiceName) const
{
return StringMatch(mServiceName.AsCString(), aServiceName, kStringCaseInsensitiveMatch);
}
bool Server::Service::MatchesFlags(Flags aFlags) const
{
bool matches = false;
@@ -1585,6 +1597,11 @@ Error Server::Service::Description::Init(const char *aInstanceName, Host &aHost)
return mInstanceName.Set(aInstanceName);
}
bool Server::Service::Description::Matches(const char *aInstanceName) const
{
return StringMatch(mInstanceName.AsCString(), aInstanceName, kStringCaseInsensitiveMatch);
}
void Server::Service::Description::ClearResources(void)
{
mPort = 0;
@@ -1665,6 +1682,11 @@ Error Server::Host::SetFullName(const char *aFullName)
return error;
}
bool Server::Host::Matches(const char *aFullName) const
{
return StringMatch(mFullName.AsCString(), aFullName, kStringCaseInsensitiveMatch);
}
void Server::Host::SetKey(Dns::Ecdsa256KeyRecord &aKey)
{
OT_ASSERT(aKey.IsValid());
+4 -7
View File
@@ -325,10 +325,7 @@ public:
* @retval FALSE If the service does not match the service instance name.
*
*/
bool MatchesInstanceName(const char *aInstanceName) const
{
return (mDescription->mInstanceName == aInstanceName);
}
bool MatchesInstanceName(const char *aInstanceName) const;
/**
* This method tells whether this service matches a given service name.
@@ -339,7 +336,7 @@ public:
* @retval FALSE If the service does not match the full service name.
*
*/
bool MatchesServiceName(const char *aServiceName) const { return (mServiceName == aServiceName); }
bool MatchesServiceName(const char *aServiceName) const;
private:
struct Description : public LinkedListEntry<Description>,
@@ -348,7 +345,7 @@ public:
{
Error Init(const char *aInstanceName, Host &aHost);
const char *GetInstanceName(void) const { return mInstanceName.AsCString(); }
bool Matches(const char *aInstanceName) const { return (mInstanceName == aInstanceName); }
bool Matches(const char *aInstanceName) const;
void ClearResources(void);
void TakeResourcesFrom(Description &aDescription);
Error SetTxtDataFromMessage(const Message &aMessage, uint16_t aOffset, uint16_t aLength);
@@ -510,7 +507,7 @@ public:
* @returns A boolean that indicates whether the host matches the given name.
*
*/
bool Matches(const char *aFullName) const { return (mFullName == aFullName); }
bool Matches(const char *aFullName) const;
private:
static constexpr uint16_t kMaxAddresses = OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM;