Files

60 lines
1.4 KiB
C++
Raw Permalink Normal View History

2025-08-06 12:10:18 -04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
2025-08-06 12:10:18 -04:00
* (c) ZeroTier, Inc.
* https://www.zerotier.com/
*/
#include "CertificateOfOwnership.hpp"
2025-07-03 11:26:23 -04:00
#include "Identity.hpp"
#include "Network.hpp"
2017-08-23 16:42:17 -07:00
#include "Node.hpp"
2025-07-03 11:26:23 -04:00
#include "RuntimeEnvironment.hpp"
#include "Switch.hpp"
#include "Topology.hpp"
namespace ZeroTier {
2025-07-03 11:26:23 -04:00
int CertificateOfOwnership::verify(const RuntimeEnvironment* RR, void* tPtr) const
{
2025-07-03 11:26:23 -04:00
if ((! _signedBy) || (_signedBy != Network::controllerFor(_networkId))) {
return -1;
2023-05-01 14:48:16 -04:00
}
2025-07-03 11:26:23 -04:00
const Identity id(RR->topology->getIdentity(tPtr, _signedBy));
if (! id) {
RR->sw->requestWhois(tPtr, RR->node->now(), _signedBy);
return 1;
}
try {
Buffer<(sizeof(CertificateOfOwnership) + 64)> tmp;
2025-07-03 11:26:23 -04:00
this->serialize(tmp, true);
return (id.verify(tmp.data(), tmp.size(), _signature) ? 0 : -1);
}
catch (...) {
return -1;
}
}
2025-07-03 11:26:23 -04:00
bool CertificateOfOwnership::_owns(const CertificateOfOwnership::Thing& t, const void* v, unsigned int l) const
{
2025-07-03 11:26:23 -04:00
for (unsigned int i = 0, j = _thingCount; i < j; ++i) {
if (_thingTypes[i] == (uint8_t)t) {
unsigned int k = 0;
while (k < l) {
2025-07-03 11:26:23 -04:00
if (reinterpret_cast<const uint8_t*>(v)[k] != _thingValues[i][k]) {
break;
2023-05-01 14:48:16 -04:00
}
++k;
}
2023-05-01 14:48:16 -04:00
if (k == l) {
return true;
2023-05-01 14:48:16 -04:00
}
}
}
return false;
}
2025-07-03 11:26:23 -04:00
} // namespace ZeroTier