diff --git a/src/core/net/srp_server.cpp b/src/core/net/srp_server.cpp index 89ce08e90..3518a2096 100644 --- a/src/core/net/srp_server.cpp +++ b/src/core/net/srp_server.cpp @@ -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..." - 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()); diff --git a/src/core/net/srp_server.hpp b/src/core/net/srp_server.hpp index aaec30c77..ebe1a4731 100644 --- a/src/core/net/srp_server.hpp +++ b/src/core/net/srp_server.hpp @@ -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, @@ -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;